MultiAgentDecisionProcess  Release 0.2.1
JointActionObservationHistoryTree.cpp
Go to the documentation of this file.
1 
30 
31 #define DEBUG_JAOHT 0
32 
33 using namespace std;
34 
37  JointActionObservationHistory * const oh, aoh_t nt) :
39 {
40  _m_nodeType = nt;
41 }
42 //Default constructor
43 /*
44 JointActionObservationHistoryTree::JointActionObservationHistoryTree()
45 {
46 }
47 
48 //Copy constructor.
49 JointActionObservationHistoryTree::JointActionObservationHistoryTree(const JointActionObservationHistoryTree& o)
50 {
51 }
52 //Destructor
53 JointActionObservationHistoryTree::~JointActionObservationHistoryTree()
54 {
55 }
56 //Copy assignment operator
57 JointActionObservationHistoryTree& JointActionObservationHistoryTree::operator= (const JointActionObservationHistoryTree& o)
58 {
59  if (this == &o) return *this; // Gracefully handle self assignment
60  // Put the normal assignment duties here...
61 
62  return *this;
63 }
64 */
66 {
67  if (_m_nodeType == O_SUC)
68  throw E("Trying JointActionObservationHistoryTree::SetIndex on O_SUC node");
69 
71 /* _m_index = i;
72  _m_indexValid = true; */
73 };
74 
77 {
78  if (_m_nodeType == O_SUC)
79  throw E("Trying JointActionObservationHistoryTree::SetSuccessor(Index aI, Index oI, JointActionObservationHistoryTree* suc) on O_SUC node");
80 
81  //first see if necessary to create a new intermediate node
86  else //we need to create an intermediate node
87  {
89  //which is the aI'th successor of this node
91  }
92 
93  //let oNode point to the actual successor.
94  //Note: SetSuccessor with 1 index should give no problem for O_SUC nodes
95  oNode->TreeNode<JointActionObservationHistory>::SetSuccessor(oI, suc);
96 }
97 
101 {
102  if (_m_nodeType == O_SUC)
103  throw E("Trying JointActionObservationHistoryTree::SetSuccessor(Index aI, Index oI, JointActionObservationHistoryTree* suc) on O_SUC node");
104 
109  // we only put JointActionObservationHistoryTree*'s in here so
110  // this cast should be allowed.
113  ->TreeNode<JointActionObservationHistory>::GetSuccessor(oI);
114  else
115  {
116  // successor does not exist, so let's create it, as we would
117  // in
118  // PlanningUnitMADPDiscrete::CreateJointActionObservationHistories
119 
120  JointActionObservationHistory* jaoh = this->
122  JointActionObservationHistory* next_jaoh =
123  new JointActionObservationHistory(aI, oI, jaoh);
124 
126  new JointActionObservationHistoryTree(next_jaoh);
127 
128  this->SetSuccessor(aI, oI, next_jaoht);
129 
130  next_jaoht->SetIndex(next_jaoh->GetReferred()->
131  GetSuccessorJAOHI(this->GetIndex(),aI,oI));
132  // stores the pointer in the big reference vector
133  next_jaoh->GetReferred()->
134  RegisterJointActionObservationHistoryTree(next_jaoht);
135 
136  suc=next_jaoht;
137  }
138 
139  return(suc);
140 }
141 
143 {
144  if (GetLength()==0) //ts 0 - length 0 NO INITIAL OBSERVATIONS
145  throw E("Trying JointActionObservationHistoryTree::SetPredeccessor() on root node. (no predecessor)");
146  if (_m_nodeType == O_SUC)
147  throw E("Trying JointActionObservationHistoryTree::GetPredecessor() on O_SUC node");
148 
150  //we only put JointActionObservationHistoryTree*'s in here so this cast
151  //should be allowed.
154  ->TreeNode<JointActionObservationHistory>::GetPredecessor();//pred.aNode
155 
156  return(pred);
157 }
158 
159 
162 {
163  if (_m_nodeType == O_SUC)
164  throw E("Trying JointActionObservationHistoryTree::GetJointActionObservationHistory() on O_SUC node");
165 
166  return GetContainedElement();
167 }
168 
170 {
171  if(_m_nodeType == A_SUC)
172  {
173  if(_m_containedElem == 0)
174  return;
175 
176  cout << "index: ";
177  if(_m_indexValid)
178  cout<< _m_index;
179  else
180  cout << "INVALID";
181  cout << " - ";
183  cout <<endl;
184 
185  }
186  //in both cases (also if _m_nodeType == O_SUC)
187 
188  map< Index, TreeNode<JointActionObservationHistory>*>::const_iterator
189  it = _m_successor.begin();
190  while(it != _m_successor.end())
191  {
192  pair< Index, TreeNode<JointActionObservationHistory>*> p = *it;
193  TreeNode<JointActionObservationHistory>* suc_tn = p.second;
194  //we only put JointActionObservationHistoryTree's as successors, so
195  //we can do this:
197  static_cast<JointActionObservationHistoryTree*>(suc_tn);
198  if(suc_jaoht != 0)
199  suc_jaoht->Print();
200  else
201  throw E("JointActionObservationHistoryTree::Print() - encountered"\
202 "a successor of this JointActionObservationHistoryTree that is 0 (NULL) ");
203 
204  it++;
205  }
206 }