@@ -38,8 +38,10 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
3838 path = single_agent_planner_class .plan (grid , start_and_goal .start , start_and_goal .goal , start_and_goal .index , verbose )
3939 initial_solution [AgentId (start_and_goal .index )] = path
4040
41- for (agent_idx , path ) in initial_solution .items ():
42- print (f"\n Agent { agent_idx } path:\n { path } " )
41+ if verbose :
42+ print ("Initial solution:" )
43+ for (agent_idx , path ) in initial_solution .items ():
44+ print (f"\n Agent { agent_idx } path:\n { path } " )
4345
4446 constraint_tree = ConstraintTree (initial_solution )
4547
@@ -49,8 +51,8 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
4951 constraint_tree_node = constraint_tree .get_next_node_to_expand ()
5052 ancestor_constraints = constraint_tree .get_ancestor_constraints (constraint_tree_node .parent_idx )
5153
52- print (f"Expanded node: { constraint_tree_node .constraint } with parent: { constraint_tree_node .parent_idx } " )
53- print (f"\t Ancestor constraints: { ancestor_constraints } " )
54+ # print(f"Expanded node: {constraint_tree_node.constraint} with parent: {constraint_tree_node.parent_idx}")
55+ # print(f"\tAncestor constraints: {ancestor_constraints}")
5456
5557 if verbose :
5658 print (f"Expanding node with constraint { constraint_tree_node .constraint } and parent { constraint_tree_node .parent_idx } " )
@@ -66,6 +68,9 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
6668
6769 # TODO: contents of this loop should probably be in a helper?
6870 for constrained_agent in constraint_tree_node .constraint .constrained_agents :
71+ num_expansions = constraint_tree .expanded_node_count ()
72+ if num_expansions % 50 == 0 :
73+ print (f"Expanded { num_expansions } nodes so far..." )
6974 if verbose :
7075 print (f"\n Outer loop step for agent { constrained_agent } " )
7176
@@ -78,40 +83,41 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
7883 # Skip if we have already tried this set of constraints
7984 constraint_hash = hash (frozenset (all_constraints ))
8085 if constraint_hash in attempted_constraint_combos :
81- print (f"\t Skipping already attempted constraint combination: { all_constraints } " )
86+ if verbose :
87+ print (f"\t Skipping already attempted constraint combination: { all_constraints } " )
8288 continue
8389 else :
8490 attempted_constraint_combos .add (constraint_hash )
8591
8692 if verbose :
8793 print (f"\t all constraints: { all_constraints } " )
88- print (f"\t all constraints: { all_constraints } " )
8994
9095 grid .clear_constraint_points ()
9196 grid .apply_constraint_points (all_constraints )
9297
9398 # Just plan for agent with new constraint
9499 start_and_goal = ConflictBasedSearch .find_by_index (start_and_goals , constrained_agent .agent )
95100 try :
96- print ("\t planning for: {}" , start_and_goal )
101+ if verbose :
102+ print ("\t planning for: {}" , start_and_goal )
97103 new_path = single_agent_planner_class .plan (grid , start_and_goal .start , start_and_goal .goal , start_and_goal .index , verbose )
98104 except Exception as e :
99105 continue
100106
101107 applied_constraint_parent = deepcopy (constraint_tree_node ) #TODO: not sure if deepcopy is actually needed
102- paths : dict [AgentId , NodePath ] = deepcopy (applied_constraint_parent .paths ) # TODO: not sure if deepcopy is actually needed
108+ paths : dict [AgentId , NodePath ] = deepcopy (constraint_tree_node .paths ) # TODO: not sure if deepcopy is actually needed
103109 paths [constrained_agent .agent ] = new_path
104110
105- for (agent_idx , path ) in paths .items ():
106- print (f"\n Agent { agent_idx } path:\n { path } " )
111+ # for (agent_idx, path) in paths.items():
112+ # print(f"\nAgent {agent_idx} path:\n {path}")
107113
108114 applied_constraint_parent .constraint = applied_constraint
109115 parent_idx = constraint_tree .add_expanded_node (applied_constraint_parent )
110116
111- new_constraint_tree_node = ConstraintTreeNode (deepcopy ( paths ) , parent_idx , all_constraints )
117+ new_constraint_tree_node = ConstraintTreeNode (paths , parent_idx , all_constraints )
112118 if new_constraint_tree_node .constraint is None :
113119 # This means we found a solution!
114- print ("Found a path with constraints:" )
120+ print (f "Found a path with constraints after { num_expansions } expansions :" )
115121 for constraint in all_constraints :
116122 print (f"\t { constraint } " )
117123 # return (start_and_goals, [paths[AgentId(i)] for i in range(len(start_and_goals))])
@@ -131,25 +137,24 @@ def find_by_index(start_and_goal_list: list[StartAndGoal], target_index: AgentId
131137 raise RuntimeError (f"Could not find agent with index { target_index } in { start_and_goal_list } " )
132138
133139# TODO
134- # * get SIPP working w CBS
135- # * add checks for duplicate expansions
140+ # * still discrepancies between sipp and A*
136141# * fan out across multiple threads
137- # * sipp intervals seem much larger than needed?
138-
142+ # * somehow test/check that high level tree is doing what you want
143+ # * SIPP stinks at 3 robots in the hallway case
139144verbose = False
140145show_animation = True
141146def main ():
142147 grid_side_length = 21
143148
144149 # TODO: bug somewhere where it expects agent ids to match indices
145150 # start_and_goals = [StartAndGoal(i, Position(1, i), Position(19, 19-i)) for i in range(1, 12)]
146- # start_and_goals = [StartAndGoal(i, Position(1, 8+i), Position(19, 19-i)) for i in range(6)]
151+ start_and_goals = [StartAndGoal (i , Position (1 , 8 + i ), Position (19 , 19 - i )) for i in range (6 )]
147152 # start_and_goals = [StartAndGoal(i, Position(1, 2*i), Position(19, 19-i)) for i in range(4)]
148153
149154 # hallway cross
150- start_and_goals = [StartAndGoal (0 , Position (6 , 10 ), Position (13 , 10 )),
151- StartAndGoal (1 , Position (11 , 10 ), Position (6 , 10 )),
152- StartAndGoal (2 , Position (13 , 10 ), Position (7 , 10 ))]
155+ # start_and_goals = [StartAndGoal(0, Position(6, 10), Position(13, 10)),
156+ # StartAndGoal(1, Position(11, 10), Position(6, 10)),
157+ # StartAndGoal(2, Position(13, 10), Position(7, 10))]
153158
154159 # temporary obstacle
155160 # start_and_goals = [StartAndGoal(0, Position(15, 14), Position(15, 16))]
@@ -163,8 +168,8 @@ def main():
163168 num_obstacles = 250 ,
164169 obstacle_avoid_points = obstacle_avoid_points ,
165170 # obstacle_arrangement=ObstacleArrangement.TEMPORARY_OBSTACLE,
166- obstacle_arrangement = ObstacleArrangement .HALLWAY ,
167- # obstacle_arrangement=ObstacleArrangement.NARROW_CORRIDOR,
171+ # obstacle_arrangement=ObstacleArrangement.HALLWAY,
172+ obstacle_arrangement = ObstacleArrangement .NARROW_CORRIDOR ,
168173 # obstacle_arrangement=ObstacleArrangement.ARRANGEMENT1,
169174 # obstacle_arrangement=ObstacleArrangement.RANDOM,
170175 )
0 commit comments