Skip to main content

Crate mapf_search

Crate mapf_search 

Source
Expand description

§Multi-agent pathfinding

Multi-agent pathfinding (MAPF): one path per agent on a shared graph, without collisions, minimizing a joint objective.

An Instance is a Graph (such as a Grid or an AdjacencyList) and a list of Agents with distinct starts and goals. Time is discrete; each step an agent moves along an edge or waits, at cost 1. After its path ends, an agent stays at its goal and keeps blocking it. Two agents Conflict if they share a vertex at the same time or swap vertices along an edge.

  • cbs(): conflict-based search, optimal for sum_of_costs or makespan (Objective), with prioritized conflicts, bypass, the CG, DG or WDG heuristic (CbsHeuristic), a conflict avoidance table and disjoint Splitting; cbs_with and CbsConfig switch them individually.
  • cbs_ta(): CBS with task assignment over a TaskInstance, whose agents each have candidate goals; optimal over all assignments, with every CbsConfig improvement (cbs_ta_with).
  • focbs(): FOCBS for a UaInstance, where some agents have no goal and only must get out of the way; CBS over the agents with goals and a min-cost flow oracle for the others, optimal for the goal agents’ sum of costs (focbs_with, UaResult).
  • ecbs(): enhanced CBS, bounded-suboptimal within a Weight w, with focal search at both levels.
  • icts(): increasing cost tree search with pairwise pruning, optimal.
  • mstar(): recursive M* with operator decomposition (subdimensional expansion), optimal, and able to prove unsolvability; mstar_with and MStarConfig select basic M*, recursive M* without operator decomposition, and OD-M*.
  • epea(): enhanced partial expansion A* in the joint space, optimal, and able to prove unsolvability; it generates only the children at a node’s stored f.
  • lns2(): MAPF-LNS2, large neighborhood search that repairs a plan with collisions a few agents at a time; seeded (Lns2Config), neither optimal nor complete.
  • pibt(): priority inheritance with backtracking, one time step for all agents at a time; very fast, neither optimal nor complete.
  • pibt_turns(): PIBT*_T, PIBT for agents that face a heading, move only forward and need time to turn, on any OrientedGraph such as a Grid (TurnResult).
  • pbs(): priority-based search, fast but neither optimal nor complete.
  • mo_cbs, mo_cbs_with and mo_cbs_per_agent, with the multi-objective feature: multi-objective CBS (MO-CBS and MO-CBS-t, over BOA* or NAMOA*dr), every Pareto-optimal plan when moves and waits cost vectors, shared or per agent, with an opt-in feasibility check, conflict prioritization, bypass and disjoint splitting.

Every solver but lns2(), pibt() and pibt_turns(), which only seek a feasible plan, and focbs(), which minimizes the sum of costs, takes an Objective: sum of costs or makespan.

Every solver but focbs() (a UaResult) returns a MapfResult (pibt_turns() inside a TurnResult with the headings): an Outcome (with a Solution if solved) and high-level Stats. Budget, Limits and Stats are re-exported from heuristic-search; they bound and count the high-level expansions. Weight is too.

The crate is no_std and needs only alloc.

§Example

use mapf_search::{Agent, Grid, Instance, Limits, Objective, cbs, first_conflict};

// Two agents swap the ends of a corridor that has one side pocket.
let grid = Grid::parse(&["...", "@.@"]);
let agents = vec![
    Agent { start: grid.vertex(0, 0), goal: grid.vertex(2, 0) },
    Agent { start: grid.vertex(2, 0), goal: grid.vertex(0, 0) },
];
let instance = Instance::new(grid, agents)?;

let result = cbs(&instance, Objective::SumOfCosts, Limits::expansions(1_000));
let solution = result.solution().expect("the pocket lets them pass");

assert_eq!(first_conflict(&solution.paths), None);
assert_eq!(solution.sum_of_costs, 7);

Repository: https://github.com/sunsided/mapf-search

Structs§

AdjacencyList
A graph stored as one list of out-neighbours per vertex.
Agent
One agent: where it starts and where it must end up and stay.
CbsConfig
What cbs_with optimizes and which improvements it uses.
ConstraintSet
The constraints of one agent, indexed for the checks of a space-time search.
Grid
A rectangular 4-connected grid. Cells are vertices in row-major order, y * width + x; blocked cells are vertices without edges.
Instance
A validated MAPF instance.
Limits
Simple counter limits. The default is unlimited.
Lns2Config
The settings of lns2.
MStarConfig
What mstar_with optimizes and which form of M* it runs.
MapfResult
The result of a solver run.
MoCbsConfig
How mo_cbs_with orders the high-level search, which low level it uses and which improvements it applies.
ParetoResult
The result of an mo_cbs run.
ParetoSolution
One Pareto-optimal joint plan.
ParseError
A syntax error in a Moving AI file.
ScenarioEntry
One agent of a Moving AI .scen file.
Solution
A conflict-free plan: one path per agent.
Stats
Counters collected during one search run.
TaskAgent
One agent of a TaskInstance: where it starts and the goals it may be assigned.
TaskInstance
A validated task-assignment MAPF instance: each agent must end at one of its candidate goals, and no two agents at the same one.
TurnResult
The result of a pibt_turns run.
UaInstance
A validated instance of MAPF with unassigned agents (MAPF-UA): agents with a goal, and agents with only a start that may end anywhere but must not get in the way.
UaResult
The result of a focbs run.
UaSolution
A plan for a UaInstance.
Weight
A rational heuristic weight w = numerator / denominator for Weighted A*.

Enums§

CbsHeuristic
An admissible estimate of how much the sum of costs of a constraint-tree node must still rise (CbsConfig::heuristic).
Conflict
A conflict between the paths of two agents.
Constraint
Forbids or requires one agent one vertex or one move at one time.
InstanceError
Why Instance::new, TaskInstance::new or UaInstance::new rejected an instance.
LowLevel
Which multi-objective search the low level runs.
Objective
What a multi-agent search minimizes.
Outcome
How a solver run ended.
ParetoOutcome
How an mo_cbs run ended.
ParseErrorKind
What is wrong in a ParseError.
ScenarioError
Why scenario_instance could not build an instance.
Splitting
How CBS splits a conflict between agents a and b (CbsConfig::splitting).
UaOutcome
How a focbs run ended.

Traits§

Budget
Decides when a search must stop before it finishes, given its counters so far.
Graph
A finite directed graph over vertices 0..vertex_count().
OrientedGraph
A Graph on which agents face a heading and only move forward, for solvers that model turning in place as taking time (pibt_turns).

Functions§

cbs
Finds a conflict-free plan that is optimal for objective with conflict-based search, with every improvement of CbsConfig::improved.
cbs_ta
Assigns each agent one of its candidate goals and finds a conflict-free plan to them, optimal for objective over all assignments and plans, with conflict-based search with task assignment and every improvement of CbsConfig::improved.
cbs_ta_with
Assigns each agent one of its candidate goals and finds a conflict-free plan to them, optimal for config.objective over all assignments and plans, with conflict-based search with task assignment and the improvements config selects.
cbs_with
Finds a conflict-free plan that is optimal for config.objective with conflict-based search and the improvements config selects.
conflicts
All conflicts among paths, in the order of first_conflict.
ecbs
Finds a conflict-free plan whose objective value is at most weight times the optimum, with enhanced conflict-based search.
epea
Finds a conflict-free plan with the optimal objective value with enhanced partial expansion A* in the joint space.
first_conflict
The earliest conflict among paths, indexed by agent: smallest time first, then the smallest agent pair, and a vertex conflict before a swap starting at the same time.
focbs
Plans the assigned agents of instance with the least sum of costs that still lets the unassigned agents get out of the way, and routes those at the fewest moves, with FOCBS and every improvement of CbsConfig::improved.
focbs_with
Plans the assigned agents of instance with the least sum of costs that still lets the unassigned agents get out of the way, and routes those at the fewest moves, with FOCBS and the improvements config selects.
icts
Finds a conflict-free plan with the optimal objective value by increasing cost tree search.
lns2
Finds a conflict-free plan with MAPF-LNS2: an initial plan that may have collisions, then large neighborhood search that replans a few agents at a time until no two paths collide.
makespan
The largest path_cost of all paths: when the last agent arrives for good. 0 for no paths.
mo_cbs
mo_cbs_with with MoCbsConfig::improved: every Pareto-optimal plan of instance.
mo_cbs_per_agent
mo_cbs_with with one cost function per agent: costs(agent, from, to) is what the move (or, if from == to, the wait) costs agent.
mo_cbs_with
Multi-objective CBS: every cost-unique Pareto-optimal plan of instance under the vector costs costs, shared by all agents (see mo_cbs), searched as config says.
mstar
Finds a conflict-free plan with the optimal objective value with recursive M* and operator decomposition (MStarConfig::od_recursive).
mstar_with
Finds a conflict-free plan with the optimal config.objective value with the form of M* that config selects.
parse_map
Parses a Moving AI .map file into a Grid.
parse_scenario
Parses a Moving AI .scen file: a version line, then one entry per line with nine whitespace-separated fields (see ScenarioEntry). Empty lines are skipped.
path_cost
The cost of one path: the time of its final arrival at its last vertex.
pbs
Finds a conflict-free plan with priority-based search, aiming at a low objective value.
pibt
Finds a conflict-free plan with PIBT: one time step for every agent at a time, by priority, with priority inheritance and backtracking.
pibt_turns
Finds a conflict-free plan for agents that need time to turn, with PIBT*_T: one step for all agents at a time, by priority, with priority inheritance, backtracking, cycle handling, swaps and the push escape trigger.
position_at
The vertex path occupies at time, counting the stay at the last vertex.
scenario_instance
Builds an instance from the first agents entries of a scenario on grid.
space_time_astar
The cheapest path of agent on graph that satisfies constraints and ends at the goal for good (goal-stay: no later constraint forbids the goal).
sum_of_costs
The sum of the path_costs of all paths.

Type Aliases§

AgentId
Index of an agent in Instance::agents.
Heading
The direction an agent faces on an OrientedGraph, below OrientedGraph::heading_count.
Path
The positions of one agent at t = 0, 1, .... Never empty in a solution.
Time
A time step. Time starts at 0.
Vertex
A vertex id. Graphs number their vertices densely as 0..vertex_count().