aGrUM  0.16.0
influenceDiagram.h
Go to the documentation of this file.
1 
30 #ifndef GUM_INF_DIAG_H
31 #define GUM_INF_DIAG_H
32 
33 #include <string>
34 #include <utility>
35 
36 #include <agrum/agrum.h>
37 
38 #include <agrum/core/hashTable.h>
39 
41 
43 
44 namespace gum {
45 
53  template < typename GUM_SCALAR >
54  class InfluenceDiagram : public DAGmodel {
55  // friend class InfluenceDiagramFactory<GUM_SCALAR>;
56 
57  public:
58  // ===========================================================================
60  // ===========================================================================
62 
67 
71  virtual ~InfluenceDiagram();
72 
77 
83 
85 
87  std::string toDot() const;
88 
90  std::string toString() const;
91 
92  // ===========================================================================
94  // ===========================================================================
96 
101  virtual const Potential< GUM_SCALAR >& cpt(NodeId varId) const;
102 
107  virtual const Potential< GUM_SCALAR >& utility(NodeId varId) const;
108 
113  virtual const VariableNodeMap& variableNodeMap() const;
114 
118  bool isUtilityNode(NodeId varId) const;
119 
123  bool isDecisionNode(NodeId varId) const;
124 
128  bool isChanceNode(NodeId varId) const;
129 
133  Size utilityNodeSize() const;
134 
138  Size chanceNodeSize() const;
139 
143  Size decisionNodeSize() const;
144 
149  virtual const DiscreteVariable& variable(NodeId id) const;
150 
155  virtual NodeId nodeId(const DiscreteVariable& var) const;
156 
159  virtual NodeId idFromName(const std::string& name) const;
160 
163  virtual const DiscreteVariable&
164  variableFromName(const std::string& name) const;
165 
180  NodeId add(const DiscreteVariable& variable, NodeId id = 0);
181 
196  NodeId addChanceNode(const DiscreteVariable& variable, NodeId id = 0);
197 
213  NodeId addUtilityNode(const DiscreteVariable& variable, NodeId id = 0);
214 
226  NodeId addDecisionNode(const DiscreteVariable& variable, NodeId id = 0);
227 
241  NodeId addChanceNode(const DiscreteVariable& variable,
243  NodeId id = 0);
244 
258  NodeId addUtilityNode(const DiscreteVariable& variable,
260  NodeId id = 0);
261 
269  void erase(NodeId id);
270 
278  void erase(const DiscreteVariable& var);
279 
284  void changeVariableName(NodeId id, const std::string& new_name);
285 
287  // ===========================================================================
289  // ===========================================================================
291 
301  void addArc(NodeId tail, NodeId head);
302 
310  void eraseArc(const Arc& arc);
311 
320  void eraseArc(NodeId tail, NodeId head);
321 
323 
324  // ===========================================================================
326  // ===========================================================================
328 
332  bool decisionOrderExists() const;
333 
337  gum::DAG* getDecisionGraph() const;
338 
343  std::vector< NodeId >* getDecisionOrder() const;
344 
348  bool existsPathBetween(NodeId src, NodeId dest) const;
349 
354  const List< NodeSet >& getPartialTemporalOrder(bool clear = true) const;
355 
357 
358  protected:
360  virtual void _moralGraph(UndiGraph& graph) const;
361 
365  void _removeTables();
366 
370  void _copyTables(const InfluenceDiagram< GUM_SCALAR >& IDsource);
371 
375  NodeId _addNode(const DiscreteVariable& variableType, NodeId DesiredId);
376 
380  Sequence< NodeId > _getChildrenDecision(NodeId parentDecision) const;
381 
382  private:
385 
390 
393  };
394 
395 } /* namespace gum */
396 
398 
399 #endif /* GUM_INF_DIAG_H */
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
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
void addArc(NodeId tail, NodeId head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
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.
bool existsPathBetween(NodeId src, NodeId dest) const
Returns true if a path exists between two nodes.
std::string toString() const
gum::DAG * getDecisionGraph() const
Returns the temporal Graph.
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.
std::vector< NodeId > * getDecisionOrder() const
Returns the sequence of decision nodes in the directed path.
VariableNodeMap __variableMap
Mapping between id and variable.
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.
NodeProperty< Potential< GUM_SCALAR > *> __utilityMap
Mapping between utility variable&#39;s id and their utility table.
NodeId _addNode(const DiscreteVariable &variableType, NodeId DesiredId)
Add a node.
The class for generic Hash Tables.
Definition: hashTable.h:679
std::string toDot() const
const List< NodeSet > & getPartialTemporalOrder(bool clear=true) const
Returns partial temporal ordering.
bool isDecisionNode(NodeId varId) const
Returns true if node is a decision one.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
List< NodeSet > __temporalOrder
The temporal order.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
void _copyTables(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.
virtual ~InfluenceDiagram()
Destructor.
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.
void eraseArc(const Arc &arc)
Removes an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
NodeId addUtilityNode(const DiscreteVariable &variable, NodeId id=0)
Add a utility variable, it&#39;s associate node and it&#39;s UT.
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>
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Base class for dag.
Definition: DAG.h:102
void _removeTables()
Removing ancient table.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
Class representing an Influence Diagram.