# mapf-search
[](https://crates.io/crates/mapf-search)
[](https://docs.rs/mapf-search)
[](https://github.com/sunsided/mapf-search/actions/workflows/ci.yml)
[](https://codecov.io/gh/sunsided/mapf-search)
[](https://crates.io/crates/mapf-search)
[](https://github.com/sunsided/mapf-search#license)
[](https://github.com/rust-secure-code/safety-dance/)
Multi-agent pathfinding: CBS, ECBS, ICTS, PBS, M\* and multi-objective MO-CBS on grids and
general graphs.
Given a graph and a set of agents with start and goal vertices, the solvers find one path per
agent so that no two agents ever share a vertex or swap along an edge. CBS, ICTS and M\*
minimize the sum of costs or the makespan, ECBS stays within a given factor of the optimum,
and PBS trades optimality for speed. The optimal solvers are checked against a joint-space oracle by
property tests, and M\* also proves when an instance has no solution. The crate is
`no_std` with `alloc`, uses the A\* of
[heuristic-search](https://github.com/sunsided/heuristic-search) as its single-agent low
level, and reads the Moving AI `.map` and `.scen` benchmark formats.
## Who this is for
- Robotics and warehouse automation: fleets of mobile robots or AGVs on a grid or a roadmap
graph that must reach their goals without collisions.
- Game developers moving groups of units through tight corridors, where independent A\*
per unit deadlocks or collides.
- Researchers who want CBS and its improvements (prioritized conflicts, bypass, CG/DG/WDG
heuristics, disjoint splitting) switchable one by one, next to ECBS, ICTS, PBS and M\*
on the same instance type.
- Planners that trade off several costs per agent (time, energy, risk): MO-CBS returns every
Pareto-optimal joint plan, using
[multiobjective-search](https://github.com/sunsided/multiobjective-search) as its low
level.
- For a single agent, use [heuristic-search](https://github.com/sunsided/heuristic-search)
directly; for many connectors on a diagram that may cross at a cost rather than never
meet, [connector-routing](https://github.com/sunsided/connector-routing) is the better
fit.
## Installation
```sh
cargo add mapf-search
```
Or in `Cargo.toml`:
```toml
[dependencies]
mapf-search = "0.1"
```
## Algorithms
- CBS, optimal for sum of costs or makespan, with prioritized (cardinal) conflicts,
bypass, the CG, DG and WDG heuristics, a conflict avoidance table and disjoint
splitting (with positive constraints), each switchable (`cbs`, `cbs_with`,
`CbsConfig`)
- ECBS, bounded-suboptimal, focal search at both levels (`ecbs`)
- PBS, priority-based search: fast, neither optimal nor complete (`pbs`)
- ICTS with pairwise pruning, optimal (`icts`)
- M*, basic and recursive (rM*), each with or without operator decomposition (OD-M*,
ODrM*), optimal, proves unsolvability (`mstar`, `mstar_with`, `MStarConfig`)
- MO-CBS, multi-objective CBS: every Pareto-optimal plan when moves and waits cost
vectors, shared or per agent; plain or tree-by-tree (MO-CBS-t), over BOA* or NAMOA*dr
from `multiobjective-search`, with an opt-in feasibility check (proves unsolvability),
conflict prioritization, bypass and disjoint splitting (`mo_cbs`, `mo_cbs_with`,
`mo_cbs_per_agent`, `MoCbsConfig`; optional feature `multi-objective`)
- Every single-objective solver takes an `Objective`: sum of costs or makespan
- Shared parts: conflict detection, constraints, space-time A* low level, MDDs, Moving AI
`.map`/`.scen` parsers
Not yet implemented: CBS-TA (conflict-based search with task assignment), MAPF-LNS2
(large neighborhood search repair) and EPEA\* (enhanced partial expansion).
## Usage
```rust
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);
# Ok::<(), mapf_search::InstanceError>(())
```
The crate is `no_std` and needs only `alloc`. The feature `multi-objective` adds MO-CBS
over `multiobjective-search`.
## MSRV
Rust 1.86 (`rust-version` in `Cargo.toml`), for every feature. The MSRV is a signal, not a
contract: it may rise in a minor release.
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](https://github.com/sunsided/mapf-search/blob/main/LICENSE-APACHE))
- MIT license ([LICENSE-MIT](https://github.com/sunsided/mapf-search/blob/main/LICENSE-MIT))
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for
inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed
as above, without any additional terms or conditions. See
[CONTRIBUTING.md](https://github.com/sunsided/mapf-search/blob/main/CONTRIBUTING.md).