Skip to content

Commit 2d3cdde

Browse files
committed
agent id todo
1 parent 3ffd2ff commit 2d3cdde

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

PathPlanning/TimeBasedPathPlanning/BaseClasses.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Grid,
55
Position,
66
)
7+
from PathPlanning.TimeBasedPathPlanning.ConstraintTree import AgentId
78
from PathPlanning.TimeBasedPathPlanning.Node import NodePath
89
import random
910
import numpy.random as numpy_random
@@ -26,8 +27,7 @@ def plan(grid: Grid, start: Position, goal: Position, agent_idx: int, verbose: b
2627
@dataclass
2728
class StartAndGoal:
2829
# Index of this agent
29-
# TODO: better name and use AgentId type
30-
index: int
30+
agent_id: AgentId
3131
# Start position of the robot
3232
start: Position
3333
# Goal position of the robot

PathPlanning/TimeBasedPathPlanning/ConflictBasedSearch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
3737

3838
# Generate initial solution (no constraints)
3939
for start_and_goal in start_and_goals:
40-
path = single_agent_planner_class.plan(grid, start_and_goal.start, start_and_goal.goal, start_and_goal.index, verbose)
41-
initial_solution[AgentId(start_and_goal.index)] = path
40+
path = single_agent_planner_class.plan(grid, start_and_goal.start, start_and_goal.goal, start_and_goal.agent_id, verbose)
41+
initial_solution[AgentId(start_and_goal.agent_id)] = path
4242

4343
if verbose:
4444
print("Initial solution:")
@@ -62,7 +62,7 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
6262
# This means we found a solution!
6363
print(f"Found a path with constraints after {constraint_tree.expanded_node_count()} expansions:")
6464
print(f"Final cost: {constraint_tree_node.cost}")
65-
return (start_and_goals, [constraint_tree_node.paths[start_and_goal.index] for start_and_goal in start_and_goals])
65+
return (start_and_goals, [constraint_tree_node.paths[start_and_goal.agent_id] for start_and_goal in start_and_goals])
6666

6767
if not isinstance(constraint_tree_node.constraint, ForkingConstraint):
6868
raise ValueError(f"Expected a ForkingConstraint, but got: {constraint_tree_node.constraint}")
@@ -108,7 +108,7 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
108108

109109
def get_agents_start_and_goal(start_and_goal_list: list[StartAndGoal], target_index: AgentId) -> StartAndGoal:
110110
for item in start_and_goal_list:
111-
if item.index == target_index:
111+
if item.agent_id == target_index:
112112
return item
113113
raise RuntimeError(f"Could not find agent with index {target_index} in {start_and_goal_list}")
114114

@@ -142,11 +142,11 @@ def plan_for_agent(constrained_agent: ConstraintTreeNode,
142142
grid.apply_constraint_points(all_constraints)
143143

144144
# Just plan for agent with new constraint
145-
start_and_goal = ConflictBasedSearch.get_agents_start_and_goal(start_and_goals, constrained_agent.agent)
145+
start_and_goal: StartAndGoal = ConflictBasedSearch.get_agents_start_and_goal(start_and_goals, constrained_agent.agent)
146146
try:
147147
if verbose:
148148
print("\tplanning for: {}", start_and_goal)
149-
new_path = single_agent_planner_class.plan(grid, start_and_goal.start, start_and_goal.goal, start_and_goal.index, verbose)
149+
new_path = single_agent_planner_class.plan(grid, start_and_goal.start, start_and_goal.goal, start_and_goal.agent_id, verbose)
150150
return new_path
151151
except Exception as e:
152152
print(f"Error: {e}")

PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
is also infrastructure to generate dynamic obstacles that move around the grid. The obstacles' paths
44
are stored in the reservation matrix on creation.
55
"""
6-
import numpy as np
7-
import matplotlib.pyplot as plt
86
from enum import Enum
7+
import matplotlib.pyplot as plt
8+
import numpy as np
99
from dataclasses import dataclass
1010
from PathPlanning.TimeBasedPathPlanning.Node import NodePath, Position
1111
from PathPlanning.TimeBasedPathPlanning.ConstraintTree import AppliedConstraint

PathPlanning/TimeBasedPathPlanning/Plotting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def PlotNodePaths(grid: Grid, start_and_goals: list[StartAndGoal], paths: list[N
7171
start_and_goal_plots = []
7272
for i, path in enumerate(paths):
7373
marker_idx = i % len(markers)
74-
agent_id = start_and_goals[i].index
74+
agent_id = start_and_goals[i].agent_id
7575
start = start_and_goals[i].start
7676
goal = start_and_goals[i].goal
7777

@@ -88,7 +88,7 @@ def PlotNodePaths(grid: Grid, start_and_goals: list[StartAndGoal], paths: list[N
8888
# Create plots for each agent's path
8989
path_plots = []
9090
for i, path in enumerate(paths):
91-
agent_id = start_and_goals[i].index
91+
agent_id = start_and_goals[i].agent_id
9292
path_plot, = ax.plot([], [], "o", c=colors[i], ms=10,
9393
label=f"Agent {agent_id} Path")
9494
path_plots.append(path_plot)

PathPlanning/TimeBasedPathPlanning/PriorityBasedPlanner.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
3333

3434
# Reserve initial positions
3535
for start_and_goal in start_and_goals:
36-
grid.reserve_position(start_and_goal.start, start_and_goal.index, Interval(0, 10))
36+
grid.reserve_position(start_and_goal.start, start_and_goal.agent_id, Interval(0, 10))
3737

3838
# Plan in descending order of distance from start to goal
3939
start_and_goals = sorted(start_and_goals,
@@ -45,14 +45,14 @@ def plan(grid: Grid, start_and_goals: list[StartAndGoal], single_agent_planner_c
4545
if verbose:
4646
print(f"\nPlanning for agent: {start_and_goal}" )
4747

48-
grid.clear_initial_reservation(start_and_goal.start, start_and_goal.index)
48+
grid.clear_initial_reservation(start_and_goal.start, start_and_goal.agent_id)
4949
path = single_agent_planner_class.plan(grid, start_and_goal.start, start_and_goal.goal, verbose)
5050

5151
if path is None:
5252
print(f"Failed to find path for {start_and_goal}")
5353
return []
5454

55-
agent_index = start_and_goal.index
55+
agent_index = start_and_goal.agent_id
5656
grid.reserve_path(path, agent_index)
5757
paths.append(path)
5858

0 commit comments

Comments
 (0)