Algorithmcore
Prioritized multi-robot planning
Also called Erdmann-Lozano-Perez prioritized planning.
Plan robots one at a time in a fixed priority order, each one treating the paths of the robots before it as moving obstacles in space-time.
- Solves
- Multi-agent pathfinding
- Time
- O(r g H log(g H)) total
- Space
- O(g H + r H) extra
- Counts
- messages O(r) total
- Where
- H = the time horizon in steps; g = the number of free grid cells; r = the number of robots
- Model
- Word RAM
- Properties
- not completedeterministicofflinenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Michael Erdmann, Tomas Lozano Perez, 1987
Prioritized planning finds collision-free paths for several robots by planning them one at a time in a fixed order. Each robot searches in space-time and treats the planned paths of all robots before it as moving obstacles, so it never has to search the joint space of the team. It is the simplest decoupled method on the coupled and decoupled planning page: it is fast and usually good, but unlike conflict-based search or a search of the joint space for multi-agent pathfinding, it is incomplete and can fail on instances that have a solution.
In plain words
The robots take turns, by rank. The first robot plans the shortest route to its goal as if it were alone. The second robot plans its route while it keeps out of the way of the first, and it may wait or step aside to let the first robot pass. The third one keeps out of the way of both, and so on. Each robot writes down where it will be at each moment, and the later robots read this list.
This is quick, because each robot plans only for itself. The weak point is that a robot with a high rank never makes room for the robots after it. If the first robot parks in the only doorway, the others can never get through, even if a better plan for the whole team exists.
The problem
The model. The workspace is a 4-connected grid with free cells. Time is discrete and synchronous: in each step every robot moves to a neighbor cell or waits. There are robots, each with a start cell and a goal cell. Two robots must never be in the same cell at the same time (a vertex conflict) and must never swap cells in one step (a swap conflict). A robot that reaches its goal stays there. The plans are computed by one planner, or by the robots in turn: robot receives the plans of robots to and broadcasts its own, so the team sends plan messages in sequential rounds over any graph that can broadcast.
Input. The grid, the starts and goals, a priority order of the robots, and a time horizon .
Output. One path per robot with no vertex or swap conflicts, or the answer "no plan found".
How it differs from close pages. Multi-agent pathfinding is the problem on a general graph, and conflict-based search solves it optimally and completely by splitting on conflicts. A coupled search over the joint space is complete but grows exponentially with ; the coupled and decoupled planning page compares the two families. Pebble motion on graphs asks only whether the robots can reach their goals, one move at a time, and is decidable in polynomial time. Prioritized planning is the greedy end of this range.
The algorithm
PRIORITIZED-PLANNING(grid, starts, goals, order, H)- 1
R ← an empty reservation table of (cell, time) and (move, time) - 2
for each robot k in order do - 3
π_k ← space-time A* from (s_k, 0) to g_k that avoids every entry of R, up to time H - 4
if π_k = none then return none - 5
add every (cell, time) and every move of π_k to R, and hold g_k from the arrival time on - 6
return π_1, ..., π_r
Line L3 runs A* on states , a cell and a time, with the Manhattan distance to the goal as the heuristic. A state is blocked if an earlier robot is in cell at time , also when it has parked there; a move from to is forbidden if an earlier robot moves from to in the same step. The search may end at the goal only at a time after which no earlier robot passes the goal, since the robot will park there. The waiting move keeps the robot in place, so a robot can let others pass. Line L5 writes the plan into the table, and parks the robot at its goal for ever.
In the code the default horizon is , a design choice, not a bound from the paper.
Example
The pocket grid has 2 rows and 4 columns, with a single free cell in row 0 above column 1:
row 0: # . # #
row 1: . . . .
Robot 0 starts at and must reach . Robot 1 starts at and must reach . They must pass each other in the corridor.
Order 0, then 1. Robot 0 takes its shortest path along row 1 and reaches at time 3. Robot 1 now needs to step into the pocket , but it cannot get there before robot 0 passes, and it cannot swap with robot 0. The search returns no plan.
Order 1, then 0. Robot 1 takes . Robot 0 plans around it: . It steps into the pocket at time 2, while robot 1 passes below, and arrives at time 5. A search of the joint space also finds makespan 5, so this order is optimal here.
No order works. On the grid with rows .... and ..##, robot 0 starts at with goal , and robot 1 starts at with goal . Prioritized planning fails for both orders, but a joint plan with makespan 4 exists: robot 0 moves to , steps down to to let robot 1 pass, and steps back. In each order, the first robot takes its shortest path and blocks the other.
Correctness
The proof shows three theorems. Soundness: if line L6 returns plans, no two of them have a vertex or swap conflict, also after the robots park. Greedy optimality per robot: robot gets the earliest arrival time among all plans that avoid robots to , because A* with a consistent heuristic finds the earliest final goal state. Incompleteness: the 2-robot instance above has a plan with makespan 4, and prioritized planning fails for both orders and every horizon.
Proof: Prioritized planning returns only conflict-free plans, each robot gets the earliest arrival that the robots before it allow, and the method is incompletefull
The workspace is a grid of free cells. Time is discrete. In each step a robot moves to one of the 4 neighbor cells or waits. A plan for robot is a path with and , and the robot stays at for all . Write for . Two plans have a vertex conflict if for some , and a swap conflict if and for some . A robot may move into a cell that another robot leaves in the same step. Lines L1 to L6 refer to the pseudocode on the prioritized multi-robot planning page.
The reservation table after robots (in priority order) holds the pairs for , the moves , and for each goal the time from which it is held for ever. A space-time state is blocked if some earlier robot is at at time , counting the parked robots. A move from to is forbidden if is blocked or an earlier robot moves from to at time . A goal state is final if no earlier robot is at at any time .
Lemma 1 (the search). If there is a path in space-time from to a final goal state that uses no blocked state and no forbidden move, and its arrival time is at most the horizon , then the search of line L3 returns such a path with the smallest arrival time. Otherwise it returns nothing.
Proof. The search is A* on the graph of states with unit cost per step, so the cost of a state is its time . The heuristic changes by at most 1 per step, and a step costs 1, so it is consistent, and . With a consistent heuristic, A* pops states in nondecreasing order of , and each state is reached first by a shortest path. A goal state has , so the first final goal state that is popped has the smallest time among all reachable final goal states. States are expanded only up to time , so a path is found exactly when one with arrival time at most exists. The state graph is finite, states, so the search ends.
Theorem 1 (soundness). If line L6 returns plans, no two of them have a vertex conflict or a swap conflict.
Proof. Take robots before in the order. The plan of was found when the plan of was in the table. For , the state is not blocked, so , both while moves and after parks. For , robot is at , and the goal state was final, so for . So there is no vertex conflict. A swap needs both robots to move in the same step. If , the move of at time is not forbidden, so does not move the other way at time . If , robot does not move. So there is no swap conflict.
Theorem 2 (what each robot gets). Robot gets a plan with the earliest arrival time among all plans that avoid the plans of robots and arrive by time . The robots after have no effect on it.
Proof. This is Lemma 1 for robot ; the table holds only the plans of the robots before .
So the method is greedy over robots. A robot with high priority takes its shortest path and ignores everyone after it, which can leave no room for them.
Theorem 3 (incompleteness). There is an instance with 2 robots that has a conflict-free plan, while prioritized planning returns nothing for both orders, for every horizon.
Proof. Take the grid of 2 rows and 4 columns with walls at and :
row 0: . . . .
row 1: . . # #
Robot 0 starts at with goal . Robot 1 starts at with goal . The cell is the only link between the part and the dead end .
Order 0 then 1. Robot 0 moves to at time 1 and parks there for ever. Robot 1 is at at time 0, and it must pass to reach . The state is blocked for every . So there is no plan for robot 1.
Order 1 then 0. The only shortest path of robot 1 is , so by Lemma 1 it takes it and parks at from time 3. Robot 0 starts in the dead end. It cannot be at at time 1, because robot 1 is there. It cannot move from to between times 1 and 2, because robot 1 moves from to then, which is a swap. From it cannot reach in one step. So robot 0 is in the dead end at time 2. Robot 1 is at at time 2, so robot 0 is at . Between times 2 and 3 robot 1 moves into and stays, so robot 0 must leave , and its only free neighbor is , which is a swap with robot 1. So there is no plan for robot 0.
A plan exists. At time 1 robot 0 moves to and robot 1 waits. At time 2 robot 0 moves down to and robot 1 follows into . At time 3 robot 1 moves to and robot 0 moves back to . At time 4 robot 1 reaches . There is no vertex conflict and no swap, and the makespan is 4.
The test test_every_order_has_no_plan_but_a_plan_exists checks both orders and finds the makespan 4 with a breadth-first search over the joint states of both robots. The search over joint states is complete, which is the difference described on the coupled and decoupled planning page.
Running time. With free cells and horizon , one search visits at most states with at most 5 moves each, so it costs with a binary heap, and the whole method costs for robots. The reservation table holds one entry per step of every plan, entries. The default horizon in the code is , which is a design choice and not a bound from the paper.
Complexity
- Time (theorem). One space-time search visits at most states with 5 moves each, so it costs with a binary heap. The whole method costs in the word RAM model.
- Memory. The reservation table holds one entry per step of every plan, , and one search holds states.
- Messages. If the robots plan in turn, each one broadcasts one plan of cells, messages in sequential rounds.
- Compared with coupled search. A search of the joint space has up to states per time step, which is the price of completeness.
Properties
- Sound (theorem). Returned plans never collide.
- Incomplete (theorem). It can fail when a plan exists, for every order.
- Not optimal for the team. Each robot is optimal given the robots before it, but the makespan or the sum of path lengths can be far from the best.
- Order dependent. The pocket example succeeds in one order and fails in the other.
- Scales well (measurement). In the tests, with 2 or 3 robots on random grids of up to 3 by 4 cells, it solved more than 50 of 250 instances and failed on some that the joint search solved; it never returned a conflicting plan.
Variants and improvements
- Cooperative A.* Silver (2005) reserved space-time cells in a shared table for game characters, which is this method with a window of limited length.
- Choosing the order. Heuristics give priority to the robot with the longest path, or to robots whose start or goal blocks others. Searching over orders, or restarting with a random order after a failure, solves more instances (heuristic).
- Priority-based search. Later work searches over pairwise priorities instead of a fixed order, which is still incomplete but solves more instances.
- Path coordination. Another decoupled method fixes the paths and plans only the timing along them, in a coordination space of dimension .
- Continuous spaces. The same idea works with sampling planners such as probabilistic roadmaps, where each robot plans in configuration space-time.
When to use it
Use prioritized planning when there are many robots, the space is not crowded, and a quick plan matters more than a guarantee: warehouses with wide aisles, or game characters. Use conflict-based search or a coupled planner when the space has narrow passages, when optimal plans are needed, or when a failure is not acceptable.
Pitfalls
- Parking robots. A robot that has arrived blocks its goal for ever. If its goal lies on the path of a later robot, the later robot fails, as in the siding example. Give such robots a lower priority, or let them move away.
- Horizon too short. A robot may need to wait a long time for others. If is short, the search fails although a plan exists.
- Swap conflicts. Checking only cells, and not moves, lets two robots pass through each other on an edge.
- Goal test. The search must not stop at the goal at a time when an earlier robot will pass the goal later.
- Treating failure as proof. "No plan found" does not mean that no plan exists.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/prioritized-multi-robot-planning/. The authors are listed in prov/9VT1PP.jsonl.
"""Prioritized multi-robot planning on a grid (Erdmann and Lozano-Perez 1987).
The grid is a list of strings; '#' is an obstacle and any other character is a
free cell. Cells are (row, col). Time is discrete: in each step a robot moves to
one of the 4 neighbor cells or waits. Two robots must never be in the same cell
at the same time (vertex conflict) and must never swap cells in one step (edge
conflict). A robot that reaches its goal stays there for ever.
The robots are planned one at a time in priority order. Robot i runs a
space-time A* search that treats the plans of robots planned before it as moving
obstacles. The method is not complete: it can report no plan for an instance
that has one.
"""
import heapq
from typing import Optional, Sequence
Cell = tuple
MOVES = ((0, 0), (-1, 0), (1, 0), (0, -1), (0, 1))
def free_cells(grid: Sequence[str]) -> list:
return [(r, c) for r, row in enumerate(grid) for c, ch in enumerate(row) if ch != "#"]
def neighbors(grid: Sequence[str], cell: Cell) -> list:
"""The cells a robot can be in after one step: wait, or move by one cell."""
out = []
for dr, dc in MOVES:
r, c = cell[0] + dr, cell[1] + dc
if 0 <= r < len(grid) and 0 <= c < len(grid[r]) and grid[r][c] != "#":
out.append((r, c))
return out
class Reservations:
"""The space-time cells and moves used by the robots planned so far."""
def __init__(self):
self.vertex = {} # (cell, t) -> robot
self.moves = set() # (from cell, to cell, t): a move from time t to t + 1
self.parked = {} # cell -> first time from which a robot stays there
self.last_use = {} # cell -> last time t with a vertex reservation
def add(self, path: list) -> None:
for t, cell in enumerate(path):
self.vertex[(cell, t)] = True
self.last_use[cell] = max(self.last_use.get(cell, -1), t)
if t > 0:
self.moves.add((path[t - 1], cell, t - 1))
self.parked[path[-1]] = len(path) - 1
def blocked(self, cell: Cell, t: int) -> bool:
if (cell, t) in self.vertex:
return True
p = self.parked.get(cell)
return p is not None and t >= p
def swap(self, a: Cell, b: Cell, t: int) -> bool:
"""True if an earlier robot moves from b to a while we move from a to b."""
return (b, a, t) in self.moves
def free_after(self, cell: Cell, t: int) -> bool:
"""True if no earlier robot uses the cell at time t or later."""
if cell in self.parked:
return False
return self.last_use.get(cell, -1) < t
def space_time_astar(grid, start, goal, res: Reservations, horizon: int) -> Optional[list]:
"""Shortest path in (cell, time) that avoids the reservations, or None."""
if res.blocked(start, 0):
return None
def h(cell):
return abs(cell[0] - goal[0]) + abs(cell[1] - goal[1])
heap = [(h(start), 0, start)]
parent = {(start, 0): None}
while heap:
f, t, cell = heapq.heappop(heap)
if cell == goal and res.free_after(goal, t):
path = []
node = (cell, t)
while node is not None:
path.append(node[0])
node = parent[node]
return path[::-1]
if t >= horizon:
continue
for nxt in neighbors(grid, cell):
state = (nxt, t + 1)
if state in parent or res.blocked(nxt, t + 1) or res.swap(cell, nxt, t):
continue
parent[state] = (cell, t)
heapq.heappush(heap, (t + 1 + h(nxt), t + 1, nxt))
return None
def prioritized_planning(
grid: Sequence[str],
starts: Sequence[Cell],
goals: Sequence[Cell],
order: Optional[Sequence[int]] = None,
horizon: Optional[int] = None,
) -> Optional[list]:
"""Plan the robots in the given priority order.
Returns one path per robot (path[t] is the cell at time t, and the robot
stays at path[-1] afterwards), or None if some robot finds no path.
"""
r = len(starts)
order = list(range(r)) if order is None else list(order)
if horizon is None:
horizon = len(free_cells(grid)) * (r + 1)
res = Reservations() # @line L1
paths = [None] * r
for i in order: # @line L2
path = space_time_astar(grid, starts[i], goals[i], res, horizon) # @line L3
if path is None: # @line L4
return None
res.add(path) # @line L5
paths[i] = path
return paths # @line L6
def position(path: list, t: int) -> Cell:
return path[t] if t < len(path) else path[-1]
def check_plan(grid, starts, goals, paths) -> bool:
"""True if the paths are valid: moves to free neighbor cells, no conflicts."""
r = len(paths)
for i in range(r):
if paths[i][0] != starts[i] or paths[i][-1] != goals[i]:
return False
for t in range(1, len(paths[i])):
if paths[i][t] not in neighbors(grid, paths[i][t - 1]):
return False
end = max(len(p) for p in paths)
for t in range(end):
cells = [position(p, t) for p in paths]
if len(set(cells)) < r:
return False
for i in range(r):
for k in range(i + 1, r):
if position(paths[i], t + 1) == position(paths[k], t) and position(paths[k], t + 1) == position(paths[i], t) and position(paths[i], t) != position(paths[i], t + 1):
return False
return True
test_prioritized_multi_robot_planning.py 121 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/prioritized-multi-robot-planning/. The authors are listed in prov/9VT1PP.jsonl.
import itertools
import random
from collections import deque
from prioritized_multi_robot_planning import (
check_plan,
free_cells,
neighbors,
prioritized_planning,
)
def coupled_makespan(grid, starts, goals):
"""Brute force: BFS over the joint states of all robots (complete and optimal)."""
starts, goals = tuple(starts), tuple(goals)
dist = {starts: 0}
queue = deque([starts])
while queue:
state = queue.popleft()
if state == goals:
return dist[state]
for nxt in itertools.product(*[neighbors(grid, c) for c in state]):
if len(set(nxt)) < len(nxt):
continue
swap = any(
nxt[i] == state[k] and nxt[k] == state[i] and nxt[i] != state[i]
for i in range(len(state))
for k in range(i + 1, len(state))
)
if not swap and nxt not in dist:
dist[nxt] = dist[state] + 1
queue.append(nxt)
return None
def bfs_length(grid, start, goal):
dist = {start: 0}
queue = deque([start])
while queue:
cell = queue.popleft()
for nxt in neighbors(grid, cell):
if nxt not in dist:
dist[nxt] = dist[cell] + 1
queue.append(nxt)
return dist.get(goal)
POCKET = ["#.##", "...."]
POCKET_STARTS = [(1, 0), (1, 3)]
POCKET_GOALS = [(1, 3), (1, 0)]
SIDING = ["....", "..##"]
SIDING_STARTS = [(0, 2), (0, 0)]
SIDING_GOALS = [(0, 1), (0, 3)]
def test_order_matters_in_the_pocket():
assert prioritized_planning(POCKET, POCKET_STARTS, POCKET_GOALS, [0, 1]) is None
paths = prioritized_planning(POCKET, POCKET_STARTS, POCKET_GOALS, [1, 0])
assert paths is not None
assert check_plan(POCKET, POCKET_STARTS, POCKET_GOALS, paths)
assert paths[1] == [(1, 3), (1, 2), (1, 1), (1, 0)]
assert paths[0] == [(1, 0), (1, 1), (0, 1), (1, 1), (1, 2), (1, 3)]
assert coupled_makespan(POCKET, POCKET_STARTS, POCKET_GOALS) == 5
def test_every_order_has_no_plan_but_a_plan_exists():
for order in ([0, 1], [1, 0]):
assert prioritized_planning(SIDING, SIDING_STARTS, SIDING_GOALS, order) is None
assert coupled_makespan(SIDING, SIDING_STARTS, SIDING_GOALS) == 4
def test_one_robot_is_a_shortest_path():
rng = random.Random(8)
for _ in range(100):
rows, cols = rng.randint(1, 6), rng.randint(1, 6)
grid = ["".join("#" if rng.random() < 0.25 else "." for _ in range(cols)) for _ in range(rows)]
cells = free_cells(grid)
if len(cells) < 2:
continue
s, g = rng.sample(cells, 2)
paths = prioritized_planning(grid, [s], [g])
length = bfs_length(grid, s, g)
if length is None:
assert paths is None
else:
assert len(paths[0]) - 1 == length
def test_against_coupled_search():
rng = random.Random(21)
solved = unsolved = 0
for _ in range(250):
rows, cols = rng.randint(1, 3), rng.randint(2, 4)
grid = ["".join("#" if rng.random() < 0.25 else "." for _ in range(cols)) for _ in range(rows)]
cells = free_cells(grid)
r = rng.randint(2, 3)
if len(cells) < 2 * r:
continue
pick = rng.sample(cells, 2 * r)
starts, goals = pick[:r], pick[r:]
best = coupled_makespan(grid, starts, goals)
paths = prioritized_planning(grid, starts, goals)
if paths is None:
unsolved += 1
continue
solved += 1
assert check_plan(grid, starts, goals, paths)
assert best is not None
assert max(len(p) for p in paths) - 1 >= best
assert solved > 50 and unsolved > 0
def test_conflict_checker_rejects_swaps_and_collisions():
grid = ["..."]
starts, goals = [(0, 0), (0, 1)], [(0, 1), (0, 0)]
assert not check_plan(grid, starts, goals, [[(0, 0), (0, 1)], [(0, 1), (0, 0)]])
assert not check_plan(grid, [(0, 0), (0, 2)], [(0, 1), (0, 1)], [[(0, 0), (0, 1)], [(0, 2), (0, 1)]])
History
Erdmann and Lozano-Pérez (1987) studied several objects moving in the same space. They gave the objects priorities and planned each object in configuration space-time among the objects with higher priority, which is the prioritized method. LaValle's book (2006) presents it as a decoupled method next to path coordination. Silver (2005) used reservation tables for cooperative pathfinding in games, and the method is now a standard baseline for multi-agent pathfinding.
References
- Michael Erdmann and Tomas Lozano-Perez, On multiple moving objects, Algorithmica 2, 1987, pages 477 to 521 (priorities, configuration space-time and planning among moving obstacles)
- Steven M. LaValle, Planning Algorithms, Cambridge University Press, 2006, Chapter 7, the section on multiple robots (decoupled planning and prioritized planning)
- Bruno Siciliano and Oussama Khatib (editors), Springer Handbook of Robotics, 2nd edition, Springer, 2016, the chapter on multiple mobile robot systems (path coordination and priorities)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag 9VT1PP Edit this page History Report an error Markdown