Scheduler
mdpModel.h
Go to the documentation of this file.
1 
10 #ifndef MDPMODEL_H
11 #define MDPMODEL_H
12 
13 #include <iostream>
14 #include <string>
15 #include <vector>
16 
17 #include "action.h"
18 #include "action_impl.h" /*FIXME this and the following should not be here...*/
19 #include "state.h"
20 
21 namespace Mdp
22 {
23 
24 class ActionSpace;
25 class ConstraintList;
26 struct Context;
27 class StateSpace;
28 class LearningStrategy;
29 class MdpConfiguration;
30 class Rewards;
31 
35 class MdpModel
36 {
37 public:
38  MdpModel(std::shared_ptr<StateSpace> stateSpace,
39  std::shared_ptr<ActionSpace> actionSpace,
40  std::shared_ptr<MdpConfiguration> conf);
41  virtual ~MdpModel();
44  void init();
47  void end();
50  Action *selectAction(bool updateModel=true);
55 
56  /*Ideally we don't need to know about state and actions apart from what the builder easily provide*/
57  void setConstraintList(std::shared_ptr<ConstraintList> list); //not very good... but necessary?
58  void setRewards(std::shared_ptr<Rewards> rewards); //not very good... but necessary?
59 
66  void printReportsToFile(std::string folder);
67  void printSummary(std::ostream& stream);
68  void printPolicy(std::ostream& stream);
69 protected:
70  virtual void constructContext(std::shared_ptr<StateSpace> stateSpace,
71  std::shared_ptr<ActionSpace> actionSpace,
72  std::shared_ptr<MdpConfiguration> conf);
73  virtual void setLearningStrategy();
74  std::shared_ptr<Context> context;
76  void record(state_t state, action_t action, double reward);
77 
78  std::vector<state_t> stateHistory;
79  std::vector<action_t> actionHistory;
80  std::vector<double> rewardHistory;
81  bool recordHistory{false};
82 };
83 
84 
85 }
86 #endif
virtual void setLearningStrategy()
Definition: mdpModel.cpp:42
virtual void constructContext(std::shared_ptr< StateSpace > stateSpace, std::shared_ptr< ActionSpace > actionSpace, std::shared_ptr< MdpConfiguration > conf)
Definition: mdpModel.cpp:48
virtual ~MdpModel()
Definition: mdpModel.cpp:68
void printPolicy(std::ostream &stream)
Definition: mdpModel.cpp:122
std::vector< action_t > actionHistory
Definition: mdpModel.h:79
LearningStrategy * learningStrategy
Definition: mdpModel.h:75
void record(state_t state, action_t action, double reward)
Definition: mdpModel.cpp:129
Action * selectAction(bool updateModel=true)
Returns the optimal action for the current timestep.
Definition: mdpModel.cpp:89
std::shared_ptr< Context > context
Definition: mdpModel.h:74
std::vector< state_t > stateHistory
Definition: mdpModel.h:78
The main class of the MDP framework.
Definition: mdpModel.h:35
bool recordHistory
Definition: mdpModel.h:81
size_t action_t
Definition: action_impl.h:18
Definition: action.h:18
std::vector< double > rewardHistory
Definition: mdpModel.h:80
Action * selectActionWithoutUpdate()
similar to selectAction, but without updating the model
Definition: mdpModel.cpp:84
void setConstraintList(std::shared_ptr< ConstraintList > list)
Definition: mdpModel.cpp:162
MdpModel(std::shared_ptr< StateSpace > stateSpace, std::shared_ptr< ActionSpace > actionSpace, std::shared_ptr< MdpConfiguration > conf)
Definition: mdpModel.cpp:34
void printSummary(std::ostream &stream)
Definition: mdpModel.cpp:141
void init()
call this function first
Definition: mdpModel.cpp:72
void printReportsToFile(std::string folder)
Print reports to file.
Definition: mdpModel.cpp:103
void end()
call this function at the end
Definition: mdpModel.cpp:79
void setRewards(std::shared_ptr< Rewards > rewards)
Definition: mdpModel.cpp:167
size_t state_t
Definition: state.h:19
Definition: reward.py:1