aGrUM  0.16.0
cliqueGraph_inl.h
Go to the documentation of this file.
1 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 // to ease parser in IDE
33 
34 namespace gum {
35 
37  INLINE CliqueGraph& CliqueGraph::operator=(const CliqueGraph& g) {
38  if (this != &g) {
40  __cliques = g.__cliques;
41  __separators = g.__separators;
42  }
43 
44  return *this;
45  }
46 
47  INLINE void CliqueGraph::addEdge(const NodeId first, const NodeId second) {
48  Edge edge(first, second);
49 
50  if (!existsEdge(edge)) {
51  // create the edge in the graph
52  UndiGraph::addEdge(first, second);
53 
54  // create the separator
55  __separators.insert(edge, __cliques[first] * __cliques[second]);
56  }
57  }
58 
60 
61  INLINE void CliqueGraph::eraseEdge(const Edge& edge) {
62  if (existsEdge(edge)) {
63  __separators.erase(edge);
65  }
66  }
67 
69 
70  INLINE NodeId CliqueGraph::addNode(const NodeSet& clique) {
71  // create the new node in the graph
72  NodeId new_node = UndiGraph::addNode();
73 
74  // update the set of nodes of the clique
75  __cliques.insert(new_node, clique);
76  return new_node;
77  }
78 
79  INLINE NodeId CliqueGraph::addNode() { return addNode(NodeSet()); }
80 
82 
83  INLINE void CliqueGraph::addNode(const NodeId id, const NodeSet& clique) {
84  // create the new node in the graph
86 
87  // update the set of nodes of the clique
88  __cliques.insert(id, clique);
89  }
90 
91  INLINE void CliqueGraph::addNode(const NodeId id) { addNode(id, NodeSet()); }
92 
94 
95  INLINE void CliqueGraph::eraseNode(const NodeId id) {
96  // check if the node belongs to the graph
97  if (!exists(id)) return;
98 
99  // remove the separators
100  auto nei = neighbours(id);
101  for (auto iter = nei.beginSafe(); iter != nei.endSafe();
102  ++iter) // safe iterator needed here
103  eraseEdge(Edge(*iter, id));
104 
105  // erase the clique set
106  __cliques.erase(id);
107 
108  // erase the node and its neighbours from the graph
110  }
111 
113 
114  INLINE const NodeSet& CliqueGraph::clique(const NodeId clique) const {
115  return __cliques[clique];
116  }
117 
120 
121  INLINE NodeId CliqueGraph::container(const NodeId id) const {
122  for (const auto& elt : __cliques)
123  if (elt.second.contains(id)) return elt.first;
124 
125  GUM_ERROR(NotFound, "This node belongs to no clique");
126  }
127 
129 
130  INLINE void CliqueGraph::__updateSeparators(const NodeId id1) {
131  for (const auto nei : neighbours(id1))
132  __separators[Edge(nei, id1)] = __cliques[id1] * __cliques[nei];
133  }
134 
137 
138  INLINE void CliqueGraph::setClique(const NodeId id, const NodeSet& new_clique) {
139  // get the current clique set
140  __cliques[id] = new_clique;
141  __updateSeparators(id);
142  }
143 
145 
146  INLINE const NodeSet& CliqueGraph::separator(const Edge& edge) const {
147  return __separators[edge];
148  }
149 
151 
152  INLINE const NodeSet& CliqueGraph::separator(const NodeId node1,
153  const NodeId node2) const {
154  return separator(Edge(node1, node2));
155  }
156 
158 
159  INLINE bool CliqueGraph::isJoinTree() const {
161  }
162 
165 
166  INLINE void CliqueGraph::clear() {
168  __cliques.clear();
169  __separators.clear();
170  }
171 
173 
174  INLINE void CliqueGraph::clearEdges() {
176  __separators.clear();
177  }
178 
180 
181  INLINE bool CliqueGraph::operator!=(const CliqueGraph& from) const {
182  return (!operator==(from));
183  }
184 
185 } /* namespace gum */
186 
187 #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:43
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:35
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:58
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
NodeProperty< NodeSet > __cliques
the set of nodes contained into the cliques
Definition: cliqueGraph.h:242
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:245
bool hasUndirectedCycle() const
checks whether the graph contains cycles
Definition: undiGraph.cpp:55
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:48
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
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
bool hasRunningIntersection() const
indicates whether the running intersection property holds
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55