MultiAgentDecisionProcess  Release 0.2.1
JointActionObservationHistory.cpp
Go to the documentation of this file.
1 
29 #include "JointAction.h"
30 #include "JointObservation.h"
34 #include "IndexTools.h"
35 
36 using namespace std;
37 
38 #define DEBUG_JAOH 0
39 
40 //Default constructor
43 {
44  SetLength(0);
45  _m_pred = 0;
46  _m_jaI = 0; //HARDCODED
47  _m_joI = 0;
48  Index individualInitialAOHIndex = 0;//HARDCODED
50  GetReferred()->GetNrAgents(), individualInitialAOHIndex);
51 
52 }
54  joI, JointActionObservationHistory* pred) :
56 {
57  SetLength(pred->GetLength() + 1);
58  _m_pred = pred;
59 
60  _m_jaI = jaI;
61  _m_joI = joI;
62 
63  //calculate the new individual ActionObservationHistory indices...
64  vector<Index> iA = GetReferred()->JointToIndividualActionIndices(jaI);
65  vector<Index> iO = GetReferred()->JointToIndividualObservationIndices(joI);
66  vector<Index> pred_iAOH= pred->GetIndividualActionObservationHistoryIndices();
67  for(Index agentI = 0; agentI < GetReferred()->GetNrAgents(); agentI++)
68  {
69  Index next_indivIndex =
70  GetReferred() //=PlanningUnitMADPDiscrete
71  -> GetSuccessorAOHI(agentI,
72  pred_iAOH[agentI], iA[agentI], iO[agentI] ) ;
73  //Index next_indivIndex =
74  //GetReferred() //=PlanningUnitMADPDiscrete
75  //->GetActionObservationHistoryTree(agentI, pred_iAOH[agentI])//=aoht
76  //->GetSuccessor( iA[agentI], iO[agentI] ) //=aoht'
77  //->GetIndex(); //=aohI'
78  _m_individualActionObservationHistories.push_back(next_indivIndex);
79  }
80 
81 }
82 
84 {
85  stringstream ss;
86  if(_m_pred != 0)
87  {
88  if(_m_length >= 1)
89  {
90  ss << _m_pred->SoftPrint();
91  ss << ", ";
92  }
93  else
94  {
95  ss << "JointActionObservationHistory:Print() -Warning:_m_pred != "
96  << "null, but lenght <= 1 !"<<endl;
97  throw E(ss);
98  }
99  }
100 
101  if (_m_length >= 1)
102  {
103  ss << "< ";
105  ss << ", ";
107  ss << " >";
108  }
109  else
110  ss << "<EMPTY>";
111 
112 
113  return(ss.str());
114 
115 }
116 
118 {
119  stringstream ss;
120  if(_m_pred != 0)
121  {
122  if(_m_length >= 1)
123  {
125  ss << ", ";
126  }
127  else
128  {
129  ss << "JointActionObservationHistory:Print() -Warning:_m_pred != "
130  << "null, but lenght <= 1 !"<<endl;
131  throw E(ss);
132  }
133  }
134 
135  if (_m_length >= 1)
136  {
137  ss << "jaoI=" <<
139  _m_jaI, _m_joI,
140  GetReferred()->GetNrJointActions(),
141  GetReferred()->GetNrJointObservations() );
142  ss << "(jaI=";
143  ss << _m_jaI;
144  ss << ",joI=";
145  ss << _m_joI;
146  ss << ")";
147  }
148  else
149  ss << "<>";
150 
151 
152  return(ss.str());
153 
154 }
155 
156 void
158 // JointActionObservationHistory *joah,
159  vector<Index> &jaIs, vector<Index> &joIs)
160 {
161  vector<Index> jaIsReversed;
162  vector<Index> joIsReversed;
163 
165  joIsReversed);
166 
167  // reverse both vectors
168  for(vector<Index>::reverse_iterator it=jaIsReversed.rbegin();
169  it!=jaIsReversed.rend(); ++it)
170  jaIs.push_back(*it);
171 
172  for(vector<Index>::reverse_iterator it=joIsReversed.rbegin();
173  it!=joIsReversed.rend(); ++it)
174  joIs.push_back(*it);
175 
176 #if DEBUG_JAOH
177  cout << SoftPrint() << " " << SoftPrintVector(jaIsReversed) << " "
178  << SoftPrintVector(joIsReversed) << endl;
179 #endif
180 }
181 
182 void
184  vector<Index> &jaIs, vector<Index> &joIs)
185 {
186  if(_m_length >= 1) // for t=0, length=0 (and we don't want to include the
187  //_m_jaI, _m_joI for that stage (they are def'd to be 0) )
188  {
189  jaIs.push_back(_m_jaI);
190  joIs.push_back(_m_joI);
191  }
192  if(_m_pred!=NULL)
194 }
195 
196 /* old - this seems strange...
197 void
198 JointActionObservationHistory::GetJointActionObservationHistoryVectors(
199  JointActionObservationHistory *joah,
200  vector<Index> &jaIs, vector<Index> &joIs)
201 {
202  vector<Index> jaIsReversed;
203  vector<Index> joIsReversed;
204 
205  GetJointActionObservationHistoryVectorsRecursive(joah,
206  jaIsReversed,
207  joIsReversed);
208 
209  // reverse both vectors
210  for(vector<Index>::reverse_iterator it=jaIsReversed.rbegin();
211  it!=jaIsReversed.rend(); ++it)
212  jaIs.push_back(*it);
213 
214  for(vector<Index>::reverse_iterator it=joIsReversed.rbegin();
215  it!=joIsReversed.rend(); ++it)
216  joIs.push_back(*it);
217 
218 }
219 
220 void
221 JointActionObservationHistory::GetJointActionObservationHistoryVectorsRecursive(
222  JointActionObservationHistory *joah,
223  vector<Index> &jaIs, vector<Index> &joIs)
224 {
225  if(joah->_m_length > 1)
226  {
227  jaIs.push_back(joah->_m_jaI);
228  joIs.push_back(joah->_m_joI);
229  }
230  if(joah->_m_pred!=NULL)
231  GetJointActionObservationHistoryVectorsRecursive(joah->_m_pred,
232  jaIs,joIs);
233 }
234 
235 */