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).
  • 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.
  • 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() and pibt(), which only seek a feasible plan, takes an Objective: sum of costs or makespan.

Every solver returns a MapfResult: 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.
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 or TaskInstance::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).

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().

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.
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.
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.
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().