aGrUM  0.16.0
fmdpFactory_tpl.h
Go to the documentation of this file.
1 
30 #include <agrum/FMDP/fmdpFactory.h>
31 
34 
35 
36 // #define FMDP_VERBOSITY(x) { if (isVerbose()) std::cerr << "[FMDP factory]
37 // "<< x << std::endl; }
38 
39 
40 namespace gum {
41 
42  /* ****************************************************************************************************
43  * **/
44  /* ** **/
45  /* ** Constructor &
46  * Destructor **/
47  /* ** **/
48  /* ****************************************************************************************************
49  * **/
50 
51 
52  // Default constructor.
53  // @param fmdp A pointer over the Factored Markov Decision Process filled by
54  // this factory.
55 
56  template < typename GUM_SCALAR >
58  __fmdp(fmdp) {
59  GUM_CONSTRUCTOR(FMDPFactory);
60 
62  resetVerbose();
63  __actionIdcpt = 1;
64  }
65 
66 
67  // Destructor
68 
69  template < typename GUM_SCALAR >
71  GUM_DESTRUCTOR(FMDPFactory);
72  }
73 
74  /* ****************************************************************************************************
75  * **/
76  /* ** **/
77  /* ** Getter and
78  * setters **/
79  /* ** **/
80  /* ****************************************************************************************************
81  * **/
82 
83 
84  // Returns the IBayesNet created by this factory.
85 
86  template < typename GUM_SCALAR >
90  "Illegal state to return the factored "
91  "markov decision process: it is not yet "
92  "finished.");
93 
94  return __fmdp;
95  }
96 
97 
98  // Returns the current state of the factory.
99 
100  template < typename GUM_SCALAR >
102  // This is ok because there is alway at least the state
103  // FMDPfactory_state::NONE in the stack.
104  return __states.back();
105  }
106 
107 
108  // Returns a constant reference on a variable given it's name.
109  // @throw NotFound Raised if no variable matches the name.
110 
111  template < typename GUM_SCALAR >
112  INLINE const DiscreteVariable*
113  FMDPFactory< GUM_SCALAR >::variable(const std::string& name) const {
114  for (const auto& elt : __varNameMap)
115  if (elt.first.compare(name) == 0) return elt.second;
116 
117  GUM_ERROR(NotFound, name);
118 
119  return nullptr;
120  }
121 
122 
123  /* ****************************************************************************************************
124  * **/
125  /* ** **/
126  /* ** Variable declaration methods (FMDPfactory_state::NONE <->
127  * FMDPfactory_state::VARIABLE) **/
128  /* ** **/
129  /* ****************************************************************************************************
130  * **/
131 
132 
133  // Tells the factory that we're in a variable declaration.
134 
135  template < typename GUM_SCALAR >
138  __illegalStateError("startVariableDeclaration");
139  else {
141  __stringBag.push_back("name");
142  __stringBag.push_back("desc");
143  }
144 
145  // VERBOSITY ( " starting variable" );
146  }
147 
148 
149  // Tells the factory the current variable's name.
150 
151  template < typename GUM_SCALAR >
152  INLINE void FMDPFactory< GUM_SCALAR >::variableName(const std::string& name) {
154  __illegalStateError("variableName");
155  else {
156  if (__varNameMap.exists(name))
157  GUM_ERROR(DuplicateElement, "Name already used: " + name);
158 
159  __foo_flag = true;
160  __stringBag[0] = name;
161  // VERBOSITY ( " -- variable " << name );
162  }
163  }
164 
165 
166  // Tells the factory the current variable's description.
167 
168  template < typename GUM_SCALAR >
169  INLINE void
172  __illegalStateError("variableDescription");
173  else {
174  __bar_flag = true;
175  __stringBag[1] = desc;
176  }
177  }
178 
179 
180  // Adds a modality to the current variable.
181  // @throw DuplicateElement If the current variable already has a modality
182  // with the same name.
183 
184  template < typename GUM_SCALAR >
185  INLINE void FMDPFactory< GUM_SCALAR >::addModality(const std::string& name) {
187  __illegalStateError("addModality");
188  else {
189  __checkModalityInBag(name);
190  __stringBag.push_back(name);
191  }
192  }
193 
194 
195  // Check if in __stringBag there is no other modality with the same name.
196 
197  template < typename GUM_SCALAR >
198  INLINE void
200  for (size_t i = 2; i < __stringBag.size(); ++i)
201  if (mod == __stringBag[i])
202  GUM_ERROR(DuplicateElement, "Modality" << mod << " already exists.");
203  }
204 
205 
206  // Tells the factory that we're out of a variable declaration.
207 
208  template < typename GUM_SCALAR >
211  __illegalStateError("endVariableDeclaration");
212  else if (__foo_flag && (__stringBag.size() > 3)) {
214  __stringBag[0], (__bar_flag) ? __stringBag[1] : "", 0);
215 
216  for (size_t i = 2; i < __stringBag.size(); ++i) {
217  var->addLabel(__stringBag[i]);
218  }
219 
220  __fmdp->addVariable(var);
221  __varNameMap.insert(var->name(), var);
222  __varNameMap.insert(__fmdp->main2prime(var)->name(),
223  __fmdp->main2prime(var));
224 
225  __resetParts();
226  __states.pop_back();
227 
228  // VERBOSITY ( " variable " << var->name() << " OK" );
229 
230  } else {
231  std::stringstream msg;
232  msg << "Not enough modalities (";
233 
234  if (__stringBag.size() > 2)
235  msg << __stringBag.size() - 2;
236  else
237  msg << 0;
238 
239  msg << ") declared for variable ";
240 
241  if (__foo_flag)
242  msg << __stringBag[0];
243  else
244  msg << "unknown";
245 
246  __resetParts();
247  __states.pop_back();
248 
249  GUM_ERROR(OperationNotAllowed, msg.str());
250  }
251  }
252 
253 
254  /* ****************************************************************************************************
255  * **/
256  /* ** **/
257  /* ** Action declaration methods (FMDPfactory_state::NONE <->
258  * FMDPfactory_state::ACTION) **/
259  /* ** **/
260  /* ****************************************************************************************************
261  * **/
262 
263 
264  // Tells the factory that we're declaring action
265 
266  template < typename GUM_SCALAR >
269  __illegalStateError("startActionDeclaration");
270  else {
271  __foo_flag = true;
273  }
274 
275  // VERBOSITY ( "starting action declaration" );
276  }
277 
278 
279  // Tells the factory to add an action
280 
281  template < typename GUM_SCALAR >
282  INLINE void FMDPFactory< GUM_SCALAR >::addAction(const std::string& action) {
284  __illegalStateError("addAction");
285  else {
286  __stringBag.push_back(action);
287  __fmdp->addAction(__actionIdcpt++, action);
288  }
289  }
290 
291 
292  // Tells the factory that we're out of an action declaration.
293 
294  template < typename GUM_SCALAR >
297  __illegalStateError("endActionDeclaration");
298  else {
299  __states.pop_back();
300  __resetParts();
301  }
302 
303  // VERBOSITY ( "action OK" );
304  }
305 
306 
307  /* ****************************************************************************************************
308  * **/
309  /* ** **/
310  /* ** Transition declaration methods **/
311  /* ** (FMDPfactory_state::NONE <-> FMDPfactory_state::TRANSITION <->
312  * FMDPfactory_state::ACTION) **/
313  /* ** **/
314  /* ****************************************************************************************************
315  * **/
316 
317 
318  // Tells the factory that we're declaring transition
319 
320  template < typename GUM_SCALAR >
323  __illegalStateError("startTransitionDeclaration");
324  else
326 
327  // VERBOSITY ( "starting transition declaration" );
329  }
330 
331 
332  // Tells the factory to add an action
333 
334  template < typename GUM_SCALAR >
336  const std::string& var, const MultiDimAdressable* transition) {
338  reinterpret_cast< const MultiDimImplementation< GUM_SCALAR >* >(transition);
339 
341  __illegalStateError("addTransition");
342  else if (__foo_flag)
343  __fmdp->addTransitionForAction(
344  __fmdp->actionId(__stringBag[0]), __varNameMap[var], t);
345  else
346  __fmdp->addTransition(__varNameMap[var], t);
347  }
348 
349 
350  // Tells the factory to add a transition table to the current fmdp.
351  // This transition table will be extracted from incorporated
352  // multiDimFunctionGraph.
353 
354  template < typename GUM_SCALAR >
355  INLINE void FMDPFactory< GUM_SCALAR >::addTransition(const std::string& var) {
357  __illegalStateError("addTransition");
358  else {
359  this->__finalizeFunctionGraph();
360 
361  if (__foo_flag) {
362  this->__FunctionGraph->setTableName("ACTION :" + __stringBag[0]
363  + " - VARIABLE : " + var);
364  __fmdp->addTransitionForAction(__fmdp->actionId(__stringBag[0]),
365  __varNameMap[var],
366  this->__FunctionGraph);
367  } else {
368  __fmdp->addTransition(__varNameMap[var], this->__FunctionGraph);
369  }
370  }
371  }
372 
373 
374  // Tells the factory that we're out of a transition declaration.
375 
376  template < typename GUM_SCALAR >
379  __illegalStateError("endTransitionDeclaration");
380  else
381  __states.pop_back();
382 
383  // VERBOSITY ( "transition OK" );
384  }
385 
386 
387  /* ****************************************************************************************************
388  * **/
389  /* ** **/
390  /* ** Cost declaration methods **/
391  /* ** (FMDPfactory_state::NONE <-> FMDPfactory_state::COST <->
392  * FMDPfactory_state::ACTION) **/
393  /* ** **/
394  /* ****************************************************************************************************
395  * **/
396 
397 
398  // Tells the factory that we're declaring cost
399 
400  template < typename GUM_SCALAR >
403  __illegalStateError("startTransitionDeclaration");
404  else
406 
407  // VERBOSITY ( "starting Cost declaration" );
409  }
410 
411 
412  // Tells the factory to add a cost
413 
414  template < typename GUM_SCALAR >
417  reinterpret_cast< const MultiDimImplementation< GUM_SCALAR >* >(cost);
418 
420  __illegalStateError("addCost");
421  else if (__foo_flag)
422  __fmdp->addCostForAction(__fmdp->actionId(__stringBag[0]), c);
423  else
424  __fmdp->addCost(c);
425  }
426 
427 
428  // Tells the factory to add a cost
429  // This cost table will be extracted from incorporated multiDimFunctionGraph.
430 
431  template < typename GUM_SCALAR >
434  __illegalStateError("addCost");
435  else {
436  this->__finalizeFunctionGraph();
437 
438  if (__foo_flag)
439  __fmdp->addCostForAction(__fmdp->actionId(__stringBag[0]),
440  this->__FunctionGraph);
441  else
442  __fmdp->addCost(this->__FunctionGraph);
443  }
444  }
445 
446 
447  // Tells the factory that we're out of a cost declaration.
448 
449  template < typename GUM_SCALAR >
452  __illegalStateError("endCostDeclaration");
453  else
454  __states.pop_back();
455 
456  // VERBOSITY ( "Cost OK" );
457  }
458 
459 
460  /* ****************************************************************************************************
461  * **/
462  /* ** **/
463  /* ** Reward declaration methods **/
464  /* ** (FMDPfactory_state::NONE <-> FMDPfactory_state::REWARD <->
465  * FMDPfactory_state::ACTION) **/
466  /* ** **/
467  /* ****************************************************************************************************
468  * **/
469 
470 
471  // Tells the factory that we're declaring reward
472 
473  template < typename GUM_SCALAR >
476  __illegalStateError("startRewardDeclaration");
477  else
479 
480  // VERBOSITY ( "starting reward declaration" );
482  }
483 
484 
485  // Tells the factory that we're in a reward declaration mode where the global
486  // reward diagram is an operation between simplier dd
487 
488  template < typename GUM_SCALAR >
489  INLINE void
491  __foo_flag = true;
492  std::string ot(operationType);
493  __stringBag.push_back(ot);
494  }
495 
496 
497  // Tells the factory to add a reward
498 
499  template < typename GUM_SCALAR >
500  INLINE void
503  reinterpret_cast< const MultiDimImplementation< GUM_SCALAR >* >(reward);
504 
506  __illegalStateError("addReward");
507  else
508  __fmdp->addReward(r);
509  }
510 
511 
512  // Tells the factory to add a reward
513  // This reward table will be extracted from incorporated
514  // multiDimFunctionGraph.
515 
516  template < typename GUM_SCALAR >
519  __illegalStateError("addReward");
520  else {
521  this->__finalizeFunctionGraph();
522  __FunctionGraph->setTableName("Reward");
523 
524  if (__foo_flag)
525  __ddBag.push_back(this->__FunctionGraph);
526  else
527  __fmdp->addReward(this->__FunctionGraph);
528  }
529  }
530 
531 
532  // Tells the factory that we're out of a reward declaration.
533 
534  template < typename GUM_SCALAR >
537  __illegalStateError("endRewardDeclaration");
538  else {
539  if (__foo_flag) {
542 
543  for (const auto elt : __ddBag) {
544  temp = res;
545 
546  switch (__stringBag[0][0]) {
547  case '+': res = add2MultiDimFunctionGraphs(res, elt); break;
548 
549  case '-': res = subtract2MultiDimFunctionGraphs(res, elt); break;
550 
551  case '*': res = multiply2MultiDimFunctionGraphs(res, elt); break;
552 
553  case '/': res = divide2MultiDimFunctionGraphs(res, elt); break;
554 
555  default: break;
556  }
557 
558  delete elt;
559 
560  if (temp != nullptr) delete temp;
561  }
562  reinterpret_cast< MultiDimFunctionGraph< GUM_SCALAR >* >(res)
563  ->setTableName("Reward");
564  __fmdp->addReward(res);
565  }
566 
567  __resetParts();
568  __states.pop_back();
569  }
570  // VERBOSITY ( "reward OK" );
571  }
572 
573 
574  /* ****************************************************************************************************
575  * **/
576  /* ** **/
577  /* ** Discount declaration methods **/
578  /* ** (FMDPfactory_state::NONE <-> FMDPfactory_state::DISCOUNT <->
579  * FMDPfactory_state::ACTION) **/
580  /* ** **/
581  /* ****************************************************************************************************
582  * **/
583 
584 
585  // Tells the factory that we're declaring discount
586  template < typename GUM_SCALAR >
589  __illegalStateError("startDiscountDeclaration");
590  else
592 
593  // VERBOSITY ( "starting discount declaration" );
594  }
595 
596 
597  // Tells the factory to add a discount
598 
599  template < typename GUM_SCALAR >
600  INLINE void FMDPFactory< GUM_SCALAR >::addDiscount(float discount) {
601  if (state() != FMDPfactory_state::DISCOUNT) __illegalStateError("addDiscount");
602  // else
603  // __fmdp->setDiscount ( ( GUM_SCALAR ) discount );
604  }
605 
606 
607  // Tells the factory that we're out of a discount declaration.
608 
609  template < typename GUM_SCALAR >
612  __illegalStateError("endDiscountDeclaration");
613  else
614  __states.pop_back();
615 
616  // VERBOSITY ( "discount OK" );
617  }
618 
619 
620  /* ****************************************************************************************************
621  * **/
622  /* ** **/
623  /* ** Discount declaration methods **/
624  /* ** (FMDPfactory_state::NONE <-> FMDPfactory_state::DISCOUNT <->
625  * FMDPfactory_state::ACTION) **/
626  /* ** **/
627  /* ****************************************************************************************************
628  * **/
629 
630 
631  // Insert in diagram a non terminal node
632 
633  template < typename GUM_SCALAR >
634  INLINE NodeId
636  return __FunctionGraph->manager()->addInternalNode(variable(name_of_var));
637  }
638 
639 
640  // Insert in diagram a terminal node
641 
642  template < typename GUM_SCALAR >
644  return __FunctionGraph->manager()->addTerminalNode((GUM_SCALAR)value);
645  }
646 
647 
648  // Insert an arc in diagram
649  template < typename GUM_SCALAR >
650  INLINE void
652  __FunctionGraph->manager()->setSon(from, modality, to);
653  }
654 
655 
656  template < typename GUM_SCALAR >
658  __FunctionGraph->manager()->setRootNode(rootId);
659  }
660 
661  /* ****************************************************************************************************
662  * **/
663  /* ** **/
664  /* ** Various Private Methods **/
665  /* ** **/
666  /* ****************************************************************************************************
667  * **/
668 
669 
670  // Raise an OperationNotAllowed with the message "Illegal state."
671 
672  template < typename GUM_SCALAR >
673  INLINE void
675  std::string msg = "Illegal state call (";
676  msg += s;
677  msg += ") in state ";
678 
679  switch (state()) {
680  case FMDPfactory_state::NONE: msg += "FMDPfactory_state::NONE"; break;
681 
683  msg += "FMDPfactory_state::VARIABLE";
684  break;
685 
686  case FMDPfactory_state::ACTION: msg += "FMDPfactory_state::ACTION"; break;
687 
689  msg += "FMDPfactory_state::TRANSITION";
690  break;
691 
692  case FMDPfactory_state::COST: msg += "FMDPfactory_state::COST"; break;
693 
694  case FMDPfactory_state::REWARD: msg += "FMDPfactory_state::REWARD"; break;
695 
697  msg += "FMDPfactory_state::DISCOUNT";
698  break;
699 
700  default: msg += "Unknown state";
701  }
702 
704  }
705 
706 
707  // Reset the different parts used to constructed the IBayesNet.
708 
709  template < typename GUM_SCALAR >
711  __foo_flag = false;
712  __bar_flag = false;
713  __stringBag.clear();
714  __ddBag.clear();
715  }
716 
717 
718  template < typename GUM_SCALAR >
720  this->__FunctionGraph =
722  // Recopie des variables principales dans le graphe de décision
723  for (auto varIter = __fmdp->beginVariables();
724  varIter != __fmdp->endVariables();
725  ++varIter) {
726  __FunctionGraph->add(**varIter);
727  }
728 
729  // Recopie des version primes des variables dans le graphe de décision
730  for (auto varIter = __fmdp->beginVariables();
731  varIter != __fmdp->endVariables();
732  ++varIter) {
733  __FunctionGraph->add(*(__fmdp->main2prime(*varIter)));
734  }
735  }
736 
737 
738  template < typename GUM_SCALAR >
740  this->__FunctionGraph->manager()->reduce();
741  this->__FunctionGraph->manager()->clean();
742  }
743 
744  //~ ==============
745  //~ // Check if a variable with the given name exists, if not raise an
746  // NotFound
747  //~ // exception.
748  //~ ==============
749  //~ template<typename GUM_SCALAR> INLINE
750  //~ void
751  //~ FMDPFactory<GUM_SCALAR>::__checkVariableName ( const std::string& name ) {
752  //~ if ( !__varNameMap.exists ( name ) )
753  //~ GUM_ERROR ( NotFound, name );
754  //~ }
755 
756 
757  // Copy operator is illegal, use only copy constructor.
758 
759  template < typename GUM_SCALAR >
762  GUM_ERROR(FatalError, "Illegal!");
763  // For noisy compilers
764  return *this;
765  }
766 } /* namespace gum */
void addReward()
Tells the factory to add a reward table to the current fmdp. This reward table will be extracted from...
void __illegalStateError(const std::string &s)
Raise an OperationNotAllowed with the message "Illegal state.".
std::vector< std::string > __stringBag
Just to keep track of strings between two start/end calls.
Definition: fmdpFactory.h:274
void endTransitionDeclaration()
Tells the factory that we&#39;re out of a transition declaration.
FMDPfactory_state state() const
Returns the current state of the factory.
void __resetParts()
Reset the different parts used to constructed the FMDP.
void endActionDeclaration()
Tells the factory that we&#39;re out of an action declaration.
A factory class to ease Factored Markov Decision Process construction.
Definition: fmdpFactory.h:71
FMDPFactory< GUM_SCALAR > & operator=(const FMDPFactory< GUM_SCALAR > &source)
Copy operator is illegal, use only copy constructor.
void addAction(const std::string &action)
Tells the factory to add an action to the current fmdp.
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
void __initializeFunctionGraph()
Insert every variables in the function graph.
void clean()
Removes var without nodes in the diagram.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
class LabelizedVariable
MultiDimFunctionGraph< GUM_SCALAR > * __FunctionGraph
The FunctionGraph we&#39;re building at a given time.
Definition: fmdpFactory.h:301
void startDiscountDeclaration()
Tells the factory that we&#39;re in a cost declaration.
FMDPfactory_state
The enumeration of states in which the factory can be in.
Definition: IfmdpFactory.h:53
void startActionDeclaration()
Tells the factory that we&#39;re in an action declaration.
void addDiscount(float discount)
Tells the factory to add a cost table to the current fmdp.
void startVariableDeclaration()
Tells the factory that we&#39;re in a variable declaration.
void endCostDeclaration()
Tells the factory that we&#39;re out of a cost declaration.
void addArc(NodeId from, NodeId to, Idx modality)
Insert in diagram a non terminal node.
void setRoot(NodeId rootId)
add an arc in diagram
const DiscreteVariable * variable(const std::string &name) const
Returns a constant reference on a variable given it&#39;s name.
MultiDimFunctionGraph< T > * subtract2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for subtracting two multiDimArraysThe function produces a tensorial subtractio...
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
This class is used to implement factored decision process.
Definition: fmdp.h:57
void addModality(const std::string &name)
Adds a modality to the current variable.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void __checkModalityInBag(const std::string &mod)
Used in VARIABLE mode Checks if in __stringBag there is no other modality with the same name...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool __bar_flag
Depending on the context this flag is used for some VERY important reasons.
Definition: fmdpFactory.h:271
FMDP< GUM_SCALAR > * fmdp() const
Returns the Factored Markov Decision Process created by this factory.
void endDiscountDeclaration()
Tells the factory that we&#39;re out of a cost declaration.
~FMDPFactory()
Destructor.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void addTransition(const std::string &var, const MultiDimAdressable *transition)
Tells the factory to add a transition 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 inc...
MultiDimFunctionGraph< T > * multiply2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for multiplying two multiDimArraysThe function produces a tensorial product of...
Idx __actionIdcpt
Action Id counter.
Definition: fmdpFactory.h:307
void endRewardDeclaration()
Tells the factory that we&#39;re out of a cost declaration.
HashTable< std::string, const DiscreteVariable *> __varNameMap
Mapping between a declared variable&#39;s name and itself.
Definition: fmdpFactory.h:304
std::vector< FMDPfactory_state > __states
State stack.
Definition: fmdpFactory.h:295
void endVariableDeclaration()
Tells the factory that we&#39;re out of a variable declaration.
NodeId addInternalNode(std::string name_of_var)
Insert in diagram a non terminal node.
void startCostDeclaration()
Tells the factory that we&#39;re in a cost declaration.
NodeId addTerminalNode(float value)
Insert in diagram a terminal node.
void variableName(const std::string &name)
Tells the factory the current variable&#39;s name.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool __foo_flag
Depending on the context this flag is used for some VERY important reasons.
Definition: fmdpFactory.h:267
Abstract base class for all multi dimensionnal addressable.
FMDP< GUM_SCALAR > * __fmdp
The constructed FMDP.
Definition: fmdpFactory.h:298
std::vector< const MultiDimImplementation< GUM_SCALAR > *> __ddBag
Just to keep track of multidim between two start/end calls.
Definition: fmdpFactory.h:277
MultiDimFunctionGraph< T > * add2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for summing two multiDimArraysThe function produces a tensorial addition of t1...
MultiDimFunctionGraph< T > * divide2MultiDimFunctionGraphs(const MultiDimFunctionGraph< T > *t1, const MultiDimFunctionGraph< T > *t2)
a specialized function for dividing two multiDimArraysThe function produces a tensorial division of t...
void variableDescription(const std::string &desc)
Tells the factory the current variable&#39;s description.
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:53
void setOperationModeOn(std::string operationType)
Tells the factory that we&#39;re in a reward declaration mode where the global reward diagram is an opera...
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
void __finalizeFunctionGraph()
Insert every variables in the function graph.
void startRewardDeclaration()
Tells the factory that we&#39;re in a reward declaration.
void setTableName(const std::string &name)
Sets the name of the table represented by this structure.
FMDPFactory(FMDP< GUM_SCALAR > *fmdp)
Use this constructor if you want to use an already created factored markov decision process...
const std::string & name() const
returns the name of the variable
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
virtual void reduce()=0
Ensures that every isomorphic subgraphs are merged together.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void startTransitionDeclaration()
Tells the factory that we&#39;re in a transition declaration.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getReducedAndOrderedInstance()
Returns a reduced and ordered instance.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55