@@ -66,8 +66,6 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
6666
6767 # TODO: contents of this loop should probably be in a helper?
6868 for constrained_agent in constraint_tree_node .constraint .constrained_agents :
69- paths : dict [AgentId , NodePath ] = {}
70-
7169 if verbose :
7270 print (f"\n Outer loop step for agent { constrained_agent } " )
7371
@@ -90,37 +88,31 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
9088 grid .clear_constraint_points ()
9189 grid .apply_constraint_points (all_constraints )
9290
93- failed_to_plan = False
94- for agent_idx , start_and_goal in enumerate (start_and_goals ):
95- # print("planning for:", agent_idx)
96- try :
97- path = single_agent_planner_class .plan (grid , start_and_goal .start , start_and_goal .goal , agent_idx , verbose )
98- except Exception as e :
99- print (f"Failed to plan with constraints: { all_constraints } " )
100- failed_to_plan = True
101-
102- if path is None :
103- raise RuntimeError (f"Failed to find path for { start_and_goal } " )
104- paths [AgentId (start_and_goal .index )] = path
105-
106- if failed_to_plan :
107- print (f"Failed to plan with constraints: { all_constraints } " )
91+ # Just plan for agent with new constraint
92+ start_and_goal = start_and_goals [constrained_agent .agent ]
93+ try :
94+ new_path = single_agent_planner_class .plan (grid , start_and_goal .start , start_and_goal .goal , start_and_goal .index , verbose )
95+ except Exception as e :
10896 continue
10997
98+ applied_constraint_parent = deepcopy (constraint_tree_node ) #TODO: not sure if deepcopy is actually needed
99+ paths : dict [AgentId , NodePath ] = deepcopy (applied_constraint_parent .paths ) # TODO: not sure if deepcopy is actually needed
100+ paths [constrained_agent .agent ] = new_path
101+
110102 # for (agent_idx, path) in paths.items():
111103 # print(f"\nAgent {agent_idx} path:\n {path}")
112104
113- applied_constraint_parent = deepcopy (constraint_tree_node ) #TODO: not sure if deepcopy is actually needed
114105 applied_constraint_parent .constraint = applied_constraint
115106 parent_idx = constraint_tree .add_expanded_node (applied_constraint_parent )
116107
117- new_constraint_tree_node = ConstraintTreeNode (paths , parent_idx )
108+ new_constraint_tree_node = ConstraintTreeNode (deepcopy ( paths ) , parent_idx , all_constraints )
118109 if new_constraint_tree_node .constraint is None :
119110 # This means we found a solution!
120111 print ("Found a path with constraints:" )
121112 for constraint in all_constraints :
122113 print (f"\t { constraint } " )
123- return (start_and_goals , [paths [AgentId (i )] for i in range (len (start_and_goals ))])
114+ # return (start_and_goals, [paths[AgentId(i)] for i in range(len(start_and_goals))])
115+ return (start_and_goals , paths .values ())
124116
125117 # if verbose:
126118 print (f"Adding new constraint tree node with constraint: { new_constraint_tree_node .constraint } " )
@@ -140,13 +132,13 @@ def main():
140132
141133 # TODO: bug somewhere where it expects agent ids to match indices
142134 # start_and_goals = [StartAndGoal(i, Position(1, i), Position(19, 19-i)) for i in range(1, 12)]
143- # start_and_goals = [StartAndGoal(i, Position(1, 8+i), Position(19, 19-i)) for i in range(6)]
135+ start_and_goals = [StartAndGoal (i , Position (1 , 8 + i ), Position (19 , 19 - i )) for i in range (6 )]
144136 # start_and_goals = [StartAndGoal(i, Position(1, 2*i), Position(19, 19-i)) for i in range(4)]
145137
146138 # hallway cross
147- start_and_goals = [StartAndGoal (0 , Position (6 , 10 ), Position (13 , 10 )),
148- StartAndGoal (1 , Position (12 , 10 ), Position (7 , 10 )),
149- StartAndGoal (2 , Position (11 , 10 ), Position (6 , 10 ))]
139+ # start_and_goals = [StartAndGoal(0, Position(6, 10), Position(13, 10)),
140+ # StartAndGoal(1, Position(13 , 10), Position(7, 10)),
141+ # StartAndGoal(2, Position(11, 10), Position(6, 10))]
150142
151143 # temporary obstacle
152144 # start_and_goals = [StartAndGoal(0, Position(15, 14), Position(15, 16))]
@@ -160,8 +152,8 @@ def main():
160152 num_obstacles = 250 ,
161153 obstacle_avoid_points = obstacle_avoid_points ,
162154 # obstacle_arrangement=ObstacleArrangement.TEMPORARY_OBSTACLE,
163- obstacle_arrangement = ObstacleArrangement .HALLWAY ,
164- # obstacle_arrangement=ObstacleArrangement.NARROW_CORRIDOR,
155+ # obstacle_arrangement=ObstacleArrangement.HALLWAY,
156+ obstacle_arrangement = ObstacleArrangement .NARROW_CORRIDOR ,
165157 # obstacle_arrangement=ObstacleArrangement.ARRANGEMENT1,
166158 # obstacle_arrangement=ObstacleArrangement.RANDOM,
167159 )
0 commit comments