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
use std::hash;
pub trait ProblemSpace {
type State: Copy + Eq + hash::Hash;
type Iter: Iterator<Item = (Self::State, f64)>;
fn heuristic(&self, _: &Self::State, _: &Self::State) -> f64;
fn succ(&self, _: &Self::State) -> Self::Iter;
fn pred(&self, _: &Self::State) -> Self::Iter;
}
pub trait Lifelong: ProblemSpace {
fn update(&mut self, _: &Self::State) {}
}
pub trait Anytime: ProblemSpace {
fn callback(&mut self, _: &Self::State);
}
pub trait SharedStates: ProblemSpace {
fn is_public(&self, _: &Self::State) -> bool;
fn serialize(&self, msg_type: u8, _: &Self::State, _: Vec<f64>) -> String;
fn deserialize(&self, _: String) -> (u8, Self::State, Vec<f64>);
}
#[cfg(test)]
mod tests {
use std::vec;
use crate::planner::Lifelong;
use crate::planner::ProblemSpace;
use crate::planner::SharedStates;
struct Environment {}
impl ProblemSpace for Environment {
type State = usize;
type Iter = vec::IntoIter<(Self::State, f64)>;
fn heuristic(&self, _: &Self::State, _: &Self::State) -> f64 {
0.0
}
fn succ(&self, _: &Self::State) -> Self::Iter {
vec![].into_iter()
}
fn pred(&self, s: &Self::State) -> Self::Iter {
self.succ(s)
}
}
impl Lifelong for Environment {
}
impl SharedStates for Environment {
fn is_public(&self, _: &Self::State) -> bool {
false
}
fn serialize(&self, _: u8, _: &Self::State, _: Vec<f64>) -> String {
String::from("0")
}
fn deserialize(&self, _: String) -> (u8, Self::State, Vec<f64>) {
(0, 1, vec![])
}
}
#[test]
fn test_update_for_success() {
let mut env = Environment {};
env.update(&1);
}
#[test]
fn test_traits_for_success() {
let mut env = Environment {};
env.update(&1);
env.heuristic(&0, &1);
env.succ(&0);
env.pred(&0);
env.is_public(&0);
env.serialize(0, &0, vec![]);
env.deserialize(String::from("0"));
}
}