Skip to main content

mct_rs/
policy.rs

1use crate::{action::Action, mdp::MDP, rand::genrand};
2
3pub trait RolloutPolicy<M, S, A> {
4    fn pick(&self, state: &S, actions: &Vec<A>) -> A;
5}
6
7pub struct RandomRollout;
8
9impl RandomRollout {
10    pub fn new() -> Self {
11        Self
12    }
13}
14
15impl<M, S, A> RolloutPolicy<M, S, A> for RandomRollout
16where
17    M: MDP<S, A>,
18    A: Action,
19{
20    fn pick(&self, _state: &S, actions: &Vec<A>) -> A {
21        if actions.len() == 1 {
22            return actions[0];
23        }
24
25        let index = genrand(0, actions.len());
26        return actions[index];
27    }
28}