1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! What every solver returns: a [`Solution`], how the run ended ([`Outcome`]) and its
//! counters ([`MapfResult`]).
use alloc::vec::Vec;
use heuristic_search::Stats;
use crate::path::{Objective, Path, makespan, sum_of_costs};
/// A conflict-free plan: one path per agent.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Solution {
/// The path of each agent, indexed by [`AgentId`](crate::AgentId). Each starts at the
/// agent's start and ends at its goal, where the agent stays.
pub paths: Vec<Path>,
/// The sum of costs of [`Solution::paths`] (see [`sum_of_costs`]).
pub sum_of_costs: u32,
/// The makespan of [`Solution::paths`] (see [`makespan`](crate::makespan())).
pub makespan: u32,
}
impl Solution {
/// A solution of `paths`, with both objectives computed.
pub(crate) fn new(paths: Vec<Path>) -> Self {
Self {
sum_of_costs: sum_of_costs(&paths),
makespan: makespan(&paths),
paths,
}
}
/// The value of `objective` for this solution.
#[must_use]
pub fn cost(&self, objective: Objective) -> u32 {
match objective {
Objective::SumOfCosts => self.sum_of_costs,
Objective::Makespan => self.makespan,
}
}
}
/// How a solver run ended.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Outcome {
/// A conflict-free solution. Its quality is what the solver guarantees: optimal for
/// CBS, CBS-TA, ICTS, M* and EPEA*, within the suboptimality factor for ECBS, none for PBS,
/// PIBT and LNS2.
Solved(Solution),
/// Proven unsolvable: an agent cannot reach its goal even alone, or a complete solver
/// ran out of options.
Unsolvable,
/// The [`Budget`](crate::Budget) stopped the search. The instance may be unsolvable:
/// for some unsolvable instances, such as two agents swapping the ends of a corridor,
/// the search space is infinite and complete solvers only ever stop this way.
LimitReached,
/// An incomplete solver ([`pbs`](crate::pbs())) ran out of options before its budget.
/// This proves nothing: the instance may still be solvable.
Exhausted,
}
/// The result of a solver run.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MapfResult {
/// How the run ended.
pub outcome: Outcome,
/// High-level counters; each solver documents what it counts.
pub stats: Stats,
}
impl MapfResult {
/// The solution, if one was found.
#[must_use]
pub fn solution(&self) -> Option<&Solution> {
match &self.outcome {
Outcome::Solved(solution) => Some(solution),
Outcome::Unsolvable | Outcome::LimitReached | Outcome::Exhausted => None,
}
}
}