MultiAgentDecisionProcess  Release 0.2.1
QFunctionJAOH.cpp
Go to the documentation of this file.
1 
28 #include "QFunctionJAOH.h"
29 #include "MDPSolver.h"
31 #include <fstream>
32 
33 #define DEBUG_QHEUR_COMP 0
34 
35 using namespace std;
36 
38  const PlanningUnitDecPOMDPDiscrete &pu) :
39  QFunctionForDecPOMDP(pu), //virtual base first
41 {
42 }
43 
44 void QFunctionJAOH::ComputeWithCachedQValues(string filenameCache)
45 {
46  bool cached;
47 
48  {
49  ifstream fp(filenameCache.c_str());
50  if(!fp)
51  cached=false;
52  else
53  cached=true;
54  }
55 
56  // Couldn't open cache file, so compute
57  if(!cached)
58  {
59  Compute();
60  MDPSolver::SaveQTable(_m_QValues,filenameCache);
61 
62 #if DEBUG_QHEUR_COMP
63  cout << "QFunctionJAOH::ComputeWithCachedQValues saved Q values to "
64  << filenameCache << endl;
65 #endif
66  }
67  else // load Q values from file
68  {
69  _m_QValues=
70  MDPSolver::LoadQTable(filenameCache,
71  GetPU()->
72  GetNrJointActionObservationHistories(),
73  GetPU()->GetNrJointActions());
74 #if DEBUG_QHEUR_COMP
75  cout << "QFunctionJAOH::ComputeWithCachedQValues loaded Q values from "
76  << filenameCache << endl;
77 #endif
78  }
79 }
81 {
83 }