MultiAgentDecisionProcess  Release 0.2.1
JointObservationHistory.cpp
Go to the documentation of this file.
1 
29 #include "JointObservation.h"
30 //Necessary as header file contains a forward declaration:
32 #include "ObservationHistoryTree.h"
33 
34 using namespace std;
35 
36 #define DEBUG_JOH 0
37 
38 //Default constructor
41 {
42  SetLength(0);
44  _m_containsEmptyJOI = true;
45  _m_pred = 0;
46  size_t nrAgents = pu.GetNrAgents();
47  _m_individualObservationHistories = vector<Index>(nrAgents,0);
48 }
49 
50 
51 /*Creates a observation history specifying jObsI for the last joint
52  * observation and pred as the preceeding JointObservationHistory.*/
55  Referrer<PlanningUnitMADPDiscrete>( pred->GetReferred() )
56 {
57  SetLength(pred->GetLength() + 1);
59  _m_containsEmptyJOI = false;
60  _m_pred = pred;
61  size_t nrAgents = pred->_m_individualObservationHistories.size();
62 
63  const vector<Index>& indivOIndices = GetReferred()->
64  JointToIndividualObservationIndices(joI);
65 
66  //we also maintain the indices of the individual observation histories
67  //represented by this joint observation history
68  for(Index aI=0; aI < nrAgents; aI++)
69  {
70  //get the individual observation history for the predecessor
71  Index predOHindex_ai = pred->_m_individualObservationHistories[aI];
73  GetObservationHistoryTree(aI, predOHindex_ai);
74  Index ai_last_observation = indivOIndices[aI];
75  Index sucOHindex_ai =
76  oht_ai->GetSuccessor(ai_last_observation)->
77  GetIndex();
78  _m_individualObservationHistories.push_back(sucOHindex_ai);
79  }
80 }
81 
82 //Copy assignment constructor.
84 {
85 if(DEBUG_JOH){ cout << "Cloning JointObservationHistory: ";
86  Print(); cout <<endl;}
87 }
88 //Destructor
90 {
91 if(DEBUG_JOH){ cout << "Deleting JointObservationHistory: ";
92  Print(); cout <<endl;}
93 
95 }
97 {
99 }
100 
102 {
103  stringstream ss;
104  if(_m_pred != 0)
105  {
106  if(_m_length >= 1)
107  ss << _m_pred->SoftPrint();
108  else
109  {
110  ss << "JointObservationHistory:Print() - Warning:_m_pred != "<<
111  "null, but lenght <= 1 !"<<endl;
112  throw E(ss);
113  }
114  }
115 
116  if (!_m_containsEmptyJOI) // don't print the empty observation
117  {
120  }
121  else
122  ss << "JOnull, ";
123 
124  return(ss.str());
125 }