aGrUM 3.1.1
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-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#ifndef GUM_FMDP_FACTORY_H
51#define GUM_FMDP_FACTORY_H
52//======================================================================
53#include <string>
54#include <vector>
55
56#include <string_view>
57//======================================================================
58
61
62namespace gum {
63
87
88 template < typename GUM_ELEMENT >
90 public:
91 // ==========================================================================
93 // ==========================================================================
95
102
112 ~FMDPFactory() override;
113
115 // ==========================================================================
117 // ==========================================================================
119
125 FMDP< GUM_ELEMENT >* fmdp() const;
126
128 FMDPfactory_state state() const override;
129
132 const DiscreteVariable* variable(std::string_view name) const override;
133
135 // ==========================================================================
137 // ==========================================================================
139
141 void startVariableDeclaration() override;
142
146 void variableName(std::string_view name) override;
147
149 void variableDescription(std::string_view desc) override;
150
152 void addModality(std::string_view name) override;
153
157 void endVariableDeclaration() override;
158
160 // ==========================================================================
162 // ==========================================================================
164
166 void startActionDeclaration() override;
167
169 void addAction(std::string_view action) override;
170
172 void endActionDeclaration() override;
173
175 // ==========================================================================
177 // ==========================================================================
179
181 void startTransitionDeclaration() override;
182
184 void addTransition(std::string_view var, const MultiDimAdressable* transition) override;
185
189 void addTransition(std::string_view var) override;
190
192 void endTransitionDeclaration() override;
193
195 // ==========================================================================
197 // ==========================================================================
199
201 void startCostDeclaration() override;
202
204 void addCost(const MultiDimAdressable* cost) override;
205
209 void addCost() override;
210
212 void endCostDeclaration() override;
213
215 // ==========================================================================
217 // ==========================================================================
219
221 void startRewardDeclaration() override;
222
226 void setOperationModeOn(std::string_view operationType) override;
227
229 void addReward(const MultiDimAdressable* reward) override;
230
234 void addReward() override;
235
237 void endRewardDeclaration() override;
238
240 // ==========================================================================
242 // ==========================================================================
244
246 void startDiscountDeclaration() override;
247
249 void addDiscount(float discount) override;
250
252 void endDiscountDeclaration() override;
253
255 // ==========================================================================
259 // ==========================================================================
261
263 NodeId addInternalNode(std::string_view name_of_var) override;
264
266 NodeId addTerminalNode(float value) override;
267
269 void addArc(NodeId from, NodeId to, Idx modality) override;
270
272 void setRoot(NodeId rootId) override;
273
275
276 private:
277 // ==========================================================================
279 // ==========================================================================
281
285
289
291 std::vector< std::string > _stringBag_;
292
294 std::vector< const MultiDimImplementation< GUM_ELEMENT >* > _ddBag_;
295
298 void _checkModalityInBag_(std::string_view mod);
299
301 void _resetParts_();
302
305
308
310
312 std::vector< FMDPfactory_state > _states_;
313
316
319
322
325
328
330 void _illegalStateError_(std::string_view s);
331 };
332
333
334#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
335 extern template class FMDPFactory< double >;
336#endif
337
338} /* namespace gum */
339
341
342#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:89
void variableName(std::string_view name) override
Tells the factory the current variable's name.
void addModality(std::string_view name) override
Adds a modality to the current variable.
void endVariableDeclaration() override
Tells the factory that we're out of a variable declaration.
NodeId addInternalNode(std::string_view name_of_var) override
Insert in diagram a non terminal node.
const DiscreteVariable * variable(std::string_view name) const override
Returns a constant reference on a variable given it's name.
void endTransitionDeclaration() override
Tells the factory that we're out of a transition declaration.
void endDiscountDeclaration() override
Tells the factory that we're out of a cost declaration.
~FMDPFactory() override
Destructor.
std::vector< FMDPfactory_state > _states_
State stack.
FMDPFactory< GUM_ELEMENT > & operator=(const FMDPFactory< GUM_ELEMENT > &source)
Copy operator is illegal, use only copy constructor.
void startActionDeclaration() override
Tells the factory that we're in an action declaration.
void addCost() override
Tells the factory to add a cost table to the current fmdp. This cost table will be extracted from inc...
void _resetParts_()
Reset the different parts used to constructed the FMDP.
HashTable< std::string, const DiscreteVariable * > _varNameMap_
Mapping between a declared variable's name and itself.
FMDP< GUM_ELEMENT > * _fmdp_
The constructed FMDP.
void addTransition(std::string_view var, const MultiDimAdressable *transition) override
Tells the factory to add a transition table to the current fmdp.
void _finalizeFunctionGraph_()
Insert every variables in the function graph.
void addArc(NodeId from, NodeId to, Idx modality) override
Insert in diagram a non terminal node.
void addReward() override
Tells the factory to add a reward table to the current fmdp. This reward table will be extracted from...
void endActionDeclaration() override
Tells the factory that we're out of an action declaration.
bool _foo_flag_
Depending on the context this flag is used for some VERY important reasons.
void _initializeFunctionGraph_()
Insert every variables in the function graph.
void setRoot(NodeId rootId) override
add an arc in diagram
void addDiscount(float discount) override
Tells the factory to add a cost table to the current fmdp.
MultiDimFunctionGraph< GUM_ELEMENT > * _FunctionGraph_
The FunctionGraph we're building at a given time.
void _checkModalityInBag_(std::string_view mod)
Used in VARIABLE mode Checks if in stringBag there is no other modality with the same name.
void endRewardDeclaration() override
Tells the factory that we're out of a cost declaration.
void startVariableDeclaration() override
Tells the factory that we're in a variable declaration.
FMDP< GUM_ELEMENT > * fmdp() const
Returns the Factored Markov Decision Process created by this factory.
void startDiscountDeclaration() override
Tells the factory that we're in a cost declaration.
void startCostDeclaration() override
Tells the factory that we're in a cost declaration.
FMDPFactory(FMDP< GUM_ELEMENT > *fmdp)
Use this constructor if you want to use an already created factored markov decision process.
FMDPfactory_state state() const override
Returns the current state of the factory.
NodeId addTerminalNode(float value) override
Insert in diagram a terminal node.
bool _bar_flag_
Depending on the context this flag is used for some VERY important reasons.
void endCostDeclaration() override
Tells the factory that we're out of a cost declaration.
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.
Idx _actionIdcpt_
Action Id counter.
void variableDescription(std::string_view desc) override
Tells the factory the current variable's description.
std::vector< const MultiDimImplementation< GUM_ELEMENT > * > _ddBag_
Just to keep track of multidim between two start/end calls.
void startRewardDeclaration() override
Tells the factory that we're in a reward declaration.
void _illegalStateError_(std::string_view s)
Raise an OperationNotAllowed with the message "Illegal state.".
void startTransitionDeclaration() override
Tells the factory that we're in a transition declaration.
void addAction(std::string_view action) override
Tells the factory to add an action to the current fmdp.
void setOperationModeOn(std::string_view operationType) override
Tells the factory that we're in a reward declaration mode where the global reward diagram is an opera...
This class is used to implement factored decision process.
Definition fmdp.h:75
The class for generic Hash Tables.
Definition hashTable.h:640
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.