aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::FMDPFactory< GUM_SCALAR > Class Template Reference

A factory class to ease Factored Markov Decision Process construction. More...

#include <agrum/FMDP/fmdpFactory.h>

Inheritance diagram for gum::FMDPFactory< GUM_SCALAR >:
Collaboration diagram for gum::FMDPFactory< GUM_SCALAR >:

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 DiscreteVariablevariable (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.

Detailed Description

template<typename GUM_SCALAR>
class gum::FMDPFactory< GUM_SCALAR >

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.

Constructor & Destructor Documentation

◆ FMDPFactory()

template<typename GUM_SCALAR>
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.

Parameters
fmdpA pointer over the FMDP filled by this factory.

Definition at line 76 of file fmdpFactory_tpl.h.

76 : _fmdp_(fmdp) {
78
81 _actionIdcpt_ = 1;
82 }
A factory class to ease Factored Markov Decision Process construction.
Definition fmdpFactory.h:87
FMDP< GUM_SCALAR > * _fmdp_
The constructed FMDP.
FMDPFactory(FMDP< GUM_SCALAR > *fmdp)
Use this constructor if you want to use an already created factored markov decision process.
FMDP< GUM_SCALAR > * fmdp() const
Returns the Factored Markov Decision Process created by this factory.
std::vector< FMDPfactory_state > _states_
State stack.
Idx _actionIdcpt_
Action Id counter.

References FMDPFactory(), _actionIdcpt_, _fmdp_, _states_, fmdp(), gum::NONE, and gum::AbstractFMDPFactory::resetVerbose().

Referenced by FMDPFactory(), ~FMDPFactory(), and operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~FMDPFactory()

template<typename GUM_SCALAR>
INLINE gum::FMDPFactory< GUM_SCALAR >::~FMDPFactory ( )

Destructor.

To prevent strange behaviour you should always destroy a FMDPFactory when it's state equals NONE.

Exceptions
FatalErrorRaised if the state of the factory prevents it to die peacefully.

Definition at line 87 of file fmdpFactory_tpl.h.

87 {
89 }

References FMDPFactory().

Here is the call graph for this function:

Member Function Documentation

◆ _checkModalityInBag_()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::_checkModalityInBag_ ( const std::string & mod)
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.

202 {
203 for (size_t i = 2; i < _stringBag_.size(); ++i)
204 if (mod == _stringBag_[i])
205 GUM_ERROR(DuplicateElement, "Modality" << mod << " already exists.")
206 }
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References _stringBag_, and GUM_ERROR.

Referenced by addModality().

Here is the caller graph for this function:

◆ _finalizeFunctionGraph_()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::_finalizeFunctionGraph_ ( )
private

Insert every variables in the function graph.

Definition at line 661 of file fmdpFactory_tpl.h.

661 {
662 this->_FunctionGraph_->manager()->reduce();
663 this->_FunctionGraph_->manager()->clean();
664 }
MultiDimFunctionGraph< GUM_SCALAR > * _FunctionGraph_
The FunctionGraph we're building at a given time.

References _FunctionGraph_.

Referenced by addCost(), addReward(), and addTransition().

Here is the caller graph for this function:

◆ _illegalStateError_()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::_illegalStateError_ ( const std::string & s)
private

Raise an OperationNotAllowed with the message "Illegal state.".

Definition at line 610 of file fmdpFactory_tpl.h.

610 {
611 std::string msg = "Illegal state call (";
612 msg += s;
613 msg += ") in state ";
614
615 switch (state()) {
616 case FMDPfactory_state::NONE : msg += "FMDPfactory_state::NONE"; break;
617
618 case FMDPfactory_state::VARIABLE : msg += "FMDPfactory_state::VARIABLE"; break;
619
620 case FMDPfactory_state::ACTION : msg += "FMDPfactory_state::ACTION"; break;
621
622 case FMDPfactory_state::TRANSITION : msg += "FMDPfactory_state::TRANSITION"; break;
623
624 case FMDPfactory_state::COST : msg += "FMDPfactory_state::COST"; break;
625
626 case FMDPfactory_state::REWARD : msg += "FMDPfactory_state::REWARD"; break;
627
628 case FMDPfactory_state::DISCOUNT : msg += "FMDPfactory_state::DISCOUNT"; break;
629
630 default : msg += "Unknown state";
631 }
632
634 }
FMDPfactory_state state() const
Returns the current state of the factory.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _initializeFunctionGraph_()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::_initializeFunctionGraph_ ( )
private

Insert every variables in the function graph.

Definition at line 647 of file fmdpFactory_tpl.h.

647 {
649 // Recopie des variables principales dans le graphe de décision
650 for (auto varIter = _fmdp_->beginVariables(); varIter != _fmdp_->endVariables(); ++varIter) {
651 _FunctionGraph_->add(**varIter);
652 }
653
654 // Recopie des version primes des variables dans le graphe de décision
655 for (auto varIter = _fmdp_->beginVariables(); varIter != _fmdp_->endVariables(); ++varIter) {
656 _FunctionGraph_->add(*(_fmdp_->main2prime(*varIter)));
657 }
658 }
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.

References _fmdp_, _FunctionGraph_, and gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::getReducedAndOrderedInstance().

Referenced by startCostDeclaration(), startRewardDeclaration(), and startTransitionDeclaration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _resetParts_()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::_resetParts_ ( )
private

Reset the different parts used to constructed the FMDP.

Definition at line 639 of file fmdpFactory_tpl.h.

639 {
640 _foo_flag_ = false;
641 _bar_flag_ = false;
642 _stringBag_.clear();
643 _ddBag_.clear();
644 }
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.
std::vector< const MultiDimImplementation< GUM_SCALAR > * > _ddBag_
Just to keep track of multidim between two start/end calls.

References _bar_flag_, _ddBag_, _foo_flag_, and _stringBag_.

Referenced by endActionDeclaration(), endRewardDeclaration(), and endVariableDeclaration().

Here is the caller graph for this function:

◆ addAction()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addAction ( const std::string & action)
virtual

Tells the factory to add an action to the current fmdp.

Implements gum::AbstractFMDPFactory.

Definition at line 275 of file fmdpFactory_tpl.h.

275 {
277 else {
278 _stringBag_.push_back(action);
279 _fmdp_->addAction(_actionIdcpt_++, action);
280 }
281 }
void _illegalStateError_(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".

References _actionIdcpt_, _fmdp_, _illegalStateError_(), _stringBag_, gum::ACTION, and state().

Here is the call graph for this function:

◆ addArc()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addArc ( NodeId from,
NodeId to,
Idx modality )
virtual

Insert in diagram a non terminal node.

Implements gum::AbstractFMDPFactory.

Definition at line 589 of file fmdpFactory_tpl.h.

589 {
590 _FunctionGraph_->manager()->setSon(from, modality, to);
591 }

References _FunctionGraph_.

◆ addCost() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addCost ( )
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.

403 {
405 else {
407
408 if (_foo_flag_)
409 _fmdp_->addCostForAction(_fmdp_->actionId(_stringBag_[0]), this->_FunctionGraph_);
410 else _fmdp_->addCost(this->_FunctionGraph_);
411 }
412 }
void _finalizeFunctionGraph_()
Insert every variables in the function graph.

References _finalizeFunctionGraph_(), _fmdp_, _foo_flag_, _FunctionGraph_, _illegalStateError_(), _stringBag_, gum::COST, and state().

Here is the call graph for this function:

◆ addCost() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addCost ( const MultiDimAdressable * cost)
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.

390 {
392 = reinterpret_cast< const MultiDimImplementation< GUM_SCALAR >* >(cost);
393
395 else if (_foo_flag_) _fmdp_->addCostForAction(_fmdp_->actionId(_stringBag_[0]), c);
396 else _fmdp_->addCost(c);
397 }

References _fmdp_, _foo_flag_, _illegalStateError_(), _stringBag_, gum::COST, and state().

Here is the call graph for this function:

◆ addDiscount()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addDiscount ( float discount)
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.

546 {
548 // else
549 // _fmdp_->setDiscount ( ( GUM_SCALAR ) discount );
550 }

References _illegalStateError_(), gum::DISCOUNT, and state().

Here is the call graph for this function:

◆ addInternalNode()

template<typename GUM_SCALAR>
INLINE NodeId gum::FMDPFactory< GUM_SCALAR >::addInternalNode ( std::string name_of_var)
virtual

Insert in diagram a non terminal node.

Implements gum::AbstractFMDPFactory.

Definition at line 576 of file fmdpFactory_tpl.h.

576 {
577 return _FunctionGraph_->manager()->addInternalNode(variable(name_of_var));
578 }
const DiscreteVariable * variable(const std::string &name) const
Returns a constant reference on a variable given it's name.

References _FunctionGraph_, and variable().

Here is the call graph for this function:

◆ addModality()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addModality ( const std::string & name)
virtual

Adds a modality to the current variable.

Implements gum::AbstractFMDPFactory.

Definition at line 191 of file fmdpFactory_tpl.h.

191 {
193 else {
195 _stringBag_.push_back(name);
196 }
197 }
void _checkModalityInBag_(const std::string &mod)
Used in VARIABLE mode Checks if in stringBag there is no other modality with the same name.

References _checkModalityInBag_(), _illegalStateError_(), _stringBag_, state(), and gum::VARIABLE.

Here is the call graph for this function:

◆ addReward() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addReward ( )
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.

473 {
475 else {
477 _FunctionGraph_->setTableName("Reward");
478
479 if (_foo_flag_) _ddBag_.push_back(this->_FunctionGraph_);
480 else _fmdp_->addReward(this->_FunctionGraph_);
481 }
482 }

References _ddBag_, _finalizeFunctionGraph_(), _fmdp_, _foo_flag_, _FunctionGraph_, _illegalStateError_(), gum::REWARD, and state().

Here is the call graph for this function:

◆ addReward() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addReward ( const MultiDimAdressable * reward)
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.

460 {
462 = reinterpret_cast< const MultiDimImplementation< GUM_SCALAR >* >(reward);
463
465 else _fmdp_->addReward(r);
466 }

References _fmdp_, _illegalStateError_(), gum::REWARD, and state().

Here is the call graph for this function:

◆ addTerminalNode()

template<typename GUM_SCALAR>
INLINE NodeId gum::FMDPFactory< GUM_SCALAR >::addTerminalNode ( float value)
virtual

Insert in diagram a terminal node.

Implements gum::AbstractFMDPFactory.

Definition at line 583 of file fmdpFactory_tpl.h.

583 {
584 return _FunctionGraph_->manager()->addTerminalNode((GUM_SCALAR)value);
585 }

References _FunctionGraph_.

◆ addTransition() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addTransition ( const std::string & var)
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.

338 {
340 else {
342
343 if (_foo_flag_) {
344 this->_FunctionGraph_->setTableName("ACTION :" + _stringBag_[0] + " - VARIABLE : " + var);
345 _fmdp_->addTransitionForAction(_fmdp_->actionId(_stringBag_[0]),
348 } else {
349 _fmdp_->addTransition(_varNameMap_[var], this->_FunctionGraph_);
350 }
351 }
352 }
HashTable< std::string, const DiscreteVariable * > _varNameMap_
Mapping between a declared variable's name and itself.

References _finalizeFunctionGraph_(), _fmdp_, _foo_flag_, _FunctionGraph_, _illegalStateError_(), _stringBag_, _varNameMap_, state(), and gum::TRANSITION.

Here is the call graph for this function:

◆ addTransition() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::addTransition ( const std::string & var,
const MultiDimAdressable * 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.

323 {
325 = reinterpret_cast< const MultiDimImplementation< GUM_SCALAR >* >(transition);
326
328 else if (_foo_flag_)
329 _fmdp_->addTransitionForAction(_fmdp_->actionId(_stringBag_[0]), _varNameMap_[var], t);
330 else _fmdp_->addTransition(_varNameMap_[var], t);
331 }

References _fmdp_, _foo_flag_, _illegalStateError_(), _stringBag_, _varNameMap_, state(), and gum::TRANSITION.

Here is the call graph for this function:

◆ endActionDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::endActionDeclaration ( )
virtual

Tells the factory that we're out of an action declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 286 of file fmdpFactory_tpl.h.

286 {
287 if (state() != FMDPfactory_state::ACTION) _illegalStateError_("endActionDeclaration");
288 else {
289 _states_.pop_back();
290 _resetParts_();
291 }
292
293 // VERBOSITY ( "action OK" );
294 }
void _resetParts_()
Reset the different parts used to constructed the FMDP.

References _illegalStateError_(), _resetParts_(), _states_, gum::ACTION, and state().

Here is the call graph for this function:

◆ endCostDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::endCostDeclaration ( )
virtual

Tells the factory that we're out of a cost declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 417 of file fmdpFactory_tpl.h.

417 {
418 if (state() != FMDPfactory_state::COST) _illegalStateError_("endCostDeclaration");
419 else _states_.pop_back();
420
421 // VERBOSITY ( "Cost OK" );
422 }

References _illegalStateError_(), _states_, gum::COST, and state().

Here is the call graph for this function:

◆ endDiscountDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::endDiscountDeclaration ( )
virtual

Tells the factory that we're out of a cost declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 555 of file fmdpFactory_tpl.h.

555 {
556 if (state() != FMDPfactory_state::DISCOUNT) _illegalStateError_("endDiscountDeclaration");
557 else _states_.pop_back();
558
559 // VERBOSITY ( "discount OK" );
560 }

References _illegalStateError_(), _states_, gum::DISCOUNT, and state().

Here is the call graph for this function:

◆ endRewardDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::endRewardDeclaration ( )
virtual

Tells the factory that we're out of a cost declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 487 of file fmdpFactory_tpl.h.

487 {
488 if (state() != FMDPfactory_state::REWARD) _illegalStateError_("endRewardDeclaration");
489 else {
490 if (_foo_flag_) {
493
494 for (const auto elt: _ddBag_) {
495 temp = res;
496
497 switch (_stringBag_[0][0]) {
498 case '+' : res = add2MultiDimFunctionGraphs(res, elt); break;
499
500 case '-' : res = subtract2MultiDimFunctionGraphs(res, elt); break;
501
502 case '*' : res = multiply2MultiDimFunctionGraphs(res, elt); break;
503
504 case '/' : res = divide2MultiDimFunctionGraphs(res, elt); break;
505
506 default : break;
507 }
508
509 delete elt;
510
511 if (temp != nullptr) delete temp;
512 }
513 reinterpret_cast< MultiDimFunctionGraph< GUM_SCALAR >* >(res)->setTableName("Reward");
514 _fmdp_->addReward(res);
515 }
516
517 _resetParts_();
518 _states_.pop_back();
519 }
520 // VERBOSITY ( "reward OK" );
521 }
MultiDimFunctionGraph< T > * divide2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for dividing two multiDimArrays
MultiDimFunctionGraph< T > * multiply2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for multiplying two multiDimArrays
MultiDimFunctionGraph< T > * subtract2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for subtracting two multiDimArrays
MultiDimFunctionGraph< T > * add2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for summing two multiDimArrays

References _ddBag_, _fmdp_, _foo_flag_, _illegalStateError_(), _resetParts_(), _states_, _stringBag_, gum::add2MultiDimFunctionGraphs(), gum::divide2MultiDimFunctionGraphs(), gum::multiply2MultiDimFunctionGraphs(), gum::REWARD, state(), and gum::subtract2MultiDimFunctionGraphs().

Here is the call graph for this function:

◆ endTransitionDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::endTransitionDeclaration ( )
virtual

Tells the factory that we're out of a transition declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 357 of file fmdpFactory_tpl.h.

357 {
358 if (state() != FMDPfactory_state::TRANSITION) _illegalStateError_("endTransitionDeclaration");
359 else _states_.pop_back();
360
361 // VERBOSITY ( "transition OK" );
362 }

References _illegalStateError_(), _states_, state(), and gum::TRANSITION.

Here is the call graph for this function:

◆ endVariableDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::endVariableDeclaration ( )
virtual

Tells the factory that we're out of a variable declaration.

Exceptions
UndefinedElementRaised if the variable isn't defined (or not enough defined).

Implements gum::AbstractFMDPFactory.

Definition at line 211 of file fmdpFactory_tpl.h.

211 {
212 if (state() != FMDPfactory_state::VARIABLE) _illegalStateError_("endVariableDeclaration");
213 else if (_foo_flag_ && (_stringBag_.size() > 3)) {
215 = new LabelizedVariable(_stringBag_[0], (_bar_flag_) ? _stringBag_[1] : "", 0);
216
217 for (size_t i = 2; i < _stringBag_.size(); ++i) {
218 var->addLabel(_stringBag_[i]);
219 }
220
221 _fmdp_->addVariable(var);
222 _varNameMap_.insert(var->name(), var);
223 _varNameMap_.insert(_fmdp_->main2prime(var)->name(), _fmdp_->main2prime(var));
224
225 _resetParts_();
226 _states_.pop_back();
227
228 // VERBOSITY ( " variable " << var->name() << " OK" );
229
230 } else {
232 msg << "Not enough modalities (";
233
234 if (_stringBag_.size() > 2) msg << _stringBag_.size() - 2;
235 else msg << 0;
236
237 msg << ") declared for variable ";
238
239 if (_foo_flag_) msg << _stringBag_[0];
240 else msg << "unknown";
241
242 _resetParts_();
243 _states_.pop_back();
244
246 }
247 }

References _bar_flag_, _fmdp_, _foo_flag_, _illegalStateError_(), _resetParts_(), _states_, _stringBag_, _varNameMap_, gum::LabelizedVariable::addLabel(), GUM_ERROR, gum::Variable::name(), state(), and gum::VARIABLE.

Here is the call graph for this function:

◆ fmdp()

template<typename GUM_SCALAR>
INLINE FMDP< GUM_SCALAR > * gum::FMDPFactory< GUM_SCALAR >::fmdp ( ) const

Returns the Factored Markov Decision Process created by this factory.

Exceptions
OperationNotAllowedRaise if the state of the factory is different than NONE.

Definition at line 104 of file fmdpFactory_tpl.h.

104 {
107 "Illegal state to return the factored "
108 "markov decision process: it is not yet "
109 "finished.");
110
111 return _fmdp_;
112 }

References _fmdp_, GUM_ERROR, gum::NONE, and state().

Referenced by FMDPFactory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isVerbose()

bool gum::AbstractFMDPFactory::isVerbose ( )
inlineinherited

Definition at line 291 of file IfmdpFactory.h.

291{ return _verbose_; }

References _verbose_.

◆ operator=()

template<typename GUM_SCALAR>
INLINE FMDPFactory< GUM_SCALAR > & gum::FMDPFactory< GUM_SCALAR >::operator= ( const FMDPFactory< GUM_SCALAR > & source)
private

Copy operator is illegal, use only copy constructor.

Definition at line 683 of file fmdpFactory_tpl.h.

683 {
684 GUM_ERROR(FatalError, "Illegal!")
685 // For noisy compilers
686 return *this;
687 }

References FMDPFactory(), and GUM_ERROR.

Here is the call graph for this function:

◆ resetVerbose()

void gum::AbstractFMDPFactory::resetVerbose ( )
inlineinherited

Definition at line 289 of file IfmdpFactory.h.

289{ _verbose_ = false; }

References _verbose_.

Referenced by gum::FMDPFactory< GUM_SCALAR >::FMDPFactory().

Here is the caller graph for this function:

◆ setOperationModeOn()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::setOperationModeOn ( std::string operationType)
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.

451 {
452 _foo_flag_ = true;
454 _stringBag_.push_back(ot);
455 }

References _foo_flag_, and _stringBag_.

◆ setRoot()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::setRoot ( NodeId rootId)
virtual

add an arc in diagram

Implements gum::AbstractFMDPFactory.

Definition at line 594 of file fmdpFactory_tpl.h.

594 {
595 _FunctionGraph_->manager()->setRootNode(rootId);
596 }

References _FunctionGraph_.

◆ setVerbose()

void gum::AbstractFMDPFactory::setVerbose ( )
inlineinherited

Definition at line 287 of file IfmdpFactory.h.

287{ _verbose_ = true; }

References _verbose_.

◆ startActionDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::startActionDeclaration ( )
virtual

Tells the factory that we're in an action declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 262 of file fmdpFactory_tpl.h.

262 {
263 if (state() != FMDPfactory_state::NONE) _illegalStateError_("startActionDeclaration");
264 else {
265 _foo_flag_ = true;
267 }
268
269 // VERBOSITY ( "starting action declaration" );
270 }

References _foo_flag_, _illegalStateError_(), _states_, gum::ACTION, gum::NONE, and state().

Here is the call graph for this function:

◆ startCostDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::startCostDeclaration ( )
virtual

Tells the factory that we're in a cost declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 378 of file fmdpFactory_tpl.h.

378 {
380 _illegalStateError_("startTransitionDeclaration");
381 else _states_.push_back(FMDPfactory_state::COST);
382
383 // VERBOSITY ( "starting Cost declaration" );
385 }
void _initializeFunctionGraph_()
Insert every variables in the function graph.

References _illegalStateError_(), _initializeFunctionGraph_(), _states_, gum::ACTION, gum::COST, gum::NONE, and state().

Here is the call graph for this function:

◆ startDiscountDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::startDiscountDeclaration ( )
virtual

Tells the factory that we're in a cost declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 536 of file fmdpFactory_tpl.h.

536 {
537 if (state() != FMDPfactory_state::NONE) _illegalStateError_("startDiscountDeclaration");
539
540 // VERBOSITY ( "starting discount declaration" );
541 }

References _illegalStateError_(), _states_, gum::DISCOUNT, gum::NONE, and state().

Here is the call graph for this function:

◆ startRewardDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::startRewardDeclaration ( )
virtual

Tells the factory that we're in a reward declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 438 of file fmdpFactory_tpl.h.

438 {
440 _illegalStateError_("startRewardDeclaration");
441 else _states_.push_back(FMDPfactory_state::REWARD);
442
443 // VERBOSITY ( "starting reward declaration" );
445 }

References _illegalStateError_(), _initializeFunctionGraph_(), _states_, gum::ACTION, gum::NONE, gum::REWARD, and state().

Here is the call graph for this function:

◆ startTransitionDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::startTransitionDeclaration ( )
virtual

Tells the factory that we're in a transition declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 310 of file fmdpFactory_tpl.h.

310 {
312 _illegalStateError_("startTransitionDeclaration");
314
315 // VERBOSITY ( "starting transition declaration" );
317 }

References _illegalStateError_(), _initializeFunctionGraph_(), _states_, gum::ACTION, gum::NONE, state(), and gum::TRANSITION.

Here is the call graph for this function:

◆ startVariableDeclaration()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::startVariableDeclaration ( )
virtual

Tells the factory that we're in a variable declaration.

Implements gum::AbstractFMDPFactory.

Definition at line 150 of file fmdpFactory_tpl.h.

150 {
151 if (state() != FMDPfactory_state::NONE) _illegalStateError_("startVariableDeclaration");
152 else {
154 _stringBag_.push_back("name");
155 _stringBag_.push_back("desc");
156 }
157
158 // VERBOSITY ( " starting variable" );
159 }

References _illegalStateError_(), _states_, _stringBag_, gum::NONE, state(), and gum::VARIABLE.

Here is the call graph for this function:

◆ state()

template<typename GUM_SCALAR>
INLINE FMDPfactory_state gum::FMDPFactory< GUM_SCALAR >::state ( ) const
virtual

Returns the current state of the factory.

Implements gum::AbstractFMDPFactory.

Definition at line 117 of file fmdpFactory_tpl.h.

117 {
118 // This is ok because there is alway at least the state
119 // FMDPfactory_state::NONE in the stack.
120 return _states_.back();
121 }

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().

Here is the caller graph for this function:

◆ variable()

template<typename GUM_SCALAR>
INLINE const DiscreteVariable * gum::FMDPFactory< GUM_SCALAR >::variable ( const std::string & name) const
virtual

Returns a constant reference on a variable given it's name.

Exceptions
NotFoundRaised if no variable matches the name.

Implements gum::AbstractFMDPFactory.

Definition at line 128 of file fmdpFactory_tpl.h.

128 {
129 for (const auto& elt: _varNameMap_)
130 if (elt.first.compare(name) == 0) return elt.second;
131
133
134 return nullptr;
135 }

References _varNameMap_, and GUM_ERROR.

Referenced by addInternalNode().

Here is the caller graph for this function:

◆ variableDescription()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::variableDescription ( const std::string & desc)
virtual

Tells the factory the current variable's description.

Implements gum::AbstractFMDPFactory.

Definition at line 178 of file fmdpFactory_tpl.h.

178 {
179 if (state() != FMDPfactory_state::VARIABLE) _illegalStateError_("variableDescription");
180 else {
181 _bar_flag_ = true;
182 _stringBag_[1] = desc;
183 }
184 }

References _bar_flag_, _illegalStateError_(), _stringBag_, state(), and gum::VARIABLE.

Here is the call graph for this function:

◆ variableName()

template<typename GUM_SCALAR>
INLINE void gum::FMDPFactory< GUM_SCALAR >::variableName ( const std::string & name)
virtual

Tells the factory the current variable's name.

Exceptions
DuplicateElementRaised if a variable with the same name already exist.

Implements gum::AbstractFMDPFactory.

Definition at line 164 of file fmdpFactory_tpl.h.

164 {
165 if (state() != FMDPfactory_state::VARIABLE) _illegalStateError_("variableName");
166 else {
167 if (_varNameMap_.exists(name)) GUM_ERROR(DuplicateElement, "Name already used: " + name)
168
169 _foo_flag_ = true;
170 _stringBag_[0] = name;
171 // VERBOSITY ( " -- variable " << name );
172 }
173 }

References _foo_flag_, _illegalStateError_(), _stringBag_, _varNameMap_, GUM_ERROR, state(), and gum::VARIABLE.

Here is the call graph for this function:

Member Data Documentation

◆ _actionIdcpt_

template<typename GUM_SCALAR>
Idx gum::FMDPFactory< GUM_SCALAR >::_actionIdcpt_
private

Action Id counter.

Definition at line 322 of file fmdpFactory.h.

Referenced by FMDPFactory(), and addAction().

◆ _bar_flag_

template<typename GUM_SCALAR>
bool gum::FMDPFactory< GUM_SCALAR >::_bar_flag_
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().

◆ _ddBag_

template<typename GUM_SCALAR>
std::vector< const MultiDimImplementation< GUM_SCALAR >* > gum::FMDPFactory< GUM_SCALAR >::_ddBag_
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().

◆ _fmdp_

template<typename GUM_SCALAR>
FMDP< GUM_SCALAR >* gum::FMDPFactory< GUM_SCALAR >::_fmdp_
private

◆ _foo_flag_

template<typename GUM_SCALAR>
bool gum::FMDPFactory< GUM_SCALAR >::_foo_flag_
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().

◆ _FunctionGraph_

template<typename GUM_SCALAR>
MultiDimFunctionGraph< GUM_SCALAR >* gum::FMDPFactory< GUM_SCALAR >::_FunctionGraph_
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().

◆ _states_

◆ _stringBag_

template<typename GUM_SCALAR>
std::vector< std::string > gum::FMDPFactory< GUM_SCALAR >::_stringBag_
private

◆ _varNameMap_

template<typename GUM_SCALAR>
HashTable< std::string, const DiscreteVariable* > gum::FMDPFactory< GUM_SCALAR >::_varNameMap_
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().

◆ _verbose_

bool gum::AbstractFMDPFactory::_verbose_
privateinherited

Definition at line 296 of file IfmdpFactory.h.

Referenced by isVerbose(), resetVerbose(), and setVerbose().


The documentation for this class was generated from the following files: