aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
fmdp.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#ifndef GUM_FACTORED_MARKOV_DECISION_PROCESS_H
50#define GUM_FACTORED_MARKOV_DECISION_PROCESS_H
51//======================================================================
52#include <string>
53#include <vector>
54
55#include <string_view>
56//======================================================================
57//======================================================================
59
60//======================================================================
61
62namespace gum {
73
74 template < typename GUM_ELEMENT >
75 class FMDP {
76 template < typename GUM_ELEMENT_O >
79
80 public:
81 // ===========================================================================
83 // ===========================================================================
85
89 FMDP(bool onDestructionDeleteVar = false);
90
94 ~FMDP();
95
97
98 // ===========================================================================
100 // ===========================================================================
102
107 void addVariable(const DiscreteVariable* var);
108
113
118
122 const DiscreteVariable* main2prime(const DiscreteVariable* mainVar) const;
123
128
130
131 // ===========================================================================
133 // ===========================================================================
135
140 void addAction(Idx actionId, std::string_view action);
141
146
151
153
154 // ===========================================================================
156 // ===========================================================================
158
166 const DiscreteVariable* var,
168
174 void addTransition(const DiscreteVariable* var,
176
182 const DiscreteVariable* v) const;
183
185
186 // ===========================================================================
188 // ===========================================================================
190
196
202
207
209
210 // ===========================================================================
212 // ===========================================================================
214
220
226
231
233
234 // ===========================================================================
236 // ===========================================================================
238
242 const std::string& actionName(Idx actionId) const;
243
247 Idx actionId(std::string_view) const;
248
252 std::string toString() const;
253
257 Size size() const;
258
264
268 void setDiscount(GUM_ELEMENT discount);
269
273 GUM_ELEMENT discount() const;
274
276
277 private:
282
285
288
292
295
298
304 GUM_ELEMENT _discount_{GUM_ELEMENT(1)};
305 };
306
307
308#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
309 extern template class FMDP< double >;
310#endif
311
312
313} /* namespace gum */
314
315#include <agrum/FMDP/fmdp_tpl.h>
316
317#endif // GUM_FACTORED_MARKOV_DECISION_PROCESS_H
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1640
Base class for discrete random variable.
Bijection< Idx, const std::string * > _actionMap_
Bijection mapping an action name to its id.
Definition fmdp.h:286
HashTable< Idx, const MultiDimImplementation< GUM_ELEMENT > * > _actionRewardTable_
Table which give for each action reward table.
Definition fmdp.h:296
void addRewardForAction(Idx actionId, const MultiDimImplementation< GUM_ELEMENT > *reward)
Adds a default variable reward.
Definition fmdp_tpl.h:288
void addVariable(const DiscreteVariable *var)
Adds a variable to FMDP description.
Definition fmdp_tpl.h:137
Size size() const
Returns the map binding main variables and prime variables.
Definition fmdp_tpl.h:377
void addCost(const MultiDimImplementation< GUM_ELEMENT > *cost)
Adds a default variable cost.
Definition fmdp_tpl.h:430
HashTable< Idx, const MultiDimImplementation< GUM_ELEMENT > * > _actionCostTable_
Table which give for each action cost table.
Definition fmdp.h:293
void setDiscount(GUM_ELEMENT discount)
Sets the discount factor.
Definition fmdp_tpl.h:445
void addTransitionForAction(Idx actionId, const DiscreteVariable *var, const MultiDimImplementation< GUM_ELEMENT > *transition)
Adds a variable transition table to specified action.
Definition fmdp_tpl.h:202
SequenceIteratorSafe< Idx > beginActions() const
Returns an iterator reference to he beginning of the list of actions.
Definition fmdp_tpl.h:414
FMDP(bool onDestructionDeleteVar=false)
Default constructor.
Definition fmdp_tpl.h:75
void addAction(Idx actionId, std::string_view action)
Adds an action to FMDP description.
Definition fmdp_tpl.h:164
void addCostForAction(Idx actionId, const MultiDimImplementation< GUM_ELEMENT > *cost)
Adds a cost table to specified action.
Definition fmdp_tpl.h:250
void setDeleteVariablesOnDestruction(bool b)
Transfers ownership of variables to this FMDP (they will be deleted on destruction).
Definition fmdp_tpl.h:440
Sequence< const DiscreteVariable * > _varSeq_
Sequence de variables and its iterator.
Definition fmdp.h:278
const DiscreteVariable * main2prime(const DiscreteVariable *mainVar) const
Returns the primed variable associate to the given main variable.
Definition fmdp_tpl.h:403
SequenceIteratorSafe< const DiscreteVariable * > beginVariables() const
Returns an iterator reference to he beginning of the list of variables.
Definition fmdp_tpl.h:393
Idx actionId(std::string_view) const
Returns action id.
Definition fmdp_tpl.h:336
SequenceIteratorSafe< Idx > endActions() const
Returns an iterator reference to the end of the list of actions.
Definition fmdp_tpl.h:419
void addReward(const MultiDimImplementation< GUM_ELEMENT > *reward)
Adds a default variable reward.
Definition fmdp_tpl.h:435
bool _onDestructionDeleteVars_
Boolean indicates whether or not main variables should be deleted on destruction of this instance Usu...
Definition fmdp.h:301
const Bijection< const DiscreteVariable *, const DiscreteVariable * > & mapMainPrime() const
Returns the map binding main variables and prime variables.
Definition fmdp_tpl.h:409
HashTable< const DiscreteVariable *, const MultiDimImplementation< GUM_ELEMENT_O > * > VarTransitionTable
Definition fmdp.h:77
GUM_ELEMENT discount() const
Returns the discount factor.
Definition fmdp_tpl.h:450
Bijection< const DiscreteVariable *, const DiscreteVariable * > _main2primed_
Mapping from a main variable to its associated primed version.
Definition fmdp.h:283
void addTransition(const DiscreteVariable *var, const MultiDimImplementation< GUM_ELEMENT > *transition)
Adds a default variable transition.
Definition fmdp_tpl.h:424
~FMDP()
Default destructor.
Definition fmdp_tpl.h:90
Sequence< Idx > _actionSeq_
Definition fmdp.h:280
SequenceIteratorSafe< const DiscreteVariable * > endVariables() const
Returns an iterator reference to the end of the list of variables.
Definition fmdp_tpl.h:398
HashTable< Idx, VarTransitionTable< GUM_ELEMENT > * > _actionTransitionTable_
Table which give for each action a table containing variables transition cpt.
Definition fmdp.h:290
const MultiDimImplementation< GUM_ELEMENT > * cost(Idx actionId=0) const
Returns the reward table of mdp.
Definition fmdp_tpl.h:266
const MultiDimImplementation< GUM_ELEMENT > * transition(Idx actionId, const DiscreteVariable *v) const
Returns transition associated to given in parameter variable and the given action.
Definition fmdp_tpl.h:226
std::string toString() const
Displays the FMDP in a Dot format.
Definition fmdp_tpl.h:346
const std::string & actionName(Idx actionId) const
Returns name of action given in parameter.
Definition fmdp_tpl.h:325
const MultiDimImplementation< GUM_ELEMENT > * reward(Idx actionId=0) const
Returns the reward table of mdp.
Definition fmdp_tpl.h:305
GUM_ELEMENT _discount_
Definition fmdp.h:303
The class for generic Hash Tables.
Definition hashTable.h:640
<agrum/base/multidim/multiDimImplementation.h>
Safe iterators for Sequence.
Definition sequence.h:1148
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:994
Template implementation of FMDP/FMDP.h classes.
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
Headers of MultiDimFunctionGraph.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46