1 #ifndef AI_TOOLBOX_MDP_ROLLOUT_HEADER_FILE
2 #define AI_TOOLBOX_MDP_ROLLOUT_HEADER_FILE
30 template <
typename M,
typename Gen>
31 requires AIToolbox::IsGenerativeModel<M> && HasIntegralActionSpace<M>
32 double rollout(
const M & m, std::remove_cvref_t<decltype(std::declval<M>().getS())> s,
const unsigned maxDepth, Gen & rnd) {
33 double rew = 0.0, totalRew = 0.0, gamma = 1.0;
40 if constexpr (HasFixedActionSpace<M>) {
44 std::uniform_int_distribution<size_t> dist(0, m.getA()-1);
45 for (
unsigned depth = 0; depth < maxDepth; ++depth ) {
47 std::tie( s, rew ) = m.sampleSR( s, dist(rnd) );
48 totalRew += gamma * rew;
53 gamma *= m.getDiscount();
58 for (
unsigned depth = 0; depth < maxDepth; ++depth ) {
59 std::uniform_int_distribution<size_t> dist(0, m.getA(s)-1);
61 std::tie( s, rew ) = m.sampleSR( s, dist(rnd) );
62 totalRew += gamma * rew;
67 gamma *= m.getDiscount();