AtsushiSakai/PythonRobotics · error · Exception
Agent {agent_index} tried to reserve a position already rese
Error message
Agent {agent_index} tried to reserve a position already reserved by another agent: {position} at time {t}, reserved by {current_reserver} What it means
Raised by reserve_position when the target cell in reservation_matrix already holds a different agent's index during any timestep in the requested interval. This is a collision/conflict detection mechanism for multi-agent space-time reservation.
Source
Thrown at PathPlanning/TimeBasedPathPlanning/GridWithDynamicObstacles.py:319
for i, node in enumerate(node_path.path):
reservation_finish_time = node.time + 1
if i < len(node_path.path) - 1:
reservation_finish_time = node_path.path[i + 1].time
self.reserve_position(node.position, agent_index, Interval(node.time, reservation_finish_time))
"""
Reserve a position for the provided agent during the provided time interval.
Raises an exception if the agent's index is 0, or if the position is already reserved by a different agent during the interval.
"""
def reserve_position(self, position: Position, agent_index: int, interval: Interval):
if agent_index == 0:
raise Exception("Agent index cannot be 0")
for t in range(interval.start_time, interval.end_time + 1):
current_reserver = self.reservation_matrix[position.x, position.y, t]
if current_reserver not in [0, agent_index]:
raise Exception(
f"Agent {agent_index} tried to reserve a position already reserved by another agent: {position} at time {t}, reserved by {current_reserver}"
)
self.reservation_matrix[position.x, position.y, t] = agent_index
"""
Clears the initial reservation for an agent by clearing reservations at its start position with its index for
from time 0 to the time limit.
"""
def clear_initial_reservation(self, position: Position, agent_index: int):
for t in range(self.time_limit):
if self.reservation_matrix[position.x, position.y, t] == agent_index:
self.reservation_matrix[position.x, position.y, t] = 0
show_animation = True
def main():
grid = Grid(
np.array([11, 11]),View on GitHub (pinned to 1fe4fb980f)
Solutions
- Re-plan the conflicting agent with the reservation matrix as a constraint (treat reserved cells as blocked)
- Adjust the path or departure time so it avoids the conflicting (position, time) pair named in the message
- Clear stale reservations for an agent before replanning its path (clear_initial_reservation / reset matrix)
Example fix
# before path = planner.plan(start, goal) grid.reserve_path(path, agent_index) # may collide # after # use a planner that respects reservations (SpaceTimeAStar/SafeInterval with the grid), then reserve path = planner.plan(start, goal) grid.reserve_path(path, agent_index) # planner already avoided reserved cells
Defensive patterns
Strategy: try-catch
Validate before calling
def is_free(grid, position, interval, agent_index) -> bool:
return all(
grid.reservation_matrix[position.x, position.y, t] in (0, agent_index)
for t in range(interval.start_time, interval.end_time + 1)
) Try / catch
try:
grid.reserve_path(path, agent_index)
except Exception as e:
if 'already reserved by another agent' in str(e):
# replan with reservations as constraints, then retry
path = planner.plan(grid, start, goal)
grid.reserve_path(path, agent_index)
else:
raise Prevention
- Always plan with a reservation-aware planner (SpaceTimeAStar/SafeInterval on the same grid) before reserving
- Reserve paths sequentially and replan on conflict rather than precomputing all paths independently
When it happens
Trigger: Calling reserve_position/reserve_path for a path that passes through (or waits on) a cell-time already reserved by another agent; typically when planning paths sequentially without accounting for previously reserved intervals.
Common situations: Planning multi-agent paths where a later agent's plan crosses an earlier agent's reserved trajectory; wait-in-place actions that collide with another agent's reservation; replanning without clearing stale reservations.
Related errors
- Agent index cannot be 0
- Number of obstacles is greater than grid size!
- Path position not found for time {i}.
- No path found
- No path found
AI-assisted analysis of AtsushiSakai/PythonRobotics@1fe4fb980f (2026-08-28).
Data as JSON: /api/errors/eb88ff8a258a73ce.
Report an issue: GitHub.