MultiAgentDecisionProcess  Release 0.2.1
JESPExhaustivePlanner.cpp
Go to the documentation of this file.
1 
28 #include "JESPExhaustivePlanner.h"
29 #include <float.h>
30 
31 using namespace std;
32 
33 #define DEBUG_EXHBR 0
34 #define DEBUG_EXJESP 0
35 
38  size_t horizon,
40  ) :
41  PlanningUnitDecPOMDPDiscrete(params, horizon, p),
42  _m_foundPolicy(*this)
43  //,_m_exhBRBestPol(*this)
44 {
45 }
46 
48  int horizon,
50  ) :
51  PlanningUnitDecPOMDPDiscrete(horizon, p),
52  _m_foundPolicy(*this)
53  //,_m_exhBRBestPol(*this)
54 {
55 }
56 
58 {
59  if(DEBUG_EXJESP){
60  cout << "\n---------------------------------"<<endl;
61  cout << "Exhaustive JESP - Plan() started"<<endl;
62  cout << "---------------------------------"<<endl;
63  }
64  double v_best = -DBL_MAX;
67  jpol->RandomInitialization();
68 
69  if(DEBUG_EXJESP) {cout << "joint policy randomly initialized to:";
70  jpol->Print();}
71 
72  int stop = 0;
73  size_t nr_non_improving_agents = 0;
74  while(nr_non_improving_agents < GetReferred()->GetNrAgents()
75  && stop++ < 1000)
76  {
77  int agentI = GetNextAgentIndex();
78  double v = ExhaustiveBestResponse(jpol, agentI);
79  if(v > v_best + 1e-9)
80  {
81  (*best) = (*jpol);
82  if(DEBUG_EXHBR)
83  {cout << "Plan: new best policy:"<<endl; best->Print();}
84  v_best = v;
85  nr_non_improving_agents = 0;
86  }
87  else
88  nr_non_improving_agents++;
89  }
90  _m_foundPolicy = *best;
92 
93 
94  if(DEBUG_EXJESP){
95  cout << "Exhaustive JESP - resulting policy:"<<endl;
96  cout << "------------------------------------"<<endl;
97  best->Print();
98  }
99 }
100 
102  jpol, int agentI)
103 {
104  if(DEBUG_EXHBR)
105  cout << "JESPExhaustivePlanner::ExhaustiveBestResponse called "
106  << "for agent " << agentI << endl;
107 
108  bool round = false;
109  JointPolicyPureVector best(*this);
110  double v_best = -DBL_MAX;
111  double v = 0.0;
112  jpol->ZeroInitialization(agentI);
113 
114  while(!round)
115  {
116  ValueFunctionDecPOMDPDiscrete vf(this, jpol);
117  v = vf.CalculateV(true);
118  if(v > v_best)
119  {
120  best = (*jpol);
121  if(DEBUG_EXHBR)
122  {cout << "ExhaustiveBestResponse: new best policy:"<<endl;
123  best.Print();}
124  v_best = v;
125  }
126  round = jpol->Increment(agentI);
127  }
128  //_m_exhBRBestPol = best;
129  *jpol = best;
130  if(DEBUG_EXJESP){ cout << "Best response V="<<v_best<<endl;}
131  if(DEBUG_EXHBR){ cout << "policy="; jpol->Print();}
132  return(v_best);
133 }