aGrUM  0.14.2
fmdpFactory.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef GUM_FMDP_FACTORY_H
28 #define GUM_FMDP_FACTORY_H
29 //======================================================================
30 #include <string>
31 #include <vector>
32 //======================================================================
33 #include <agrum/core/sequence.h>
34 
36 
38 #include <agrum/FMDP/fmdp.h>
39 
40 
41 namespace gum {
42 
67  template < typename GUM_SCALAR >
69  public:
70  // ==========================================================================
72  // ==========================================================================
74 
81 
91  ~FMDPFactory();
92 
94  // ==========================================================================
96  // ==========================================================================
98 
104  FMDP< GUM_SCALAR >* fmdp() const;
105 
107  FMDPfactory_state state() const;
108 
111  const DiscreteVariable* variable(const std::string& name) const;
112 
114  // ==========================================================================
116  // ==========================================================================
118 
121 
125  void variableName(const std::string& name);
126 
128  void variableDescription(const std::string& desc);
129 
131  void addModality(const std::string& name);
132 
136  void endVariableDeclaration();
137 
139  // ==========================================================================
141  // ==========================================================================
143 
145  void startActionDeclaration();
146 
148  void addAction(const std::string& action);
149 
151  void endActionDeclaration();
152 
154  // ==========================================================================
156  // ==========================================================================
158 
161 
163  void addTransition(const std::string& var,
164  const MultiDimAdressable* transition);
165 
169  void addTransition(const std::string& var);
170 
173 
175  // ==========================================================================
177  // ==========================================================================
179 
181  void startCostDeclaration();
182 
184  void addCost(const MultiDimAdressable* cost);
185 
189  void addCost();
190 
192  void endCostDeclaration();
193 
195  // ==========================================================================
197  // ==========================================================================
199 
201  void startRewardDeclaration();
202 
206  void setOperationModeOn(std::string operationType);
207 
209  void addReward(const MultiDimAdressable* reward);
210 
214  void addReward();
215 
217  void endRewardDeclaration();
218 
220  // ==========================================================================
222  // ==========================================================================
224 
227 
229  void addDiscount(float discount);
230 
232  void endDiscountDeclaration();
233 
235  // ==========================================================================
239  // ==========================================================================
241 
243  NodeId addInternalNode(std::string name_of_var);
244 
246  NodeId addTerminalNode(float value);
247 
249  void addArc(NodeId from, NodeId to, Idx modality);
250 
252  void setRoot(NodeId rootId);
253 
255 
256  private:
257  // ==========================================================================
259  // ==========================================================================
261 
265 
269 
271  std::vector< std::string > __stringBag;
272 
274  std::vector< const MultiDimImplementation< GUM_SCALAR >* > __ddBag;
275 
278  void __checkModalityInBag(const std::string& mod);
279 
281  void __resetParts();
282 
285 
288 
290 
292  std::vector< FMDPfactory_state > __states;
293 
296 
299 
302 
305 
308 
310  void __illegalStateError(const std::string& s);
311  };
312 
313 
314 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
315  extern template class FMDPFactory< double >;
316 #endif
317 
318 } /* namespace gum */
319 
320 
322 
323 #endif // GUM_FMDP_FACTORY_H
void addReward()
Tells the factory to add a reward table to the current fmdp. This reward table will be extracted from...
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
Definition: fmdpFactory.h:271
void endTransitionDeclaration()
Tells the factory that we&#39;re out of a transition declaration.
FMDPfactory_state state() const
Returns the current state of the factory.
void __resetParts()
Reset the different parts used to constructed the FMDP.
void endActionDeclaration()
Tells the factory that we&#39;re out of an action declaration.
A factory class to ease Factored Markov Decision Process construction.
Definition: fmdpFactory.h:68
FMDPFactory< GUM_SCALAR > & operator=(const FMDPFactory< GUM_SCALAR > &source)
Copy operator is illegal, use only copy constructor.
void addAction(const std::string &action)
Tells the factory to add an action to the current fmdp.
void __initializeFunctionGraph()
Insert every variables in the function graph.
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
MultiDimFunctionGraph< GUM_SCALAR > * __FunctionGraph
The FunctionGraph we&#39;re building at a given time.
Definition: fmdpFactory.h:298
void startDiscountDeclaration()
Tells the factory that we&#39;re in a cost declaration.
FMDPfactory_state
The enumeration of states in which the factory can be in.
Definition: IfmdpFactory.h:50
void startActionDeclaration()
Tells the factory that we&#39;re in an action declaration.
Template Implementation of the FMDPFactory class.
void addDiscount(float discount)
Tells the factory to add a cost table to the current fmdp.
void startVariableDeclaration()
Tells the factory that we&#39;re in a variable declaration.
void endCostDeclaration()
Tells the factory that we&#39;re out of a cost declaration.
void addArc(NodeId from, NodeId to, Idx modality)
Insert in diagram a non terminal node.
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&#39;s name.
This class is used to implement factored decision process.
Definition: fmdp.h:54
void addModality(const std::string &name)
Adds a modality to the current variable.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void __checkModalityInBag(const std::string &mod)
Used in VARIABLE mode Checks if in __stringBag there is no other modality with the same name...
bool __bar_flag
Depending on the context this flag is used for some VERY important reasons.
Definition: fmdpFactory.h:268
The class for generic Hash Tables.
Definition: hashTable.h:676
FMDP< GUM_SCALAR > * fmdp() const
Returns the Factored Markov Decision Process created by this factory.
Class for implementation of factored markov decision process.
void endDiscountDeclaration()
Tells the factory that we&#39;re out of a cost declaration.
~FMDPFactory()
Destructor.
void addTransition(const std::string &var, const MultiDimAdressable *transition)
Tells the factory to add a transition table to the current fmdp.
void addCost()
Tells the factory to add a cost table to the current fmdp. This cost table will be extracted from inc...
Idx __actionIdcpt
Action Id counter.
Definition: fmdpFactory.h:304
void endRewardDeclaration()
Tells the factory that we&#39;re out of a cost declaration.
HashTable< std::string, const DiscreteVariable *> __varNameMap
Mapping between a declared variable&#39;s name and itself.
Definition: fmdpFactory.h:301
std::vector< FMDPfactory_state > __states
State stack.
Definition: fmdpFactory.h:292
void endVariableDeclaration()
Tells the factory that we&#39;re out of a variable declaration.
NodeId addInternalNode(std::string name_of_var)
Insert in diagram a non terminal node.
void startCostDeclaration()
Tells the factory that we&#39;re in a cost declaration.
NodeId addTerminalNode(float value)
Insert in diagram a terminal node.
void variableName(const std::string &name)
Tells the factory the current variable&#39;s name.
bool __foo_flag
Depending on the context this flag is used for some VERY important reasons.
Definition: fmdpFactory.h:264
Abstract base class for all multi dimensionnal addressable.
FMDP< GUM_SCALAR > * __fmdp
The constructed FMDP.
Definition: fmdpFactory.h:295
std::vector< const MultiDimImplementation< GUM_SCALAR > *> __ddBag
Just to keep track of multidim between two start/end calls.
Definition: fmdpFactory.h:274
void variableDescription(const std::string &desc)
Tells the factory the current variable&#39;s description.
Headers of the IFMDPFactory interface-like class.
A factory class to ease Factored Markov Decision Process construction.
Definition: IfmdpFactory.h:83
Size Idx
Type for indexes.
Definition: types.h:50
void setOperationModeOn(std::string operationType)
Tells the factory that we&#39;re in a reward declaration mode where the global reward diagram is an opera...
void __finalizeFunctionGraph()
Insert every variables in the function graph.
void startRewardDeclaration()
Tells the factory that we&#39;re in a reward declaration.
FMDPFactory(FMDP< GUM_SCALAR > *fmdp)
Use this constructor if you want to use an already created factored markov decision process...
Base class for labelized discrete random variables.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void startTransitionDeclaration()
Tells the factory that we&#39;re in a transition declaration.