MultiAgentDecisionProcess  Release 0.2.1
JointObservationDiscrete.cpp
Go to the documentation of this file.
1 
29 #include "ObservationDiscrete.h"
30 
31 using namespace std;
32 
33 #define DEBUG_JOD 0
34 
35 //Default constructor
37  DiscreteEntity(index)
38 {
39 }
40 
42  vector<const ObservationDiscrete*> a) :
43  DiscreteEntity(index),
44  _m_opVector(a)
45 
46 {
48 }
49 
50 //Copy assignment constructor.
54 {
55 if(DEBUG_JOD) cout << " cloning JointObservationDiscrete ";
56  vector<const ObservationDiscrete*>::const_iterator itp = o._m_opVector.begin();
57  vector<const ObservationDiscrete*>::const_iterator lastp = o._m_opVector.end();
58  while(itp != lastp)
59  {
60  const ObservationDiscrete* t = *itp;
61  _m_opVector.push_back(t);
62  itp++;
63  }
65 }
66 
67 //Destructor
69 {
70 if(DEBUG_JOD) cout << "deleting JointObservationDiscrete";
71 /* Do not delete the individual observations - only one copy of these, so
72  * would lead to segfaults.
73  for(Index i=0; i<_m_opVector.size(); i++)
74  delete _m_opVector[i];*/
75  _m_opVector.clear();
76 }
77 
79 {
80  if (agentI != _m_opVector.size() )
81  cout << "WARNING! AddIndividualAction: size of _m_opVector does not match index of agent!\n _m_opVector.size()="<< _m_opVector.size()<<" - agentI="<<agentI<<endl;
82  _m_opVector.push_back(a);
83  _m_oIndexVector.push_back(a->GetIndex());
84 }
85 
87 {
88  stringstream ss;
89  vector<const ObservationDiscrete*>::const_iterator it = _m_opVector.begin();
90  vector<const ObservationDiscrete*>::const_iterator last = _m_opVector.end();
91 
92  ss << "JO" << GetIndex();
93 
94  while(it != last)
95  {
96  if(*it != 0)
97  ss << "_" << (*it)->SoftPrintBrief();
98  it++;
99  }
100  //ss << "(vector="<< PrintTools::SoftPrintVector(_m_oIndexVector) <<", size="
101  //<<_m_oIndexVector.size()<<")";
102  return(ss.str());
103 }
104 
106 {
107  stringstream ss;
108  vector<const ObservationDiscrete*>::const_iterator it = _m_opVector.begin();
109  vector<const ObservationDiscrete*>::const_iterator last = _m_opVector.end();
110 
111  while(it != last)
112  {
113  if(*it != 0)
114  ss << (*it)->SoftPrintBrief();
115  if(it != last-1)
116  ss << "_";
117 
118  it++;
119  }
120  return(ss.str());
121 }
122 
123 
125 {
126  vector<Index> iv;
127  vector<const ObservationDiscrete*>::const_iterator it = _m_opVector.begin();
128  vector<const ObservationDiscrete*>::const_iterator last = _m_opVector.end();
129 if(DEBUG_JOD){ cout << " JointObservationDiscrete::" <<
130  "GetIndividualObservationDiscretesIndices() _m_opVector size ="
131  << _m_opVector.size() << endl;
132 }
133  while(it != last)
134  {
135 
136  Index index = (*it)->GetIndex();
137  iv.push_back( index );
138  it++;
139  }
140  return(iv);
141 }