MultiAgentDecisionProcess
Release 0.2.1
Main Page
Namespaces
Classes
Files
File List
File Members
AgentBG.cpp
Go to the documentation of this file.
1
28
#include "
AgentBG.h
"
29
#include <float.h>
30
#include "
PlanningUnitDecPOMDPDiscrete.h
"
31
#include "
PerseusBGPlanner.h
"
32
#include "
BayesianGameIdenticalPayoff.h
"
33
#include "
JointPolicyPureVector.h
"
34
#include "
QFunctionJAOHInterface.h
"
35
36
using namespace
std;
37
38
#define DEBUG_AgentBG 0
39
40
AgentBG::AgentBG
(
const
PlanningUnitDecPOMDPDiscrete
&pu,
Index
id
,
41
QAV<PerseusBGPlanner>
*
QBG
) :
42
AgentDelayedSharedObservations
(pu,id),
43
_m_QBG(QBG),
44
_m_t(0)
45
{
46
_m_bgip
=
new
BayesianGameIdenticalPayoff
(pu.
GetNrAgents
(),
47
pu.
GetReferred
()->
GetNrActions
(),
48
pu.
GetReferred
()->
49
GetNrObservations());
50
_m_jpol
=
new
JointPolicyPureVector
(*
_m_bgip
);
51
#if DEBUG_AgentBG
52
cout <<
GetIndex
() <<
" "
<<_m_jpol->
SoftPrint
() << endl;
53
#endif
54
}
55
56
AgentBG::AgentBG
(
const
AgentBG
& a) :
57
AgentDelayedSharedObservations
(a),
58
_m_QBG(a._m_QBG),
// share the QBG, just copy the pointer
59
_m_t(a._m_t),
60
_m_prevJB(a._m_prevJB),
61
_m_oIs(a._m_oIs),
62
_m_prevJoIs(a._m_prevJoIs),
63
_m_prevJaIs(a._m_prevJaIs),
64
_m_aIs(a._m_aIs),
65
_m_jaIfirst(a._m_jaIfirst)
66
{
67
_m_bgip
=
new
BayesianGameIdenticalPayoff
(*a.
_m_bgip
);
68
_m_jpol
=
new
JointPolicyPureVector
(*a.
_m_jpol
);
69
}
70
71
//Destructor
72
AgentBG::~AgentBG
()
73
{
74
delete
_m_bgip
;
75
delete
_m_jpol
;
76
}
77
78
Index
AgentBG::Act
(
Index
oI,
Index
prevJoI)
79
{
80
int
betaMaxI=INT_MAX;
81
Index
aI=INT_MAX;
82
83
_m_oIs
.push_back(oI);
84
_m_prevJoIs
.push_back(prevJoI);
85
86
#if DEBUG_AgentBG
87
// cout << " oIs "; PrintVectorCout(_m_oIs);
88
// cout << " prevJoIs "; PrintVectorCout(_m_prevJoIs);
89
#endif
90
91
switch
(
_m_t
)
92
{
93
case
0:
// we know joint belief at t=0, namely the ISD, so we can
94
// use the POMDP action
95
{
96
JointBeliefInterface
* jbi =
GetPU
()->
GetNewJointBeliefFromISD
();
97
Index
ja=
GetMaximizingActionIndex
(*jbi);
98
delete
jbi;
99
vector<Index> aIs=
GetPU
()->
JointToIndividualActionIndices
(ja);
100
aI=aIs[
GetIndex
()];
101
_m_jaIfirst
=ja;
102
#if DEBUG_AgentBG
103
cout <<
GetIndex
() <<
": ja "
<< ja <<
" aI "
<< aI << endl;
104
#endif
105
break
;
106
}
107
case
1:
// at t=1, the previous joint belief is the ISD, but now
108
// we use the BG policy
109
{
110
JointBeliefInterface
* jbi =
GetPU
()->
GetNewJointBeliefFromISD
();
111
betaMaxI=
GetMaximizingBGIndex
(*jbi);
112
delete
jbi;
113
114
_m_jpol
->
SetIndex
(betaMaxI);
115
aI=
_m_jpol
->
GetActionIndex
(
GetIndex
(),oI);
116
break
;
117
}
118
case
2:
// now we start updating the previous joint beliefs, using
119
// the joint action we took at t=0
120
{
121
_m_prevJB
.
Update
(*
GetPU
()->GetReferred(),
_m_jaIfirst
,prevJoI);
122
123
betaMaxI=
GetMaximizingBGIndex
(
_m_prevJB
);
124
125
_m_jpol
->
SetIndex
(betaMaxI);
126
aI=
_m_jpol
->
GetActionIndex
(
GetIndex
(),oI);
127
break
;
128
}
129
default
:
// the rest of the time we use the previous BG jpol to
130
// get the joint action to update the joint belief
131
{
132
_m_prevJB
.
Update
(*
GetPU
()->GetReferred(),
_m_jpol
->
GetJointActionIndex
(prevJoI),
133
prevJoI);
134
135
betaMaxI=
GetMaximizingBGIndex
(
_m_prevJB
);
136
137
_m_jpol
->
SetIndex
(betaMaxI);
138
aI=
_m_jpol
->
GetActionIndex
(
GetIndex
(),oI);
139
break
;
140
}
141
}
142
143
_m_t
++;
144
145
_m_aIs
.push_back(aI);
146
147
#if DEBUG_AgentBG
148
// cout << GetIndex() << ": t " << _m_t << " oI " << oI
149
// << " prevJoI " << prevJoI << endl;
150
151
// cout << GetIndex() << ":";
152
// cout << " prevJaIs "; PrintVectorCout(_m_prevJaIs);
153
// cout << " aIs "; PrintVectorCout(_m_aIs);
154
// cout << endl;
155
156
#endif
157
158
return
(aI);
159
}
160
161
void
AgentBG::ResetEpisode
()
162
{
163
_m_t
=0;
164
165
JointBeliefInterface
* jbi =
GetPU
()->
GetNewJointBeliefFromISD
();
166
_m_prevJB
.
Set
(jbi->
Get
());
167
delete
jbi;
168
_m_oIs
.clear();
169
_m_prevJoIs
.clear();
170
_m_prevJaIs
.clear();
171
_m_aIs
.clear();
172
}
173
174
int
AgentBG::GetMaximizingBGIndex
(
const
JointBeliefInterface
&jb)
const
175
{
176
double
v=-DBL_MAX,q;
177
int
bI,betaMaxI=INT_MAX;
178
179
for
(
Index
a=0;a!=
GetPU
()->
GetNrJointActions
();++a)
180
{
181
q=
_m_QBG
->
GetQ
(jb,a,bI);
182
if
(q>v)
183
{
184
v=q;
185
betaMaxI=bI;
186
}
187
}
188
189
#if DEBUG_AgentBG
190
cout <<
"GetMaximizingBGIndex "
<<
GetIndex
() <<
": betaMaxI "
<< betaMaxI
191
<<
" "
<< jb.
SoftPrint
() << endl;
192
#endif
193
return
(betaMaxI);
194
}
195
196
Index
AgentBG::GetMaximizingActionIndex
(
const
JointBeliefInterface
&jb)
const
197
{
198
double
v=-DBL_MAX,q;
199
Index
ja=INT_MAX;
200
int
bI;
201
202
for
(
Index
a=0;a!=
GetPU
()->
GetNrJointActions
();++a)
203
{
204
q=
_m_QBG
->
GetQ
(jb,a,bI);
205
206
if
(q>v)
207
{
208
v=q;
209
ja=a;
210
}
211
}
212
213
return
(ja);
214
}
src
planning
AgentBG.cpp
Generated on Mon Sep 23 2013 14:50:05 for MultiAgentDecisionProcess by
1.8.1.2