aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
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 
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  bool isUtilityNode(const std::string& name) const {
120  return isUtilityNode(idFromName(name));
121  };
125  bool isDecisionNode(NodeId varId) const;
126  bool isDecisionNode(const std::string& name) const {
127  return isDecisionNode(idFromName(name));
128  };
129 
133  bool isChanceNode(NodeId varId) const;
134  bool isChanceNode(const std::string& name) const {
135  return isChanceNode(idFromName(name));
136  };
140  Size utilityNodeSize() const;
141 
145  Size chanceNodeSize() const;
146 
150  Size decisionNodeSize() const;
151 
156  virtual const DiscreteVariable& variable(NodeId id) const;
157 
162  virtual NodeId nodeId(const DiscreteVariable& var) const;
163 
166  virtual NodeId idFromName(const std::string& name) const;
167 
170  virtual const DiscreteVariable&
171  variableFromName(const std::string& name) const;
172 
187  NodeId add(const DiscreteVariable& variable, NodeId id = 0);
188 
203  NodeId addChanceNode(const DiscreteVariable& variable, NodeId id = 0);
204 
219  NodeId addUtilityNode(const DiscreteVariable& variable, NodeId id = 0);
220 
232  NodeId addDecisionNode(const DiscreteVariable& variable, NodeId id = 0);
233 
247  NodeId addChanceNode(const DiscreteVariable& variable,
249  NodeId id = 0);
250 
264  NodeId addUtilityNode(const DiscreteVariable& variable,
266  NodeId id = 0);
267 
275  void erase(NodeId id);
276  void erase(const std::string& name) { erase(variableFromName(name)); };
277 
285  void erase(const DiscreteVariable& var);
286 
291  void changeVariableName(NodeId id, const std::string& new_name);
292  void changeVariableName(const std::string& name, const std::string& new_name) {
293  changeVariableName(idFromName(name), new_name);
294  }
295 
297  // ===========================================================================
299  // ===========================================================================
301 
311  void addArc(NodeId tail, NodeId head);
312  void addArc(const std::string& tail, const std::string& head) {
313  addArc(idFromName(tail), idFromName(head));
314  }
315 
323  void eraseArc(const Arc& arc);
324 
333  void eraseArc(NodeId tail, NodeId head);
334  void eraseArc(const std::string& tail, const std::string& head) {
335  eraseArc(idFromName(tail), idFromName(head));
336  }
337 
339 
340  // ===========================================================================
342  // ===========================================================================
344 
348  bool decisionOrderExists() const;
349 
353  gum::DAG* getDecisionGraph() const;
354 
359  std::vector< NodeId >* getDecisionOrder() const;
360 
364  bool existsPathBetween(NodeId src, NodeId dest) const;
365  bool existsPathBetween(const std::string& src, const std::string& dest) const {
366  return existsPathBetween(idFromName(src), idFromName(dest));
367  }
368 
373  const List< NodeSet >& getPartialTemporalOrder(bool clear = true) const;
374 
376 
377  protected:
379  virtual void _moralGraph(UndiGraph& graph) const;
380 
384  void _removeTables();
385 
389  void _copyTables(const InfluenceDiagram< GUM_SCALAR >& IDsource);
390 
394  NodeId _addNode(const DiscreteVariable& variableType, NodeId DesiredId);
395 
399  Sequence< NodeId > _getChildrenDecision(NodeId parentDecision) const;
400 
401  private:
404 
409 
412  };
413 
414 } /* namespace gum */
415 
417 
418 #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:47
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.
bool existsPathBetween(const std::string &src, const std::string &dest) const
True if a directed path exist with all decison 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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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.
bool isChanceNode(const std::string &name) const
Returns the CPT of a potential variable.
void addArc(const std::string &tail, const std::string &head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
List< NodeSet > __temporalOrder
The temporal order.
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
void changeVariableName(const std::string &name, const std::string &new_name)
Returns the CPT of a potential variable.
void _copyTables(const InfluenceDiagram< GUM_SCALAR > &IDsource)
Copying tables from another influence diagram.
virtual ~InfluenceDiagram()
Destructor.
void eraseArc(const std::string &tail, const std::string &head)
Add an arc in the ID, and update diagram&#39;s potential nodes cpt if necessary.
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.
void erase(const std::string &name)
Returns the CPT of a potential variable.
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.
bool isUtilityNode(const std::string &name) const
Returns the CPT of a potential variable.
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/tools/multidim/multiDimImplementation.h>
Copyright 2005-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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-2020 Pierre-Henri WUILLEMIN () et Christophe GONZALES () info_at_agrum_dot_org.
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.
bool isDecisionNode(const std::string &name) const
Returns the CPT of a potential variable.
Class representing an Influence Diagram.