aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
structuredPlaner.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49
50// =========================================================================
51#ifndef GUM_STRUCTURED_PLANNING_H
52#define GUM_STRUCTURED_PLANNING_H
53// =========================================================================
54#include <thread>
55// =========================================================================
56// =========================================================================
57// =========================================================================
61
62// =========================================================================
63
64namespace gum {
65
81 template < typename GUM_ELEMENT >
82 class StructuredPlaner: public IPlanningStrategy< GUM_ELEMENT > {
83 // ###################################################################
85 // ###################################################################
87
88 public:
89 // ==========================================================================
91 // ==========================================================================
92 static StructuredPlaner< GUM_ELEMENT >* spumddInstance(GUM_ELEMENT discountFactor = 0.9,
93 GUM_ELEMENT epsilon = 0.00001,
94 bool verbose = true);
95
96 // ==========================================================================
98 // ==========================================================================
99 static StructuredPlaner< GUM_ELEMENT >* sviInstance(GUM_ELEMENT discountFactor = 0.9,
100 GUM_ELEMENT epsilon = 0.00001,
101 bool verbose = true);
102
104
105 // ###################################################################
107 // ###################################################################
109
110 protected:
111 // ==========================================================================
113 // ==========================================================================
115 GUM_ELEMENT discountFactor,
116 GUM_ELEMENT epsilon,
117 bool verbose);
118
119 // ==========================================================================
121 // ==========================================================================
122
123 public:
124 ~StructuredPlaner() override;
125
127
128 // ###################################################################
130 // ###################################################################
132
133 public:
134 // ==========================================================================
137 // ==========================================================================
138 const FMDP< GUM_ELEMENT >* fmdp();
139
140 // ==========================================================================
142 // ==========================================================================
144
145 // ==========================================================================
147 // ==========================================================================
148 Size vFunctionSize() override;
149
150 // ==========================================================================
152 // ==========================================================================
154
155 // ==========================================================================
157 // ==========================================================================
158 Size optimalPolicySize() override;
159
160 // ==========================================================================
164 // ==========================================================================
165 std::string optimalPolicy2String() override;
166
168
169
170 // ###################################################################
172 // ###################################################################
174
175 public:
176 // ==========================================================================
182 // ==========================================================================
183 void initialize(const FMDP< GUM_ELEMENT >* fmdp) override;
184
185
186 // ==========================================================================
195 // ==========================================================================
196 void makePlanning(Idx nbStep = 1000000) override;
197
199
200
201 // ###################################################################
203 // ###################################################################
205
206 protected:
207 // ==========================================================================
209 // ==========================================================================
210 virtual void initVFunction_();
211
212 // ==========================================================================
214 // ==========================================================================
216
217 // ==========================================================================
219 // ==========================================================================
222
223 // ==========================================================================
226 // ==========================================================================
229
230 // ==========================================================================
233 // ==========================================================================
236
237 // ==========================================================================
240 // ==========================================================================
242 addReward_(MultiDimFunctionGraph< GUM_ELEMENT >* function, Idx actionId = 0);
243
245
246
247 // ###################################################################
249 // ###################################################################
251
252 protected:
253 // ==========================================================================
255 // ==========================================================================
256 virtual void evalPolicy_();
257
258 // ==========================================================================
269 // ==========================================================================
271 makeArgMax_(const MultiDimFunctionGraph< GUM_ELEMENT >* Qaction, Idx actionId);
272
273 private:
274 // ==========================================================================
276 // ==========================================================================
278 NodeId,
279 Idx,
283
284 protected:
285 // ==========================================================================
288 // ==========================================================================
292
293 // ==========================================================================
298 // ==========================================================================
301 optimalValueFunction);
302
303 private:
304 // ==========================================================================
306 // ==========================================================================
308 NodeId,
311
312 // ==========================================================================
314 // ==========================================================================
316
317
319
320 protected:
321 // ==========================================================================
325 // ==========================================================================
327
328 // ==========================================================================
330 // ==========================================================================
332
333 // ==========================================================================
340 // ==========================================================================
342
343 // ==========================================================================
345 // ==========================================================================
347
348 // ==========================================================================
350 // ==========================================================================
351 GUM_ELEMENT discountFactor_;
352
354
355 // ==========================================================================
358 // ==========================================================================
360
361
362 private:
363 // ==========================================================================
366 // ==========================================================================
367 GUM_ELEMENT _threshold_;
369 };
370
371} /* namespace gum */
372
374
375#endif // GUM_STRUCTURED_PLANNING_H
Headers of the Planning Strategy interface.
A class to store the optimal actions.
Definition actionSet.h:98
Class to handle efficiently argMaxSet.
Definition argMaxSet.h:78
This class is used to implement factored decision process.
Definition fmdp.h:75
<agrum/FMDP/SDyna/IOperatorStrategy.h>
<agrum/FMDP/SDyna/IPlanningStrategy.h>
Class implementingting a function graph.
Implementation of a Terminal Node Policy that maps nodeid to a set of value.
GUM_ELEMENT _threshold_
The threshold value Whenever | V^{n} - V^{n+1} | < threshold, we consider that V ~ V*.
virtual MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > * argmaximiseQactions_(std::vector< MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > * > &)
Performs argmax_a Q(s,a).
Size optimalPolicySize() override
Returns optimalPolicy computed so far current size.
const FMDP< GUM_ELEMENT > * fmdp()
Returns a const ptr on the Factored Markov Decision Process on which we're planning.
NodeId _recurExtractOptPol_(NodeId, const MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > *, HashTable< NodeId, NodeId > &)
Recursion part for the createArgMaxCopy.
gum::VariableSet elVarSeq_
A Set to eleminate primed variables.
void initialize(const FMDP< GUM_ELEMENT > *fmdp) override
Initializes data structure needed for making the planning.
GUM_ELEMENT discountFactor_
Discount Factor used for infinite horizon planning.
void _transferActionIds_(const ArgMaxSet< GUM_ELEMENT, Idx > &, ActionSet &)
Extract from an ArgMaxSet the associated ActionSet.
virtual void evalPolicy_()
Perform the required tasks to extract an optimal policy.
IOperatorStrategy< GUM_ELEMENT > * operator_
void extractOptimalPolicy_(const MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > *optimalValueFunction)
From V(s)* = argmax_a Q*(s,a), this function extract pi*(s) This function mainly consists in extracti...
void makePlanning(Idx nbStep=1000000) override
Performs a value iteration.
virtual MultiDimFunctionGraph< GUM_ELEMENT > * addReward_(MultiDimFunctionGraph< GUM_ELEMENT > *function, Idx actionId=0)
Perform the R(s) + gamma . function.
MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > * makeArgMax_(const MultiDimFunctionGraph< GUM_ELEMENT > *Qaction, Idx actionId)
Creates a copy of given Qaction that can be exploit by a Argmax.
std::string optimalPolicy2String() override
Provide a better toDot for the optimal policy where the leaves have the action name instead of its id...
const MultiDimFunctionGraph< GUM_ELEMENT > * vFunction()
Returns a const ptr on the value function computed so far.
MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * optimalPolicy() override
Returns the best policy obtained so far.
bool verbose_
Boolean used to indcates whether or not iteration informations should be displayed on terminal.
const FMDP< GUM_ELEMENT > * fmdp_
The Factored Markov Decision Process describing our planning situation (NB : this one must have funct...
static StructuredPlaner< GUM_ELEMENT > * spumddInstance(GUM_ELEMENT discountFactor=0.9, GUM_ELEMENT epsilon=0.00001, bool verbose=true)
static StructuredPlaner< GUM_ELEMENT > * sviInstance(GUM_ELEMENT discountFactor=0.9, GUM_ELEMENT epsilon=0.00001, bool verbose=true)
virtual MultiDimFunctionGraph< GUM_ELEMENT > * minimiseFunctions_(std::vector< MultiDimFunctionGraph< GUM_ELEMENT > * > &)
Performs min_i F_i.
StructuredPlaner(IOperatorStrategy< GUM_ELEMENT > *opi, GUM_ELEMENT discountFactor, GUM_ELEMENT epsilon, bool verbose)
Default constructor.
Size vFunctionSize() override
Returns vFunction computed so far current size.
MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * optimalPolicy_
The associated optimal policy.
MultiDimFunctionGraph< GUM_ELEMENT > * vFunction_
The Value Function computed iteratively.
virtual MultiDimFunctionGraph< GUM_ELEMENT > * evalQaction_(const MultiDimFunctionGraph< GUM_ELEMENT > *, Idx)
Performs the P(s'|s,a).V^{t-1}(s') part of the value itération.
virtual void initVFunction_()
Performs a single step of value iteration.
virtual MultiDimFunctionGraph< GUM_ELEMENT > * maximiseQactions_(std::vector< MultiDimFunctionGraph< GUM_ELEMENT > * > &)
Performs max_a Q(s,a).
virtual MultiDimFunctionGraph< GUM_ELEMENT > * valueIteration_()
Performs a single step of value iteration.
NodeId _recurArgMaxCopy_(NodeId, Idx, const MultiDimFunctionGraph< GUM_ELEMENT > *, MultiDimFunctionGraph< ArgMaxSet< GUM_ELEMENT, Idx >, SetTerminalNodePolicy > *, HashTable< NodeId, NodeId > &)
Recursion part for the createArgMaxCopy.
~StructuredPlaner() override
Default destructor.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
Headers of the MDDOperatorStrategy planer class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
Template implementation of FMDP/planning/StructuredPlaner.h classes.
Headers of the TreeOperatorStrategy planer class.