MultiAgentDecisionProcess
Release 0.2.1
Main Page
Namespaces
Classes
Files
File List
File Members
ActionObservationHistoryTree.cpp
Go to the documentation of this file.
1
28
#include "
ActionObservationHistoryTree.h
"
29
30
#define DEBUG_AOHT 0
31
32
using namespace
std;
33
35
ActionObservationHistoryTree::ActionObservationHistoryTree
(
36
ActionObservationHistory
*
const
oh,
aoh_t
nt) :
37
TreeNode
<
ActionObservationHistory
> (oh)
38
{
39
_m_nodeType
= nt;
40
}
41
//Copy constructor.
42
ActionObservationHistoryTree::
43
ActionObservationHistoryTree
(
const
ActionObservationHistoryTree
& o) :
44
TreeNode
<
ActionObservationHistory
>(o)
45
{
46
}
47
48
void
ActionObservationHistoryTree::SetIndex
(
Index
i)
49
{
50
if
(
_m_nodeType
==
O_SUC
)
51
throw
E
(
"Trying ActionObservationHistoryTree::SetIndex on O_SUC node"
);
52
53
this->
TreeNode<ActionObservationHistory>::SetIndex
(i);
54
};
55
56
void
ActionObservationHistoryTree::SetSuccessor
(
Index
aI,
Index
oI,
57
ActionObservationHistoryTree
* suc)
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
63
ActionObservationHistoryTree
* oNode;
64
if
(this->
TreeNode<ActionObservationHistory>::ExistsSuccessor
(aI))
65
oNode = (
ActionObservationHistoryTree
*)
66
this->
TreeNode<ActionObservationHistory>::GetSuccessor
(aI);
67
else
//we need to create an intermediate node
68
{
69
oNode =
new
ActionObservationHistoryTree
(
O_SUC
);
70
71
//which is the aI'th successor of this node
72
this->
TreeNode<ActionObservationHistory>::SetSuccessor
(aI, oNode);
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
80
ActionObservationHistoryTree
*
ActionObservationHistoryTree::GetSuccessor
(
Index
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
86
ActionObservationHistoryTree
* suc;
87
try
{
88
suc = (
ActionObservationHistoryTree
*)
89
//we only put ActionObservationHistoryTree*'s in here so this cast
90
//should be allowed.
91
this->
TreeNode<ActionObservationHistory>::GetSuccessor
(aI)
//the oNode
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
103
ActionObservationHistory
*
ActionObservationHistoryTree::
104
GetActionObservationHistory
()
const
105
{
106
if
(
_m_nodeType
==
O_SUC
)
107
throw
E
(
"Trying ActionObservationHistoryTree::GetActionObservationHistory() on O_SUC node"
);
108
109
return
GetContainedElement
();
110
}
111
112
void
ActionObservationHistoryTree::Print
()
const
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 <<
" - "
;
125
_m_containedElem
->
Print
();
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
src
support
ActionObservationHistoryTree.cpp
Generated on Mon Sep 23 2013 14:50:06 for MultiAgentDecisionProcess by
1.8.1.2