Scheduler
actionSpaceBuilder.cpp
Go to the documentation of this file.
1 
10 #include "actionSpaceBuilder.h"
11 
12 #include <stdexcept>
13 
14 #include <utils/counter.h>
15 
16 #include "action.h"
17 #include "actionSpace.h"
18 #include "actionDimension.h"
19 #include "complexAction.h"
20 
21 using namespace Mdp;
22 
23 std::shared_ptr<ActionSpace> ActionSpaceBuilder::getActionSpace()
24 {
25  if (domainModel == nullptr) /*FIXME domainModel is a shared_ptr*/
26  {
27  throw std::runtime_error("Domain model not set");
28  }
29  std::shared_ptr<ActionSpace> space(new ActionSpace);
30  space->domainModel = domainModel;
31  std::vector<Action*> actionVector;
32  if (dimensions.size() == 0)
33  {
34  actionVector = actions;
35  }
36  else
37  {
38  long long int nbActions = actionDimensionCounter.getNumberOfValues();
39  actionDimensionCounter.initialize();
40  std::vector<unsigned int> counterValue;
41  for (long long int i = 0; i < nbActions; i++)
42  {
43  ComplexAction *complexAction = new ComplexAction;
44  counterValue = actionDimensionCounter.getValue();
45  for (unsigned int j = 0; j < dimensions.size(); j++)
46  {
47  Action *action = dimensions[j]->getAction(counterValue[j]);
48  action->domainModel = domainModel; /*TODO: this is very ugly*/
49  complexAction->actions.push_back(action);
50  }
51  actionVector.push_back(complexAction);
52  actionDimensionCounter.increment();
53  }
54  }
55  space->actions = actionVector;
56  space->setDomainModelOfActions(); /*TODO: can we do better?*/
57  return space;
58 }
59 
61 {
62  actions.push_back(action);
63 }
64 
65 
66 
67 void ActionSpaceBuilder::setDomainModel(std::shared_ptr<DomainModel> model)
68 {
69  domainModel = model;
70 }
71 
73 {
74  dimensions.push_back(dim);
75  actionDimensionCounter.addWheel(dim->getNumberOfActions());
76 }
void setDomainModel(std::shared_ptr< DomainModel > model)
sets the domain model used by the actions to act on the environment
void addAction(Action *action)
add an action to the actino space
std::shared_ptr< DomainModel > domainModel
Definition: action.h:43
std::shared_ptr< ActionSpace > getActionSpace()
get the action space
bool increment()
Definition: counter.cpp:36
std::vector< unsigned int > getValue()
Definition: counter.cpp:48
void addWheel(unsigned int base)
Definition: counter.cpp:23
long long unsigned int getNumberOfValues()
Definition: counter.cpp:60
void addActionDimension(ActionDimension *)
Definition: action.h:18
std::vector< Action * > actions
Definition: complexAction.h:29
void initialize()
Definition: counter.cpp:28