Scheduler
mdpGovernor.cpp
Go to the documentation of this file.
1 
10 #include "mdpGovernor.h"
11 
12 #include <cassert>
13 #include <string>
14 #include <memory>
15 
16 #include <mdp/mdpModel.h>
17 #include <mdp/actionSpaceBuilder.h>
18 #include <mdp/stateSpaceBuilder.h>
19 #include <mdp/mdpConfiguration.h>
20 
21 #include <scheduler/processor.h>
22 #include <scheduler/system.h>
23 #include <scheduler/queue.h>
24 
25 #include "schedulerDimensions.h"
26 #include "schedulerActions.h"
27 #include "schedulerDomainModel.h"
29 
30 using namespace MdpGov;
31 
33 {
34  std::shared_ptr<SchedulerDomainModel> domainModel = std::make_shared<SchedulerDomainModel>();
35  domainModel->readyQueue = Scheduler::Queue::getReadyQueue();
36  domainModel->waitQueue = Scheduler::Queue::getWaitQueue();
37  domainModel->proc = Scheduler::System::getInstance()->getProc();
38 
39  Mdp::StateSpaceBuilder builder;
40  builder.setDomainModel(domainModel);
41 
42  MdpGovernorConfiguration conf("configuration.conf");
43  std::shared_ptr<Mdp::MdpConfiguration> mdpConf = std::make_shared<Mdp::MdpConfiguration>("configuration.conf"); /*FIXME this is ugly*/
44  std::vector<Mdp::StateSpaceDimension*> dims = conf.getDimensionsFromFile();
45  for (size_t i = 0; i < dims.size(); i++)
46  {
47  builder.addDimension(dims[i]);
48  }
49 
50  std::shared_ptr<Mdp::StateSpace> stateSpace = builder.getStateSpace();
51 
52  Mdp::ActionSpaceBuilder abuilder;
53  abuilder.setDomainModel(domainModel);
54  abuilder.addAction(new SetMinFreq);
55  abuilder.addAction(new SetMaxFreq);
56  abuilder.setDomainModel(domainModel);
57  std::shared_ptr<Mdp::ActionSpace> actionSpace = abuilder.getActionSpace();
58 
59  model = new Mdp::MdpModel(stateSpace, actionSpace, mdpConf);
60 }
61 
63 {
64  delete model;
65 }
66 
68 {
69  static bool first = true;
70  if (first)
71  {
72  first = false;
73  model->init();
74  }
75  Mdp::Action *action = model->selectAction();
76  action->performAction();
77 }
78 
79 
81 {
83  return true;
84  return false;
85 }
86 
87 
88 
89 std::string MdpGovernor::getName()
90 {
91  return "MDP Governor";
92 }
93 
94 
95 void MdpGovernor::printReport(std::string folder)
96 {
97  model->printReportsToFile(folder);
98 }
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
void setDomainModel(std::shared_ptr< DomainModel > model)
sets the domain model used by the state space to determine current state
void setDomainModel(std::shared_ptr< DomainModel > model)
sets the domain model used by the actions to act on the environment
virtual void performAction()=0
void addAction(Action *action)
add an action to the actino space
TriggeringEvent
Definition: eventType.h:16
std::shared_ptr< StateSpace > getStateSpace()
call this function last!
virtual bool freqChangeEvent(Scheduler::TriggeringEvent trigger)
Definition: mdpGovernor.cpp:80
std::shared_ptr< ActionSpace > getActionSpace()
get the action space
This class implements the ready queue and the wait queue. Those queues contain processes ready to run...
Definition: queue.h:28
void addDimension(StateSpaceDimension *dimension)
adds a dimension to the state space
virtual std::string getName()
Definition: mdpGovernor.cpp:89
virtual ~MdpGovernor()
Definition: mdpGovernor.cpp:62
static System * getInstance()
Definition: system.cpp:28
Action * selectAction(bool updateModel=true)
Returns the optimal action for the current timestep.
Definition: mdpModel.cpp:89
static Queue * getReadyQueue()
get a pointer to the system&#39;s ready queue
Definition: queue.cpp:30
static Queue * getWaitQueue()
get a pointer to the system&#39;s wait queue
Definition: queue.cpp:37
Builds the action space.
The main class of the MDP framework.
Definition: mdpModel.h:35
virtual void printReport(std::string folder) override
Definition: mdpGovernor.cpp:95
virtual void updateFreq(Scheduler::Processor *proc, Scheduler::Queue *readyQueue)
Definition: mdpGovernor.cpp:67
Processor * getProc()
return the processor
Definition: system.cpp:76
void init()
call this function first
Definition: mdpModel.cpp:72
void printReportsToFile(std::string folder)
Print reports to file.
Definition: mdpModel.cpp:103
virtual std::vector< Mdp::StateSpaceDimension * > getDimensionsFromFile()
builds a domain specific state space