![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
A factory class to ease Factored Markov Decision Process construction. More...
#include <agrum/FMDP/fmdpFactory.h>
Public Member Functions | |
Constructor & destructor. | |
| FMDPFactory (FMDP< GUM_SCALAR > *fmdp) | |
| Use this constructor if you want to use an already created factored markov decision process. | |
| ~FMDPFactory () | |
| Destructor. | |
Getter and setters. | |
| FMDP< GUM_SCALAR > * | fmdp () const |
| Returns the Factored Markov Decision Process created by this factory. | |
| FMDPfactory_state | state () const |
| Returns the current state of the factory. | |
| const DiscreteVariable * | variable (const std::string &name) const |
| Returns a constant reference on a variable given it's name. | |
Variable declaration methods (NONE -> VARIABLE) | |
| void | startVariableDeclaration () |
| Tells the factory that we're in a variable declaration. | |
| void | variableName (const std::string &name) |
| Tells the factory the current variable's name. | |
| void | variableDescription (const std::string &desc) |
| Tells the factory the current variable's description. | |
| void | addModality (const std::string &name) |
| Adds a modality to the current variable. | |
| void | endVariableDeclaration () |
| Tells the factory that we're out of a variable declaration. | |
Action declaration methods (NONE -> ACTION) | |
| void | startActionDeclaration () |
| Tells the factory that we're in an action declaration. | |
| void | addAction (const std::string &action) |
| Tells the factory to add an action to the current fmdp. | |
| void | endActionDeclaration () |
| Tells the factory that we're out of an action declaration. | |
Transition declaration methods (NONE -> TRANSITION <- ACTION) | |
| void | startTransitionDeclaration () |
| Tells the factory that we're in 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 | addTransition (const std::string &var) |
| Tells the factory to add a transition table to the current fmdp. This transition table will be extracted from incorporated multiDimFunctionGraph. | |
| void | endTransitionDeclaration () |
| Tells the factory that we're out of a transition declaration. | |
Cost declaration methods (NONE -> COST <- ACTION) | |
| void | startCostDeclaration () |
| Tells the factory that we're in a cost declaration. | |
| void | addCost (const MultiDimAdressable *cost) |
| Tells the factory to add a cost 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 incorporated multiDimFunctionGraph. | |
| void | endCostDeclaration () |
| Tells the factory that we're out of a cost declaration. | |
Reward declaration methods (NONE -> REWARD <- ACTION) | |
| void | startRewardDeclaration () |
| Tells the factory that we're in a reward declaration. | |
| void | setOperationModeOn (std::string operationType) |
| Tells the factory that we're in a reward declaration mode where the global reward diagram is an operation between simplier decision diagram.. | |
| void | addReward (const MultiDimAdressable *reward) |
| Tells the factory to add a reward table to the current fmdp. | |
| void | addReward () |
| Tells the factory to add a reward table to the current fmdp. This reward table will be extracted from incorporated multiDimFunctionGraph. | |
| void | endRewardDeclaration () |
| Tells the factory that we're out of a cost declaration. | |
Discount declaration methods (NONE -> DISCOUNT) | |
| void | startDiscountDeclaration () |
| Tells the factory that we're in a cost declaration. | |
| void | addDiscount (float discount) |
| Tells the factory to add a cost table to the current fmdp. | |
| void | endDiscountDeclaration () |
| Tells the factory that we're out of a cost declaration. | |
FunctionGraph Creation specific methods | |
methods used by internal FunctionGraphfactory to build up a multidimFunctionGraph | |
| NodeId | addInternalNode (std::string name_of_var) |
| Insert in diagram a non terminal node. | |
| NodeId | addTerminalNode (float value) |
| Insert in diagram a terminal node. | |
| void | addArc (NodeId from, NodeId to, Idx modality) |
| Insert in diagram a non terminal node. | |
| void | setRoot (NodeId rootId) |
| add an arc in diagram | |
verbosity control | |
| void | setVerbose () |
| void | resetVerbose () |
| bool | isVerbose () |
Private Member Functions | |
| FMDPFactory< GUM_SCALAR > & | operator= (const FMDPFactory< GUM_SCALAR > &source) |
| Copy operator is illegal, use only copy constructor. | |
| void | _illegalStateError_ (const std::string &s) |
| Raise an OperationNotAllowed with the message "Illegal state.". | |
Private Attributes | |
| std::vector< FMDPfactory_state > | _states_ |
| State stack. | |
| FMDP< GUM_SCALAR > * | _fmdp_ |
| The constructed FMDP. | |
| MultiDimFunctionGraph< GUM_SCALAR > * | _FunctionGraph_ |
| The FunctionGraph we're building at a given time. | |
| HashTable< std::string, const DiscreteVariable * > | _varNameMap_ |
| Mapping between a declared variable's name and itself. | |
| Idx | _actionIdcpt_ |
| Action Id counter. | |
| bool | _verbose_ |
Current constructed FMDP's parts. | |
| bool | _foo_flag_ |
| Depending on the context this flag is used for some VERY important reasons. | |
| bool | _bar_flag_ |
| Depending on the context this flag is used for some VERY important reasons. | |
| std::vector< std::string > | _stringBag_ |
| Just to keep track of strings between two start/end calls. | |
| std::vector< const MultiDimImplementation< GUM_SCALAR > * > | _ddBag_ |
| Just to keep track of multidim between two start/end calls. | |
| void | _checkModalityInBag_ (const std::string &mod) |
| Used in VARIABLE mode Checks if in stringBag there is no other modality with the same name. | |
| void | _resetParts_ () |
| Reset the different parts used to constructed the FMDP. | |
| void | _initializeFunctionGraph_ () |
| Insert every variables in the function graph. | |
| void | _finalizeFunctionGraph_ () |
| Insert every variables in the function graph. | |
A factory class to ease Factored Markov Decision Process construction.
A FMDPFactory will never create a Factored Markov Decision Process and works on only one Factored Markov Decision Process.
The only exception of this behaviour is when you create a copy of the factory, it will create a copy of its FMDP. This is useful when you want to create two FMDP sharing a common base. However be very careful because the copy will not delete its FMDP.
Each method will raise an OperationNotAllowed if you call it when the factory is not in a valid state for that call. The error message is "Illegal state.".
Definition at line 87 of file fmdpFactory.h.
| INLINE gum::FMDPFactory< GUM_SCALAR >::FMDPFactory | ( | FMDP< GUM_SCALAR > * | fmdp | ) |
Use this constructor if you want to use an already created factored markov decision process.
Definition at line 76 of file fmdpFactory_tpl.h.
References FMDPFactory(), _actionIdcpt_, _fmdp_, _states_, fmdp(), gum::NONE, and gum::AbstractFMDPFactory::resetVerbose().
Referenced by FMDPFactory(), ~FMDPFactory(), and operator=().
| INLINE gum::FMDPFactory< GUM_SCALAR >::~FMDPFactory | ( | ) |
Destructor.
To prevent strange behaviour you should always destroy a FMDPFactory when it's state equals NONE.
| FatalError | Raised if the state of the factory prevents it to die peacefully. |
Definition at line 87 of file fmdpFactory_tpl.h.
References FMDPFactory().
|
private |
Used in VARIABLE mode Checks if in stringBag there is no other modality with the same name.
Definition at line 202 of file fmdpFactory_tpl.h.
References _stringBag_, and GUM_ERROR.
Referenced by addModality().
|
private |
Insert every variables in the function graph.
Definition at line 661 of file fmdpFactory_tpl.h.
References _FunctionGraph_.
Referenced by addCost(), addReward(), and addTransition().
|
private |
Raise an OperationNotAllowed with the message "Illegal state.".
Definition at line 610 of file fmdpFactory_tpl.h.
References gum::ACTION, gum::COST, gum::DISCOUNT, GUM_ERROR, gum::NONE, gum::REWARD, state(), gum::TRANSITION, and gum::VARIABLE.
Referenced by addAction(), addCost(), addCost(), addDiscount(), addModality(), addReward(), addReward(), addTransition(), addTransition(), endActionDeclaration(), endCostDeclaration(), endDiscountDeclaration(), endRewardDeclaration(), endTransitionDeclaration(), endVariableDeclaration(), startActionDeclaration(), startCostDeclaration(), startDiscountDeclaration(), startRewardDeclaration(), startTransitionDeclaration(), startVariableDeclaration(), variableDescription(), and variableName().
|
private |
Insert every variables in the function graph.
Definition at line 647 of file fmdpFactory_tpl.h.
References _fmdp_, _FunctionGraph_, and gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::getReducedAndOrderedInstance().
Referenced by startCostDeclaration(), startRewardDeclaration(), and startTransitionDeclaration().
|
private |
Reset the different parts used to constructed the FMDP.
Definition at line 639 of file fmdpFactory_tpl.h.
References _bar_flag_, _ddBag_, _foo_flag_, and _stringBag_.
Referenced by endActionDeclaration(), endRewardDeclaration(), and endVariableDeclaration().
|
virtual |
Tells the factory to add an action to the current fmdp.
Implements gum::AbstractFMDPFactory.
Definition at line 275 of file fmdpFactory_tpl.h.
References _actionIdcpt_, _fmdp_, _illegalStateError_(), _stringBag_, gum::ACTION, and state().
|
virtual |
Insert in diagram a non terminal node.
Implements gum::AbstractFMDPFactory.
Definition at line 589 of file fmdpFactory_tpl.h.
References _FunctionGraph_.
|
virtual |
Tells the factory to add a cost table to the current fmdp. This cost table will be extracted from incorporated multiDimFunctionGraph.
Implements gum::AbstractFMDPFactory.
Definition at line 403 of file fmdpFactory_tpl.h.
References _finalizeFunctionGraph_(), _fmdp_, _foo_flag_, _FunctionGraph_, _illegalStateError_(), _stringBag_, gum::COST, and state().
|
virtual |
Tells the factory to add a cost table to the current fmdp.
Implements gum::AbstractFMDPFactory.
Definition at line 390 of file fmdpFactory_tpl.h.
References _fmdp_, _foo_flag_, _illegalStateError_(), _stringBag_, gum::COST, and state().
|
virtual |
Tells the factory to add a cost table to the current fmdp.
Implements gum::AbstractFMDPFactory.
Definition at line 546 of file fmdpFactory_tpl.h.
References _illegalStateError_(), gum::DISCOUNT, and state().
|
virtual |
Insert in diagram a non terminal node.
Implements gum::AbstractFMDPFactory.
Definition at line 576 of file fmdpFactory_tpl.h.
References _FunctionGraph_, and variable().
|
virtual |
Adds a modality to the current variable.
Implements gum::AbstractFMDPFactory.
Definition at line 191 of file fmdpFactory_tpl.h.
References _checkModalityInBag_(), _illegalStateError_(), _stringBag_, state(), and gum::VARIABLE.
|
virtual |
Tells the factory to add a reward table to the current fmdp. This reward table will be extracted from incorporated multiDimFunctionGraph.
Implements gum::AbstractFMDPFactory.
Definition at line 473 of file fmdpFactory_tpl.h.
References _ddBag_, _finalizeFunctionGraph_(), _fmdp_, _foo_flag_, _FunctionGraph_, _illegalStateError_(), gum::REWARD, and state().
|
virtual |
Tells the factory to add a reward table to the current fmdp.
Implements gum::AbstractFMDPFactory.
Definition at line 460 of file fmdpFactory_tpl.h.
References _fmdp_, _illegalStateError_(), gum::REWARD, and state().
|
virtual |
Insert in diagram a terminal node.
Implements gum::AbstractFMDPFactory.
Definition at line 583 of file fmdpFactory_tpl.h.
References _FunctionGraph_.
|
virtual |
Tells the factory to add a transition table to the current fmdp. This transition table will be extracted from incorporated multiDimFunctionGraph.
Implements gum::AbstractFMDPFactory.
Definition at line 338 of file fmdpFactory_tpl.h.
References _finalizeFunctionGraph_(), _fmdp_, _foo_flag_, _FunctionGraph_, _illegalStateError_(), _stringBag_, _varNameMap_, state(), and gum::TRANSITION.
|
virtual |
Tells the factory to add a transition table to the current fmdp.
Implements gum::AbstractFMDPFactory.
Definition at line 322 of file fmdpFactory_tpl.h.
References _fmdp_, _foo_flag_, _illegalStateError_(), _stringBag_, _varNameMap_, state(), and gum::TRANSITION.
|
virtual |
Tells the factory that we're out of an action declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 286 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _resetParts_(), _states_, gum::ACTION, and state().
|
virtual |
Tells the factory that we're out of a cost declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 417 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _states_, gum::COST, and state().
|
virtual |
Tells the factory that we're out of a cost declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 555 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _states_, gum::DISCOUNT, and state().
|
virtual |
Tells the factory that we're out of a cost declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 487 of file fmdpFactory_tpl.h.
References _ddBag_, _fmdp_, _foo_flag_, _illegalStateError_(), _resetParts_(), _states_, _stringBag_, gum::add2MultiDimFunctionGraphs(), gum::divide2MultiDimFunctionGraphs(), gum::multiply2MultiDimFunctionGraphs(), gum::REWARD, state(), and gum::subtract2MultiDimFunctionGraphs().
|
virtual |
Tells the factory that we're out of a transition declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 357 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _states_, state(), and gum::TRANSITION.
|
virtual |
Tells the factory that we're out of a variable declaration.
| UndefinedElement | Raised if the variable isn't defined (or not enough defined). |
Implements gum::AbstractFMDPFactory.
Definition at line 211 of file fmdpFactory_tpl.h.
References _bar_flag_, _fmdp_, _foo_flag_, _illegalStateError_(), _resetParts_(), _states_, _stringBag_, _varNameMap_, gum::LabelizedVariable::addLabel(), GUM_ERROR, gum::Variable::name(), state(), and gum::VARIABLE.
| INLINE FMDP< GUM_SCALAR > * gum::FMDPFactory< GUM_SCALAR >::fmdp | ( | ) | const |
Returns the Factored Markov Decision Process created by this factory.
| OperationNotAllowed | Raise if the state of the factory is different than NONE. |
Definition at line 104 of file fmdpFactory_tpl.h.
References _fmdp_, GUM_ERROR, gum::NONE, and state().
Referenced by FMDPFactory().
|
inlineinherited |
|
private |
Copy operator is illegal, use only copy constructor.
Definition at line 683 of file fmdpFactory_tpl.h.
References FMDPFactory(), and GUM_ERROR.
|
inlineinherited |
Definition at line 289 of file IfmdpFactory.h.
References _verbose_.
Referenced by gum::FMDPFactory< GUM_SCALAR >::FMDPFactory().
|
virtual |
Tells the factory that we're in a reward declaration mode where the global reward diagram is an operation between simplier decision diagram..
Implements gum::AbstractFMDPFactory.
Definition at line 451 of file fmdpFactory_tpl.h.
References _foo_flag_, and _stringBag_.
|
virtual |
add an arc in diagram
Implements gum::AbstractFMDPFactory.
Definition at line 594 of file fmdpFactory_tpl.h.
References _FunctionGraph_.
|
inlineinherited |
|
virtual |
Tells the factory that we're in an action declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 262 of file fmdpFactory_tpl.h.
References _foo_flag_, _illegalStateError_(), _states_, gum::ACTION, gum::NONE, and state().
|
virtual |
Tells the factory that we're in a cost declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 378 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _initializeFunctionGraph_(), _states_, gum::ACTION, gum::COST, gum::NONE, and state().
|
virtual |
Tells the factory that we're in a cost declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 536 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _states_, gum::DISCOUNT, gum::NONE, and state().
|
virtual |
Tells the factory that we're in a reward declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 438 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _initializeFunctionGraph_(), _states_, gum::ACTION, gum::NONE, gum::REWARD, and state().
|
virtual |
Tells the factory that we're in a transition declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 310 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _initializeFunctionGraph_(), _states_, gum::ACTION, gum::NONE, state(), and gum::TRANSITION.
|
virtual |
Tells the factory that we're in a variable declaration.
Implements gum::AbstractFMDPFactory.
Definition at line 150 of file fmdpFactory_tpl.h.
References _illegalStateError_(), _states_, _stringBag_, gum::NONE, state(), and gum::VARIABLE.
|
virtual |
Returns the current state of the factory.
Implements gum::AbstractFMDPFactory.
Definition at line 117 of file fmdpFactory_tpl.h.
References _states_.
Referenced by _illegalStateError_(), addAction(), addCost(), addCost(), addDiscount(), addModality(), addReward(), addReward(), addTransition(), addTransition(), endActionDeclaration(), endCostDeclaration(), endDiscountDeclaration(), endRewardDeclaration(), endTransitionDeclaration(), endVariableDeclaration(), fmdp(), startActionDeclaration(), startCostDeclaration(), startDiscountDeclaration(), startRewardDeclaration(), startTransitionDeclaration(), startVariableDeclaration(), variableDescription(), and variableName().
|
virtual |
Returns a constant reference on a variable given it's name.
| NotFound | Raised if no variable matches the name. |
Implements gum::AbstractFMDPFactory.
Definition at line 128 of file fmdpFactory_tpl.h.
References _varNameMap_, and GUM_ERROR.
Referenced by addInternalNode().
|
virtual |
Tells the factory the current variable's description.
Implements gum::AbstractFMDPFactory.
Definition at line 178 of file fmdpFactory_tpl.h.
References _bar_flag_, _illegalStateError_(), _stringBag_, state(), and gum::VARIABLE.
|
virtual |
Tells the factory the current variable's name.
| DuplicateElement | Raised if a variable with the same name already exist. |
Implements gum::AbstractFMDPFactory.
Definition at line 164 of file fmdpFactory_tpl.h.
References _foo_flag_, _illegalStateError_(), _stringBag_, _varNameMap_, GUM_ERROR, state(), and gum::VARIABLE.
|
private |
Action Id counter.
Definition at line 322 of file fmdpFactory.h.
Referenced by FMDPFactory(), and addAction().
|
private |
Depending on the context this flag is used for some VERY important reasons.
Definition at line 286 of file fmdpFactory.h.
Referenced by _resetParts_(), endVariableDeclaration(), and variableDescription().
|
private |
Just to keep track of multidim between two start/end calls.
Definition at line 292 of file fmdpFactory.h.
Referenced by _resetParts_(), addReward(), and endRewardDeclaration().
|
private |
The constructed FMDP.
Definition at line 313 of file fmdpFactory.h.
Referenced by FMDPFactory(), _initializeFunctionGraph_(), addAction(), addCost(), addCost(), addReward(), addReward(), addTransition(), addTransition(), endRewardDeclaration(), endVariableDeclaration(), and fmdp().
|
private |
Depending on the context this flag is used for some VERY important reasons.
Definition at line 282 of file fmdpFactory.h.
Referenced by _resetParts_(), addCost(), addCost(), addReward(), addTransition(), addTransition(), endRewardDeclaration(), endVariableDeclaration(), setOperationModeOn(), startActionDeclaration(), and variableName().
|
private |
The FunctionGraph we're building at a given time.
Definition at line 316 of file fmdpFactory.h.
Referenced by _finalizeFunctionGraph_(), _initializeFunctionGraph_(), addArc(), addCost(), addInternalNode(), addReward(), addTerminalNode(), addTransition(), and setRoot().
|
private |
State stack.
Definition at line 310 of file fmdpFactory.h.
Referenced by FMDPFactory(), endActionDeclaration(), endCostDeclaration(), endDiscountDeclaration(), endRewardDeclaration(), endTransitionDeclaration(), endVariableDeclaration(), startActionDeclaration(), startCostDeclaration(), startDiscountDeclaration(), startRewardDeclaration(), startTransitionDeclaration(), startVariableDeclaration(), and state().
|
private |
Just to keep track of strings between two start/end calls.
Definition at line 289 of file fmdpFactory.h.
Referenced by _checkModalityInBag_(), _resetParts_(), addAction(), addCost(), addCost(), addModality(), addTransition(), addTransition(), endRewardDeclaration(), endVariableDeclaration(), setOperationModeOn(), startVariableDeclaration(), variableDescription(), and variableName().
|
private |
Mapping between a declared variable's name and itself.
Definition at line 319 of file fmdpFactory.h.
Referenced by addTransition(), addTransition(), endVariableDeclaration(), variable(), and variableName().
|
privateinherited |
Definition at line 296 of file IfmdpFactory.h.
Referenced by isVerbose(), resetVerbose(), and setVerbose().