aGrUM  0.16.0
multiDimFunctionGraphManager.h
Go to the documentation of this file.
1 
31 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
32 # define GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
33 
34 # include <agrum/agrum.h>
38 
39 namespace gum {
40 
41  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
42  class MultiDimFunctionGraph;
43 
76  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
77  class MultiDimFunctionGraphManager {
78  // =========================================================================
80  // =========================================================================
82 
89  friend MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >*
91 
98  protected:
100  MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* master);
101 
102  public:
107 
109  // =========================================================================
111  // =========================================================================
113 
118  void setRootNode(const NodeId& root);
119 
128  NodeId addInternalNode(const DiscreteVariable* var);
129 
143  virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons) = 0;
144 
145  protected:
152  NodeId _addInternalNode(const DiscreteVariable* var, NodeId* sons);
153 
154  public:
167  NodeId addInternalNode(const DiscreteVariable* var, NodeId nid);
168 
179  NodeId addTerminalNode(const GUM_SCALAR& value);
180 
191  void eraseNode(NodeId id, NodeId replacingId = 0, bool updateParents = true);
192 
194  // =========================================================================
196  // =========================================================================
198 
205  void setSon(const NodeId& node, const Idx& modality, const NodeId& sonNode);
206 
207 
211  void minimizeSize();
212 
218  void moveTo(const DiscreteVariable* x, Idx desiredPos);
219 
220  private:
231  void __adjacentSwap(const DiscreteVariable* x, const DiscreteVariable* y);
232 
233  protected:
241  void _migrateNode(const NodeId& x, const NodeId& y);
242 
244  // =========================================================================
246  // =========================================================================
248 
249  protected:
263  NodeId _nodeRedundancyCheck(const DiscreteVariable* var, NodeId* sonsMap);
264 
265  private:
278  NodeId __checkIsomorphism(const DiscreteVariable* var, NodeId* sons);
279 
289  bool __isRedundant(const DiscreteVariable* var, NodeId* sons);
290 
291  public:
295  virtual void reduce() = 0;
296 
297  protected:
301  void _reduce();
302 
304 
305  public:
309  void clean();
310 
311  private:
314  };
315 
316  // ===========================================================================
317  // MultiDimFunctionGraphTreeManager
318  // ===========================================================================
319 
335  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
337  : public MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > {
342 
343  // ========================================================================
345  // ========================================================================
347 
352 
353  public:
358 
360  // ========================================================================
362  // ========================================================================
364  virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons);
365 
366  virtual void reduce();
368  };
369 
370  // ===========================================================================
371  // MultiDimFunctionGraphROManager
372  // ===========================================================================
373 
389  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
391  : public MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > {
396 
397  // ========================================================================
399  // ========================================================================
403 
404  public:
406 
408  // ========================================================================
410  // ========================================================================
412 
413  virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons);
414 
415  virtual void reduce();
416 
418  };
419 
420 } // namespace gum
421 
422 // ============================================================================
424 // ============================================================================
425 #endif // GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
426 // ============================================================================
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
void clean()
Removes var without nodes in the diagram.
void __adjacentSwap(const DiscreteVariable *x, const DiscreteVariable *y)
Swap two adjacent variable.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
void moveTo(const DiscreteVariable *x, Idx desiredPos)
Changes var position in variable sequence.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __functionGraph
The multidimdecisiongraph supposed to be edited.
void eraseNode(NodeId id, NodeId replacingId=0, bool updateParents=true)
Erases a node from the diagram.
Class implementingting a function graph manager.
void _migrateNode(const NodeId &x, const NodeId &y)
Remaps all arcs going to ou going from the first given node to the second node, then delete first nod...
void minimizeSize()
Performs a sifting in search of a(local) minimal size.
MultiDimFunctionGraphManager(MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *master)
Default constructor.
Class implementingting a function graph.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void _reduce()
Ensures that every isomorphic subgraphs are merged together.
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
bool __isRedundant(const DiscreteVariable *var, NodeId *sons)
Checks if node has the same child for every variable value.
NodeId _nodeRedundancyCheck(const DiscreteVariable *var, NodeId *sonsMap)
Check for redundancy.
NodeId _addInternalNode(const DiscreteVariable *var, NodeId *sons)
Adds an internal node.
virtual void reduce()=0
Ensures that every isomorphic subgraphs are merged together.
virtual ~MultiDimFunctionGraphManager()
Class destructor.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
NodeId __checkIsomorphism(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.