aGrUM  0.14.2
simplicialSet.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  ***************************************************************************/
26 #ifndef GUM_SIMPLICIAL_SET_H
27 #define GUM_SIMPLICIAL_SET_H
28 
29 #include <iostream>
30 #include <utility>
31 
32 #include <agrum/agrum.h>
33 
36 
37 #define GUM_QUASI_RATIO 0.99
38 #define GUM_WEIGHT_THRESHOLD 0.0
39 
40 namespace gum {
41 
42  /* ===========================================================================
43  */
44  /* === CLASS FOR RETRIEVING SIMPLICIAL, ALMOST AND QUASI SIMPLICIAL NODES ===
45  */
46  /* ===========================================================================
47  */
55  /* ===========================================================================
56  */
57  class SimplicialSet {
58  public:
59  // ############################################################################
61  // ############################################################################
63 
65 
102  explicit SimplicialSet(UndiGraph* graph,
103  const NodeProperty< double >* log_domain_sizes,
104  NodeProperty< double >* log_weights,
105  double theRatio = GUM_QUASI_RATIO,
106  double theThreshold = GUM_WEIGHT_THRESHOLD);
107 
109 
147  SimplicialSet(const SimplicialSet& simplicial_from,
148  UndiGraph* graph,
149  const NodeProperty< double >* log_domain_sizes,
150  NodeProperty< double >* log_weights,
151  bool avoid_check = false);
152 
155 
157  ~SimplicialSet();
158 
160 
161  // ############################################################################
163  // ############################################################################
165 
168 
169  void makeClique(const NodeId id);
170 
172 
177  void eraseClique(const NodeId id);
178 
180 
184  void eraseNode(const NodeId id);
185 
187 
190  void eraseEdge(const Edge& edge);
191 
193 
199  void addEdge(NodeId first, NodeId second);
200 
202 
205  bool isSimplicial(const NodeId id);
206 
208 
210  bool hasSimplicialNode();
211 
214 
216  bool hasQuasiSimplicialNode();
217 
219 
222 
224 
227 
230 
232 
235 
238 
240 
243 
245 
249  void setFillIns(bool on_off);
250 
252  const EdgeSet& fillIns() const;
253 
255 
281  void setGraph(UndiGraph* graph,
282  const NodeProperty< double >* log_domain_sizes,
283  NodeProperty< double >* log_weights,
284  double theRatio = GUM_QUASI_RATIO,
285  double theThreshold = GUM_WEIGHT_THRESHOLD);
286 
288 
291  void replaceLogWeights(NodeProperty< double >* old_weigths,
292  NodeProperty< double >* new_weights);
293 
295 
296 
297  private:
300 
303 
306 
309 
312 
315 
318  enum class __Belong : char {
319  SIMPLICIAL,
322  NO_LIST
323  };
325 
329 
332 
334 
342 
347 
351 
354 
357  bool __we_want_fill_ins{false};
358 
361 
362 
365  void __updateList(const NodeId id);
366 
368  void __updateAllNodes();
369 
376  void __initialize();
377 
379 
385 
387 
392  };
393 
394 } /* namespace gum */
395 
396 #ifndef GUM_NO_INLINE
398 #endif /* GUM_NO_INLINE */
399 
400 #endif /* GUM_SIMPLICIAL_SET_H */
void makeClique(const NodeId id)
adds the necessary edges so that node &#39;id&#39; and its neighbors form a clique
void __initialize()
initialize: compute __nb_triangles, __nb_adjacent_neighbors, etc when a new graph is set ...
NodeId bestQuasiSimplicialNode()
gets a quasi simplicial node with the lowest clique weight
void eraseNode(const NodeId id)
removes a node and its adjacent edges from the underlying graph
NodeProperty< __Belong > __containing_list
#define GUM_WEIGHT_THRESHOLD
Definition: simplicialSet.h:38
void setGraph(UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
initialize the simplicial set w.r.t. a new graph
bool hasQuasiSimplicialNode()
indicates whether there exists a quasi simplicial node
void replaceLogWeights(NodeProperty< double > *old_weigths, NodeProperty< double > *new_weights)
reassigns a new set of cliques&#39; log weights (with the same content)
bool hasAlmostSimplicialNode()
indicates whether there exists an almost simplicial node
void eraseClique(const NodeId id)
removes a node and its adjacent edges from the underlying graph
double __log_threshold
quasi and almost simplicial nodes may not be eliminated unless their weight is lower than (1 + thresh...
NodeProperty< Size > __nb_adjacent_neighbours
for each node, the number of pairs of adjacent neighbours
UndiGraph * __graph
the graph on which we perform the simplicial computations
void __updateAllNodes()
put all the nodes in their appropriate list
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
__Belong
indicates for each node to which list (simplicial, almost simplicial, quasi simplicial) it belongs ...
NodeProperty< double > * __log_weights
the weights of the nodes (i.e., weight of their clique)
double __log_tree_width
the current (induced) tree width
The class for generic Hash Tables.
Definition: hashTable.h:676
void __updateList(const NodeId id)
put node id in the correct simplicial/almost simplicial/quasi simplicial list
NodeSet __changed_status
the set of nodes that have potentially changed of status
const PriorityQueue< NodeId, double > & allSimplicialNodes()
returns all the simplicial nodes
double __quasi_ratio
for a given node, if the number of pairs of neighbors that are adjacent / the number of adjacent neig...
inline implementations of simplicial set
EdgeProperty< Size > __nb_triangles
for each edge, keep track of the number of triangles passing through this egde
Class enabling fast retrieval of simplicial, quasi and almost simplicial nodes.
Definition: simplicialSet.h:57
PriorityQueue< NodeId, double > __simplicial_nodes
a queue of the simplicial nodes ordered by increasing node weight
void addEdge(NodeId first, NodeId second)
adds a new edge to the graph and recomputes the simplicial set
PriorityQueue< NodeId, double > __quasi_simplicial_nodes
a queue of the quasi simplicial nodes ordered by increasing node weight
bool hasSimplicialNode()
indicates whether there exists a simplicial node
EdgeSet __fill_ins_list
fill-ins list
priority queues (in which an element cannot appear more than once)
SimplicialSet(UndiGraph *graph, const NodeProperty< double > *log_domain_sizes, NodeProperty< double > *log_weights, double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
constructor. initializes the simplicial set w.r.t. a given graph
bool isSimplicial(const NodeId id)
indicates whether a given node is a simplicial node
The base class for all undirected edges.
NodeId bestAlmostSimplicialNode()
gets the almost simplicial node with the lowest clique weight
SimplicialSet & operator=(const SimplicialSet &)
prevent a copy operator to be used
Base class for undirected graphs.
Definition: undiGraph.h:106
NodeId bestSimplicialNode()
returns the simplicial node with the lowest clique weight
const PriorityQueue< NodeId, double > & allAlmostSimplicialNodes()
returns all the almost simplicial nodes
PriorityQueue< NodeId, double > __almost_simplicial_nodes
a queue of the almost simplicial nodes ordered by increasing node weight
#define GUM_QUASI_RATIO
Definition: simplicialSet.h:37
bool __we_want_fill_ins
a boolean indicating if we want fill-ins list with the standard triangulation method ...
~SimplicialSet()
destructor
Basic class for all graphs of cliques (join trees, etc)
const PriorityQueue< NodeId, double > & allQuasiSimplicialNodes()
returns all the quasi simplicial nodes
const NodeProperty< double > * __log_domain_sizes
the log of the modalities of the nodes
void setFillIns(bool on_off)
sets/unset the fill-ins storage in the standard triangulation procedure
Size NodeId
Type for node ids.
Definition: graphElements.h:97
const EdgeSet & fillIns() const
returns the set of all the fill-ins added to the graph so far
void eraseEdge(const Edge &edge)
removes an edge from the graph and recomputes the simplicial set