MultiAgentDecisionProcess  Release 0.2.1
JointActionDiscrete.cpp
Go to the documentation of this file.
1 
28 #include "JointActionDiscrete.h"
29 #include "ActionDiscrete.h"
30 
31 using namespace std;
32 
33 #define DEBUG_JAD 0
34 
35 //Default constructor
37  DiscreteEntity(index)
38 {
39 }
40 
42  vector<const ActionDiscrete*> a) :
43  DiscreteEntity(index),
44  _m_apVector(a)
45 {
47 }
48 
49 //Copy assignment constructor.
52 {
53 if(DEBUG_JAD) cout << " cloning joint action ";
54 
55  vector<const ActionDiscrete*>::const_iterator itp = o._m_apVector.begin();
56  vector<const ActionDiscrete*>::const_iterator lastp = o._m_apVector.end();
57  while(itp != lastp)
58  {
59  const ActionDiscrete* t = *itp;
60  _m_apVector.push_back(t);
61  itp++;
62  }
64 }
65 
66 //Destructor
68 {
69 if(DEBUG_JAD) cout << "deleting joint action";
70 
71 /* Do not delete the individual actions that are pointed to (there is only
72  * one copy of those, so that will lead to segfaults)
73  for(Index i=0; i<_m_apVector.size(); i++)
74  delete _m_apVector[i];*/
75 
76  _m_apVector.clear();
77 }
78 
80 {
81  for(vector<const ActionDiscrete*>::size_type i=0; i<_m_apVector.size(); i++)
82  delete _m_apVector[i];
83 }
84 
86  Index agentI)
87 {
88  if( static_cast< vector<const ActionDiscrete*>::size_type >(agentI) !=
89  _m_apVector.size() )
90  {
91  stringstream ss;
92  ss << "WARNING! AddIndividualAction: size of _m_apVector does not match index of agent!\n _m_apVector.size()="
93  << _m_apVector.size()<<" - agentI="<<agentI;
94  throw(E(ss));
95  }
96  _m_apVector.push_back(a);
97  _m_aIndexVector.push_back(a->GetIndex());
98 }
99 
101 {
102  stringstream ss;
103  vector<const ActionDiscrete*>::const_iterator it = _m_apVector.begin();
104  vector<const ActionDiscrete*>::const_iterator last = _m_apVector.end();
105 
106  ss << "JA" << GetIndex();
107 
108  while(it != last)
109  {
110  if(*it != 0)
111  ss << "_" << (*it)->SoftPrintBrief();
112  it++;
113  }
114  return(ss.str());
115 }
116 
118 {
119  stringstream ss;
120  vector<const ActionDiscrete*>::const_iterator it = _m_apVector.begin();
121  vector<const ActionDiscrete*>::const_iterator last = _m_apVector.end();
122 
123  while(it != last)
124  {
125  if(*it != 0)
126  ss << (*it)->SoftPrintBrief();
127  if(it != last-1)
128  ss << "_";
129  it++;
130  }
131  return(ss.str());
132 }
133 
135 {
136  vector<Index> iv;
137  vector<const ActionDiscrete*>::const_iterator it = _m_apVector.begin();
138  vector<const ActionDiscrete*>::const_iterator last = _m_apVector.end();
139  while(it != last)
140  {
141 
142  Index index = (*it)->GetIndex();
143  iv.push_back( index );
144  it++;
145  }
146  return(iv);
147 }