-
Notifications
You must be signed in to change notification settings - Fork 1
/
independent.py
43 lines (32 loc) · 1.5 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
import time as timer
from single_agent_planner import compute_heuristics, a_star, get_sum_of_cost
from mdd import get_all_optimal_paths
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 = []
for i in range(self.num_of_agents): # Find path for each agent
paths = get_all_optimal_paths(self.my_map, self.starts[i], self.goals[i], self.heuristics[i])
print(f"All optimal paths for agent {i}: {paths}")
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)))
# print(result)
return result