aGrUM 2.3.2
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-2025 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-2025 *
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//======================================================================
57
58//======================================================================
59
60namespace gum {
71
72 template < typename GUM_SCALAR >
73 class FMDP {
74 template < typename GUM_SCALAR_O >
77
78 public:
79 // ===========================================================================
81 // ===========================================================================
83
87 FMDP(bool onDestructionDeleteVar = false);
88
92 ~FMDP();
93
95
96 // ===========================================================================
98 // ===========================================================================
100
105 void addVariable(const DiscreteVariable* var);
106
112 }
113
119 }
120
123 */
124 const DiscreteVariable* main2prime(const DiscreteVariable* mainVar) const {
125 return _main2primed_.second(mainVar);
126 }
127
134 }
135
137
138 // ===========================================================================
140 // ===========================================================================
142
147 void addAction(Idx actionId, const std::string& action);
148
152 SequenceIteratorSafe< Idx > beginActions() const { return _actionSeq_.beginSafe(); }
153
157 SequenceIteratorSafe< Idx > endActions() const { return _actionSeq_.endSafe(); }
158
160
161 // ===========================================================================
163 // ===========================================================================
165
173 const DiscreteVariable* var,
175
184 }
185
191 const DiscreteVariable* v) const;
192
194
195 // ===========================================================================
197 // ===========================================================================
199
205
209 */
211 this->addCostForAction(0, cost);
212 }
213
218
220
221 // ===========================================================================
223 // ===========================================================================
225
231
235 */
237 this->addRewardForAction(0, reward);
238 }
239
244
246
247 // ===========================================================================
249 // ===========================================================================
251
255 const std::string& actionName(Idx actionId) const;
256
260 Idx actionId(const std::string&) const;
261
265 std::string toString() const;
266
270 Size size() const;
271
272
274
275 private:
280
283
286
290
293
296
301 };
302
303
304#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
305 extern template class FMDP< double >;
306#endif
307
308
309} /* namespace gum */
310
311#include <agrum/FMDP/fmdp_tpl.h>
312
313#endif // GUM_FACTORED_MARKOV_DECISION_PROCESS_H
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
Base class for discrete random variable.
bool _onDestructionDeleteVars_
Boolean indicates whether or not main variables should be deleted on destruction of this instance Usu...
Definition fmdp.h:299
const std::string & actionName(Idx actionId) const
Returns name of action given in parameter.
Definition fmdp_tpl.h:326
Sequence< Idx > _actionSeq_
Definition fmdp.h:278
Sequence< const DiscreteVariable * > _varSeq_
Sequence de variables and its iterator.
Definition fmdp.h:276
HashTable< Idx, VarTransitionTable< GUM_SCALAR > * > _actionTransitionTable_
Table which give for each action a table containing variables transition cpt.
Definition fmdp.h:288
void addCostForAction(Idx actionId, const MultiDimImplementation< GUM_SCALAR > *cost)
Adds a cost table to specified action.
Definition fmdp_tpl.h:250
const MultiDimImplementation< GUM_SCALAR > * transition(Idx actionId, const DiscreteVariable *v) const
Returns transition associated to given in parameter variable and the given action.
Definition fmdp_tpl.h:225
Idx actionId(const std::string &) const
Returns action id.
Definition fmdp_tpl.h:337
HashTable< Idx, const MultiDimImplementation< GUM_SCALAR > * > _actionRewardTable_
Table which give for each action reward table.
Definition fmdp.h:294
INLINE const Bijection< const DiscreteVariable *, const DiscreteVariable * > & mapMainPrime() const
Returns the map binding main variables and prime variables.
Definition fmdp.h:131
const DiscreteVariable * main2prime(const DiscreteVariable *mainVar) const
Returns the primed variable associate to the given main variable.
Definition fmdp.h:123
HashTable< Idx, const MultiDimImplementation< GUM_SCALAR > * > _actionCostTable_
Table which give for each action cost table.
Definition fmdp.h:291
const MultiDimImplementation< GUM_SCALAR > * cost(Idx actionId=0) const
Returns the reward table of mdp.
Definition fmdp_tpl.h:266
SequenceIteratorSafe< const DiscreteVariable * > endVariables() const
Returns an iterator reference to the end of the list of variables.
Definition fmdp.h:116
SequenceIteratorSafe< Idx > beginActions() const
Returns an iterator reference to he beginning of the list of actions.
Definition fmdp.h:151
const MultiDimImplementation< GUM_SCALAR > * reward(Idx actionId=0) const
Returns the reward table of mdp.
Definition fmdp_tpl.h:306
SequenceIteratorSafe< const DiscreteVariable * > beginVariables() const
Returns an iterator reference to he beginning of the list of variables.
Definition fmdp.h:109
FMDP(bool onDestructionDeleteVar=false)
Default constructor.
Definition fmdp_tpl.h:74
Bijection< Idx, const std::string * > _actionMap_
Bijection mapping an action name to its id.
Definition fmdp.h:284
void addTransition(const DiscreteVariable *var, const MultiDimImplementation< GUM_SCALAR > *transition)
Adds a default variable transition.
Definition fmdp.h:180
void addCost(const MultiDimImplementation< GUM_SCALAR > *cost)
Adds a default variable cost.
Definition fmdp.h:209
~FMDP()
Default destructor.
Definition fmdp_tpl.h:89
void addTransitionForAction(Idx actionId, const DiscreteVariable *var, const MultiDimImplementation< GUM_SCALAR > *transition)
Adds a variable transition table to specified action.
Definition fmdp_tpl.h:201
Bijection< const DiscreteVariable *, const DiscreteVariable * > _main2primed_
Mapping from a main variable to its associated primed version.
Definition fmdp.h:281
std::string toString() const
Displays the FMDP in a Dot format.
Definition fmdp_tpl.h:347
Size size() const
Returns the map binding main variables and prime variables.
Definition fmdp_tpl.h:366
void addReward(const MultiDimImplementation< GUM_SCALAR > *reward)
Adds a default variable reward.
Definition fmdp.h:235
void addAction(Idx actionId, const std::string &action)
Adds an action to FMDP description.
Definition fmdp_tpl.h:163
SequenceIteratorSafe< Idx > endActions() const
Returns an iterator reference to the end of the list of actions.
Definition fmdp.h:156
HashTable< const DiscreteVariable *, const MultiDimImplementation< GUM_SCALAR_O > * > VarTransitionTable
Definition fmdp.h:75
void addVariable(const DiscreteVariable *var)
Adds a variable to FMDP description.
Definition fmdp_tpl.h:136
void addRewardForAction(Idx actionId, const MultiDimImplementation< GUM_SCALAR > *reward)
Adds a default variable reward.
Definition fmdp_tpl.h:288
The class for generic Hash Tables.
Definition hashTable.h:637
<agrum/base/multidim/multiDimImplementation.h>
Safe iterators for Sequence.
Definition sequence.h:1134
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
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