-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (54 loc) · 1.85 KB
/
Copy pathmain.py
File metadata and controls
72 lines (54 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
from pydantic import ValidationError
from parser import Parser
from module import Graph, Drone
from simulation import Engine, UnsolvableGraphError
class Application:
def __init__(self, argv: list[str]) -> None:
"""Store the command-line arguments.
Args:
argv: Command-line arguments passed to the application.
"""
self.argv = argv
def run(self) -> None:
"""Execute the application workflow.
This loads the map, builds the graph, computes drone paths, and
runs the simulation.
"""
if len(self.argv) != 2:
print("Usage: python main.py <file>")
sys.exit(1)
try:
parser = Parser(self.argv[1])
self.data = parser.load_map_data()
self.graph = Graph()
for zone in self.data.zone_list:
self.graph.add_nodes(zone)
for connection in self.data.connection_list:
self.graph.add_edges(connection)
engine = Engine(self.data, self.graph)
start = self.data.zone_list[0]
self.drones = [
Drone(f"D{i + 1}", start,
engine.dijkstra(
start)[1:]
) for i in range(self.data.nb_drones)
]
engine.simulation(self.drones)
except ValidationError as e:
for error in e.errors():
print(error["msg"])
sys.exit(1)
except ValueError as e:
print(e)
sys.exit(1)
except UnsolvableGraphError as e:
print(e)
sys.exit(1)
def test(self) -> None:
"""Print the planned path for each drone."""
for d in self.drones:
print(d.path)
if __name__ == "__main__":
app = Application(sys.argv)
app.run()