aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
fmdpFactory.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
50#ifndef GUM_FMDP_FACTORY_H
51#define GUM_FMDP_FACTORY_H
52//======================================================================
53#include <string>
54#include <vector>
55//======================================================================
56
59
60namespace gum {
61
85
86 template < typename GUM_SCALAR >
88 public:
89 // ==========================================================================
91 // ==========================================================================
93
100
110 ~FMDPFactory();
111
113 // ==========================================================================
115 // ==========================================================================
117
123 FMDP< GUM_SCALAR >* fmdp() const;
124
126 FMDPfactory_state state() const;
127
130 const DiscreteVariable* variable(const std::string& name) const;
131
133 // ==========================================================================
135 // ==========================================================================
137
140
144 void variableName(const std::string& name);
145
147 void variableDescription(const std::string& desc);
148
150 void addModality(const std::string& name);
151
156
158 // ==========================================================================
160 // ==========================================================================
162
165
167 void addAction(const std::string& action);
168
171
173 // ==========================================================================
175 // ==========================================================================
177
180
182 void addTransition(const std::string& var, const MultiDimAdressable* transition);
183
187 void addTransition(const std::string& var);
188
191
193 // ==========================================================================
195 // ==========================================================================
197
200
202 void addCost(const MultiDimAdressable* cost);
203
207 void addCost();
208
210 void endCostDeclaration();
211
213 // ==========================================================================
215 // ==========================================================================
217
220
224 void setOperationModeOn(std::string operationType);
225
227 void addReward(const MultiDimAdressable* reward);
228
232 void addReward();
233
236
238 // ==========================================================================
240 // ==========================================================================
242
245
247 void addDiscount(float discount);
248
251
253 // ==========================================================================
257 // ==========================================================================
259
261 NodeId addInternalNode(std::string name_of_var);
262
264 NodeId addTerminalNode(float value);
265
267 void addArc(NodeId from, NodeId to, Idx modality);
268
270 void setRoot(NodeId rootId);
271
273
274 private:
275 // ==========================================================================
277 // ==========================================================================
279
283
287
289 std::vector< std::string > _stringBag_;
290
292 std::vector< const MultiDimImplementation< GUM_SCALAR >* > _ddBag_;
293
296 void _checkModalityInBag_(const std::string& mod);
297
299 void _resetParts_();
300
303
306
308
310 std::vector< FMDPfactory_state > _states_;
311
314
317
320
323
326
328 void _illegalStateError_(const std::string& s);
329 };
330
331
332#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
333 extern template class FMDPFactory< double >;
334#endif
335
336} /* namespace gum */
337
339
340#endif // GUM_FMDP_FACTORY_H
Headers of the IFMDPFactory interface-like class.
A factory class to ease Factored Markov Decision Process construction.
Base class for discrete random variable.
A factory class to ease Factored Markov Decision Process construction.
Definition fmdpFactory.h:87
void addCost()
Tells the factory to add a cost table to the current fmdp. This cost table will be extracted from inc...
NodeId addTerminalNode(float value)
Insert in diagram a terminal node.
void setOperationModeOn(std::string operationType)
Tells the factory that we're in a reward declaration mode where the global reward diagram is an opera...
FMDP< GUM_SCALAR > * _fmdp_
The constructed FMDP.
void addArc(NodeId from, NodeId to, Idx modality)
Insert in diagram a non terminal node.
FMDPFactory(FMDP< GUM_SCALAR > *fmdp)
Use this constructor if you want to use an already created factored markov decision process.
FMDPFactory< GUM_SCALAR > & operator=(const FMDPFactory< GUM_SCALAR > &source)
Copy operator is illegal, use only copy constructor.
void endTransitionDeclaration()
Tells the factory that we're out of a transition declaration.
void addTransition(const std::string &var, const MultiDimAdressable *transition)
Tells the factory to add a transition table to the current fmdp.
void addAction(const std::string &action)
Tells the factory to add an action to the current fmdp.
void startVariableDeclaration()
Tells the factory that we're in a variable declaration.
void startDiscountDeclaration()
Tells the factory that we're in a cost declaration.
void _resetParts_()
Reset the different parts used to constructed the FMDP.
~FMDPFactory()
Destructor.
void _initializeFunctionGraph_()
Insert every variables in the function graph.
void variableName(const std::string &name)
Tells the factory the current variable's name.
HashTable< std::string, const DiscreteVariable * > _varNameMap_
Mapping between a declared variable's name and itself.
void addModality(const std::string &name)
Adds a modality to the current variable.
void addReward()
Tells the factory to add a reward table to the current fmdp. This reward table will be extracted from...
void startTransitionDeclaration()
Tells the factory that we're in a transition declaration.
void endVariableDeclaration()
Tells the factory that we're out of a variable declaration.
void startActionDeclaration()
Tells the factory that we're in an action declaration.
bool _bar_flag_
Depending on the context this flag is used for some VERY important reasons.
bool _foo_flag_
Depending on the context this flag is used for some VERY important reasons.
void _checkModalityInBag_(const std::string &mod)
Used in VARIABLE mode Checks if in stringBag there is no other modality with the same name.
void endCostDeclaration()
Tells the factory that we're out of a cost declaration.
void startRewardDeclaration()
Tells the factory that we're in a reward declaration.
void endRewardDeclaration()
Tells the factory that we're out of a cost declaration.
std::vector< const MultiDimImplementation< GUM_SCALAR > * > _ddBag_
Just to keep track of multidim between two start/end calls.
void startCostDeclaration()
Tells the factory that we're in a cost declaration.
void endActionDeclaration()
Tells the factory that we're out of an action declaration.
void endDiscountDeclaration()
Tells the factory that we're out of a cost declaration.
FMDPfactory_state state() const
Returns the current state of the factory.
FMDP< GUM_SCALAR > * fmdp() const
Returns the Factored Markov Decision Process created by this factory.
std::vector< FMDPfactory_state > _states_
State stack.
void variableDescription(const std::string &desc)
Tells the factory the current variable's description.
void setRoot(NodeId rootId)
add an arc in diagram
const DiscreteVariable * variable(const std::string &name) const
Returns a constant reference on a variable given it's name.
void addDiscount(float discount)
Tells the factory to add a cost table to the current fmdp.
NodeId addInternalNode(std::string name_of_var)
Insert in diagram a non terminal node.
MultiDimFunctionGraph< GUM_SCALAR > * _FunctionGraph_
The FunctionGraph we're building at a given time.
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.
void _finalizeFunctionGraph_()
Insert every variables in the function graph.
void _illegalStateError_(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
Idx _actionIdcpt_
Action Id counter.
This class is used to implement factored decision process.
Definition fmdp.h:73
The class for generic Hash Tables.
Definition hashTable.h:637
Abstract base class for all multi dimensionnal addressable.
Class implementingting a function graph.
Template Implementation of the FMDPFactory class.
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
Base class for labelized discrete random variables.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
FMDPfactory_state
The enumeration of states in which the factory can be in.