MultiAgentDecisionProcess  Release 0.2.1
BayesianGameIdenticalPayoffSolver.h
Go to the documentation of this file.
1 
28 /* Only include this header file once. */
29 #ifndef _BAYESIANGAMEIDENTICALPAYOFFSOLVER_H_
30 #define _BAYESIANGAMEIDENTICALPAYOFFSOLVER_H_ 1
31 
32 /* the include directives */
33 #include <iostream>
34 #include <fstream>
35 #include "Globals.h"
36 
37 #include "Referrer.h"
39 #include "JointPolicy.h"
40 #include "JointPolicyPureVector.h"
41 #include "BGIPSolution.h"
42 
43 //needed for timing results
44 #include <sys/time.h>
45 #include <time.h>
46 
47 
54 template<class JP>
56  public Referrer<BayesianGameIdenticalPayoffInterface>
57 {
58 private:
59 
60 protected:
64 
67 
69  std::ofstream* _m_results_f;
71  std::ofstream* _m_timings_f;
72 
73 
74 public:
75  // Constructor, destructor and copy assignment.
77 
83  size_t nrSolutions=1) :
85  const_cast<BayesianGameIdenticalPayoffInterface&>(bg)),
86  _m_solution(bg, nrSolutions),
88  {
89  }
90 
93 
96  virtual double Solve() = 0;
97 
98  const JointPolicy* GetJointPolicy() const
99  { return(_m_solution.GetJointPolicy()); }
102  double GetExpectedReward() const
103  { return(_m_solution.GetPayoff()); }
104  const BGIPSolution & GetSolution() const
105  { return(_m_solution); }
107  { return(_m_solution); }
108 
110 
113  void SetAnyTimeResults(bool turn_on, std::ofstream* results,
114  std::ofstream* timings)
115  {
116  _m_writeAnyTimeResults = turn_on;
117  if(turn_on)
118  {
119  _m_results_f = results;
120  _m_timings_f = timings;
121  }
122  else
123  {
124  _m_results_f = NULL;
125  _m_timings_f = NULL;
126  }
127  }
128 
129  double Evaluate(const JP & jpolBG) const
130  {
132  double v = 0.0;
133  for(Index jt = 0; jt < bgip->GetNrJointTypes(); jt++)
134  {
135  Index jaI = jpolBG.GetJointActionIndex(jt);
136  double p = bgip->GetProbability(jt);
137  double u = bgip->GetUtility(jt, jaI);
138  v += p * u;
139  }
140  return v;
141  }
142 
143  JP *GetNewJpol() const
144  {
145  JP* jpol=new JP(*GetReferred());
146  return(jpol);
147  }
148 
150  size_t GetNrDesiredSolutions() const
153  size_t GetNrFoundSolutions() const
154  {return _m_solution.GetNrFoundSolutions();};
155 };
156 
157 
158 #endif /* !_BAYESIANGAMEIDENTICALPAYOFFSOLVER_H_ */
159 
160 // Local Variables: ***
161 // mode:c++ ***
162 // End: ***