MultiAgentDecisionProcess
Release 0.2.1
Main Page
Namespaces
Classes
Files
File List
File Members
QMDP.cpp
Go to the documentation of this file.
1
28
#include "
QMDP.h
"
29
#include "
JointActionObservationHistoryTree.h
"
30
#include "
JointBelief.h
"
31
#include "
JointBeliefSparse.h
"
32
33
using namespace
std;
34
35
//Default constructor
36
QMDP::QMDP
(
const
PlanningUnitDecPOMDPDiscrete
& pu,
37
bool
useJaohQValuesCache) :
38
QFunctionForDecPOMDP
(pu),
//virtual base first
39
QFunctionJAOH
(pu),
40
_m_initialized(false),
41
_m_useJaohQValuesCache(useJaohQValuesCache)
42
{
43
}
44
45
//Destructor
46
QMDP::~QMDP
()
47
{
48
DeInitialize
();
49
}
50
51
void
QMDP::Initialize
()
52
{
53
if
(
_m_useJaohQValuesCache
)
54
_m_QValues
.resize(
GetPU
()->GetNrJointActionObservationHistories(),
55
GetPU
()->GetNrJointActions(),
56
false
);
57
58
_m_p
=
new
MDPValueIteration
(*
GetPU
());
59
60
_m_initialized
=
true
;
61
}
62
63
void
QMDP::DeInitialize
()
64
{
65
delete
_m_p
;
66
_m_QValues
.clear();
67
_m_initialized
=
false
;
68
}
69
70
void
QMDP::SetPU
(
const
PlanningUnitDecPOMDPDiscrete
& pu)
71
{
72
DeInitialize
();
73
QFunctionJAOH::SetPU
(pu);
74
}
75
76
void
QMDP::Compute
()
77
{
78
if
(!
_m_initialized
)
79
Initialize
();
80
81
_m_p
->
Plan
();
82
83
if
(
_m_useJaohQValuesCache
)
84
CacheJaohQValues
();
85
}
86
87
void
QMDP::CacheJaohQValues
()
88
{
89
for
(
Index
jaohI=0;
90
jaohI!=
GetPU
()->
GetNrJointActionObservationHistories
();
91
++jaohI)
92
{
93
Index
t =
GetPU
()->
GetJointActionObservationHistoryTree
(jaohI)->
94
GetJointActionObservationHistory()->
GetLength
();
95
for
(
Index
jaI=0;jaI!=
GetPU
()->
GetNrJointActions
();++jaI)
96
_m_QValues
(jaohI,jaI)=
97
_m_p
->
GetQ
(t, *
GetPU
()->GetJointBeliefInterface(jaohI), jaI);
98
}
99
}
100
101
double
QMDP::GetQNoCache
(
Index
jaohI,
Index
jaI)
const
102
{
103
Index
t =
GetPU
()->
GetTimeStepForJAOHI
(jaohI);
104
//Index t = GetPU()->GetJointActionObservationHistoryTree(jaohI)->
105
//GetJointActionObservationHistory()->GetLength();
106
JointBeliefInterface
* jb =
GetPU
()->
GetJointBeliefInterface
(jaohI);
107
double
q =
_m_p
->
GetQ
(t, *jb, jaI);
108
delete
jb;
109
return
( q );
110
}
111
112
double
QMDP::GetQSA
(
Index
t,
Index
sI,
Index
jaI)
const
113
{
114
double
q =
_m_p
->
GetQ
(t, sI, jaI);
115
return
( q );
116
}
117
118
double
QMDP::GetQ
(
const
JointBeliefInterface
&b,
Index
jaI)
const
119
{
120
return
(
_m_p
->
GetQ
(b,jaI));
121
}
122
123
double
QMDP::GetQ
(
const
JointBeliefInterface
&b,
Index
time_step,
124
Index
jaI)
const
125
{
126
return
(
_m_p
->
GetQ
(time_step,b,jaI));
127
}
128
129
void
QMDP::Save
(
string
filename)
const
130
{
131
if
(
_m_useJaohQValuesCache
)
132
MDPSolver::SaveQTable
(
_m_QValues
,filename);
133
else
134
MDPSolver::SaveQTables
(
_m_p
->
GetQTables
(),filename);
135
}
136
137
void
QMDP::Load
(
string
filename)
138
{
139
if
(
_m_useJaohQValuesCache
)
140
_m_QValues
=
MDPSolver::LoadQTable
(filename,
141
GetPU
()->
142
GetNrJointActionObservationHistories(),
143
GetPU
()->GetNrJointActions());
144
else
145
_m_p
->
SetQTables
(
MDPSolver::LoadQTables
(filename,
146
GetPU
()->GetNrStates(),
147
GetPU
()->GetNrJointActions(),
148
GetPU
()->GetHorizon()));
149
}
src
planning
QMDP.cpp
Generated on Mon Sep 23 2013 14:50:06 for MultiAgentDecisionProcess by
1.8.1.2