aGrUM  0.14.2
influenceDiagram.h
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
4  * {prenom.nom}_at_lip6.fr *
5  * *
6  * This program is free software; you can redistribute it and/or modify *
7  * it under the terms of the GNU General Public License as published by *
8  * the Free Software Foundation; either version 2 of the License, or *
9  * (at your option) any later version. *
10  * *
11  * This program is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with this program; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20  ***************************************************************************/
28 #ifndef GUM_INF_DIAG_H
29 #define GUM_INF_DIAG_H
30 
31 #include <string>
32 #include <utility>
33 
34 #include <agrum/agrum.h>
35 
36 #include <agrum/core/hashTable.h>
37 
39 
41 
42 namespace gum {
43 
51  template < typename GUM_SCALAR >
52  class InfluenceDiagram : public DAGmodel {
53  // friend class InfluenceDiagramFactory<GUM_SCALAR>;
54 
55  public:
56  // ===========================================================================
58  // ===========================================================================
60 
65 
69  virtual ~InfluenceDiagram();
70 
75 
81 
83 
85  std::string toDot() const;
86 
88  std::string toString() const;
89 
90  // ===========================================================================
92  // ===========================================================================
94 
99  virtual const Potential< GUM_SCALAR >& cpt(NodeId varId) const;
100 
105  virtual const Potential< GUM_SCALAR >& utility(NodeId varId) const;
106 
111  virtual const VariableNodeMap& variableNodeMap() const;
112 
116  bool isUtilityNode(NodeId varId) const;
117 
121  bool isDecisionNode(NodeId varId) const;
122 
126  bool isChanceNode(NodeId varId) const;
127 
131  Size utilityNodeSize() const;
132 
136  Size chanceNodeSize() const;
137 
141  Size decisionNodeSize() const;
142 
147  virtual const DiscreteVariable& variable(NodeId id) const;
148 
153  virtual NodeId nodeId(const DiscreteVariable& var) const;
154 
157  virtual NodeId idFromName(const std::string& name) const;
158 
161  virtual const DiscreteVariable&
162  variableFromName(const std::string& name) const;
163 
178  NodeId add(const DiscreteVariable& variable, NodeId id = 0);
179 
194  NodeId addChanceNode(const DiscreteVariable& variable, NodeId id = 0);
195 
211  NodeId addUtilityNode(const DiscreteVariable& variable, NodeId id = 0);
212 
224  NodeId addDecisionNode(const DiscreteVariable& variable, NodeId id = 0);
225 
239  NodeId addChanceNode(const DiscreteVariable& variable,
241  NodeId id = 0);
242 
256  NodeId addUtilityNode(const DiscreteVariable& variable,
258  NodeId id = 0);
259 
267  void erase(NodeId id);
268 
276  void erase(const DiscreteVariable& var);
277 
282  void changeVariableName(NodeId id, const std::string& new_name);
283 
285  // ===========================================================================
287  // ===========================================================================
289 
299  void addArc(NodeId tail, NodeId head);
300 
308  void eraseArc(const Arc& arc);
309 
318  void eraseArc(NodeId tail, NodeId head);
319 
321 
322  // ===========================================================================
324  // ===========================================================================
326 
330  bool decisionOrderExists() const;
331 
335  gum::DAG* getDecisionGraph() const;
336 
341  std::vector< NodeId >* getDecisionOrder() const;
342 
346  bool existsPathBetween(NodeId src, NodeId dest) const;
347 
352  const List< NodeSet >& getPartialTemporalOrder(bool clear = true) const;
353 
355 
356  protected:
358  virtual void _moralGraph(UndiGraph& graph) const;
359 
363  void _removeTables();
364 
368  void _copyTables(const InfluenceDiagram< GUM_SCALAR >& IDsource);
369 
373  NodeId _addNode(const DiscreteVariable& variableType, NodeId DesiredId);
374 
378  Sequence< NodeId > _getChildrenDecision(NodeId parentDecision) const;
379 
380  private:
383 
388 
391  };
392 
393 } /* namespace gum */
394 
396 
397 #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:57
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:45
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:369
gum is the global namespace for all aGrUM entities
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:676
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.
Header of the Potential class.
bool isUtilityNode(NodeId varId) const
Returns true if node is a utility one.
List< NodeSet > __temporalOrder
The temporal order.
Class representing probabilistic DAG model.
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:106
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>
Template implementation of InfluenceDiagram/InfluenceDiagram.h classes.
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:45
virtual NodeId nodeId(const DiscreteVariable &var) const
Return id node from discrete var pointer.
Base class for dag.
Definition: DAG.h:99
void _removeTables()
Removing ancient table.
Class hash tables iterators.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
virtual const Potential< GUM_SCALAR > & cpt(NodeId varId) const
Returns the CPT of a potential variable.
Class representing an Influence Diagram.