MultiAgentDecisionProcess  Release 0.2.1
BayesianGameIdenticalPayoff.cpp
Go to the documentation of this file.
1 
29 #include <fstream>
30 
31 using namespace std;
32 
33 //Default constructor
35 {
36  _m_initialized=false;
37 }
38 
39 //TODO: make refs of these vectors?!
41  const vector<size_t>& nrActions,
42  const vector<size_t>& nrTypes) :
43  BayesianGameIdenticalPayoffInterface(nrAgents, nrActions, nrTypes),
44  _m_utilFunction(_m_nrJTypes, _m_nrJA, "type", "ja")
45 {
46  _m_initialized=false;
47 }
48 
50 {
51  //TODO implement checks
52  _m_initialized = b;
53  return(true);
54 }
55 
57 {
58  stringstream ss;
59  ss << "Utility function for jtype "<<jtype <<
60  "with prob.="<< GetProbability(jtype) << endl;
61  ss << "jtype\tja\tu(jtype,ja)"<<endl;
62  for(Index jaI=0; jaI < _m_nrJA; jaI++)
63  ss << jtype << "\t" << jaI << "\t" << GetUtility(jtype, jaI)<<endl;
64  return(ss.str());
65 }
66 
68 {
69  stringstream ss;
71  ss << "Utility function:"<<endl;
72  for(Index jtype=0; jtype < _m_nrJTypes; jtype++)
73  {
74  for(Index jaI=0; jaI < _m_nrJA; jaI++)
75  ss << GetUtility(jtype,jaI) << " ";
76  ss << endl;
77  }
78 // ss << _m_utilFunction.SoftPrint();
79  return(ss.str());
80 }
81 
83  string filename)
84 {
85  throw(E("Not implemented"));
86 }
87 
89 {
90  throw(E("Not implemented"));
91  BayesianGameIdenticalPayoff bogus; // keep compiler happy
92  return(bogus);
93 }
94 
97  size_t nrAgents,
98  std::vector<size_t> acs,
99  std::vector<size_t> obs
100  )
101 {
102  BayesianGameIdenticalPayoff bgip(nrAgents, acs, obs);
103  for(Index jtype = 0; jtype < bgip.GetNrJointTypes(); jtype++)
104  for(Index ja = 0; ja < bgip.GetNrJointActions(); ja++)
105  {
106  double rn = (rand() - (0.5 * RAND_MAX)) / (RAND_MAX / 20.0);
107  bgip.SetUtility(jtype, ja, rn );
108  }
109 
110  //create random, normalized prob distr.
111  vector<double> typeProbs;
112  double sum = 0.0;
113  for(Index jtype = 0; jtype < bgip.GetNrJointTypes(); jtype++)
114  {
115  double r = ((double)rand()) / RAND_MAX;
116  typeProbs.push_back(r);
117  }
118  for(Index jtype = 0; jtype < bgip.GetNrJointTypes(); jtype++)
119  sum += typeProbs[jtype];
120  for(Index jtype = 0; jtype < bgip.GetNrJointTypes(); jtype++)
121  bgip.SetProbability(jtype, typeProbs[jtype] / sum );
122 
123  //bgip.Print();
124  return(bgip);
125 }