1#ifndef VECTOR_TIME_STEP_H
2#define VECTOR_TIME_STEP_H
6#include "bitrl/extern/nlohmann/json/json.hpp"
11#include <unordered_map>
38 const std::vector<state_type> &obs);
44 const std::vector<state_type> &obs,
const std::vector<real_t> &discount_factors);
47 const std::vector<state_type> &obs,
const std::vector<real_t> &discount_factors,
48 std::unordered_map<std::string, std::any> &&extra);
78 const std::vector<TimeStepTp> &
types() const noexcept {
return types_; }
84 const std::vector<state_type> &
observations()
const {
return obs_; }
90 const std::vector<real_t> &
rewards() const noexcept {
return rewards_; }
122 std::vector<
real_t> rewards_;
132 std::vector<
real_t> discounts_;
137 std::unordered_map<std::
string, std::any> extra_;
140template <typename StateType>
144 const std::vector<
real_t> &discount_factors,
145 std::unordered_map<std::
string, std::any> &&extra)
146 : types_(
types), rewards_(
rewards), obs_(obs), discounts_(discount_factors), extra_(extra)
150template <
typename StateType>
152 const std::vector<real_t> &
rewards,
153 const std::vector<state_type> &obs,
154 const std::vector<real_t> &discount_factors)
155 : types_(
types), rewards_(
rewards), obs_(obs), discounts_(discount_factors)
159template <
typename StateType>
161 const std::vector<real_t> &rewards,
162 const std::vector<state_type> &obs)
167template <
typename StateType>
169 : types_(other.types_), rewards_(other.rewards_), obs_(other.obs_),
170 discounts_(other.discounts_), extra_(other.extra_)
174template <
typename StateType>
179 types_ = other.types_;
180 rewards_ = other.rewards_;
182 discounts_ = other.discounts_;
183 extra_ = other.extra_;
187template <
typename StateType>
189 : types_(other.types_), rewards_(other.rewards_), obs_(other.obs_),
190 discounts_(other.discounts_), extra_(other.extra_)
195template <
typename StateType>
200 types_ = other.types_;
201 rewards_ = other.rewards_;
203 discounts_ = other.discounts_;
204 extra_ = other.extra_;
213 sum_ = std::accumulate(rewards_.begin(), rewards_.end(), sum_);
221 for (
auto step_type : types_)
238template <
typename StateTp>
242 using json = nlohmann::json;
245 auto types = step.
types();
246 std::vector<std::string> step_to_str(types.size());
248 for (
uint_t i = 0; i < step_to_str.size(); ++i)
253 j[
"step_types"] = step_to_str;
258 out << j << std::endl;
Forward declaration.
Definition vector_time_step.h:21
VectorTimeStep & operator=(const VectorTimeStep &other)
Assignment operator.
Definition vector_time_step.h:176
const std::vector< state_type > & observations() const
observation
Definition vector_time_step.h:84
const std::vector< real_t > & rewards() const noexcept
reward
Definition vector_time_step.h:90
const std::vector< real_t > & discounts() const noexcept
discount. Returns the discount factor
Definition vector_time_step.h:105
VectorTimeStep(const std::vector< TimeStepTp > &types, const std::vector< real_t > &rewards, const std::vector< state_type > &obs, const std::vector< real_t > &discount_factors)
VectorTimeStep. Constructor.
Definition vector_time_step.h:151
VectorTimeStep(const VectorTimeStep &other)
TimeStep.
Definition vector_time_step.h:168
bool last() const noexcept
last
Definition vector_time_step.h:233
VectorTimeStep & operator=(VectorTimeStep &&other) noexcept
operator =
Definition vector_time_step.h:197
StateType state_type
state_ Type of the state
Definition vector_time_step.h:27
real_t reward() const noexcept
Returns the sum of the rewards received.
Definition vector_time_step.h:209
VectorTimeStep(const std::vector< TimeStepTp > &types, const std::vector< real_t > &rewards, const std::vector< state_type > &obs, const std::vector< real_t > &discount_factors, std::unordered_map< std::string, std::any > &&extra)
Definition vector_time_step.h:141
bool done() const noexcept
Returns true if any time step is LAST.
Definition vector_time_step.h:217
VectorTimeStep(VectorTimeStep &&other) noexcept
TimeStep.
Definition vector_time_step.h:188
const std::vector< TimeStepTp > & types() const noexcept
type
Definition vector_time_step.h:78
VectorTimeStep()=default
Default construcotr.
VectorTimeStep(const std::vector< TimeStepTp > &types, const std::vector< real_t > &rewards, const std::vector< state_type > &obs)
VectorTimeStep. Constructor.
Definition vector_time_step.h:160
Definition bitrl_consts.h:14
std::ostream & operator<<(std::ostream &out, const Null &)
Definition bitrl_types.h:165
double real_t
real_t
Definition bitrl_types.h:23
std::size_t uint_t
uint_t
Definition bitrl_types.h:43
TimeStepTp
The TimeStepTp enum.
Definition time_step_type.h:16
static std::string to_string(TimeStepTp type)
Definition time_step_type.cpp:37