57#define RECAST(x) reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(x)
73 template <
typename GUM_SCALAR >
75 GUM_CONSTRUCTOR(
FMDP);
88 template <
typename GUM_SCALAR >
95 for (
auto iterH = (iterA.val())->beginSafe(); iterH != (iterA.val())->endSafe(); ++iterH)
96 if (iterH.val())
delete iterH.val();
102 for (
auto iterA = _actionCostTable_.beginSafe(); iterA != _actionCostTable_.endSafe(); ++iterA)
103 if (iterA.val())
delete iterA.val();
108 if (iterA.val())
delete iterA.val();
112 delete iterId.second();
116 delete varIter.second();
120 GUM_DESTRUCTOR(
FMDP);
135 template <
typename GUM_SCALAR >
139 " Variable " << var->
name() <<
" has already been inserted in FMDP.");
162 template <
typename GUM_SCALAR >
169 if (*(actIter.second()) == action)
171 " Action " << action <<
" has already been inserted in FMDP with this name.");
175 " An action with same id (" <<
actionId <<
") has already been inserted.");
200 template <
typename GUM_SCALAR >
213 " Variable " << var->
name() <<
" already has a transition table in " <<
actionId
223 template <
typename GUM_SCALAR >
248 template <
typename GUM_SCALAR >
265 template < typename GUM_SCALAR >
286 template <
typename GUM_SCALAR >
304 template <
typename GUM_SCALAR >
325 template <
typename GUM_SCALAR >
336 template <
typename GUM_SCALAR >
341 if (*(actIter.second()) == action) {
return actIter.first(); }
346 template <
typename GUM_SCALAR >
348 std::stringstream fmdpCore;
352 if (this->transition(*actionIter, *varIter))
353 fmdpCore <<
RECAST(this->transition(*actionIter, *varIter))->toDot() << std::endl;
354 if (this->
reward(*actionIter))
355 fmdpCore <<
RECAST(this->
reward(*actionIter))->toDot() << std::endl;
359 if (this->transition(0, *varIter))
360 fmdpCore <<
RECAST(this->transition(0, *varIter))->toDot() << std::endl;
362 return fmdpCore.str();
365 template <
typename GUM_SCALAR >
370 if (this->transition(*actionIter, *varIter))
371 s += this->transition(*actionIter, *varIter)->
realSize();
372 if (this->
reward(*actionIter)) s += this->
reward(*actionIter)->realSize();
376 if (this->transition(0, *varIter)) s += this->transition(0, *varIter)->
realSize();
Safe iterators for bijectionIterator.
Unsafe iterators for bijection.
Base class for discrete random variable.
DiscreteVariable * clone() const override=0
Copy Factory.
Exception : a similar element already exists.
This class is used to implement factored decision process.
bool _onDestructionDeleteVars_
Boolean indicates whether or not main variables should be deleted on destruction of this instance Usu...
const std::string & actionName(Idx actionId) const
Sequence< Idx > _actionSeq_
Sequence< const DiscreteVariable * > _varSeq_
Sequence de variables and its iterator.
HashTable< Idx, VarTransitionTable< GUM_SCALAR > * > _actionTransitionTable_
Table which give for each action a table containing variables transition cpt.
void addCostForAction(Idx actionId, const MultiDimImplementation< GUM_SCALAR > *cost)
Adds a cost table to specified action.
const MultiDimImplementation< double > * transition(Idx actionId, const DiscreteVariable *v) const
Idx actionId(const std::string &) const
Returns action id.
HashTable< Idx, const MultiDimImplementation< GUM_SCALAR > * > _actionRewardTable_
Table which give for each action reward table.
HashTable< Idx, const MultiDimImplementation< GUM_SCALAR > * > _actionCostTable_
Table which give for each action cost table.
const MultiDimImplementation< GUM_SCALAR > * cost(Idx actionId=0) const
Returns the reward table of mdp.
SequenceIteratorSafe< const DiscreteVariable * > endVariables() const
Returns an iterator reference to the end of the list of variables.
SequenceIteratorSafe< Idx > beginActions() const
Returns an iterator reference to he beginning of the list of actions.
const MultiDimImplementation< GUM_SCALAR > * reward(Idx actionId=0) const
Returns the reward table of mdp.
SequenceIteratorSafe< const DiscreteVariable * > beginVariables() const
Returns an iterator reference to he beginning of the list of variables.
FMDP(bool onDestructionDeleteVar=false)
Default constructor.
Bijection< Idx, const std::string * > _actionMap_
Bijection mapping an action name to its id.
~FMDP()
Default destructor.
void addTransitionForAction(Idx actionId, const DiscreteVariable *var, const MultiDimImplementation< GUM_SCALAR > *transition)
Adds a variable transition table to specified action.
Bijection< const DiscreteVariable *, const DiscreteVariable * > _main2primed_
std::string toString() const
Displays the FMDP in a Dot format.
Size size() const
Returns the map binding main variables and prime variables.
void addAction(Idx actionId, const std::string &action)
Adds an action to FMDP description.
SequenceIteratorSafe< Idx > endActions() const
Returns an iterator reference to the end of the list of actions.
HashTable< const DiscreteVariable *, const MultiDimImplementation< GUM_SCALAR_O > * > VarTransitionTable
void addVariable(const DiscreteVariable *var)
Adds a variable to FMDP description.
void addRewardForAction(Idx actionId, const MultiDimImplementation< GUM_SCALAR > *reward)
Adds a default variable reward.
<agrum/base/multidim/multiDimImplementation.h>
virtual Size realSize() const =0
Returns the real number of parameters used for this table.
Exception : the element we looked for cannot be found.
void setName(const std::string &theValue)
sets the name of the variable
const std::string & name() const
returns the name of the variable
#define GUM_ERROR(type, msg)
Class for implementation of factored markov decision process.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
gum is the global namespace for all aGrUM entities