aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::FMDPFactory< GUM_ELEMENT > 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_ELEMENT >:
Collaboration diagram for gum::FMDPFactory< GUM_ELEMENT >:

Public Member Functions

Constructor & destructor.
 FMDPFactory (FMDP< GUM_ELEMENT > *fmdp)
 Use this constructor if you want to use an already created factored markov decision process.
 ~FMDPFactory () override
 Destructor.
Getter and setters.
FMDP< GUM_ELEMENT > * fmdp () const
 Returns the Factored Markov Decision Process created by this factory.
FMDPfactory_state state () const override
 Returns the current state of the factory.
const DiscreteVariablevariable (std::string_view name) const override
 Returns a constant reference on a variable given it's name.
Variable declaration methods (NONE -> VARIABLE)
void startVariableDeclaration () override
 Tells the factory that we're in a variable declaration.
void variableName (std::string_view name) override
 Tells the factory the current variable's name.
void variableDescription (std::string_view desc) override
 Tells the factory the current variable's description.
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.
Action declaration methods (NONE -> ACTION)
void startActionDeclaration () override
 Tells the factory that we're in an action declaration.
void addAction (std::string_view action) override
 Tells the factory to add an action to the current fmdp.
void endActionDeclaration () override
 Tells the factory that we're out of an action declaration.
Transition declaration methods (NONE -> TRANSITION <- ACTION)
void startTransitionDeclaration () override
 Tells the factory that we're in a transition declaration.
void addTransition (std::string_view var, const MultiDimAdressable *transition) override
 Tells the factory to add a transition table to the current fmdp.
void addTransition (std::string_view var) override
 Tells the factory to add a transition table to the current fmdp. This transition table will be extracted from incorporated multiDimFunctionGraph.
void endTransitionDeclaration () override
 Tells the factory that we're out of a transition declaration.
Cost declaration methods (NONE -> COST <- ACTION)
void startCostDeclaration () override
 Tells the factory that we're in a cost declaration.
void addCost (const MultiDimAdressable *cost) override
 Tells the factory to add a cost table to the current fmdp.
void addCost () override
 Tells the factory to add a cost table to the current fmdp. This cost table will be extracted from incorporated multiDimFunctionGraph.
void endCostDeclaration () override
 Tells the factory that we're out of a cost declaration.
Reward declaration methods (NONE -> REWARD <- ACTION)
void startRewardDeclaration () override
 Tells the factory that we're in a reward declaration.
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 operation between simplier decision diagram..
void addReward (const MultiDimAdressable *reward) override
 Tells the factory to add a reward table to the current fmdp.
void addReward () override
 Tells the factory to add a reward table to the current fmdp. This reward table will be extracted from incorporated multiDimFunctionGraph.
void endRewardDeclaration () override
 Tells the factory that we're out of a cost declaration.
Discount declaration methods (NONE -> DISCOUNT)
void startDiscountDeclaration () override
 Tells the factory that we're in a cost declaration.
void addDiscount (float discount) override
 Tells the factory to add a cost table to the current fmdp.
void endDiscountDeclaration () override
 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_view name_of_var) override
 Insert in diagram a non terminal node.
NodeId addTerminalNode (float value) override
 Insert in diagram a terminal node.
void addArc (NodeId from, NodeId to, Idx modality) override
 Insert in diagram a non terminal node.
void setRoot (NodeId rootId) override
 add an arc in diagram
verbosity control
void setVerbose ()
void resetVerbose ()
bool isVerbose ()

Private Member Functions

FMDPFactory< GUM_ELEMENT > & operator= (const FMDPFactory< GUM_ELEMENT > &source)
 Copy operator is illegal, use only copy constructor.
void _illegalStateError_ (std::string_view s)
 Raise an OperationNotAllowed with the message "Illegal state.".

Private Attributes

std::vector< FMDPfactory_state_states_
 State stack.
FMDP< GUM_ELEMENT > * _fmdp_
 The constructed FMDP.
MultiDimFunctionGraph< GUM_ELEMENT > * _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_ELEMENT > * > _ddBag_
 Just to keep track of multidim between two start/end calls.
void _checkModalityInBag_ (std::string_view 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_ELEMENT>
class gum::FMDPFactory< GUM_ELEMENT >

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 89 of file fmdpFactory.h.

Constructor & Destructor Documentation

◆ FMDPFactory()

template<typename GUM_ELEMENT>
gum::FMDPFactory< GUM_ELEMENT >::FMDPFactory ( FMDP< GUM_ELEMENT > * 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 77 of file fmdpFactory_tpl.h.

77 : _fmdp_(fmdp) {
79
82 _actionIdcpt_ = 1;
83 }
A factory class to ease Factored Markov Decision Process construction.
Definition fmdpFactory.h:89
std::vector< FMDPfactory_state > _states_
State stack.
FMDP< GUM_ELEMENT > * _fmdp_
The constructed FMDP.
FMDP< GUM_ELEMENT > * fmdp() const
Returns the Factored Markov Decision Process created by this factory.
FMDPFactory(FMDP< GUM_ELEMENT > *fmdp)
Use this constructor if you want to use an already created factored markov decision process.
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_ELEMENT>
gum::FMDPFactory< GUM_ELEMENT >::~FMDPFactory ( )
override

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 88 of file fmdpFactory_tpl.h.

88 {
90 }

References FMDPFactory().

Here is the call graph for this function:

Member Function Documentation

◆ _checkModalityInBag_()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::_checkModalityInBag_ ( std::string_view 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:76

References _stringBag_, and GUM_ERROR.

Referenced by addModality().

Here is the caller graph for this function:

◆ _finalizeFunctionGraph_()

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

Insert every variables in the function graph.

Definition at line 659 of file fmdpFactory_tpl.h.

659 {
660 this->_FunctionGraph_->manager()->reduce();
661 this->_FunctionGraph_->manager()->clean();
662 }
MultiDimFunctionGraph< GUM_ELEMENT > * _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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::_illegalStateError_ ( std::string_view s)
private

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

Definition at line 608 of file fmdpFactory_tpl.h.

608 {
609 std::string msg = "Illegal state call (";
610 msg += s;
611 msg += ") in state ";
612
613 switch (state()) {
614 case FMDPfactory_state::NONE : msg += "FMDPfactory_state::NONE"; break;
615
616 case FMDPfactory_state::VARIABLE : msg += "FMDPfactory_state::VARIABLE"; break;
617
618 case FMDPfactory_state::ACTION : msg += "FMDPfactory_state::ACTION"; break;
619
620 case FMDPfactory_state::TRANSITION : msg += "FMDPfactory_state::TRANSITION"; break;
621
622 case FMDPfactory_state::COST : msg += "FMDPfactory_state::COST"; break;
623
624 case FMDPfactory_state::REWARD : msg += "FMDPfactory_state::REWARD"; break;
625
626 case FMDPfactory_state::DISCOUNT : msg += "FMDPfactory_state::DISCOUNT"; break;
627
628 default : msg += "Unknown state";
629 }
630
632 }
FMDPfactory_state state() const override
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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::_initializeFunctionGraph_ ( )
private

Insert every variables in the function graph.

Definition at line 645 of file fmdpFactory_tpl.h.

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

References _fmdp_, _FunctionGraph_, and gum::MultiDimFunctionGraph< GUM_ELEMENT, 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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::_resetParts_ ( )
private

Reset the different parts used to constructed the FMDP.

Definition at line 637 of file fmdpFactory_tpl.h.

637 {
638 _foo_flag_ = false;
639 _bar_flag_ = false;
640 _stringBag_.clear();
641 _ddBag_.clear();
642 }
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< const MultiDimImplementation< GUM_ELEMENT > * > _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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addAction ( std::string_view action)
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 269 of file fmdpFactory_tpl.h.

269 {
271 else {
272 _stringBag_.emplace_back(action);
273 _fmdp_->addAction(_actionIdcpt_++, std::string(action));
274 }
275 }
void _illegalStateError_(std::string_view 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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addArc ( NodeId from,
NodeId to,
Idx modality )
overridevirtual

Insert in diagram a non terminal node.

Implements gum::AbstractFMDPFactory.

Definition at line 587 of file fmdpFactory_tpl.h.

587 {
588 _FunctionGraph_->manager()->setSon(from, modality, to);
589 }

References _FunctionGraph_.

◆ addCost() [1/2]

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addCost ( )
overridevirtual

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 398 of file fmdpFactory_tpl.h.

398 {
400 else {
402
403 if (_foo_flag_)
404 _fmdp_->addCostForAction(_fmdp_->actionId(_stringBag_[0]), this->_FunctionGraph_);
405 else _fmdp_->addCost(this->_FunctionGraph_);
406 }
407 }
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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addCost ( const MultiDimAdressable * cost)
overridevirtual

Tells the factory to add a cost table to the current fmdp.

Implements gum::AbstractFMDPFactory.

Definition at line 385 of file fmdpFactory_tpl.h.

385 {
387 = static_cast< const MultiDimImplementation< GUM_ELEMENT >* >(cost);
388
390 else if (_foo_flag_) _fmdp_->addCostForAction(_fmdp_->actionId(_stringBag_[0]), c);
391 else _fmdp_->addCost(c);
392 }

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

Here is the call graph for this function:

◆ addDiscount()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addDiscount ( float discount)
overridevirtual

Tells the factory to add a cost table to the current fmdp.

Implements gum::AbstractFMDPFactory.

Definition at line 545 of file fmdpFactory_tpl.h.

545 {
547 else _fmdp_->setDiscount((GUM_ELEMENT)discount);
548 }

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

Here is the call graph for this function:

◆ addInternalNode()

template<typename GUM_ELEMENT>
NodeId gum::FMDPFactory< GUM_ELEMENT >::addInternalNode ( std::string_view name_of_var)
overridevirtual

Insert in diagram a non terminal node.

Implements gum::AbstractFMDPFactory.

Definition at line 574 of file fmdpFactory_tpl.h.

574 {
575 return _FunctionGraph_->manager()->addInternalNode(variable(name_of_var));
576 }
const DiscreteVariable * variable(std::string_view name) const override
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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addModality ( std::string_view name)
overridevirtual

Adds a modality to the current variable.

Implements gum::AbstractFMDPFactory.

Definition at line 191 of file fmdpFactory_tpl.h.

191 {
193 else {
195 _stringBag_.emplace_back(name);
196 }
197 }
void _checkModalityInBag_(std::string_view 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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addReward ( )
overridevirtual

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 467 of file fmdpFactory_tpl.h.

467 {
469 else {
471 _FunctionGraph_->setTableName("Reward");
472
473 if (_foo_flag_) _ddBag_.push_back(this->_FunctionGraph_);
474 else _fmdp_->addReward(this->_FunctionGraph_);
475 }
476 }

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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addReward ( const MultiDimAdressable * reward)
overridevirtual

Tells the factory to add a reward table to the current fmdp.

Implements gum::AbstractFMDPFactory.

Definition at line 454 of file fmdpFactory_tpl.h.

454 {
456 = static_cast< const MultiDimImplementation< GUM_ELEMENT >* >(reward);
457
459 else _fmdp_->addReward(r);
460 }

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

Here is the call graph for this function:

◆ addTerminalNode()

template<typename GUM_ELEMENT>
NodeId gum::FMDPFactory< GUM_ELEMENT >::addTerminalNode ( float value)
overridevirtual

Insert in diagram a terminal node.

Implements gum::AbstractFMDPFactory.

Definition at line 581 of file fmdpFactory_tpl.h.

581 {
582 return _FunctionGraph_->manager()->addTerminalNode((GUM_ELEMENT)value);
583 }

References _FunctionGraph_.

◆ addTransition() [1/2]

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addTransition ( std::string_view var)
overridevirtual

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 332 of file fmdpFactory_tpl.h.

332 {
334 else {
336
337 if (_foo_flag_) {
338 this->_FunctionGraph_->setTableName("ACTION :" + _stringBag_[0]
339 + " - VARIABLE : " + std::string(var));
340 _fmdp_->addTransitionForAction(_fmdp_->actionId(_stringBag_[0]),
341 variable(var),
342 this->_FunctionGraph_);
343 } else {
344 _fmdp_->addTransition(variable(var), this->_FunctionGraph_);
345 }
346 }
347 }

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

Here is the call graph for this function:

◆ addTransition() [2/2]

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::addTransition ( std::string_view var,
const MultiDimAdressable * transition )
overridevirtual

Tells the factory to add a transition table to the current fmdp.

Implements gum::AbstractFMDPFactory.

Definition at line 316 of file fmdpFactory_tpl.h.

317 {
319 = static_cast< const MultiDimImplementation< GUM_ELEMENT >* >(transition);
320
322 else if (_foo_flag_)
323 _fmdp_->addTransitionForAction(_fmdp_->actionId(_stringBag_[0]), variable(var), t);
324 else _fmdp_->addTransition(variable(var), t);
325 }

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

Here is the call graph for this function:

◆ endActionDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::endActionDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 280 of file fmdpFactory_tpl.h.

280 {
281 if (state() != FMDPfactory_state::ACTION) _illegalStateError_("endActionDeclaration");
282 else {
283 _states_.pop_back();
284 _resetParts_();
285 }
286
287 // VERBOSITY ( "action OK" );
288 }
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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::endCostDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 412 of file fmdpFactory_tpl.h.

412 {
413 if (state() != FMDPfactory_state::COST) _illegalStateError_("endCostDeclaration");
414 else _states_.pop_back();
415
416 // VERBOSITY ( "Cost OK" );
417 }

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

Here is the call graph for this function:

◆ endDiscountDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::endDiscountDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 553 of file fmdpFactory_tpl.h.

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

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

Here is the call graph for this function:

◆ endRewardDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::endRewardDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 481 of file fmdpFactory_tpl.h.

481 {
482 if (state() != FMDPfactory_state::REWARD) _illegalStateError_("endRewardDeclaration");
483 else {
484 if (_foo_flag_) {
486
487 for (const auto elt: _ddBag_) {
488 if (res == nullptr) {
490 continue;
491 }
493
494 switch (_stringBag_[0][0]) {
495 case '+' : res = add2MultiDimFunctionGraphs(res, elt); break;
496
497 case '-' : res = subtract2MultiDimFunctionGraphs(res, elt); break;
498
499 case '*' : res = multiply2MultiDimFunctionGraphs(res, elt); break;
500
501 case '/' : res = divide2MultiDimFunctionGraphs(res, elt); break;
502
503 default : break;
504 }
505
506 delete elt;
507 delete temp;
508 }
509
510 if (res != nullptr) {
511 static_cast< MultiDimFunctionGraph< GUM_ELEMENT >* >(res)->setTableName("Reward");
512 _fmdp_->addReward(res);
513 }
514 }
515
516 _resetParts_();
517 _states_.pop_back();
518 }
519 // VERBOSITY ( "reward OK" );
520 }
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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::endTransitionDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 352 of file fmdpFactory_tpl.h.

352 {
353 if (state() != FMDPfactory_state::TRANSITION) _illegalStateError_("endTransitionDeclaration");
354 else _states_.pop_back();
355
356 // VERBOSITY ( "transition OK" );
357 }

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

Here is the call graph for this function:

◆ endVariableDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::endVariableDeclaration ( )
overridevirtual

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 _fmdp_->setDeleteVariablesOnDestruction(true);
223 _varNameMap_.insert(var->name(), var);
224 _varNameMap_.insert(_fmdp_->main2prime(var)->name(), _fmdp_->main2prime(var));
225
226 _resetParts_();
227 _states_.pop_back();
228
229 // VERBOSITY ( " variable " << var->name() << " OK" );
230
231 } else {
232 const size_t nModa = _stringBag_.size() > 2 ? _stringBag_.size() - 2 : size_t{0};
233 const std::string varName = _foo_flag_ ? _stringBag_[0] : "unknown";
234
235 _resetParts_();
236 _states_.pop_back();
237
239 std::format("Not enough modalities ({}) declared for variable {}", nModa, varName))
240 }
241 }
HashTable< std::string, const DiscreteVariable * > _varNameMap_
Mapping between a declared variable's name and itself.

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_ELEMENT>
FMDP< GUM_ELEMENT > * gum::FMDPFactory< GUM_ELEMENT >::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 105 of file fmdpFactory_tpl.h.

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

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

INLINE bool gum::AbstractFMDPFactory::isVerbose ( )
inherited

Definition at line 52 of file IfmdpFactory_inl.h.

52{ return _verbose_; }

References _verbose_.

◆ operator=()

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

Copy operator is illegal, use only copy constructor.

Definition at line 681 of file fmdpFactory_tpl.h.

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

References FMDPFactory(), and GUM_ERROR.

Here is the call graph for this function:

◆ resetVerbose()

INLINE void gum::AbstractFMDPFactory::resetVerbose ( )
inherited

Definition at line 50 of file IfmdpFactory_inl.h.

50{ _verbose_ = false; }

References _verbose_.

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

Here is the caller graph for this function:

◆ setOperationModeOn()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::setOperationModeOn ( std::string_view operationType)
overridevirtual

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 446 of file fmdpFactory_tpl.h.

446 {
447 _foo_flag_ = true;
449 }

References _foo_flag_, and _stringBag_.

◆ setRoot()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::setRoot ( NodeId rootId)
overridevirtual

add an arc in diagram

Implements gum::AbstractFMDPFactory.

Definition at line 592 of file fmdpFactory_tpl.h.

592 {
593 _FunctionGraph_->manager()->setRootNode(rootId);
594 }

References _FunctionGraph_.

◆ setVerbose()

INLINE void gum::AbstractFMDPFactory::setVerbose ( )
inherited

Definition at line 48 of file IfmdpFactory_inl.h.

48{ _verbose_ = true; }

References _verbose_.

◆ startActionDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::startActionDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 256 of file fmdpFactory_tpl.h.

256 {
257 if (state() != FMDPfactory_state::NONE) _illegalStateError_("startActionDeclaration");
258 else {
259 _foo_flag_ = true;
261 }
262
263 // VERBOSITY ( "starting action declaration" );
264 }

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

Here is the call graph for this function:

◆ startCostDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::startCostDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 373 of file fmdpFactory_tpl.h.

373 {
375 _illegalStateError_("startTransitionDeclaration");
376 else _states_.push_back(FMDPfactory_state::COST);
377
378 // VERBOSITY ( "starting Cost declaration" );
380 }
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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::startDiscountDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 535 of file fmdpFactory_tpl.h.

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

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

Here is the call graph for this function:

◆ startRewardDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::startRewardDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 433 of file fmdpFactory_tpl.h.

433 {
435 _illegalStateError_("startRewardDeclaration");
436 else _states_.push_back(FMDPfactory_state::REWARD);
437
438 // VERBOSITY ( "starting reward declaration" );
440 }

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

Here is the call graph for this function:

◆ startTransitionDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::startTransitionDeclaration ( )
overridevirtual

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

Implements gum::AbstractFMDPFactory.

Definition at line 304 of file fmdpFactory_tpl.h.

304 {
306 _illegalStateError_("startTransitionDeclaration");
308
309 // VERBOSITY ( "starting transition declaration" );
311 }

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

Here is the call graph for this function:

◆ startVariableDeclaration()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::startVariableDeclaration ( )
overridevirtual

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_ELEMENT>
FMDPfactory_state gum::FMDPFactory< GUM_ELEMENT >::state ( ) const
overridevirtual

Returns the current state of the factory.

Implements gum::AbstractFMDPFactory.

Definition at line 118 of file fmdpFactory_tpl.h.

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

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_ELEMENT>
const DiscreteVariable * gum::FMDPFactory< GUM_ELEMENT >::variable ( std::string_view name) const
overridevirtual

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(), addTransition(), and addTransition().

Here is the caller graph for this function:

◆ variableDescription()

template<typename GUM_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::variableDescription ( std::string_view desc)
overridevirtual

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_ELEMENT>
void gum::FMDPFactory< GUM_ELEMENT >::variableName ( std::string_view name)
overridevirtual

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_ELEMENT>
Idx gum::FMDPFactory< GUM_ELEMENT >::_actionIdcpt_
private

Action Id counter.

Definition at line 324 of file fmdpFactory.h.

Referenced by FMDPFactory(), and addAction().

◆ _bar_flag_

template<typename GUM_ELEMENT>
bool gum::FMDPFactory< GUM_ELEMENT >::_bar_flag_
private

Depending on the context this flag is used for some VERY important reasons.

Definition at line 288 of file fmdpFactory.h.

Referenced by _resetParts_(), endVariableDeclaration(), and variableDescription().

◆ _ddBag_

template<typename GUM_ELEMENT>
std::vector< const MultiDimImplementation< GUM_ELEMENT >* > gum::FMDPFactory< GUM_ELEMENT >::_ddBag_
private

Just to keep track of multidim between two start/end calls.

Definition at line 294 of file fmdpFactory.h.

Referenced by _resetParts_(), addReward(), and endRewardDeclaration().

◆ _fmdp_

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

◆ _foo_flag_

template<typename GUM_ELEMENT>
bool gum::FMDPFactory< GUM_ELEMENT >::_foo_flag_
private

Depending on the context this flag is used for some VERY important reasons.

Definition at line 284 of file fmdpFactory.h.

Referenced by _resetParts_(), addCost(), addCost(), addReward(), addTransition(), addTransition(), endRewardDeclaration(), endVariableDeclaration(), setOperationModeOn(), startActionDeclaration(), and variableName().

◆ _FunctionGraph_

template<typename GUM_ELEMENT>
MultiDimFunctionGraph< GUM_ELEMENT >* gum::FMDPFactory< GUM_ELEMENT >::_FunctionGraph_
private

The FunctionGraph we're building at a given time.

Definition at line 318 of file fmdpFactory.h.

Referenced by _finalizeFunctionGraph_(), _initializeFunctionGraph_(), addArc(), addCost(), addInternalNode(), addReward(), addTerminalNode(), addTransition(), and setRoot().

◆ _states_

◆ _stringBag_

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

◆ _varNameMap_

template<typename GUM_ELEMENT>
HashTable< std::string, const DiscreteVariable* > gum::FMDPFactory< GUM_ELEMENT >::_varNameMap_
private

Mapping between a declared variable's name and itself.

Definition at line 321 of file fmdpFactory.h.

Referenced by endVariableDeclaration(), variable(), and variableName().

◆ _verbose_

bool gum::AbstractFMDPFactory::_verbose_
privateinherited

Definition at line 298 of file IfmdpFactory.h.

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


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