Skip to content

Commit 7a7e507

Browse files
committed
add random positions start_and_goals
1 parent d4b11a8 commit 7a7e507

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

PathPlanning/TimeBasedPathPlanning/ConflictBasedSearch.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
6868

6969
# TODO: contents of this loop should probably be in a helper?
7070
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...")
7471
if verbose:
7572
print(f"\nOuter loop step for agent {constrained_agent}")
7673

@@ -80,6 +77,11 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
8077
all_constraints = deepcopy(ancestor_constraints) # TODO - no deepcopy pls
8178
all_constraints.append(applied_constraint)
8279

80+
num_expansions = constraint_tree.expanded_node_count()
81+
if num_expansions % 50 == 0:
82+
print(f"Expanded {num_expansions} nodes so far...")
83+
print(f"\tlen of constraints {len(all_constraints)}")
84+
8385
# Skip if we have already tried this set of constraints
8486
constraint_hash = hash(frozenset(all_constraints))
8587
if constraint_hash in attempted_constraint_combos:
@@ -143,14 +145,26 @@ def find_by_index(start_and_goal_list: list[StartAndGoal], target_index: AgentId
143145
# * SIPP stinks at 3 robots in the hallway case
144146
verbose = False
145147
show_animation = True
148+
np.random.seed(42) # For reproducibility
146149
def main():
147150
grid_side_length = 21
148151

149152
# TODO: bug somewhere where it expects agent ids to match indices
150153
# start_and_goals = [StartAndGoal(i, Position(1, i), Position(19, 19-i)) for i in range(1, 12)]
151-
start_and_goals = [StartAndGoal(i, Position(1, 8+i), Position(19, 19-i)) for i in range(6)]
154+
# start_and_goals = [StartAndGoal(i, Position(1, 8+i), Position(19, 19-i)) for i in range(6)]
152155
# start_and_goals = [StartAndGoal(i, Position(1, 2*i), Position(19, 19-i)) for i in range(4)]
153156

157+
# generate random start and goals
158+
start_and_goals: list[StartAndGoal] = []
159+
for i in range(40):
160+
start = Position(np.random.randint(0, grid_side_length), np.random.randint(0, grid_side_length))
161+
goal = Position(np.random.randint(0, grid_side_length), np.random.randint(0, grid_side_length))
162+
while any([start_and_goal.start == start for start_and_goal in start_and_goals]):
163+
start = Position(np.random.randint(0, grid_side_length), np.random.randint(0, grid_side_length))
164+
goal = Position(np.random.randint(0, grid_side_length), np.random.randint(0, grid_side_length))
165+
166+
start_and_goals.append(StartAndGoal(i, start, goal))
167+
154168
# hallway cross
155169
# start_and_goals = [StartAndGoal(0, Position(6, 10), Position(13, 10)),
156170
# StartAndGoal(1, Position(11, 10), Position(6, 10)),
@@ -169,14 +183,15 @@ def main():
169183
obstacle_avoid_points=obstacle_avoid_points,
170184
# obstacle_arrangement=ObstacleArrangement.TEMPORARY_OBSTACLE,
171185
# obstacle_arrangement=ObstacleArrangement.HALLWAY,
172-
obstacle_arrangement=ObstacleArrangement.NARROW_CORRIDOR,
186+
# obstacle_arrangement=ObstacleArrangement.NARROW_CORRIDOR,
187+
obstacle_arrangement=ObstacleArrangement.NONE,
173188
# obstacle_arrangement=ObstacleArrangement.ARRANGEMENT1,
174189
# obstacle_arrangement=ObstacleArrangement.RANDOM,
175190
)
176191

177192
start_time = time.time()
178-
# start_and_goals, paths = ConflictBasedSearch.plan(grid, start_and_goals, SafeIntervalPathPlanner, verbose)
179-
start_and_goals, paths = ConflictBasedSearch.plan(grid, start_and_goals, SpaceTimeAStar, verbose)
193+
start_and_goals, paths = ConflictBasedSearch.plan(grid, start_and_goals, SafeIntervalPathPlanner, verbose)
194+
# start_and_goals, paths = ConflictBasedSearch.plan(grid, start_and_goals, SpaceTimeAStar, verbose)
180195

181196
runtime = time.time() - start_time
182197
print(f"\nPlanning took: {runtime:.5f} seconds")

PathPlanning/TimeBasedPathPlanning/ConstraintTree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def get_ancestor_constraints(self, parent_index: int) -> list[AppliedConstraint]
142142
if node.constraint and isinstance(node.constraint, AppliedConstraint):
143143
constraints.append(node.constraint)
144144
else:
145-
print(f"Aha!!! {node.constraint}")
145+
raise RuntimeError(f"Expected AppliedConstraint, but got: {node.constraint}")
146146
parent_index = node.parent_idx
147147
return constraints
148148

PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ class Interval:
1616
end_time: int
1717

1818
class ObstacleArrangement(Enum):
19+
# No obstacles
20+
NONE = 0
1921
# Random obstacle positions and movements
20-
RANDOM = 0
22+
RANDOM = 1
2123
# Obstacles start in a line in y at center of grid and move side-to-side in x
22-
ARRANGEMENT1 = 1
24+
ARRANGEMENT1 = 2
2325
# Static obstacle arrangement
24-
NARROW_CORRIDOR = 2
26+
NARROW_CORRIDOR = 3
2527
# A hallway surrounded by obstacles with a 2-cell opening in the middle
26-
HALLWAY = 3
28+
HALLWAY = 4
2729
# A temporary obstacle that vanishes after some time
28-
TEMPORARY_OBSTACLE = 4
30+
TEMPORARY_OBSTACLE = 5
2931

3032
"""
3133
Generates a 2d numpy array with lists for elements.
@@ -91,6 +93,8 @@ def __init__(
9193
self.obstacle_paths = self.generate_hallway_obstacles()
9294
elif obstacle_arrangement == ObstacleArrangement.TEMPORARY_OBSTACLE:
9395
self.obstacle_paths = self.generate_temporary_obstacle()
96+
elif obstacle_arrangement == ObstacleArrangement.NONE:
97+
self.obstacle_paths = []
9498

9599
for i, path in enumerate(self.obstacle_paths):
96100
# TODO: i think this is a bug. obstacle indices will overlap with robot indices

0 commit comments

Comments
 (0)