MultiAgentDecisionProcess
Release 0.2.1
Main Page
Namespaces
Classes
Files
File List
File Members
JointActionObservationHistoryTree.cpp
Go to the documentation of this file.
1
28
#include "
JointActionObservationHistoryTree.h
"
29
#include "
PlanningUnitMADPDiscrete.h
"
30
31
#define DEBUG_JAOHT 0
32
33
using namespace
std;
34
36
JointActionObservationHistoryTree::JointActionObservationHistoryTree
(
37
JointActionObservationHistory
*
const
oh,
aoh_t
nt) :
38
TreeNode
<
JointActionObservationHistory
> (oh)
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
*/
65
void
JointActionObservationHistoryTree::SetIndex
(
Index
i)
66
{
67
if
(
_m_nodeType
==
O_SUC
)
68
throw
E
(
"Trying JointActionObservationHistoryTree::SetIndex on O_SUC node"
);
69
70
this->
TreeNode<JointActionObservationHistory>::SetIndex
(i);
71
/* _m_index = i;
72
_m_indexValid = true; */
73
};
74
75
void
JointActionObservationHistoryTree::SetSuccessor
(
Index
aI,
Index
oI,
76
JointActionObservationHistoryTree
* suc)
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
82
JointActionObservationHistoryTree
* oNode;
83
if
(this->
TreeNode<JointActionObservationHistory>::ExistsSuccessor
(aI))
84
oNode = (
JointActionObservationHistoryTree
*)
85
this->
TreeNode<JointActionObservationHistory>::GetSuccessor
(aI);
86
else
//we need to create an intermediate node
87
{
88
oNode =
new
JointActionObservationHistoryTree
(
O_SUC
);
89
//which is the aI'th successor of this node
90
this->
TreeNode<JointActionObservationHistory>::SetSuccessor
(aI, oNode);
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
100
JointActionObservationHistoryTree
*
JointActionObservationHistoryTree::GetSuccessor
(
Index
aI,
Index
oI)
101
{
102
if
(
_m_nodeType
==
O_SUC
)
103
throw
E
(
"Trying JointActionObservationHistoryTree::SetSuccessor(Index aI, Index oI, JointActionObservationHistoryTree* suc) on O_SUC node"
);
104
105
JointActionObservationHistoryTree
* suc;
106
if
(this->
TreeNode<JointActionObservationHistory>::ExistsSuccessor
(aI) &&
107
this->
TreeNode<JointActionObservationHistory>::GetSuccessor
(aI)->
108
TreeNode<JointActionObservationHistory>::ExistsSuccessor
(oI))
109
// we only put JointActionObservationHistoryTree*'s in here so
110
// this cast should be allowed.
111
suc = (
JointActionObservationHistoryTree
*)
112
this->
TreeNode<JointActionObservationHistory>::GetSuccessor
(aI)
//oNode
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->
121
GetJointActionObservationHistory
();
122
JointActionObservationHistory
* next_jaoh =
123
new
JointActionObservationHistory
(aI, oI, jaoh);
124
125
JointActionObservationHistoryTree
* next_jaoht =
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
142
JointActionObservationHistoryTree
*
JointActionObservationHistoryTree::GetPredecessor
()
const
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
149
JointActionObservationHistoryTree
* pred =
150
//we only put JointActionObservationHistoryTree*'s in here so this cast
151
//should be allowed.
152
(
JointActionObservationHistoryTree
*)
153
this->
TreeNode<JointActionObservationHistory>::GetPredecessor
()
//=oNode
154
->TreeNode<JointActionObservationHistory>::GetPredecessor();
//pred.aNode
155
156
return
(pred);
157
}
158
159
160
JointActionObservationHistory
*
JointActionObservationHistoryTree::
161
GetJointActionObservationHistory
()
const
162
{
163
if
(
_m_nodeType
==
O_SUC
)
164
throw
E
(
"Trying JointActionObservationHistoryTree::GetJointActionObservationHistory() on O_SUC node"
);
165
166
return
GetContainedElement
();
167
}
168
169
void
JointActionObservationHistoryTree::Print
()
const
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 <<
" - "
;
182
_m_containedElem
->
Print
();
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:
196
JointActionObservationHistoryTree
* suc_jaoht =
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
}
src
support
JointActionObservationHistoryTree.cpp
Generated on Mon Sep 23 2013 14:50:06 for MultiAgentDecisionProcess by
1.8.1.2