MultiAgentDecisionProcess
Release 0.2.1
Main Page
Namespaces
Classes
Files
File List
File Members
JointActionHistory.cpp
Go to the documentation of this file.
1
28
#include "
JointActionHistory.h
"
29
#include "
JointAction.h
"
30
//Necessary as header file contains a forward declaration:
31
#include "
PlanningUnitMADPDiscrete.h
"
32
33
using namespace
std;
34
35
#define DEBUG_JOH 0
36
37
//Default constructor
38
JointActionHistory::JointActionHistory
(
PlanningUnitMADPDiscrete
& pu) :
39
Referrer
<
PlanningUnitMADPDiscrete
>(pu)
40
{
41
SetLength
(0);
42
_m_jointActionI
= 0;
43
_m_isEmpty
=
true
;
44
_m_pred
= 0;
45
size_t
nrAgents = pu.
GetNrAgents
();
46
_m_individualActionHistories
= vector<Index>(nrAgents,0);
47
}
48
JointActionHistory::JointActionHistory
(
PlanningUnitMADPDiscrete
& pu,
49
Index
jObsI)
50
{
51
throw
E
(
"JointActionHistory::JointActionHistory(Index obsI) not yet implemented - non-empty initial actions not yet supported."
);
52
}
53
54
JointActionHistory::JointActionHistory
(
Index
jaI,
55
JointActionHistory
* pred) :
56
Referrer
<
PlanningUnitMADPDiscrete
>( pred->GetReferred() )
57
{
58
SetLength
(pred->
GetLength
() + 1);
59
_m_jointActionI
= jaI;
60
_m_isEmpty
=
false
;
61
_m_pred
= pred;
62
size_t
nrAgents = pred->
_m_individualActionHistories
.size();
63
64
vector<Index> indivActionIndices =
GetReferred
()->
65
JointToIndividualActionIndices(jaI);
66
67
for
(
Index
aI=0; aI < nrAgents; aI++)
68
{
69
//get previous history index for agent ai
70
Index
predOHindex_ai = pred->
_m_individualActionHistories
[aI];
71
//get the corresponding previous history
72
//ActionHistoryTree* oht_ai = GetReferred()->
73
//GetActionHistoryTree(aI, predOHindex_ai);
74
//get the successor for the action taken by ai
75
//Index sucOHindex_ai = oht_ai->GetSuccessor(indivActionIndices[aI])->
76
//GetIndex();
77
//and store it...
78
Index
sucOHindex_ai =
79
GetReferred
()
//=PlanningUnitMADPDiscrete
80
-> GetSuccessorAHI(aI,
81
predOHindex_ai, indivActionIndices[aI] ) ;
82
83
_m_individualActionHistories
.push_back(sucOHindex_ai);
84
}
85
86
}
87
88
//Copy assignment constructor.
89
JointActionHistory::JointActionHistory
(
const
JointActionHistory
& o)
90
{
91
if
(
DEBUG_JOH
){ cout <<
"Cloning JointActionHistory: "
;
92
Print
(); cout <<endl;}
93
}
94
//Destructor
95
JointActionHistory::~JointActionHistory
()
96
{
97
if
(
DEBUG_JOH
){ cout <<
"Deleting JointActionHistory: "
;
98
Print
(); cout <<endl;}
99
100
// _m_individualActionHistories.clear();
101
}
102
103
const
vector<Index>&
JointActionHistory::GetIndividualActionHistoryIndices
()
const
104
{
105
return
(
_m_individualActionHistories
);
106
}
107
108
string
JointActionHistory::SoftPrint
()
const
109
{
110
stringstream ss;
111
if
(
_m_pred
!= 0)
112
{
113
//if the predec. is the empty action sequence (with length 0)
114
//we don't want to print this. (and this is the case when
115
//this action history has length 1)
116
if
(
_m_length
>= 1)
// action histories of length 1 have a pred.
117
ss <<
_m_pred
->
SoftPrint
();
118
else
if
(
_m_length
< 1)
119
{
120
ss <<
"JointActionHistory:Print() - Warning:_m_pred != "
<<
121
"null, but lenght < 1 !"
<<endl;
122
throw
E
(ss);
123
}
124
//else length == 1 and we simply skip
125
}
126
127
if
(!
_m_isEmpty
)
// don't print the empty action
128
{
129
// GetReferred()->GetJointActionDiscrete(
130
ss <<
GetReferred
()->
GetJointAction
(
131
_m_jointActionI
)->
SoftPrintBrief
();
132
}
133
else
134
ss <<
"EMPTY_JAH"
;
135
return
(ss.str());
136
}
src
support
JointActionHistory.cpp
Generated on Mon Sep 23 2013 14:50:06 for MultiAgentDecisionProcess by
1.8.1.2