MultiAgentDecisionProcess  Release 0.2.1
QMDP.cpp
Go to the documentation of this file.
1 
28 #include "QMDP.h"
30 #include "JointBelief.h"
31 #include "JointBeliefSparse.h"
32 
33 using namespace std;
34 
35 //Default constructor
37  bool useJaohQValuesCache) :
38  QFunctionForDecPOMDP(pu), //virtual base first
39  QFunctionJAOH(pu),
40  _m_initialized(false),
41  _m_useJaohQValuesCache(useJaohQValuesCache)
42 {
43 }
44 
45 //Destructor
47 {
48  DeInitialize();
49 }
50 
52 {
54  _m_QValues.resize(GetPU()->GetNrJointActionObservationHistories(),
55  GetPU()->GetNrJointActions(),
56  false);
57 
59 
60  _m_initialized=true;
61 }
62 
64 {
65  delete _m_p;
66  _m_QValues.clear();
67  _m_initialized=false;
68 }
69 
71 {
72  DeInitialize();
74 }
75 
77 {
78  if(!_m_initialized)
79  Initialize();
80 
81  _m_p->Plan();
82 
85 }
86 
88 {
89  for(Index jaohI=0;
91  ++jaohI)
92  {
94  GetJointActionObservationHistory()->GetLength();
95  for(Index jaI=0;jaI!=GetPU()->GetNrJointActions();++jaI)
96  _m_QValues(jaohI,jaI)=
97  _m_p->GetQ (t, *GetPU()->GetJointBeliefInterface(jaohI), jaI);
98  }
99 }
100 
101 double QMDP::GetQNoCache(Index jaohI, Index jaI) const
102 {
103  Index t = GetPU()->GetTimeStepForJAOHI(jaohI);
104  //Index t = GetPU()->GetJointActionObservationHistoryTree(jaohI)->
105  //GetJointActionObservationHistory()->GetLength();
107  double q = _m_p->GetQ (t, *jb, jaI);
108  delete jb;
109  return( q );
110 }
111 
112 double QMDP::GetQSA(Index t, Index sI, Index jaI) const
113 {
114  double q = _m_p->GetQ (t, sI, jaI);
115  return( q );
116 }
117 
118 double QMDP::GetQ(const JointBeliefInterface &b, Index jaI) const
119 {
120  return(_m_p->GetQ(b,jaI));
121 }
122 
123 double QMDP::GetQ(const JointBeliefInterface &b, Index time_step,
124  Index jaI) const
125 {
126  return(_m_p->GetQ(time_step,b,jaI));
127 }
128 
129 void QMDP::Save(string filename) const
130 {
133  else
135 }
136 
137 void QMDP::Load(string filename)
138 {
141  GetPU()->
142  GetNrJointActionObservationHistories(),
143  GetPU()->GetNrJointActions());
144  else
146  GetPU()->GetNrStates(),
147  GetPU()->GetNrJointActions(),
148  GetPU()->GetHorizon()));
149 }