aGrUM  0.16.0
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 >
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() << "\""
203  << ";" << std::endl;
204  }
205 
206  output << decisionNode.str() << std::endl
207  << utilityNode.str() << std::endl
208  << chanceNode.str() << std::endl
209  << arcstream.str() << std::endl
210  << "}" << std::endl;
211 
212  return output.str();
213  }
214 
215  template < typename GUM_SCALAR >
217  std::stringstream output;
218 
219  output << "Influence Diagram{" << std::endl;
220  output << " chance: " << chanceNodeSize() << "," << std::endl;
221  output << " utility: " << utilityNodeSize() << "," << std::endl;
222  output << " decision: " << decisionNodeSize() << "," << std::endl;
223  output << " arcs: " << dag().sizeArcs() << "," << std::endl;
224 
225  double dSize = log10DomainSize();
226 
227  if (dSize > 6)
228  output << " domainSize: 10^" << dSize;
229  else
230  output << " domainSize: " << std::round(std::pow(10.0, dSize));
231 
232  output << std::endl << "}";
233 
234  return output.str();
235  }
236 
237  // ===========================================================================
238  // Variable manipulation methods.
239  // ===========================================================================
240 
241  /*
242  * Returns the CPT of a chance variable.
243  */
244  template < typename GUM_SCALAR >
245  INLINE const Potential< GUM_SCALAR >&
247  return *(__potentialMap[varId]);
248  }
249 
250  /*
251  * Returns the utility table of a utility node.
252  */
253  template < typename GUM_SCALAR >
254  INLINE const Potential< GUM_SCALAR >&
256  return *(__utilityMap[varId]);
257  }
258 
259  /*
260  * Return true if node is a utility one
261  */
262  template < typename GUM_SCALAR >
264  return __utilityMap.exists(varId);
265  }
266 
267  /*
268  * Return true if node is a utility one
269  */
270  template < typename GUM_SCALAR >
272  bool ret = true;
273 
274  if (isUtilityNode(varId) || isChanceNode(varId)) ret = false;
275 
276  return ret;
277  }
278 
279  /*
280  * Return true if node is a chance one
281  */
282  template < typename GUM_SCALAR >
284  return __potentialMap.exists(varId);
285  }
286 
287  /*
288  * Returns the number of utility nodes
289  */
290  template < typename GUM_SCALAR >
292  return __utilityMap.size();
293  }
294 
295  /*
296  * Returns the number of chance nodes
297  */
298  template < typename GUM_SCALAR >
300  return __potentialMap.size();
301  }
302 
303  /*
304  * Returns the number of decision nodes
305  */
306  template < typename GUM_SCALAR >
308  return (size() - __utilityMap.size() - __potentialMap.size());
309  }
310 
311  /*
312  * Returns a constant reference to the VariableNodeMap of this Influence
313  * Diagram
314  */
315  template < typename GUM_SCALAR >
316  INLINE const VariableNodeMap&
318  return __variableMap;
319  }
320 
321  /*
322  * Returns a constant reference over a variable given it's node id.
323  */
324  template < typename GUM_SCALAR >
325  INLINE const DiscreteVariable&
327  return __variableMap[id];
328  }
329 
330  /*
331  * Return id node from discrete var pointer.
332  */
333  template < typename GUM_SCALAR >
334  INLINE NodeId
336  return __variableMap.get(var);
337  }
338 
339  // Getter by name
340  template < typename GUM_SCALAR >
341  INLINE NodeId
342  InfluenceDiagram< GUM_SCALAR >::idFromName(const std::string& name) const {
343  return __variableMap.idFromName(name);
344  }
345 
346  // Getter by name
347  template < typename GUM_SCALAR >
349  const std::string& name) const {
350  return __variableMap.variableFromName(name);
351  }
352 
353  /*
354  * Add a chance variable, it's associate node and it's CPT. The id of the new
355  * variable is automatically generated.
356  */
357  template < typename GUM_SCALAR >
359  NodeId varId) {
360  return addChanceNode(var, varId);
361  }
362 
363  /*
364  * Add a utility variable, it's associate node and it's UT. The id of the new
365  * variable is automatically generated.
366  * @Throws : Gum::InvalidArgument if var has more than one state
367  */
368  template < typename GUM_SCALAR >
369  NodeId
371  NodeId varId) {
373  NodeId res = 0;
374 
375  try {
376  res = addUtilityNode(var, newMultiDim, varId);
377  } catch (Exception&) {
378  delete newMultiDim;
379  throw;
380  }
381 
382  return res;
383  }
384 
385  /*
386  * Add a decision variable. The id of the new
387  * variable is automatically generated.
388  */
389  template < typename GUM_SCALAR >
390  NodeId
392  NodeId varId) {
393  return _addNode(var, varId);
394  }
395 
396  /*
397  * Add a chance variable, it's associate node and it's CPT. The id of the new
398  * variable is automatically generated.
399  */
400  template < typename GUM_SCALAR >
402  NodeId varId) {
404  NodeId res = 0;
405 
406  try {
407  res = addChanceNode(var, newMultiDim, varId);
408  } catch (Exception&) {
409  delete newMultiDim;
410  throw;
411  }
412 
413  return res;
414  }
415 
416  /*
417  * Add a chance variable, it's associate node and it's CPT. The id of the new
418  * variable is automatically generated.
419  */
420  template < typename GUM_SCALAR >
422  const DiscreteVariable& var,
424  NodeId DesiredId) {
425  NodeId proposedId = _addNode(var, DesiredId);
426 
427  Potential< GUM_SCALAR >* varcpt = new Potential< GUM_SCALAR >(aContent);
428  (*varcpt) << variable(proposedId);
429  __potentialMap.insert(proposedId, varcpt);
430 
431  return proposedId;
432  }
433 
434  /*
435  * Add a utility variable, it's associate node and it's UT. The id of the new
436  * variable is automatically generated.
437  * @Throws : Gum::InvalidArgument if var has more than one state
438  */
439  template < typename GUM_SCALAR >
441  const DiscreteVariable& var,
443  NodeId DesiredId) {
444  if (var.domainSize() != 1) {
446  "Utility var have no state ( which implicates a "
447  "single label for data output reasons ).");
448  }
449 
450  NodeId proposedId = _addNode(var, DesiredId);
451 
452  Potential< GUM_SCALAR >* varut = new Potential< GUM_SCALAR >(aContent);
453 
454  (*varut) << variable(proposedId);
455 
456  __utilityMap.insert(proposedId, varut);
457 
458  return proposedId;
459  }
460 
461  /*
462  * Add a node
463  */
464  template < typename GUM_SCALAR >
465  NodeId
467  NodeId DesiredId) {
468  // None thread safe code!
469  NodeId proposedId;
470 
471  if (DesiredId == 0)
472  proposedId = _dag.nextNodeId();
473  else
474  proposedId = DesiredId;
475 
476  __variableMap.insert(proposedId, variableType);
477 
478  _dag.addNodeWithId(proposedId);
479 
480  // end critical section
481  return proposedId;
482  }
483 
484  /*
485  * Erase a Variable from the network and remove the variable from
486  * all childs of id.
487  * If no variable matches the id, then nothing is done.
488  */
489  template < typename GUM_SCALAR >
491  if (__variableMap.exists(varId)) {
492  // Reduce the variable child's CPT or Utility Table if necessary
493  for (const auto chi : _dag.children(varId))
494  if (isChanceNode(chi))
495  __potentialMap[chi]->erase(variable(varId));
496  else if (isUtilityNode(chi))
497  __utilityMap[chi]->erase(variable(varId));
498 
499  if (isChanceNode(varId)) {
500  delete __potentialMap[varId];
501  __potentialMap.erase(varId);
502  } else if (isUtilityNode(varId)) {
503  delete __utilityMap[varId];
504  __utilityMap.erase(varId);
505  }
506 
507  __variableMap.erase(varId);
508  _dag.eraseNode(varId);
509  }
510  }
511 
512  /*
513  * Erase a Variable from the network and remove the variable from
514  * all childs of var.
515  * If no variable matches, then nothing is done.
516  */
517  template < typename GUM_SCALAR >
519  erase(__variableMap.get(var));
520  }
521 
522  /* we allow the user to change the name of a variable
523  */
524  template < typename GUM_SCALAR >
526  NodeId id, const std::string& new_name) {
527  __variableMap.changeName(id, new_name);
528  }
529 
530  // ===========================================================================
531  // @name Arc manipulation methods.
532  // ===========================================================================
533  /*
534  * Add an arc in the ID, and update diagram's chance nodes cpt if necessary.
535  */
536  template < typename GUM_SCALAR >
538  if (isUtilityNode(tail)) {
539  GUM_ERROR(InvalidArc, "Tail cannot be a utility node");
540  }
541 
542  _dag.addArc(tail, head);
543 
544  if (isChanceNode(head))
545  // Add parent in the child's CPT
546  (*(__potentialMap[head])) << variable(tail);
547  else if (isUtilityNode(head))
548  // Add parent in the child's UT
549  (*(__utilityMap[head])) << variable(tail);
550  }
551 
552  /*
553  * Removes an arc in the ID, and update diagram chance nodes cpt if necessary.
554  *
555  * If (tail, head) doesn't exist, the nothing happens.
556  */
557  template < typename GUM_SCALAR >
559  if (_dag.existsArc(arc)) {
560  NodeId head = arc.head(), tail = arc.tail();
561  _dag.eraseArc(arc);
562 
563  if (isChanceNode(head))
564  // Removes parent in the child's CPT
565  (*(__potentialMap[head])) >> variable(tail);
566  else if (isUtilityNode(head))
567  // Removes parent in the child's UT
568  (*(__utilityMap[head])) >> variable(tail);
569  }
570  }
571 
572  /*
573  * Removes an arc in the ID, and update diagram chance nodes cpt if necessary.
574  *
575  * If (tail, head) doesn't exist, the nothing happens.
576  */
577  template < typename GUM_SCALAR >
579  eraseArc(Arc(tail, head));
580  }
581 
582  // ===========================================================================
583  // Graphical methods
584  // ===========================================================================
585 
586  /*
587  * The node's id are coherent with the variables and nodes of the topology.
588  */
589  template < typename GUM_SCALAR >
591  for (const auto node : _dag.nodes())
592  if (!isUtilityNode(node)) graph.addNodeWithId(node);
593 
594  for (const auto node : _dag.nodes()) {
595  if (!isDecisionNode(node))
596  for (const auto par : _dag.parents(node)) {
597  if (isChanceNode(node)) graph.addEdge(node, par);
598 
599  for (const auto par2 : _dag.parents(node))
600  if (par != par2) graph.addEdge(par, par2);
601  }
602  }
603  }
604 
605  /*
606  * True if a directed path exist with all decison nodes
607  */
608  template < typename GUM_SCALAR >
610  const Sequence< NodeId >& order = topologicalOrder(true);
611 
612  // Finding first decision node
613  Sequence< NodeId >::const_iterator orderIter = order.begin();
614 
615  while ((orderIter != order.end()) && (!isDecisionNode(*orderIter)))
616  ++orderIter;
617 
618  if (orderIter == order.end()) return true;
619 
620  NodeId parentDecision = (*orderIter);
621  ++orderIter;
622 
623  // Checking path between decisions nodes
624  while (orderIter != order.end()) {
625  if (isDecisionNode(*orderIter)) {
626  if (!existsPathBetween(parentDecision, *orderIter)) return false;
627 
628  parentDecision = *orderIter;
629  }
630 
631  ++orderIter;
632  }
633 
634  return true;
635  }
636 
637  /*
638  * Returns true if a path exists between source and destination
639  */
640  template < typename GUM_SCALAR >
642  NodeId dest) const {
643  List< NodeId > nodeFIFO;
644  // mark[node] contains 0 if not visited
645  // mark[node] = predecessor if visited
646  NodeProperty< int > mark = _dag.nodesProperty((int)-1);
647  NodeId current;
648 
649  mark[src] = (int)src;
650  nodeFIFO.pushBack(src);
651 
652  while (!nodeFIFO.empty()) {
653  current = nodeFIFO.front();
654  nodeFIFO.popFront();
655 
656  for (const auto new_one : _dag.children(current)) {
657  if (mark[new_one] != -1)
658  continue; // if this node is already marked, continue
659 
660  mark[new_one] = (int)current;
661 
662  if (new_one == dest) break; // if we reach *orderIter, stop.
663 
664  nodeFIFO.pushBack(new_one);
665  }
666  }
667 
668  if (mark[dest] == -1) return false;
669 
670  return true;
671  }
672 
673  /*
674  * Returns the decision graph
675  */
676  template < typename GUM_SCALAR >
678  gum::DAG* temporalGraph = new gum::DAG();
679 
680  for (const auto node : _dag.nodes()) {
681  if (isDecisionNode(node)) {
682  if (!temporalGraph->existsNode(node)) temporalGraph->addNodeWithId(node);
683 
684  for (const auto chi : _getChildrenDecision(node)) {
685  if (!temporalGraph->existsNode(chi)) temporalGraph->addNodeWithId(chi);
686 
687  temporalGraph->addArc(node, chi);
688  }
689  }
690  }
691 
692  return temporalGraph;
693  }
694 
695  /*
696  * Returns the list of children decision for a given nodeId
697  */
698  template < typename GUM_SCALAR >
700  NodeId parentDecision) const {
701  Sequence< NodeId > childrenSeq;
702 
703  List< NodeId > nodeFIFO;
704  NodeId current;
705 
706  // mark[node] contains false if not visited
707  // mark[node] contains true if visited
709 
710  mark[parentDecision] = true;
711 
712  nodeFIFO.pushBack(parentDecision);
713 
714  while (!nodeFIFO.empty()) {
715  current = nodeFIFO.front();
716  nodeFIFO.popFront();
717 
718  for (const auto new_one : _dag.children(current)) {
719  if (mark[new_one]) continue; // if this node is already marked, continue
720 
721  mark[new_one] = true;
722 
723  if (!isDecisionNode(new_one))
724  nodeFIFO.pushBack(new_one);
725  else
726  childrenSeq.insert(new_one);
727  }
728  }
729 
730  return childrenSeq;
731  }
732 
733  /*
734  * Returns the sequence of decision nodes
735  * @throw NotFound if such a sequence does not exist
736  */
737  template < typename GUM_SCALAR >
738  std::vector< NodeId >* InfluenceDiagram< GUM_SCALAR >::getDecisionOrder() const {
739  if (!decisionOrderExists()) { GUM_ERROR(NotFound, "No decision path exists"); }
740 
741  std::vector< NodeId >* decisionSequence = new std::vector< NodeId >();
742 
743  for (const auto elt : topologicalOrder(false))
744  if (isDecisionNode(elt)) decisionSequence->push_back(elt);
745 
746  return decisionSequence;
747  }
748 
749  /*
750  * Returns partial temporal ordering
751  * @throw NotFound if such a sequence does not exist
752  */
753  template < typename GUM_SCALAR >
754  const List< NodeSet >&
756  if (clear) {
757  __temporalOrder.clear();
758 
759  std::vector< NodeId >* decisionOrder = getDecisionOrder();
760  NodeSet nodeList = _dag.asNodeSet();
761 
762  for (Idx i = 0; i < decisionOrder->size(); i++) {
763  NodeSet partialOrderedSet;
764 
765  for (const auto par : _dag.parents(decisionOrder->at(i))) {
766  if (nodeList.contains(par) && isChanceNode(par)) {
767  partialOrderedSet.insert(par);
768  nodeList.erase(par);
769  }
770  }
771 
772  if (!partialOrderedSet.empty())
773  __temporalOrder.pushFront(partialOrderedSet);
774 
775  NodeSet decisionSet;
776 
777  decisionSet.insert(decisionOrder->at(i));
778 
779  __temporalOrder.pushFront(decisionSet);
780  }
781 
782  NodeSet lastSet; //= new gum::NodeSet();
783 
784  for (const auto node : nodeList)
785  if (isChanceNode(node)) lastSet.insert(node);
786 
787  if (!lastSet.empty()) __temporalOrder.pushFront(lastSet);
788  }
789 
790  return __temporalOrder;
791  }
792 } // 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:581
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:707
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:656
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:203
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:701
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:613
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