aGrUM 3.2.0
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 >:
[legend]
Collaboration diagram for gum::FMDPFactory< GUM_ELEMENT >:
[legend]

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 DiscreteVariable * variable (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 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: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 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_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 199 of file fmdpFactory_tpl.h.

199 {
200 for (size_t i = 2; i < _stringBag_.size(); ++i)
201 if (mod == _stringBag_[i])
202 GUM_ERROR(DuplicateElement, "Modality" << mod << " already exists.")
203 }
std::vector< std::string > _stringBag_
Just to keep track of strings between two start/end calls.

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

649 {
650 this->_FunctionGraph_->manager()->reduce();
651 this->_FunctionGraph_->manager()->clean();
652 }
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 598 of file fmdpFactory_tpl.h.

598 {
599 std::string msg = "Illegal state call (";
600 msg += s;
601 msg += ") in state ";
602
603 switch (state()) {
604 case FMDPfactory_state::NONE : msg += "FMDPfactory_state::NONE"; break;
605
606 case FMDPfactory_state::VARIABLE : msg += "FMDPfactory_state::VARIABLE"; break;
607
608 case FMDPfactory_state::ACTION : msg += "FMDPfactory_state::ACTION"; break;
609
610 case FMDPfactory_state::TRANSITION : msg += "FMDPfactory_state::TRANSITION"; break;
611
612 case FMDPfactory_state::COST : msg += "FMDPfactory_state::COST"; break;
613
614 case FMDPfactory_state::REWARD : msg += "FMDPfactory_state::REWARD"; break;
615
616 case FMDPfactory_state::DISCOUNT : msg += "FMDPfactory_state::DISCOUNT"; break;
617
618 default : msg += "Unknown state";
619 }
620
622 }
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 635 of file fmdpFactory_tpl.h.

635 {
637 // Recopie des variables principales dans le graphe de décision
638 for (auto varIter = _fmdp_->beginVariables(); varIter != _fmdp_->endVariables(); ++varIter) {
639 _FunctionGraph_->add(**varIter);
640 }
641
642 // Recopie des version primes des variables dans le graphe de décision
643 for (auto varIter = _fmdp_->beginVariables(); varIter != _fmdp_->endVariables(); ++varIter) {
644 _FunctionGraph_->add(*(_fmdp_->main2prime(*varIter)));
645 }
646 }
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 627 of file fmdpFactory_tpl.h.

627 {
628 _foo_flag_ = false;
629 _bar_flag_ = false;
630 _stringBag_.clear();
631 _ddBag_.clear();
632 }
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 265 of file fmdpFactory_tpl.h.

265 {
267 else {
268 _stringBag_.emplace_back(action);
269 _fmdp_->addAction(_actionIdcpt_++, std::string(action));
270 }
271 }
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 578 of file fmdpFactory_tpl.h.

578 {
579 _FunctionGraph_->manager()->setSon(from, modality, to);
580 }

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

392 {
394 else {
396
397 if (_foo_flag_)
398 _fmdp_->addCostForAction(_fmdp_->actionId(_stringBag_[0]), this->_FunctionGraph_);
399 else _fmdp_->addCost(this->_FunctionGraph_);
400 }
401 }
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 379 of file fmdpFactory_tpl.h.

379 {
381 = static_cast< const MultiDimImplementation< GUM_ELEMENT >* >(cost);
382
384 else if (_foo_flag_) _fmdp_->addCostForAction(_fmdp_->actionId(_stringBag_[0]), c);
385 else _fmdp_->addCost(c);
386 }

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

537 {
539 else _fmdp_->setDiscount((GUM_ELEMENT)discount);
540 }

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

565 {
566 return _FunctionGraph_->manager()->addInternalNode(variable(name_of_var));
567 }
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 188 of file fmdpFactory_tpl.h.

188 {
190 else {
192 _stringBag_.emplace_back(name);
193 }
194 }
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 460 of file fmdpFactory_tpl.h.

460 {
462 else {
464 _FunctionGraph_->setTableName("Reward");
465
466 if (_foo_flag_) _ddBag_.push_back(this->_FunctionGraph_);
467 else _fmdp_->addReward(this->_FunctionGraph_);
468 }
469 }

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

447 {
449 = static_cast< const MultiDimImplementation< GUM_ELEMENT >* >(reward);
450
452 else _fmdp_->addReward(r);
453 }

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

572 {
573 return _FunctionGraph_->manager()->addTerminalNode((GUM_ELEMENT)value);
574 }

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

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

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

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

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

276 {
277 if (state() != FMDPfactory_state::ACTION) _illegalStateError_("endActionDeclaration");
278 else {
279 _states_.pop_back();
280 _resetParts_();
281 }
282
283 // VERBOSITY ( "action OK" );
284 }
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 406 of file fmdpFactory_tpl.h.

406 {
407 if (state() != FMDPfactory_state::COST) _illegalStateError_("endCostDeclaration");
408 else _states_.pop_back();
409
410 // VERBOSITY ( "Cost OK" );
411 }

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

545 {
546 if (state() != FMDPfactory_state::DISCOUNT) _illegalStateError_("endDiscountDeclaration");
547 else _states_.pop_back();
548
549 // VERBOSITY ( "discount OK" );
550 }

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

474 {
475 if (state() != FMDPfactory_state::REWARD) _illegalStateError_("endRewardDeclaration");
476 else {
477 if (_foo_flag_) {
479
480 for (const auto elt: _ddBag_) {
481 if (res == nullptr) {
483 continue;
484 }
486
487 switch (_stringBag_[0][0]) {
488 case '+' : res = add2MultiDimFunctionGraphs(res, elt); break;
489
490 case '-' : res = subtract2MultiDimFunctionGraphs(res, elt); break;
491
492 case '*' : res = multiply2MultiDimFunctionGraphs(res, elt); break;
493
494 case '/' : res = divide2MultiDimFunctionGraphs(res, elt); break;
495
496 default : break;
497 }
498
499 delete elt;
500 delete temp;
501 }
502
503 if (res != nullptr) {
504 static_cast< MultiDimFunctionGraph< GUM_ELEMENT >* >(res)->setTableName("Reward");
505 _fmdp_->addReward(res);
506 }
507 }
508
509 _resetParts_();
510 _states_.pop_back();
511 }
512 // VERBOSITY ( "reward OK" );
513 }

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

347 {
348 if (state() != FMDPfactory_state::TRANSITION) _illegalStateError_("endTransitionDeclaration");
349 else _states_.pop_back();
350
351 // VERBOSITY ( "transition OK" );
352 }

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

208 {
209 if (state() != FMDPfactory_state::VARIABLE) _illegalStateError_("endVariableDeclaration");
210 else if (_foo_flag_ && (_stringBag_.size() > 3)) {
212 = new LabelizedVariable(_stringBag_[0], (_bar_flag_) ? _stringBag_[1] : "", 0);
213
214 for (size_t i = 2; i < _stringBag_.size(); ++i) {
215 var->addLabel(_stringBag_[i]);
216 }
217
218 _fmdp_->addVariable(var);
219 _fmdp_->setDeleteVariablesOnDestruction(true);
220 _varNameMap_.insert(var->name(), var);
221 _varNameMap_.insert(_fmdp_->main2prime(var)->name(), _fmdp_->main2prime(var));
222
223 _resetParts_();
224 _states_.pop_back();
225
226 // VERBOSITY ( " variable " << var->name() << " OK" );
227
228 } else {
229 const size_t nModa = _stringBag_.size() > 2 ? _stringBag_.size() - 2 : size_t{0};
230 const std::string varName = _foo_flag_ ? _stringBag_[0] : "unknown";
231
232 _resetParts_();
233 _states_.pop_back();
234
236 std::format("Not enough modalities ({}) declared for variable {}", nModa, varName))
237 }
238 }
HashTable< std::string, const DiscreteVariable * > _varNameMap_
Mapping between a declared variable's name and itself.
LabelizedVariable()
(protected) Default constructor

References gum::LabelizedVariable::LabelizedVariable(), _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 103 of file fmdpFactory_tpl.h.

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

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_.

Referenced by setRoot().

Here is the caller graph for this function:

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

671 {
672 GUM_ERROR(FatalError, "Illegal!")
673 // For noisy compilers
674 return *this;
675 }

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

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

439 {
440 _foo_flag_ = true;
442 }

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

583 {
584 _FunctionGraph_->manager()->setRootNode(rootId);
585 }

References _FunctionGraph_.

◆ setVerbose()

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

Definition at line 48 of file IfmdpFactory_inl.h.

48{ _verbose_ = true; }

References _verbose_.

Referenced by setRoot().

Here is the caller graph for this function:

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

252 {
253 if (state() != FMDPfactory_state::NONE) _illegalStateError_("startActionDeclaration");
254 else {
255 _foo_flag_ = true;
257 }
258
259 // VERBOSITY ( "starting action declaration" );
260 }

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

367 {
369 _illegalStateError_("startTransitionDeclaration");
370 else _states_.push_back(FMDPfactory_state::COST);
371
372 // VERBOSITY ( "starting Cost declaration" );
374 }
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 527 of file fmdpFactory_tpl.h.

527 {
528 if (state() != FMDPfactory_state::NONE) _illegalStateError_("startDiscountDeclaration");
530
531 // VERBOSITY ( "starting discount declaration" );
532 }

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

426 {
428 _illegalStateError_("startRewardDeclaration");
429 else _states_.push_back(FMDPfactory_state::REWARD);
430
431 // VERBOSITY ( "starting reward declaration" );
433 }

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

299 {
301 _illegalStateError_("startTransitionDeclaration");
303
304 // VERBOSITY ( "starting transition declaration" );
306 }

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

147 {
148 if (state() != FMDPfactory_state::NONE) _illegalStateError_("startVariableDeclaration");
149 else {
151 _stringBag_.push_back("name");
152 _stringBag_.push_back("desc");
153 }
154
155 // VERBOSITY ( " starting variable" );
156 }

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

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

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

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

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

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

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

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

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: