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
use crate::algorithm::search::SearchTree;
/// the result of running a [`super::SearchAlgorithm`].
#[derive(Default)]
pub struct SearchResult {
/// the tree created by the search algorithm
pub tree: SearchTree,
/// number of iterations run to create this tree
pub iterations: u64,
/// if present, a message explaining a forced termination of the search.
/// if not present, the search terminated naturally by reaching an
/// empty frontier state.
pub terminated: Option<String>,
}
impl SearchResult {
/// create a [`SearchResult`] for a search that completed, aka, which reached
/// an empty frontier state.
pub fn completed(tree: SearchTree, iterations: u64) -> SearchResult {
SearchResult {
tree,
iterations,
terminated: None,
}
}
/// create a [`SearchResult`] for a search that was forced to terminate by the
/// [`crate::model::termination::TerminationModel`]. include a message explaining the
/// reason it was terminated.
pub fn terminated(tree: SearchTree, iterations: u64, explanation: String) -> SearchResult {
SearchResult {
tree,
iterations,
terminated: Some(explanation),
}
}
}