aGrUM  0.14.2
multiDimFunctionGraphManager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 #ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
29 # define GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
30 
31 # include <agrum/agrum.h>
35 
36 namespace gum {
37 
38  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
39  class MultiDimFunctionGraph;
40 
73  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
74  class MultiDimFunctionGraphManager {
75  // =========================================================================
77  // =========================================================================
79 
86  friend MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >*
88 
95  protected:
97  MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* master);
98 
99  public:
104 
106  // =========================================================================
108  // =========================================================================
110 
115  void setRootNode(const NodeId& root);
116 
125  NodeId addInternalNode(const DiscreteVariable* var);
126 
140  virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons) = 0;
141 
142  protected:
149  NodeId _addInternalNode(const DiscreteVariable* var, NodeId* sons);
150 
151  public:
164  NodeId addInternalNode(const DiscreteVariable* var, NodeId nid);
165 
176  NodeId addTerminalNode(const GUM_SCALAR& value);
177 
188  void eraseNode(NodeId id, NodeId replacingId = 0, bool updateParents = true);
189 
191  // =========================================================================
193  // =========================================================================
195 
202  void setSon(const NodeId& node, const Idx& modality, const NodeId& sonNode);
203 
204 
208  void minimizeSize();
209 
215  void moveTo(const DiscreteVariable* x, Idx desiredPos);
216 
217  private:
228  void __adjacentSwap(const DiscreteVariable* x, const DiscreteVariable* y);
229 
230  protected:
238  void _migrateNode(const NodeId& x, const NodeId& y);
239 
241  // =========================================================================
243  // =========================================================================
245 
246  protected:
260  NodeId _nodeRedundancyCheck(const DiscreteVariable* var, NodeId* sonsMap);
261 
262  private:
275  NodeId __checkIsomorphism(const DiscreteVariable* var, NodeId* sons);
276 
286  bool __isRedundant(const DiscreteVariable* var, NodeId* sons);
287 
288  public:
292  virtual void reduce() = 0;
293 
294  protected:
298  void _reduce();
299 
301 
302  public:
306  void clean();
307 
308  private:
311  };
312 
313  // ===========================================================================
314  // MultiDimFunctionGraphTreeManager
315  // ===========================================================================
316 
332  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
334  : public MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > {
339 
340  // ========================================================================
342  // ========================================================================
344 
349 
350  public:
355 
357  // ========================================================================
359  // ========================================================================
361  virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons);
362 
363  virtual void reduce();
365  };
366 
367  // ===========================================================================
368  // MultiDimFunctionGraphROManager
369  // ===========================================================================
370 
386  template < typename GUM_SCALAR, template < typename > class TerminalNodePolicy >
388  : public MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > {
393 
394  // ========================================================================
396  // ========================================================================
400 
401  public:
403 
405  // ========================================================================
407  // ========================================================================
409 
410  virtual NodeId addInternalNode(const DiscreteVariable* var, NodeId* sons);
411 
412  virtual void reduce();
413 
415  };
416 
417 } // namespace gum
418 
419 // ============================================================================
421 // ============================================================================
422 #endif // GUM_MULTI_DIM_FUNCTION_GRAPH_MANAGER_H
423 // ============================================================================
Base node set class for graphs.
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.
Template methods of gum::MultiDimFunctionGraphManager.
Headers of the InternalNode class.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
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.
Headers of MultiDimFunctionGraph.
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:97
NodeId __checkIsomorphism(const DiscreteVariable *var, NodeId *sons)
Checks if a similar node does not already exists in the graph.