MultiAgentDecisionProcess  Release 0.2.1
MADPComponentDiscreteActions.h
Go to the documentation of this file.
1 
28 /* Only include this header file once. */
29 #ifndef _MADPCOMPONENTDISCRETEACTIONS_H_
30 #define _MADPCOMPONENTDISCRETEACTIONS_H_ 1
31 
32 
33 /* the include directives */
34 #include <iostream>
35 #include <sstream>
36 #include "Globals.h"
38 #include "ActionDiscrete.h"
39 #include "JointActionDiscrete.h"
40 #include "IndexTools.h"
41 
42 #include <map>
43 
44 
45 namespace {
46  typedef std::vector<ActionDiscrete> ActionDVec;
47 }
48 
55  :
56  virtual public MultiAgentDecisionProcessDiscreteInterface //which this implements partly
57 {
58  private:
59 
64 
65  //cache this here (set by SetInitialized)
66  size_t _m_nr_agents;
67 
70 
72 
73  std::vector<JointActionDiscrete*> _m_jointActionVec;
74 
78  std::map<Index, std::vector<Index> *> *_m_jointActionIndices;
79 
81  size_t ConstructJointActionsRecursively( Index curAgentI,
82  JointActionDiscrete& ja, Index jaI);
83 
84  std::string SoftPrintActionSets() const;
85  std::string SoftPrintJointActionSet() const;
86 
87  protected:
89  std::vector<size_t> _m_nrActions;
91  std::vector<std::vector<ActionDiscrete> > _m_actionVecs;
92 
93  public:
94 
97 
100 
101  //data manipulation (set) functions:
102 
104  bool SetInitialized(bool b);
105 
107  void SetNrActions(Index AI, size_t nrA);
108 
110  void AddAction(Index AI, std::string name);
111 
113  size_t ConstructJointActions();
114 
115  //get (data) functions:
116 
118  const std::vector<size_t>& GetNrActions() const
119  {return _m_nrActions;}
120 
122  size_t GetNrActions(Index AgentI) const;
123 
125  size_t GetNrJointActions() const;
126 
128  Index GetActionIndexByName(std::string s, Index agentI) const;
129 
131  std::string GetActionName(Index a, Index i) const {
132  return(_m_actionVecs.at(i).at(a).GetName()); }
133 
135  std::string GetJointActionName(Index a) const {
136  return(_m_jointActionVec.at(a)->SoftPrint()); }
137 
139  const Action* GetAction(Index agentI, Index a) const;
140 
142  const ActionDiscrete* GetActionDiscrete(Index agentI, Index a) const;
143 
145  const JointAction* GetJointAction(Index i) const;
146 
149 
152  Index IndividualToJointActionIndices(const std::vector<Index>&
153  indivActionIndices) const;
154 
157  Index IndividualToJointActionIndices(const Index* IndexArray) const
159  IndexArray, _m_actionStepSize, _m_nr_agents);}
160 
163  const std::vector<Index>& JointToIndividualActionIndices(Index jaI)const
164  {
166  {
167  throw(E("MADPComponentDiscreteActions::JointToIndividualActionIndices() joint indices are not available, overflow detected"));
168  }
170  return GetJointActionDiscrete(jaI)->
171  GetIndividualActionDiscretesIndices();
172  else if(_m_jointActionIndices->find(jaI)!=
173  _m_jointActionIndices->end())
174  return(*_m_jointActionIndices->find(jaI)->second);
175  else // create new
176  {
177  std::vector<Index> *indices=new std::vector<Index>();
179  GetNrActions());
180  _m_jointActionIndices->insert(make_pair(jaI,indices));
181  return(*indices);
182  }
183  }
184 
185  std::string SoftPrint() const;
186  void Print() const
188 };
189 
190 
191 #endif /* !_MADPCOMPONENTDISCRETEACTIONS_H_ */
192 
193 
194 // Local Variables: ***
195 // mode:c++ ***
196 // End: ***