-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (30 loc) · 2.01 KB
/
main.py
File metadata and controls
40 lines (30 loc) · 2.01 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
if __name__ == "__main__":
from pathfinder import PathFinder
import argparse
parser = argparse.ArgumentParser(description="Amazon Path Finder")
parser.add_argument("--grid-width", type=int, help="Grid width", default=5)
parser.add_argument("--grid-height", type=int, help="Grid height", default=5)
parser.add_argument("--start", nargs='+', type=int, help="Starting coordinates. eg. --start (0,0)", default=(0,0))
parser.add_argument("--end", nargs='+', type=int, help="Delivery coordinates. eg. --end (1,2)", default=(0,0))
parser.add_argument("--obstacle", nargs='+', type=int, action='append', help="Coordinate of an obstacle. eg. --obstacle (1,1)", default=[])
parser.add_argument("--random-obstacles", type=int, help="Number of obstacles", default=0)
parser.add_argument("--obstacles-unremovable", action='store_true', help="Include flag to restrict path without suggestions to remove obstacles", default=False)
parser.add_argument("--visualize", action='store_true', help="Include flag to visualize the pathfinder", default=False)
args = parser.parse_args()
amazon_pathfinder = PathFinder(visualize=args.visualize)
amazon_pathfinder.create_grid(args.grid_width, args.grid_height)
amazon_pathfinder.set_starting_point(tuple(args.start))
amazon_pathfinder.set_delivery_point(tuple(args.end))
try:
amazon_pathfinder.add_obstacles([tuple(obstacle) for obstacle in args.obstacle])
amazon_pathfinder.add_random_obstacles(args.random_obstacles)
print(f"\nCreated grid of size {args.grid_height}x{args.grid_width}")
print(f"Starting point: {tuple(args.start)}")
print(f"Delivery point: {tuple(args.end)}")
print(f"Obstacles are placed at: {amazon_pathfinder.obstacles}")
amazon_pathfinder.shortest_path(allow_obstacle_elimination=not(args.obstacles_unremovable))
except AssertionError:
pass
if args.visualize:
while True:
amazon_pathfinder.pathfinder_visualizer.check_exit_clicked()