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
mod plain;
pub use self::plain::PlainModel;
use environment::{Space, Transition};
macro_rules! implement_model_for_deterministicmodel {
($name:ident, $state:ident, $action:ident) => {
impl<S: $state, A: $action> Model<S, A> for $name<S, A> {
fn transition(&self, curr: &S::Element, action: &A::Element, next: &S::Element) -> f64 {
let actual_next = self.transition2(curr, action);
if *next == actual_next {1.0} else {0.0}
}
fn reward(&self, curr: &S::Element, action: &A::Element, next: &S::Element) -> f64 {
let actual_next = self.transition2(curr, action);
if *next == actual_next {self.reward2(curr, action)} else {0.0}
}
fn update(&mut self, transition: Transition<S, A>) {
self.update(transition);
}
}
}
}
pub trait Model<S: Space, A: Space> {
fn transition(&self, curr: &S::Element, action: &A::Element, next: &S::Element) -> f64;
fn reward(&self, curr: &S::Element, action: &A::Element, next: &S::Element) -> f64;
fn update(&mut self, transition: Transition<S, A>);
}
pub trait DeterministicModel<S: Space, A: Space> {
fn transition2(&self, curr: &S::Element, action: &A::Element) -> S::Element;
fn reward2(&self, curr: &S::Element, action: &A::Element) -> f64;
fn update(&mut self, transition: Transition<S, A>);
}