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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//! Real-time heuristic search: an agent that plans a bounded amount, moves, and learns a
//! heuristic table that persists across trials.
//!
//! Every search here runs one *trial*: the agent starts at `start` and acts until it stands
//! on a goal, proves that no goal is reachable, or the [`Budget`] stops it. Before each move
//! it spends at most a fixed amount of work (a lookahead of `n` expansions) and updates the
//! values of the states it looked at in a [`LearnedHeuristic`], which the caller keeps. Run
//! the next trial with the same table and the agent does better; with an admissible initial
//! heuristic on a finite graph with positive edge costs from which the goal stays
//! reachable, repeated trials converge to cheapest paths and the table to exact costs along
//! them. That is proven for LRTA* and, from consistent tables, for the lookahead searches;
//! from admissible but inconsistent tables it is tested on random graphs, not proven.
//!
//! | Search | Lookahead | Update of the expanded states |
//! | ----------------- | ----------------------- | ---------------------------------------------- |
//! | [`lrta_star`] | the successors | `h(s) = min c(s, s') + h(s')` |
//! | [`rta_star`] | the successors | second-best `c(s, s') + h(s')`, not admissible |
//! | [`lss_lrta_star`] | A*, `n` expansions | Dijkstra from the open list (Koenig and Sun) |
//! | [`lhb_lrta_star`] | A*, `n` expansions | shortest paths to the frontier leaves (LHB) |
//! | [`lhb_gbfs`] | GBFS, `n` expansions | LHB |
//! | [`lhb_bwa_star`] | BWAS, `n` expansions | LHB |
//! | [`rtaa_star`] | A*, `n` expansions | `h(s) = f(best open) - g(s)` |
//!
//! [`lhb_update`] is the limited-horizon Bellman update of Hadar et al. on its own: a bounded
//! A* from one state and the update, without moving, as the paper uses it to label sampled
//! states offline.
//!
//! [`RealTimeDStar`] (Real-time D*) is a planner rather than a trial function: an agent on a
//! [`DynamicGraph`](crate::DynamicGraph) whose costs change, stepped by the caller one move
//! at a time. It runs D* Lite from the goal and falls back to LSS-LRTA*'s lookahead and
//! update until D* Lite's search reaches it, and reports its run as a [`TrialResult`].
//!
//! The lookahead searches move along the search path to the open state their search would
//! expand next (for A* the smallest `f`), or to the goal, if the search selected one, then
//! plan again from there. [`lhb_gbfs`] and [`lhb_bwa_star`] run the LHB update after the
//! other search phases the paper names: greedy best-first search, and batch weighted A*
//! (BWAS) of Agostinelli et al., which expands a batch of open states at once. Their moves follow
//! their own order, so a trial that learns nothing is not always a cheapest path: GBFS
//! ignores path costs, and batches expand states out of order. With a batch of one, BWAS
//! with weight `w` stayed within `w` times the cheapest cost on the test graphs.
//!
//! ```mermaid
//! flowchart TD
//! goal{at a goal?} -->|yes| found[Found: the travelled path]
//! goal -->|no| plan[bounded lookahead from the current state]
//! plan -->|budget| limit[LimitReached]
//! plan --> learn[update the table]
//! learn -->|no goal reachable| unsolvable[Unsolvable]
//! learn --> act[move along the planned path]
//! act --> goal
//! ```
//!
//! [`Outcome::Found`] holds the path the agent travelled, loops included; its cost is what
//! the trial cost. [`Outcome::Unsolvable`] means the agent proved that no goal is reachable
//! from where it stands, which on a graph with irreversible edges need not hold for `start`.
pub use ;
pub use ;
pub use ;
pub use LearnedHeuristic;
use Vec;
use Cost;
use Budget;
use crate;
/// Counters of one real-time trial, beyond the search [`Stats`].
///
/// Non-exhaustive: later algorithms may add counters.
/// The result of one real-time trial.
/// The path the agent has travelled so far in a trial.
/// Why a trial ended.