aGrUM  0.14.2
cliqueGraph.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  ***************************************************************************/
25 #ifndef GUM_CLIQUE_GRAPH_H
26 #define GUM_CLIQUE_GRAPH_H
27 
28 #include <iostream>
29 
30 #include <agrum/agrum.h>
31 
32 #include <agrum/graphs/undiGraph.h>
33 
34 namespace gum {
35  /* ===========================================================================
36  */
37  /* === GRAPHS OF CLIQUES ===
38  */
39  /* ===========================================================================
40  */
52  /* ===========================================================================
53  */
54 
55  class CliqueGraph : public UndiGraph {
56  public:
57  // ############################################################################
59  // ############################################################################
61 
63 
68  explicit CliqueGraph(Size nodes_size = HashTableConst::default_size,
69  bool nodes_resize_policy = true,
71  bool edges_resize_policy = true);
72 
74 
76  CliqueGraph(const CliqueGraph& from);
77 
79 
80  virtual ~CliqueGraph();
81 
83 
84  // ############################################################################
86  // ############################################################################
88 
90 
98  virtual void addEdge(const NodeId first, const NodeId second);
99 
101 
105  virtual void eraseEdge(const Edge& edge);
106 
108 
109  virtual void clearEdges();
110 
112 
113  NodeId addNode(const NodeSet& clique);
114 
116 
117  virtual NodeId addNode();
118 
120 
122  virtual void addNode(const NodeId id, const NodeSet& clique);
123 
125 
127  virtual void addNode(const NodeId id);
128 
130 
133  virtual void eraseNode(const NodeId node);
134 
138  virtual void clear();
139 
141 
144  const NodeSet& clique(const NodeId idClique) const;
145 
155  NodeId container(const NodeId idNode) const;
156 
162  virtual void setClique(const NodeId idClique, const NodeSet& new_clique);
163 
171  virtual void addToClique(const NodeId clique_id, const NodeId node_id);
172 
174 
178  virtual void eraseFromClique(const NodeId clique_id, const NodeId node_id);
179 
181 
184  const NodeSet& separator(const Edge& edge) const;
185 
187 
190  const NodeSet& separator(const NodeId clique1, const NodeId clique) const;
191 
194 
196  std::vector< NodeId > containerPath(const NodeId node1,
197  const NodeId node2) const;
198 
200 
202  bool hasRunningIntersection() const;
203 
205 
206  bool isJoinTree() const;
207 
209 
210  virtual const std::string toString() const;
211 
213 
214  virtual const std::string toDot() const;
215 
217 
218  // ############################################################################
220  // ############################################################################
222 
224 
225  CliqueGraph& operator=(const CliqueGraph& from);
226 
228 
229  bool operator!=(const CliqueGraph& from) const;
230 
232 
233  bool operator==(const CliqueGraph& from) const;
234 
236 
237  private:
240 
243 
245 
246  void __updateSeparators(const NodeId clique1);
247 
249 
254 
257 
261 
264 
267 
287  };
288 
290 
291  bool __runningIntersectionDFS(const NodeId clique,
292  const NodeId from,
293  __RunningIntersect& infos_DFS) const;
294  };
295 
300 
304 
306 
307  std::ostream& operator<<(std::ostream&, const CliqueGraph&);
308 
309 } /* namespace gum */
310 
311 #ifndef GUM_NO_INLINE
313 #endif // GUM_NOINLINE
314 
315 #endif /* GUM_CLIQUE_GRAPH_H */
bool operator==(const CliqueGraph &from) const
checks whether two clique graphs are equal
bool operator!=(const CliqueGraph &from) const
checks whether two clique graphs are different
bool isJoinTree() const
indicates whether the graph is a join tree
virtual void eraseNode(const NodeId node)
removes a given clique from the clique graph
const NodeSet & separator(const Edge &edge) const
returns the separator included in a given edge
virtual void setClique(const NodeId idClique, const NodeSet &new_clique)
changes the set of nodes included into a given clique and returns the new set
virtual const std::string toDot() const
friendly displays the content of the CliqueGraph in DOT format
static constexpr Size default_size
The default number of slots in hashtables.
Definition: hashTable.h:77
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
structure used for the computation of the running intersection property
Definition: cliqueGraph.h:250
Base classes for undirected graphs.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
NodeProperty< NodeSet > cliques_DFS_chain
for each clique, the list of its nodes that require accessing the clique through a chain ...
Definition: cliqueGraph.h:286
NodeSet nodes_DFS_seen
set of the nodes examined during the current DFS
Definition: cliqueGraph.h:266
The class for generic Hash Tables.
Definition: hashTable.h:676
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
bool __runningIntersectionDFS(const NodeId clique, const NodeId from, __RunningIntersect &infos_DFS) const
function used for the computation of the running intersection property
NodeProperty< NodeSet > __cliques
the set of nodes contained into the cliques
Definition: cliqueGraph.h:239
virtual ~CliqueGraph()
destructor
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:583
void __updateSeparators(const NodeId clique1)
function used to update the separators when a clique is modified
virtual void addToClique(const NodeId clique_id, const NodeId node_id)
changes the set of nodes included into a given clique and returns the new set
NodeSet visited_cliques
structure indicating for each clique whether it has been examined by a DFS (Depth First Search) ...
Definition: cliqueGraph.h:253
CliqueGraph JoinTree
a join tree is a clique graph satisfying the running intersection property (but some cliques may be i...
Definition: cliqueGraph.h:303
virtual void eraseEdge(const Edge &edge)
removes an edge (and its separator) from the clique graph
virtual const std::string toString() const
friendly displays the content of the CliqueGraph
virtual void addEdge(const NodeId first, const NodeId second)
inserts a new edge between two cliques
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
NodeSet nodes_other_components
structure indicating the nodes that belong to other connected components
Definition: cliqueGraph.h:260
Basic graph of cliques.
Definition: cliqueGraph.h:55
NodeId container(const NodeId idNode) const
returns the id of a clique containing the node the id of which is in argument
CliqueGraph JunctionTree
a junction tree is a clique graph satisfying the running intersection property and such that no cliqu...
Definition: cliqueGraph.h:299
The base class for all undirected edges.
std::vector< NodeId > containerPath(const NodeId node1, const NodeId node2) const
returns a path from a clique containing node1 to a clique containing node2
NodeSet nodes_DFS_forbidden
the nodes that are currently forbidden by separators in the DFS
Definition: cliqueGraph.h:263
Base class for undirected graphs.
Definition: undiGraph.h:106
EdgeProperty< NodeSet > __separators
the set of nodes contained into the separators
Definition: cliqueGraph.h:242
CliqueGraph & operator=(const CliqueGraph &from)
copy operator
virtual NodeId addNode()
adds a new clique to the graph
CliqueGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
basic constructor: creates an empty clique graph
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
virtual void eraseFromClique(const NodeId clique_id, const NodeId node_id)
remove a node from a clique
virtual void clearEdges()
removes all edges and their separators
Size NodeId
Type for node ids.
Definition: graphElements.h:97
bool hasRunningIntersection() const
indicates whether the running intersection property holds
inline source of basic clique graphs