aGrUM  0.14.2
cliqueGraph_inl.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 DOXYGEN_SHOULD_SKIP_THIS
27 
28 // to ease parser in IDE
30 
31 namespace gum {
32 
34  INLINE CliqueGraph& CliqueGraph::operator=(const CliqueGraph& g) {
35  if (this != &g) {
37  __cliques = g.__cliques;
38  __separators = g.__separators;
39  }
40 
41  return *this;
42  }
43 
44  INLINE void CliqueGraph::addEdge(const NodeId first, const NodeId second) {
45  Edge edge(first, second);
46 
47  if (!existsEdge(edge)) {
48  // create the edge in the graph
49  UndiGraph::addEdge(first, second);
50 
51  // create the separator
52  __separators.insert(edge, __cliques[first] * __cliques[second]);
53  }
54  }
55 
57 
58  INLINE void CliqueGraph::eraseEdge(const Edge& edge) {
59  if (existsEdge(edge)) {
60  __separators.erase(edge);
62  }
63  }
64 
66 
67  INLINE NodeId CliqueGraph::addNode(const NodeSet& clique) {
68  // create the new node in the graph
69  NodeId new_node = UndiGraph::addNode();
70 
71  // update the set of nodes of the clique
72  __cliques.insert(new_node, clique);
73  return new_node;
74  }
75 
76  INLINE NodeId CliqueGraph::addNode() { return addNode(NodeSet()); }
77 
79 
80  INLINE void CliqueGraph::addNode(const NodeId id, const NodeSet& clique) {
81  // create the new node in the graph
83 
84  // update the set of nodes of the clique
85  __cliques.insert(id, clique);
86  }
87 
88  INLINE void CliqueGraph::addNode(const NodeId id) { addNode(id, NodeSet()); }
89 
91 
92  INLINE void CliqueGraph::eraseNode(const NodeId id) {
93  // check if the node belongs to the graph
94  if (!exists(id)) return;
95 
96  // remove the separators
97  auto nei = neighbours(id);
98  for (auto iter = nei.beginSafe(); iter != nei.endSafe();
99  ++iter) // safe iterator needed here
100  eraseEdge(Edge(*iter, id));
101 
102  // erase the clique set
103  __cliques.erase(id);
104 
105  // erase the node and its neighbours from the graph
107  }
108 
110 
111  INLINE const NodeSet& CliqueGraph::clique(const NodeId clique) const {
112  return __cliques[clique];
113  }
114 
117 
118  INLINE NodeId CliqueGraph::container(const NodeId id) const {
119  for (const auto& elt : __cliques)
120  if (elt.second.contains(id)) return elt.first;
121 
122  GUM_ERROR(NotFound, "This node belongs to no clique");
123  }
124 
126 
127  INLINE void CliqueGraph::__updateSeparators(const NodeId id1) {
128  for (const auto nei : neighbours(id1))
129  __separators[Edge(nei, id1)] = __cliques[id1] * __cliques[nei];
130  }
131 
134 
135  INLINE void CliqueGraph::setClique(const NodeId id, const NodeSet& new_clique) {
136  // get the current clique set
137  __cliques[id] = new_clique;
138  __updateSeparators(id);
139  }
140 
142 
143  INLINE const NodeSet& CliqueGraph::separator(const Edge& edge) const {
144  return __separators[edge];
145  }
146 
148 
149  INLINE const NodeSet& CliqueGraph::separator(const NodeId node1,
150  const NodeId node2) const {
151  return separator(Edge(node1, node2));
152  }
153 
155 
156  INLINE bool CliqueGraph::isJoinTree() const {
158  }
159 
162 
163  INLINE void CliqueGraph::clear() {
165  __cliques.clear();
166  __separators.clear();
167  }
168 
170 
171  INLINE void CliqueGraph::clearEdges() {
173  __separators.clear();
174  }
175 
177 
178  INLINE bool CliqueGraph::operator!=(const CliqueGraph& from) const {
179  return (!operator==(from));
180  }
181 
182 } /* namespace gum */
183 
184 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
bool operator!=(const CliqueGraph &from) const
checks whether two clique graphs are different
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:40
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
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
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
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 void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:32
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
bool exists(const NodeId id) const
alias for existsNode
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual NodeId addNode()
insert a new node and return its id
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
virtual void eraseNode(const NodeId id)
remove a node and its adjacent edges from the graph
Definition: undiGraph_inl.h:55
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
NodeProperty< NodeSet > __cliques
the set of nodes contained into the cliques
Definition: cliqueGraph.h:239
void __updateSeparators(const NodeId clique1)
function used to update the separators when a clique is modified
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
virtual void eraseEdge(const Edge &edge)
removes an edge (and its separator) from the clique graph
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
NodeId container(const NodeId idNode) const
returns the id of a clique containing the node the id of which is in argument
EdgeProperty< NodeSet > __separators
the set of nodes contained into the separators
Definition: cliqueGraph.h:242
bool hasUndirectedCycle() const
checks whether the graph contains cycles
Definition: undiGraph.cpp:52
CliqueGraph & operator=(const CliqueGraph &from)
copy operator
virtual NodeId addNode()
adds a new clique to the graph
UndiGraph & operator=(const UndiGraph &g)
copy operator
Definition: undiGraph_inl.h:45
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
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
virtual void clearEdges()
removes all edges and their separators
Basic class for all graphs of cliques (join trees, etc)
Size NodeId
Type for node ids.
Definition: graphElements.h:97
bool hasRunningIntersection() const
indicates whether the running intersection property holds
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52