-
Notifications
You must be signed in to change notification settings - Fork 6
/
independent.py
50 lines (36 loc) · 1.67 KB
/
independent.py
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
import time as timer
from single_agent_planner import compute_heuristics, a_star, get_sum_of_cost
class IndependentSolver(object):
"""A planner that plans for each robot independently."""
def __init__(self, my_map, starts, goals):
"""my_map - list of lists specifying obstacle positions
starts - [(x1, y1), (x2, y2), ...] list of start locations
goals - [(x1, y1), (x2, y2), ...] list of goal locations
"""
self.my_map = my_map
self.starts = starts
self.goals = goals
self.num_of_agents = len(goals)
self.CPU_time = 0
# compute heuristics for the low-level search
self.heuristics = []
for goal in self.goals:
self.heuristics.append(compute_heuristics(my_map, goal))
def find_solution(self):
""" Finds paths for all agents from their start locations to their goal locations."""
start_time = timer.time()
result = []
##############################
# Task 0: Understand the following code (see the lab description for some hints)
for i in range(self.num_of_agents): # Find path for each agent
path = a_star(self.my_map, self.starts[i], self.goals[i], self.heuristics[i],
i, [])
if path is None:
raise BaseException('No solutions')
result.append(path)
##############################
self.CPU_time = timer.time() - start_time
# print("\n Found a solution! \n")
# print("CPU time (s): {:.2f}".format(self.CPU_time))
# print("Sum of costs: {}".format(get_sum_of_cost(result)))
return result