aGrUM  0.17.1
a C++ library for (probabilistic) graphical models
influenceDiagram_tpl.h
Go to the documentation of this file.
1 
31 #include <cstdio>
32 #include <iostream>
33 
34 namespace gum {
35 
36  // ===========================================================================
37  // Constructors / Destructors
38  // ===========================================================================
39 
40  /*
41  * Default constructor.
42  */
43  template < typename GUM_SCALAR >
45  GUM_CONSTRUCTOR(InfluenceDiagram);
46  }
47 
48  /*
49  * Destructor.
50  */
51  template < typename GUM_SCALAR >
53  GUM_DESTRUCTOR(InfluenceDiagram);
54  _removeTables();
55  }
56 
57  /*
58  * Copy Constructor
59  */
60  template < typename GUM_SCALAR >
62  const InfluenceDiagram< GUM_SCALAR >& source) :
63  DAGmodel(source),
65  GUM_CONS_CPY(InfluenceDiagram);
66  _copyTables(source);
67  }
68 
69  /*
70  * Copy Operator
71  */
72  template < typename GUM_SCALAR >
74  const InfluenceDiagram< GUM_SCALAR >& source) {
75  if (this != &source) {
76  DAGmodel::operator=(source);
77  // Removing previous potentials
78  _removeTables();
79  __potentialMap.clear();
80  __utilityMap.clear();
81 
83 
84  // Copying tables
85  _copyTables(source);
86  }
87 
88  return *this;
89  }
90 
91  /*
92  * Removing ancient table
93  */
94  template < typename GUM_SCALAR >
96  for (const auto node: _dag.nodes()) {
97  if (isChanceNode(node))
98  delete &cpt(node);
99  else if (isUtilityNode(node))
100  delete &utility(node);
101  }
102  }
103 
104  /*
105  * Copying tables from another influence diagram
106  */
107  template < typename GUM_SCALAR >
109  const InfluenceDiagram< GUM_SCALAR >& IDsource) {
110  // Copying potentials
111  for (const auto& pot: IDsource.__potentialMap) {
112  // Instanciation of the node's CPT
113  auto potentialCpy = new Potential< GUM_SCALAR >;
114  (*potentialCpy) << variable(pot.first);
115 
116  // Addition of the parents
117  for (const auto par: _dag.parents(pot.first))
118  (*potentialCpy) << variable(par);
119 
120  // Filling up of the table
121  Instantiation srcInst(*pot.second);
122  Instantiation cpyInst(*potentialCpy);
123 
124  for (cpyInst.setFirst(); !cpyInst.end(); cpyInst.inc()) {
125  for (Idx i = 0; i < cpyInst.nbrDim(); i++) {
126  NodeId id = nodeId(cpyInst.variable(i));
127  srcInst.chgVal(IDsource.variable(id), cpyInst.val(i));
128  }
129 
130  potentialCpy->set(cpyInst, (*pot.second)[srcInst]);
131  }
132 
133  // Adding cpt to cpt map
134  __potentialMap.set(pot.first, potentialCpy);
135  }
136 
137  // Copying Utilities
138  for (const auto& uti: IDsource.__utilityMap) {
139  // Instanciation of the node's CPT
140  auto utilityCpy = new Potential< GUM_SCALAR >;
141  (*utilityCpy) << variable(uti.first);
142 
143  // Addition of the parents
144  for (const auto par: _dag.parents(uti.first))
145  (*utilityCpy) << variable(par);
146 
147  // Filling up of the table
148  Instantiation srcInst(*uti.second);
149 
150  Instantiation cpyInst(*utilityCpy);
151 
152  for (cpyInst.setFirst(); !cpyInst.end(); cpyInst.inc()) {
153  for (Idx i = 0; i < cpyInst.nbrDim(); i++) {
154  NodeId id = nodeId(cpyInst.variable(i));
155  srcInst.chgVal(IDsource.variable(id), cpyInst.val(i));
156  }
157 
158  utilityCpy->set(cpyInst, (*uti.second)[srcInst]);
159  }
160 
161  // Adding cpt to cpt map
162  __utilityMap.set(uti.first, utilityCpy);
163  }
164  }
165 
166  template < typename GUM_SCALAR >
168  std::stringstream output;
169  std::stringstream decisionNode;
170  std::stringstream utilityNode;
171  std::stringstream chanceNode;
172  std::stringstream arcstream;
173  output << "digraph \"";
174 
175  try {
176  output << this->property("name") << "\" {" << std::endl;
177  } catch (NotFound&) { output << "no_name\" {" << std::endl; }
178 
179  output << " node [bgcolor=\"#AAAAAA\", style=filled];" << std::endl;
180 
181  decisionNode << "node [shape = box];" << std::endl;
182 
183  utilityNode << "node [shape = diamond];" << std::endl;
184  chanceNode << "node [shape = ellipse];" << std::endl;
185  std::string tab = " ";
186 
187  for (const auto node: _dag.nodes()) {
188  if (isChanceNode(node))
189  chanceNode << tab << "\"" << variable(node).name() << "\""
190  << ";";
191  else if (isUtilityNode(node))
192  utilityNode << tab << "\"" << variable(node).name() << "\""
193  << ";";
194  else
195  decisionNode << tab << "\"" << variable(node).name() << "\""
196  << ";";
197 
198  if (_dag.children(node).size() > 0)
199  for (const auto chi: _dag.children(node))
200  arcstream << tab << "\"" << variable(node).name() << "\""
201  << " -> "
202  << "\"" << variable(chi).name() << "\";" << std::endl;
203  }
204 
205  output << decisionNode.str() << std::endl
206  << utilityNode.str() << std::endl
207  << chanceNode.str() << std::endl
208  << arcstream.str() << std::endl
209  << "}" << std::endl;
210 
211  return output.str();
212  }
213 
214  template < typename GUM_SCALAR >
216  std::stringstream output;
217 
218  output << "Influence Diagram{" << std::endl;
219  output << " chance: " << chanceNodeSize() << "," << std::endl;
220  output << " utility: " << utilityNodeSize() << "," << std::endl;
221  output << " decision: " << decisionNodeSize() << "," << std::endl;
222  output << " arcs: " << dag().sizeArcs() << "," << std::endl;
223 
224  double dSize = log10DomainSize();
225 
226  if (dSize > 6)
227  output << " domainSize: 10^" << dSize;
228  else
229  output << " domainSize: " << std::round(std::pow(10.0, dSize));
230 
231  output << std::endl << "}";
232 
233  return output.str();
234  }
235 
236  // ===========================================================================
237  // Variable manipulation methods.
238  // ===========================================================================
239 
240  /*
241  * Returns the CPT of a chance variable.
242  */
243  template < typename GUM_SCALAR >
244  INLINE const Potential< GUM_SCALAR >&
246  return *(__potentialMap[varId]);
247  }
248 
249  /*
250  * Returns the utility table of a utility node.
251  */
252  template < typename GUM_SCALAR >
253  INLINE const Potential< GUM_SCALAR >&
255  return *(__utilityMap[varId]);
256  }
257 
258  /*
259  * Return true if node is a utility one
260  */
261  template < typename GUM_SCALAR >
263  return __utilityMap.exists(varId);
264  }
265 
266  /*
267  * Return true if node is a utility one
268  */
269  template < typename GUM_SCALAR >
271  bool ret = true;
272 
273  if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
274 
275  return ret;
276  }
277 
278  /*
279  * Return true if node is a chance one
280  */
281  template < typename GUM_SCALAR >
283  return __potentialMap.exists(varId);
284  }
285 
286  /*
287  * Returns the number of utility nodes
288  */
289  template < typename GUM_SCALAR >
291  return __utilityMap.size();
292  }
293 
294  /*
295  * Returns the number of chance nodes
296  */
297  template < typename GUM_SCALAR >
299  return __potentialMap.size();
300  }
301 
302  /*
303  * Returns the number of decision nodes
304  */
305  template < typename GUM_SCALAR >
307  return (size() - __utilityMap.size() - __potentialMap.size());
308  }
309 
310  /*
311  * Returns a constant reference to the VariableNodeMap of this Influence
312  * Diagram
313  */
314  template < typename GUM_SCALAR >
315  INLINE const VariableNodeMap&
317  return __variableMap;
318  }
319 
320  /*
321  * Returns a constant reference over a variable given it's node id.
322  */
323  template < typename GUM_SCALAR >
324  INLINE const DiscreteVariable&
326  return __variableMap[id];
327  }
328 
329  /*
330  * Return id node from discrete var pointer.
331  */
332  template < typename GUM_SCALAR >
333  INLINE NodeId
335  return __variableMap.get(var);
336  }
337 
338  // Getter by name
339  template < typename GUM_SCALAR >
340  INLINE NodeId
341  InfluenceDiagram< GUM_SCALAR >::idFromName(const std::string& name) const {
342  return __variableMap.idFromName(name);
343  }
344 
345  // Getter by name
346  template < typename GUM_SCALAR >
348  const std::string& name) const {
349  return __variableMap.variableFromName(name);
350  }
351 
352  /*
353  * Add a chance variable, it's associate node and it's CPT. The id of the new
354  * variable is automatically generated.
355  */
356  template < typename GUM_SCALAR >
358  NodeId varId) {
359  return addChanceNode(var, varId);
360  }
361 
362  /*
363  * Add a utility variable, it's associate node and it's UT. The id of the new
364  * variable is automatically generated.
365  * @Throws : Gum::InvalidArgument if var has more than one state
366  */
367  template < typename GUM_SCALAR >
368  NodeId
370  NodeId varId) {
372  NodeId res = 0;
373 
374  try {
375  res = addUtilityNode(var, newMultiDim, varId);
376  } catch (Exception&) {
377  delete newMultiDim;
378  throw;
379  }
380 
381  return res;
382  }
383 
384  /*
385  * Add a decision variable. The id of the new
386  * variable is automatically generated.
387  */
388  template < typename GUM_SCALAR >
389  NodeId
391  NodeId varId) {
392  return _addNode(var, varId);
393  }
394 
395  /*
396  * Add a chance variable, it's associate node and it's CPT. The id of the new
397  * variable is automatically generated.
398  */
399  template < typename GUM_SCALAR >
401  NodeId varId) {
403  NodeId res = 0;
404 
405  try {
406  res = addChanceNode(var, newMultiDim, varId);
407  } catch (Exception&) {
408  delete newMultiDim;
409  throw;
410  }
411 
412  return res;
413  }
414 
415  /*
416  * Add a chance variable, it's associate node and it's CPT. The id of the new
417  * variable is automatically generated.
418  */
419  template < typename GUM_SCALAR >
421  const DiscreteVariable& var,
423  NodeId DesiredId) {
424  NodeId proposedId = _addNode(var, DesiredId);
425 
426  Potential< GUM_SCALAR >* varcpt = new Potential< GUM_SCALAR >(aContent);
427  (*varcpt) << variable(proposedId);
428  __potentialMap.insert(proposedId, varcpt);
429 
430  return proposedId;
431  }
432 
433  /*
434  * Add a utility variable, it's associate node and it's UT. The id of the new
435  * variable is automatically generated.
436  * @Throws : Gum::InvalidArgument if var has more than one state
437  */
438  template < typename GUM_SCALAR >
440  const DiscreteVariable& var,
442  NodeId DesiredId) {
443  if (var.domainSize() != 1) {
445  "Utility var have no state ( which implicates a "
446  "single label for data output reasons ).");
447  }
448 
449  NodeId proposedId = _addNode(var, DesiredId);
450 
451  Potential< GUM_SCALAR >* varut = new Potential< GUM_SCALAR >(aContent);
452 
453  (*varut) << variable(proposedId);
454 
455  __utilityMap.insert(proposedId, varut);
456 
457  return proposedId;
458  }
459 
460  /*
461  * Add a node
462  */
463  template < typename GUM_SCALAR >
464  NodeId
466  NodeId DesiredId) {
467  // None thread safe code!
468  NodeId proposedId;
469 
470  if (DesiredId == 0)
471  proposedId = _dag.nextNodeId();
472  else
473  proposedId = DesiredId;
474 
475  __variableMap.insert(proposedId, variableType);
476 
477  _dag.addNodeWithId(proposedId);
478 
479  // end critical section
480  return proposedId;
481  }
482 
483  /*
484  * Erase a Variable from the network and remove the variable from
485  * all childs of id.
486  * If no variable matches the id, then nothing is done.
487  */
488  template < typename GUM_SCALAR >
490  if (__variableMap.exists(varId)) {
491  // Reduce the variable child's CPT or Utility Table if necessary
492  for (const auto chi: _dag.children(varId))
493  if (isChanceNode(chi))
494  __potentialMap[chi]->erase(variable(varId));
495  else if (isUtilityNode(chi))
496  __utilityMap[chi]->erase(variable(varId));
497 
498  if (isChanceNode(varId)) {
499  delete __potentialMap[varId];
500  __potentialMap.erase(varId);
501  } else if (isUtilityNode(varId)) {
502  delete __utilityMap[varId];
503  __utilityMap.erase(varId);
504  }
505 
506  __variableMap.erase(varId);
507  _dag.eraseNode(varId);
508  }
509  }
510 
511  /*
512  * Erase a Variable from the network and remove the variable from
513  * all childs of var.
514  * If no variable matches, then nothing is done.
515  */
516  template < typename GUM_SCALAR >
518  erase(__variableMap.get(var));
519  }
520 
521  /* we allow the user to change the name of a variable
522  */
523  template < typename GUM_SCALAR >
525  NodeId id, const std::string& new_name) {
526  __variableMap.changeName(id, new_name);
527  }
528 
529  // ===========================================================================
530  // @name Arc manipulation methods.
531  // ===========================================================================
532  /*
533  * Add an arc in the ID, and update diagram's chance nodes cpt if necessary.
534  */
535  template < typename GUM_SCALAR >
537  if (isUtilityNode(tail)) {
538  GUM_ERROR(InvalidArc, "Tail cannot be a utility node");
539  }
540 
541  _dag.addArc(tail, head);
542 
543  if (isChanceNode(head))
544  // Add parent in the child's CPT
545  (*(__potentialMap[head])) << variable(tail);
546  else if (isUtilityNode(head))
547  // Add parent in the child's UT
548  (*(__utilityMap[head])) << variable(tail);
549  }
550 
551  /*
552  * Removes an arc in the ID, and update diagram chance nodes cpt if necessary.
553  *
554  * If (tail, head) doesn't exist, the nothing happens.
555  */
556  template < typename GUM_SCALAR >
558  if (_dag.existsArc(arc)) {
559  NodeId head = arc.head(), tail = arc.tail();
560  _dag.eraseArc(arc);
561 
562  if (isChanceNode(head))
563  // Removes parent in the child's CPT
564  (*(__potentialMap[head])) >> variable(tail);
565  else if (isUtilityNode(head))
566  // Removes parent in the child's UT
567  (*(__utilityMap[head])) >> variable(tail);
568  }
569  }
570 
571  /*
572  * Removes an arc in the ID, and update diagram chance nodes cpt if necessary.
573  *
574  * If (tail, head) doesn't exist, the nothing happens.
575  */
576  template < typename GUM_SCALAR >
578  eraseArc(Arc(tail, head));
579  }
580 
581  // ===========================================================================
582  // Graphical methods
583  // ===========================================================================
584 
585  /*
586  * The node's id are coherent with the variables and nodes of the topology.
587  */
588  template < typename GUM_SCALAR >
590  for (const auto node: _dag.nodes())
591  if (!isUtilityNode(node)) graph.addNodeWithId(node);
592 
593  for (const auto node: _dag.nodes()) {
594  if (!isDecisionNode(node))
595  for (const auto par: _dag.parents(node)) {
596  if (isChanceNode(node)) graph.addEdge(node, par);
597 
598  for (const auto par2: _dag.parents(node))
599  if (par != par2) graph.addEdge(par, par2);
600  }
601  }
602  }
603 
604  /*
605  * True if a directed path exist with all decison nodes
606  */
607  template < typename GUM_SCALAR >
609  const Sequence< NodeId >& order = topologicalOrder(true);
610 
611  // Finding first decision node
612  Sequence< NodeId >::const_iterator orderIter = order.begin();
613 
614  while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
615  ++orderIter;
616 
617  if (orderIter == order.end()) return true;
618 
619  NodeId parentDecision = (*orderIter);
620  ++orderIter;
621 
622  // Checking path between decisions nodes
623  while (orderIter != order.end()) {
624  if (isDecisionNode(*orderIter)) {
625  if (!existsPathBetween(parentDecision, *orderIter)) return false;
626 
627  parentDecision = *orderIter;
628  }
629 
630  ++orderIter;
631  }
632 
633  return true;
634  }
635 
636  /*
637  * Returns true if a path exists between source and destination
638  */
639  template < typename GUM_SCALAR >
641  NodeId dest) const {
642  List< NodeId > nodeFIFO;
643  // mark[node] contains 0 if not visited
644  // mark[node] = predecessor if visited
645  NodeProperty< int > mark = _dag.nodesProperty((int)-1);
646  NodeId current;
647 
648  mark[src] = (int)src;
649  nodeFIFO.pushBack(src);
650 
651  while (!nodeFIFO.empty()) {
652  current = nodeFIFO.front();
653  nodeFIFO.popFront();
654 
655  for (const auto new_one: _dag.children(current)) {
656  if (mark[new_one] != -1)
657  continue; // if this node is already marked, continue
658 
659  mark[new_one] = (int)current;
660 
661  if (new_one == dest) break; // if we reach *orderIter, stop.
662 
663  nodeFIFO.pushBack(new_one);
664  }
665  }
666 
667  if (mark[dest] == -1) return false;
668 
669  return true;
670  }
671 
672  /*
673  * Returns the decision graph
674  */
675  template < typename GUM_SCALAR >
677  gum::DAG* temporalGraph = new gum::DAG();
678 
679  for (const auto node: _dag.nodes()) {
680  if (isDecisionNode(node)) {
681  if (!temporalGraph->existsNode(node)) temporalGraph->addNodeWithId(node);
682 
683  for (const auto chi: _getChildrenDecision(node)) {
684  if (!temporalGraph->existsNode(chi)) temporalGraph->addNodeWithId(chi);
685 
686  temporalGraph->addArc(node, chi);
687  }
688  }
689  }
690 
691  return temporalGraph;
692  }
693 
694  /*
695  * Returns the list of children decision for a given nodeId
696  */
697  template < typename GUM_SCALAR >
699  NodeId parentDecision) const {
700  Sequence< NodeId > childrenSeq;
701 
702  List< NodeId > nodeFIFO;
703  NodeId current;
704 
705  // mark[node] contains false if not visited
706  // mark[node] contains true if visited
708 
709  mark[parentDecision] = true;
710 
711  nodeFIFO.pushBack(parentDecision);
712 
713  while (!nodeFIFO.empty()) {
714  current = nodeFIFO.front();
715  nodeFIFO.popFront();
716 
717  for (const auto new_one: _dag.children(current)) {
718  if (mark[new_one]) continue; // if this node is already marked, continue
719 
720  mark[new_one] = true;
721 
722  if (!isDecisionNode(new_one))
723  nodeFIFO.pushBack(new_one);
724  else
725  childrenSeq.insert(new_one);
726  }
727  }
728 
729  return childrenSeq;
730  }
731 
732  /*
733  * Returns the sequence of decision nodes
734  * @throw NotFound if such a sequence does not exist
735  */
736  template < typename GUM_SCALAR >
737  std::vector< NodeId >* InfluenceDiagram< GUM_SCALAR >::getDecisionOrder() const {
738  if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists"); }
739 
740  std::vector< NodeId >* decisionSequence = new std::vector< NodeId >();
741 
742  for (const auto elt: topologicalOrder(false))
743  if (isDecisionNode(elt)) decisionSequence->push_back(elt);
744 
745  return decisionSequence;
746  }
747 
748  /*
749  * Returns partial temporal ordering
750  * @throw NotFound if such a sequence does not exist
751  */
752  template < typename GUM_SCALAR >
753  const List< NodeSet >&
755  if (clear) {
756  __temporalOrder.clear();
757 
758  std::vector< NodeId >* decisionOrder = getDecisionOrder();
759  NodeSet nodeList = _dag.asNodeSet();
760 
761  for (Idx i = 0; i < decisionOrder->size(); i++) {
762  NodeSet partialOrderedSet;
763 
764  for (const auto par: _dag.parents(decisionOrder->at(i))) {
765  if (nodeList.contains(par) && isChanceNode(par)) {
766  partialOrderedSet.insert(par);
767  nodeList.erase(par);
768  }
769  }
770 
771  if (!partialOrderedSet.empty())
772  __temporalOrder.pushFront(partialOrderedSet);
773 
774  NodeSet decisionSet;
775 
776  decisionSet.insert(decisionOrder->at(i));
777 
778  __temporalOrder.pushFront(decisionSet);
779  }
780 
781  NodeSet lastSet; //= new gum::NodeSet();
782 
783  for (const auto node: nodeList)
784  if (isChanceNode(node)) lastSet.insert(node);
785 
786  if (!lastSet.empty()) __temporalOrder.pushFront(lastSet);
787  }
788 
789  return __temporalOrder;
790  }
791 } // namespace gum
DAGmodel & operator=(const DAGmodel &source)
Private copy operator.
Definition: DAGmodel.cpp:78
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:583
virtual const VariableNodeMap & variableNodeMap() const
Returns a constant reference to the VariableNodeMap of this Influence Diagram.
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
bool empty() const noexcept
Returns a boolean indicating whether the chained list is empty.
Definition: list_tpl.h:1970
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
NodeProperty< Potential< GUM_SCALAR > *> __potentialMap
Mapping between potential variable&#39;s id and their CPT.
Virtual base class for PGMs using a DAG.
Definition: DAGmodel.h:48
iterator begin() const
Returns an unsafe begin iterator.
Definition: sequence_tpl.h:657
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:709
bool isChanceNode(NodeId varId) const
Returns true if node is a chance one.
void erase(NodeId id)
Erase a Variable from the network and remove the variable from all his childs.
NodeId addChanceNode(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it&#39;s associate node and it&#39;s CPT.
virtual const DiscreteVariable & variable(NodeId id) const
Returns a constant reference over a variabe given it&#39;s node id.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.
NodeId insert(NodeId id, const DiscreteVariable &var)
Maps id with var.
std::string toString() const
gum::DAG * getDecisionGraph() const
Returns the temporal Graph.
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:35
Container used to map discrete variables with nodes.
Size decisionNodeSize() const
Returns the number of decision nodes.
virtual const Potential< GUM_SCALAR > & utility(NodeId varId) const
Returns the utility table of a utility node.
virtual const DiscreteVariable & variableFromName(const std::string &name) const
Getter by name.
void changeVariableName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable
Size chanceNodeSize() const
Returns the number of chance nodes.
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
bool exists(NodeId id) const
Return true if id matches a node.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
std::vector< NodeId > * getDecisionOrder() const
Returns the sequence of decision nodes in the directed path.
VariableNodeMap __variableMap
Mapping between id and variable.
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:658
Base class for discrete random variable.
Generic doubly linked lists.
Definition: list.h:372
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Size utilityNodeSize() const
Returns the number of utility nodes.
void popFront()
Removes the first element of a List, if any.
Definition: list_tpl.h:1964
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
NodeId head() const
returns the head of the arc
NodeId _addNode(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
The class for generic Hash Tables.
Definition: hashTable.h:679
std::string toDot() const
Idx val(Idx i) const
Returns the current value of the variable at position i.
void erase(NodeId id)
Removes a var and it&#39;s id of this mapping. The pointer is deleted.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
const List< NodeSet > & getPartialTemporalOrder(bool clear=true) const
Returns partial temporal ordering.
virtual Size domainSize() const =0
Size size() const
Returns the number of variables in this Directed Graphical Model.
Definition: DAGmodel_inl.h:96
DAG _dag
The DAG of this Directed Graphical Model.
Definition: DAGmodel.h:199
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
const Sequence< NodeId > & topologicalOrder(bool clear=true) const
The topological order stays the same as long as no variable or arcs are added or erased src the topol...
Definition: DAGmodel.cpp:117
List< NodeSet > __temporalOrder
The temporal order.
const std::string & property(const std::string &name) const
Return the value of the property name of this DAGModel.
Definition: DAGmodel_inl.h:37
void inc()
Operator increment.
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Val & pushBack(const Val &val)
Inserts a new element (a copy) at the end of the chained list.
Definition: list_tpl.h:1592
NodeSet asNodeSet() const
returns a copy of the set of nodes represented by the NodeGraphPart
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
void _copyTables(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.
virtual ~InfluenceDiagram()
Destructor.
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:106
Multidimensional matrix stored as an array in memory.
Definition: multiDimArray.h:54
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: DAG_inl.h:43
NodeId idFromName(const std::string &name) const
Sequence< NodeId > _getChildrenDecision(NodeId parentDecision) const
Returns the list of children decision for a given nodeId.
bool decisionOrderExists() const
True if a directed path exist with all decison nodes.
virtual void _moralGraph(UndiGraph &graph) const
Returns the moral graph of this InfluenceDiagram.
virtual NodeId idFromName(const std::string &name) const
Getter by name.
InfluenceDiagram< GUM_SCALAR > & operator=(const InfluenceDiagram< GUM_SCALAR > &source)
Copy Operator.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
Val & front() const
Returns a reference to first element of a list, if any.
Definition: list_tpl.h:1831
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
void setFirst()
Assign the first values to the tuple of the Instantiation.
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it&#39;s associate node and it&#39;s UT.
void changeName(NodeId id, const std::string &new_name)
we allow the user to change the name of a variable
Base class for undirected graphs.
Definition: undiGraph.h:109
InfluenceDiagram()
Default constructor.
NodeId add(const DiscreteVariable &variable, NodeId id=0)
Add a chance variable, it&#39;s associate node and it&#39;s CPT.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:53
NodeId nextNodeId() const
returns a new node id, not yet used by any node
NodeId addDecisionNode(const DiscreteVariable &variable, NodeId id=0)
Add a decision variable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
virtual NodeId nodeId(const DiscreteVariable &var) const
Return id node from discrete var pointer.
double log10DomainSize() const
Definition: DAGmodel_inl.h:75
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:703
const DiscreteVariable & variableFromName(const std::string &name) const
const iterator & end() const noexcept
Returns the unsafe end iterator.
Definition: sequence_tpl.h:664
const std::string & name() const
returns the name of the variable
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
Base class for dag.
Definition: DAG.h:102
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:69
void _removeTables()
Removing ancient table.
const DAG & dag() const
Returns a constant reference to the dag of this Bayes Net.
Definition: DAGmodel_inl.h:63
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:615
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
NodeId tail() const
returns the tail of the arc
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
const DiscreteVariable & get(NodeId id) const
Returns a discrete variable given it&#39;s node id.
bool end() const
Returns true if the Instantiation reached the end.
Class representing an Influence Diagram.
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408