MultiAgentDecisionProcess  Release 0.2.1
AgentQMDP.cpp
Go to the documentation of this file.
1 
28 #include "AgentQMDP.h"
29 #include <float.h>
30 #include <limits.h>
32 
33 using namespace std;
34 
35 #define DEBUG_AgentQMDP 0
36 
38  const QTable &Q) :
40  _m_Q(Q),
41  _m_t(0)
42 {
43 }
44 
47  _m_Q(a._m_Q),
48  _m_t(a._m_t),
49  _m_jb(a._m_jb),
50  _m_prevJaI(a._m_prevJaI)
51 {
52 }
53 
54 //Destructor
56 {
57 }
58 
60 {
61  if(_m_t>0)
62  _m_jb.Update(*GetPU()->GetReferred(),_m_prevJaI,joI);
63 
64  Index jaInew=INT_MAX,aI;
65  double q,v=-DBL_MAX;
66  for(size_t a=0;a!=GetPU()->GetNrJointActions();++a)
67  {
68  q=0;
69  for(unsigned s=0;s!=GetPU()->GetNrStates();++s)
70  q+=_m_jb.Get(s)*_m_Q(s,a);
71 
72 // if(q>(v+PROB_PRECISION))
73  if(q>v)
74  {
75  v=q;
76  jaInew=a;
77  }
78  }
79 
80  vector<Index> aIs=GetPU()->JointToIndividualActionIndices(jaInew);
81  aI=aIs[GetIndex()];
82 
83  _m_prevJaI=jaInew;
84  _m_t++;
85 
86 #if DEBUG_AgentQMDP
87  cout << GetIndex() << ": ";
88  _m_jb.Print();
89  cout << " v " << v << " ja " << jaInew << " aI " << aI << endl;
90 #endif
91 
92  return(aI);
93 }
94 
96 {
97  _m_t=0;
99  _m_jb.Set(jbi->Get());
100  delete jbi;
101  _m_prevJaI=INT_MAX;
102 }