MultiAgentDecisionProcess  Release 0.2.1
SimulationDecPOMDPDiscrete.h
Go to the documentation of this file.
1 
28 /* Only include this header file once. */
29 #ifndef _SIMULATIONDECPOMDPDISCRETE_H_
30 #define _SIMULATIONDECPOMDPDISCRETE_H_ 1
31 
32 /* the include directives */
33 #include <iostream>
34 #include "Globals.h"
35 
36 #include "Simulation.h"
37 #include "SimulationResult.h"
39 #include "argumentHandlers.h"
40 #include "State.h"
41 
47 
51 {
52 private:
53 
56 
58 
60 
61  Index GetAction(const std::vector<AgentLocalObservations*> &agents, Index i,
62  Index jaI, Index joI, double r, Index prevJoI,
63  Index sI) const;
64 
65  Index GetAction(const std::vector<AgentSharedObservations*> &agents, Index i,
66  Index jaI, Index joI, double r, Index prevJoI,
67  Index sI) const;
68 
69  Index GetAction(const std::vector<AgentDelayedSharedObservations*> &agents,
70  Index i, Index jaI, Index joI, double r, Index prevJoI,
71  Index sI) const;
72 
73  Index GetAction(const std::vector<AgentFullyObservable*> &agents, Index i,
74  Index jaI, Index joI, double r, Index prevJoI,
75  Index sI) const;
76 
77  void Initialize();
78 
80  void Step(Index jaI, unsigned int t, Index &sI, Index &joI,
81  double &r, double &sumR) const;
82 
84  double RunSimulation(const JointPolicyDiscrete* jp) const;
85 
86 protected:
87 
88  size_t _m_horizon;
89 
90 public:
91  // Constructor, destructor and copy assignment.
92 
95  int nrRuns, int seed=illegalRandomSeed);
96 
99  const ArgumentHandlers::Arguments &args);
100 
103 
106  RunSimulations(const JointPolicyDiscrete* jp) const;
107 
109  template <class A>
111  RunSimulations(const std::vector<A*> &agents) const
112  {
114 
115  // Run the simulations
116  int i;
117  for(i=0;i<GetNrRuns();i++)
118  {
119  Index jaI,sI,joI,prevJoI;
120  int nr=agents.size(),i;
121  std::vector<Index> aIs(nr);
122 
123  unsigned int h;
124  double r=0,sumR=0;
125 
127 
128  if(GetVerbose())
129  std::cout << "Simulation::RunSimulation set initial state to "
130  << sI << " "
132  << " (avg reward so far " << result.GetAvgReward()
133  << ")" << std::endl;
134 
135  for(i=0;i<nr;++i)
136  agents[i]->ResetEpisode();
137 
138  joI=INT_MAX;
139  jaI=INT_MAX;
140  prevJoI=INT_MAX;
141  for(h=0;h<_m_horizon;h++)
142  {
143  // get the action for each particular agent
144  for(i=0;i<nr;++i)
145  aIs[i]=GetAction(agents,i,jaI,joI,r,prevJoI,sI);
147 
148  prevJoI=joI;
149  Step(jaI, h, sI, joI, r, sumR);
150  }
151 
152  result.AddReward(sumR);
153 
156  }
157 
158  return(result);
159  }
160 
162  void SaveIntermediateResults(std::string filename);
163 
164 
165 };
166 
167 
168 #endif /* !_SIMULATIONDECPOMDPDISCRETE_H_ */
169 
170 // Local Variables: ***
171 // mode:c++ ***
172 // End: ***