1use std::hash;
2
3pub trait ProblemSpace {
10 type State: Copy + Eq + hash::Hash;
12 type Iter: Iterator<Item = (Self::State, f64)>; fn heuristic(&self, _: &Self::State, _: &Self::State) -> f64;
17 fn succ(&self, _: &Self::State) -> Self::Iter;
19 fn pred(&self, _: &Self::State) -> Self::Iter;
21}
22
23pub trait Lifelong: ProblemSpace {
27 fn update(&mut self, _: &Self::State) {}
29}
30
31pub trait Anytime: ProblemSpace {
35 fn callback(&mut self, _: &Self::State);
37}
38
39pub trait SharedStates: ProblemSpace {
43 fn is_public(&self, _: &Self::State) -> bool;
45 fn serialize(&self, msg_type: u8, _: &Self::State, _: Vec<f64>) -> String;
50 fn deserialize(&self, _: String) -> (u8, Self::State, Vec<f64>);
52}
53
54#[cfg(test)]
55mod tests {
56 use std::vec;
57
58 use crate::planner::Lifelong;
59 use crate::planner::ProblemSpace;
60 use crate::planner::SharedStates;
61
62 struct Environment {}
63
64 impl ProblemSpace for Environment {
65 type State = usize;
66 type Iter = vec::IntoIter<(Self::State, f64)>;
67 fn heuristic(&self, _: &Self::State, _: &Self::State) -> f64 {
68 0.0
69 }
70 fn succ(&self, _: &Self::State) -> Self::Iter {
71 vec![].into_iter()
72 }
73 fn pred(&self, s: &Self::State) -> Self::Iter {
74 self.succ(s)
75 }
76 }
77
78 impl Lifelong for Environment {
79 }
81
82 impl SharedStates for Environment {
83 fn is_public(&self, _: &Self::State) -> bool {
84 false
85 }
86 fn serialize(&self, _: u8, _: &Self::State, _: Vec<f64>) -> String {
87 String::from("0")
88 }
89 fn deserialize(&self, _: String) -> (u8, Self::State, Vec<f64>) {
90 (0, 1, vec![])
91 }
92 }
93
94 #[test]
97 fn test_update_for_success() {
98 let mut env = Environment {};
99 env.update(&1);
100 }
101
102 #[test]
103 fn test_traits_for_success() {
104 let mut env = Environment {};
105 env.update(&1);
106 env.heuristic(&0, &1);
107 env.succ(&0);
108 env.pred(&0);
109 env.is_public(&0);
110 env.serialize(0, &0, vec![]);
111 env.deserialize(String::from("0"));
112 }
113}