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
//! Capability traits that describe a stochastic shortest path problem: [`Mdp`], [`Goal`] and
//! [`Heuristic`].
//!
//! As in `heuristic-search`, there is no single "problem" trait. The MDP describes actions,
//! costs and outcome distributions; the goal test and the heuristic are separate values, so
//! one MDP can be solved for many goals with many heuristics. [`Goal`] is implemented for
//! plain closures, [`Heuristic`] for closures wrapped in [`heuristic_fn`].
//!
//! [`Goal`], [`Heuristic`], [`heuristic_fn`], [`HeuristicFn`] and the blind heuristic
//! [`Zero`] are `search-core`'s, so a heuristic written for one planning crate works with the
//! others. [`Mdp`] stays here: the MDP shape is specific to this crate.
//!
//! The heuristic contract is in the crate documentation, section "The heuristic contract".
pub use ;
/// A finite Markov decision process with action costs.
///
/// Together with a [`Goal`] it defines a stochastic shortest path (SSP) problem: reach a goal
/// state with minimal expected total cost. Both methods report through a callback, so
/// implementations need no allocation.
///
/// Algorithms query a state's actions and outcomes once and cache them, so the methods may be
/// moderately expensive. They are never called for goal states.
///
/// # Example
///
/// A coin flip that reaches the goal (state `1`) with probability `0.5` per attempt:
///
/// ```
/// use stochastic_search::Mdp;
///
/// struct Retry;
///
/// impl Mdp for Retry {
/// type State = u8;
/// type Action = ();
///
/// fn actions(&self, _state: &u8, mut emit: impl FnMut((), f64)) {
/// emit((), 1.0);
/// }
///
/// fn outcomes(&self, state: &u8, _action: &(), mut emit: impl FnMut(u8, f64)) {
/// emit(1, 0.5);
/// emit(*state, 0.5);
/// }
/// }
/// ```