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
mod simulator;
pub use self::simulator::*;
mod strategies;
pub use self::strategies::*;
use hashbrown::HashMap;
use std::hash::Hash;
pub type ActionsEstimate<S> = HashMap<<S as State>::Action, f64>;
pub trait State: Clone + Hash + Eq + Send + Sync {
type Action: Clone + Hash + Eq + Send + Sync;
fn reward(&self) -> f64;
}
pub trait Agent<S: State> {
fn get_state(&self) -> &S;
fn get_actions(&self, state: &S) -> ActionsEstimate<S>;
fn take_action(&mut self, action: &S::Action);
}
pub trait LearningStrategy<S: State> {
fn value(&self, reward_value: f64, old_value: f64, estimates: &ActionsEstimate<S>) -> f64;
}
pub trait PolicyStrategy<S: State> {
fn select(&self, estimates: &ActionsEstimate<S>) -> Option<S::Action>;
}