MultiAgentDecisionProcess  Release 0.2.1
ActionObservationHistoryTree.cpp
Go to the documentation of this file.
1 
29 
30 #define DEBUG_AOHT 0
31 
32 using namespace std;
33 
36  ActionObservationHistory * const oh, aoh_t nt) :
38 {
39  _m_nodeType = nt;
40 }
41 //Copy constructor.
45 {
46 }
47 
49 {
50  if (_m_nodeType == O_SUC)
51  throw E("Trying ActionObservationHistoryTree::SetIndex on O_SUC node");
52 
54 };
55 
58 {
59  if (_m_nodeType == O_SUC)
60  throw E("Trying ActionObservationHistoryTree::SetSuccessor(Index aI, Index oI, ActionObservationHistoryTree* suc) on O_SUC node");
61 
62  //first see if necessary to create a new intermediate node
67  else //we need to create an intermediate node
68  {
70 
71  //which is the aI'th successor of this node
73  }
74 
75  //let oNode point to the actual successor.
76  //Note: SetSuccessor with 1 index should give no problem for O_SUC nodes
77  oNode->TreeNode<ActionObservationHistory>::SetSuccessor(oI, suc);
78 }
79 
81  aI, Index oI)
82 {
83  if (_m_nodeType == O_SUC)
84  throw E("Trying ActionObservationHistoryTree::SetSuccessor(Index aI, Index oI, ActionObservationHistoryTree* suc) on O_SUC node");
85 
87  try {
89  //we only put ActionObservationHistoryTree*'s in here so this cast
90  //should be allowed.
92  ->TreeNode<ActionObservationHistory>::GetSuccessor(oI);
93  } catch(EInvalidIndex& e) {
94  // successor does not exist, so we should create it, see
95  // JointActionObservationHistoryTree::GetSuccessor for
96  // inspiration
97  throw(E("ActionObservationHistoryTree::GetSuccessor generation of successors on the fly not yet implemented"));
98  }
99 
100  return(suc);
101 }
102 
105 {
106  if (_m_nodeType == O_SUC)
107  throw E("Trying ActionObservationHistoryTree::GetActionObservationHistory() on O_SUC node");
108 
109  return GetContainedElement();
110 }
111 
113 {
114  if(_m_nodeType == A_SUC)
115  {
116  if(_m_containedElem == 0)
117  return;
118 
119  cout << "index: ";
120  if(_m_indexValid)
121  cout<< _m_index;
122  else
123  cout << "INVALID";
124  cout << " - ";
126  cout <<endl;
127  }
128  //else //if (_m_nodeType == O_SUC)
129 
130  map< Index, TreeNode<ActionObservationHistory>*>::const_iterator
131  it = _m_successor.begin();
132  while(it != _m_successor.end())
133  {
134  pair< Index, TreeNode<ActionObservationHistory>*> p = *it;
135  TreeNode<ActionObservationHistory>* suc_tn = p.second;
136  //we only put ActionObservationHistoryTree's as successors, so
137  //we can do this:
138  ActionObservationHistoryTree* suc_aoht =
139  static_cast<ActionObservationHistoryTree*>(suc_tn);
140  if(suc_aoht != 0)
141  suc_aoht->Print();
142  else
143  throw E("ActionObservationHistoryTree::Print() - encountered"\
144 "a successor of this ActionObservationHistoryTree that is 0 (NULL) ");
145 
146  it++;
147  }
148 
149 }
150