aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::EdgeGraphPart Class Reference

Classes for undirected edge sets. More...

#include <edgeGraphPart.h>

+ Inheritance diagram for gum::EdgeGraphPart:
+ Collaboration diagram for gum::EdgeGraphPart:

Public Attributes

Signaler2< NodeId, NodeIdonEdgeAdded
 
Signaler2< NodeId, NodeIdonEdgeDeleted
 

Public Member Functions

Constructors / Destructors
 EdgeGraphPart (Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
 default constructor More...
 
 EdgeGraphPart (const EdgeGraphPart &s)
 copy constructor More...
 
virtual ~EdgeGraphPart ()
 destructor More...
 
Operators
EdgeGraphPartoperator= (const EdgeGraphPart &s)
 copy operator More...
 
bool operator== (const EdgeGraphPart &p) const
 tests whether two EdgeGraphParts contain the same edges More...
 
bool operator!= (const EdgeGraphPart &p) const
 tests whether two EdgeGraphParts contain different edges More...
 
Accessors/Modifiers
virtual void addEdge (const NodeId n1, const NodeId n2)
 insert a new edge into the EdgeGraphPart More...
 
virtual void eraseEdge (const Edge &edge)
 removes an edge from the EdgeGraphPart More...
 
bool existsEdge (const Edge &edge) const
 indicates whether a given edge exists More...
 
bool existsEdge (const NodeId n1, const NodeId n2) const
 indicates whether a given edge exists More...
 
bool emptyEdges () const
 indicates wether the EdgeGraphPart contains any edge More...
 
virtual void clearEdges ()
 removes all the edges from the EdgeGraphPart More...
 
Size sizeEdges () const
 indicates the number of edges stored within the EdgeGraphPart More...
 
const EdgeSetedges () const
 returns the set of edges stored within the EdgeGraphPart More...
 
const NodeSetneighbours (const NodeId id) const
 returns the set of node neighbours to a given node More...
 
void eraseNeighbours (const NodeId id)
 erase all the edges adjacent to a given node More...
 
void unvirtualizedEraseNeighbours (const NodeId id)
 same function as eraseNeighbours but without any virtual call to an erase More...
 
std::string toString () const
 to friendly display the content of the EdgeGraphPart More...
 
template<typename VAL >
EdgeProperty< VAL > edgesProperty (VAL(*f)(const Edge &), Size size=0) const
 a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL f(x)) More...
 
template<typename VAL >
EdgeProperty< VAL > edgesProperty (const VAL &a, Size size=0) const
 a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL a) More...
 
template<typename VAL >
List< VAL > listMapEdges (VAL(*f)(const Edge &)) const
 a method to create a list of VAL from a set of edges (using for every edge, say x, the VAL f(x)) More...
 
const std::vector< NodeIdundirectedPath (const NodeId node1, const NodeId node2) const
 returns a possible path from node1 to node2 in the edge set More...
 
bool hasUndirectedPath (const NodeId n1, const NodeId n2) const
 return true if n1 and n2 are connected (by an undirected path) in the graph. More...
 
bool hasUndirectedPath (const NodeId n1, const NodeId n2, const NodeSet &except) const
 return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph. More...
 
bool hasUndirectedPath (const NodeSet &n1, const NodeSet &n2, const NodeSet &except) const
 return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph. More...
 

Public Types

typedef EdgeSetIterator EdgeIterator
 

Detailed Description

Classes for undirected edge sets.

Author
Pierre-Henri WUILLEMIN() & Christophe GONZALES()
Usage example:
EdgeGraphPart edges1,edges2;
// insert elements into edges1
edges1.addEdge( 2,3 );
Edge edge( 5,3 );
edges1.addEdge( 5,3 );
// copy edges1 into edges2
edges2=edges1;
std::cerr<<"edges2:"<<edges2.toString()<<std::endl;
// remove some elements from edges1
edges1.eraseEdge( Edge (2,3) );
edges1.eraseEdge( edge );
if ( edges1.empty() ) std::cerr<<" edges1 is empty"<<std::endl;
// checks whether a given edge exists
if ( edges2.exists( edge ) )
std::cerr << "set contains " << edge << endl;
if ( edges2.exists( 5,3 ) )
std::cerr << "set contains " << edge << endl;
std::cerr<<edges2.toString()<<std::endl;
std::cerr<<edges2.neighbours( 5 )<<std::endl;

Definition at line 74 of file edgeGraphPart.h.

Member Typedef Documentation

◆ EdgeIterator

Constructor & Destructor Documentation

◆ EdgeGraphPart() [1/2]

gum::EdgeGraphPart::EdgeGraphPart ( Size  edges_size = HashTableConst::default_size,
bool  edges_resize_policy = true 
)
explicit

default constructor

Parameters
edges_sizethe size of the hash table used to store all the edges
edges_resize_policythe resizing policy of this hash table

Definition at line 38 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

38  :
39  _edges_(edges_size, edges_resize_policy) {
40  GUM_CONSTRUCTOR(EdgeGraphPart);
41  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
+ Here is the call graph for this function:

◆ EdgeGraphPart() [2/2]

gum::EdgeGraphPart::EdgeGraphPart ( const EdgeGraphPart s)

copy constructor

Parameters
sthe EdgeGraphPart to copy

Definition at line 43 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

43  : _edges_(s._edges_) {
44  GUM_CONS_CPY(EdgeGraphPart);
45 
46  // copy the set of neighbours
47  _neighbours_.resize(s._neighbours_.capacity());
48 
49  for (const auto& elt: s._neighbours_) {
50  NodeSet* newneigh = new NodeSet(*elt.second);
51  _neighbours_.insert(elt.first, newneigh);
52  }
53 
54  // send signals to indicate that there are new edges
55  if (onEdgeAdded.hasListener())
56  for (const auto& edge: _edges_)
57  GUM_EMIT2(onEdgeAdded, edge.first(), edge.second());
58  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
Signaler2< NodeId, NodeId > onEdgeAdded
Definition: edgeGraphPart.h:78
+ Here is the call graph for this function:

◆ ~EdgeGraphPart()

gum::EdgeGraphPart::~EdgeGraphPart ( )
virtual

destructor

Definition at line 60 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

60  {
61  GUM_DESTRUCTOR(EdgeGraphPart);
62  // be sure to deallocate all the neighbours sets
63  clearEdges();
64  }
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
+ Here is the call graph for this function:

Member Function Documentation

◆ _checkNeighbours_()

INLINE void gum::EdgeGraphPart::_checkNeighbours_ ( const NodeId  id) const
private

when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set entry to neighbours[id]

Parameters
idthe node whose neighbours[id] is checked

Definition at line 46 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

46  {
47  if (!_neighbours_.exists(id)) { _neighbours_.insert(id, new NodeSet); }
48  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
+ Here is the call graph for this function:

◆ addEdge()

INLINE void gum::EdgeGraphPart::addEdge ( const NodeId  n1,
const NodeId  n2 
)
virtual

insert a new edge into the EdgeGraphPart

Parameters
n1the id of one extremity of the new edge to be inserted
n2the id of the other extremity of the new edge to be inserted
Warning
if the edge already exists, nothing is done. In particular, no exception is raised.

Reimplemented in gum::UndiGraph, and gum::CliqueGraph.

Definition at line 50 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

50  {
51  Edge edge(first, second);
52  _edges_.insert(edge);
53  _checkNeighbours_(first);
54  _checkNeighbours_(second);
55  _neighbours_[first]->insert(second);
56  _neighbours_[second]->insert(first);
57 
58  GUM_EMIT2(onEdgeAdded, first, second);
59  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
void _checkNeighbours_(const NodeId id) const
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
Signaler2< NodeId, NodeId > onEdgeAdded
Definition: edgeGraphPart.h:78
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ clearEdges()

void gum::EdgeGraphPart::clearEdges ( )
virtual

removes all the edges from the EdgeGraphPart

Reimplemented in gum::CliqueGraph.

Definition at line 66 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

66  {
67  for (const auto& elt: _neighbours_)
68  delete elt.second;
69 
70  _neighbours_.clear();
71 
72  if (onEdgeDeleted.hasListener()) {
73  EdgeSet tmp = _edges_;
74  _edges_.clear();
75 
76  for (const auto& edge: tmp)
77  GUM_EMIT2(onEdgeDeleted, edge.first(), edge.second());
78  } else {
79  _edges_.clear();
80  }
81  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
Signaler2< NodeId, NodeId > onEdgeDeleted
Definition: edgeGraphPart.h:79
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
+ Here is the call graph for this function:

◆ edges()

INLINE const EdgeSet & gum::EdgeGraphPart::edges ( ) const

returns the set of edges stored within the EdgeGraphPart

Definition at line 38 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

38 { return _edges_; }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ edgesProperty() [1/2]

template<typename VAL >
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( VAL(*)(const Edge &)  f,
Size  size = 0 
) const

a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL f(x))

Parameters
fa function assigning a VAL to any edge
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of edges. If you do not specify this parameter, the method will assign it for you.

◆ edgesProperty() [2/2]

template<typename VAL >
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( const VAL &  a,
Size  size = 0 
) const

a method to create a hashMap of VAL from a set of edges (using for every edge, say x, the VAL a)

Parameters
athe default value assigned to each edge in the returned Property
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of edges. If you do not specify this parameter, the method will assign it for you.

◆ emptyEdges()

INLINE bool gum::EdgeGraphPart::emptyEdges ( ) const

indicates wether the EdgeGraphPart contains any edge

Definition at line 34 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

34 { return _edges_.empty(); }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
+ Here is the call graph for this function:

◆ eraseEdge()

INLINE void gum::EdgeGraphPart::eraseEdge ( const Edge edge)
virtual

removes an edge from the EdgeGraphPart

Parameters
edgethe edge to be removed
Warning
if the edge does not exist, nothing is done. In particular, no exception is thrown. However, the signal onEdgeDeleted is fired only if a node is effectively removed.

Reimplemented in gum::CliqueGraph.

Definition at line 61 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

61  {
62  if (existsEdge(edge)) {
63  // ASSUMING first and second exists in _neighbours_ (if not, it is an
64  // error)
65  NodeId id1 = edge.first(), id2 = edge.second();
66 
67  _neighbours_[id1]->erase(id2);
68  _neighbours_[id2]->erase(id1);
69  _edges_.erase(edge);
70  GUM_EMIT2(onEdgeDeleted, id1, id2);
71  }
72  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
Signaler2< NodeId, NodeId > onEdgeDeleted
Definition: edgeGraphPart.h:79
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ eraseNeighbours()

INLINE void gum::EdgeGraphPart::eraseNeighbours ( const NodeId  id)

erase all the edges adjacent to a given node

Parameters
idthe node the adjacent edges of which will be removed
Warning
if no edge is adjacent to id, nothing is done. In particular, no exception is thrown.
although this method is not virtual, it calls method eraseEdge( const Edge& edge ) and, as such, has a "virtual" behaviour

Definition at line 79 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

79  {
80  if (_neighbours_.exists(id)) {
81  const NodeSet& set = neighbours(id);
82 
83  for (auto iter = set.beginSafe(); iter != set.endSafe();
84  ++iter) { // safe iterator needed here
85  // warning: use this erase so that you actually use the virtualized
86  // edge removal function
87  eraseEdge(Edge(*iter, id));
88  }
89  }
90  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
+ Here is the call graph for this function:

◆ existsEdge() [1/2]

INLINE bool gum::EdgeGraphPart::existsEdge ( const Edge edge) const

indicates whether a given edge exists

Parameters
edgethe edge we test whether or not it belongs to the EdgeGraphPart

Definition at line 40 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

40 { return _edges_.contains(edge); }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
+ Here is the call graph for this function:

◆ existsEdge() [2/2]

INLINE bool gum::EdgeGraphPart::existsEdge ( const NodeId  n1,
const NodeId  n2 
) const

indicates whether a given edge exists

Parameters
n1the id of one extremity of the edge we test the existence in the EdgeGraphPart
n2the id of the other extremity of the edge we test the existence in the EdgeGraphPart

Definition at line 42 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

42  {
43  return _neighbours_.exists(first) && _neighbours_[first]->exists(second);
44  }
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
+ Here is the call graph for this function:

◆ hasUndirectedPath() [1/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( const NodeId  n1,
const NodeId  n2 
) const

return true if n1 and n2 are connected (by an undirected path) in the graph.

Parameters
n1NodeId
n2NodeId
Returns
bool

Definition at line 166 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

166  {
167  NodeSet visited;
168  NodeSet temp;
169 
170  temp.insert(n1);
171  while (!temp.empty()) {
172  NodeId current = *(temp.begin());
173  if (current == n2) return true;
174  temp.erase(current);
175  visited.insert(current);
176  for (auto next: neighbours(current)) {
177  if (!temp.contains(next) && !visited.contains(next)) temp.insert(next);
178  }
179  }
180  return false;
181  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ hasUndirectedPath() [2/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( const NodeId  n1,
const NodeId  n2,
const NodeSet except 
) const

return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph.

Parameters
n1NodeId
n2NodeId
exceptNodeSet
Warning
n1 in except has no repercussion. However n2 in except naturally leads to 'false'
Returns
bool

Definition at line 183 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

183  {
184  NodeSet visited;
185  NodeSet temp;
186 
187  if (except.contains(n2)) return false;
188 
189  temp.insert(n1);
190  while (!temp.empty()) {
191  NodeId current = *(temp.begin());
192  if (current == n2) return true;
193  temp.erase(current);
194  visited.insert(current);
195  for (auto next: neighbours(current)) {
196  if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
197  temp.insert(next);
198  }
199  }
200  return false;
201  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ hasUndirectedPath() [3/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( const NodeSet n1,
const NodeSet n2,
const NodeSet except 
) const

return true if n1 and n2 are connected (by an undirected path not using the nodes of except) in the graph.

Parameters
n1NodeSet
n2NodeSet
exceptNodeSet
Returns
bool

Definition at line 203 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

205  {
206  NodeSet visited;
207  NodeSet temp;
208 
209  for (auto n: n1)
210  temp.insert(n);
211 
212  while (!temp.empty()) {
213  NodeId current = *(temp.begin());
214  if (n2.contains(current)) return true;
215  temp.erase(current);
216  visited.insert(current);
217  for (auto next: neighbours(current)) {
218  if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
219  temp.insert(next);
220  }
221  }
222  return false;
223  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ listMapEdges()

template<typename VAL >
List< VAL > gum::EdgeGraphPart::listMapEdges ( VAL(*)(const Edge &)  f) const

a method to create a list of VAL from a set of edges (using for every edge, say x, the VAL f(x))

Parameters
fa function assigning a VAL to any edge

◆ neighbours()

INLINE const NodeSet & gum::EdgeGraphPart::neighbours ( const NodeId  id) const

returns the set of node neighbours to a given node

Note that the set of nodes returned may be empty if no edge within the EdgeGraphPart is adjacent the given node.

Parameters
idthe node to which the edges are adjacent

Definition at line 74 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

74  {
76  return *(_neighbours_[id]);
77  }
void _checkNeighbours_(const NodeId id) const
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
+ Here is the call graph for this function:

◆ operator!=()

INLINE bool gum::EdgeGraphPart::operator!= ( const EdgeGraphPart p) const

tests whether two EdgeGraphParts contain different edges

Parameters
pthe EdgeGraphPart that we compare with this

Definition at line 107 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

107  {
108  return _edges_ != p._edges_;
109  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ operator=()

EdgeGraphPart & gum::EdgeGraphPart::operator= ( const EdgeGraphPart s)

copy operator

Parameters
sthe EdgeGraphPart to copy

Definition at line 83 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

83  {
84  // avoid self assignment
85  if (this != &s) {
86  clearEdges();
87 
88  _edges_ = s._edges_;
89 
90  // copy the set of neighbours
91  _neighbours_.resize(s._neighbours_.capacity());
92 
93  for (const auto& elt: s._neighbours_) {
94  NodeSet* newneigh = new NodeSet(*elt.second);
95  _neighbours_.insert(elt.first, newneigh);
96  }
97 
98  if (onEdgeAdded.hasListener())
99  for (const auto& edge: _edges_)
100  GUM_EMIT2(onEdgeAdded, edge.first(), edge.second());
101  }
102 
103  return *this;
104  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
Signaler2< NodeId, NodeId > onEdgeAdded
Definition: edgeGraphPart.h:78
+ Here is the call graph for this function:

◆ operator==()

INLINE bool gum::EdgeGraphPart::operator== ( const EdgeGraphPart p) const

tests whether two EdgeGraphParts contain the same edges

Parameters
pthe EdgeGraphPart that we compare with this

Definition at line 103 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

103  {
104  return _edges_ == p._edges_;
105  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ sizeEdges()

INLINE Size gum::EdgeGraphPart::sizeEdges ( ) const

indicates the number of edges stored within the EdgeGraphPart

Definition at line 36 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

36 { return _edges_.size(); }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
+ Here is the call graph for this function:

◆ toString()

std::string gum::EdgeGraphPart::toString ( ) const

to friendly display the content of the EdgeGraphPart

Definition at line 106 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

106  {
107  std::stringstream s;
108  bool first = true;
109  s << "{";
110 
111  for (const auto& edge: _edges_) {
112  if (first)
113  first = false;
114  else
115  s << ",";
116 
117  s << edge;
118  }
119 
120  s << "}";
121 
122  return s.str();
123  }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
+ Here is the call graph for this function:

◆ undirectedPath()

const std::vector< NodeId > gum::EdgeGraphPart::undirectedPath ( const NodeId  node1,
const NodeId  node2 
) const

returns a possible path from node1 to node2 in the edge set

Parameters
node1the id from which the path begins
node2the id to which the path ends
Exceptions
NotFoundexception is raised if no path can be found between the two nodes

Definition at line 125 of file edgeGraphPart.cpp.

References gum::Set< Key, Alloc >::emplace().

126  {
127  // not recursive version => use a FIFO for simulating the recursion
128  List< NodeId > nodeFIFO;
129  nodeFIFO.pushBack(n2);
130 
131  // mark[node] = predecessor if visited, else mark[node] does not exist
132  NodeProperty< NodeId > mark;
133  mark.insert(n2, n2);
134 
135  NodeId current;
136 
137  while (!nodeFIFO.empty()) {
138  current = nodeFIFO.front();
139  nodeFIFO.popFront();
140 
141  // check the neighbour
142  for (const auto new_one: neighbours(current)) {
143  if (mark.exists(new_one)) // if this node is already marked, stop
144  continue;
145 
146  mark.insert(new_one, current);
147 
148  if (new_one == n1) {
149  std::vector< NodeId > v;
150 
151  for (current = n1; current != n2; current = mark[current])
152  v.push_back(current);
153 
154  v.push_back(n2);
155 
156  return v;
157  }
158 
159  nodeFIFO.pushBack(new_one);
160  }
161  }
162 
163  GUM_ERROR(NotFound, "no path found")
164  }
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ unvirtualizedEraseNeighbours()

INLINE void gum::EdgeGraphPart::unvirtualizedEraseNeighbours ( const NodeId  id)

same function as eraseNeighbours but without any virtual call to an erase

Parameters
idthe node whose ingoing arcs will be removed

Definition at line 92 of file edgeGraphPart_inl.h.

References gum::Set< Key, Alloc >::emplace().

92  {
93  if (_neighbours_.exists(id)) {
94  const NodeSet& set = neighbours(id);
95 
96  for (auto iter = set.beginSafe(); iter != set.endSafe();
97  ++iter) { // safe iterator needed here
98  EdgeGraphPart::eraseEdge(Edge(*iter, id));
99  }
100  }
101  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
NodeProperty< NodeSet *> _neighbours_
for each node, the set of its adjacent edges
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
+ Here is the call graph for this function:

Member Data Documentation

◆ _edges_

EdgeSet gum::EdgeGraphPart::_edges_
private

the set of all the edges contained within the EdgeGraphPart

Definition at line 251 of file edgeGraphPart.h.

◆ _neighbours_

NodeProperty< NodeSet* > gum::EdgeGraphPart::_neighbours_
mutableprivate

for each node, the set of its adjacent edges

Definition at line 254 of file edgeGraphPart.h.

◆ onEdgeAdded

Signaler2< NodeId, NodeId > gum::EdgeGraphPart::onEdgeAdded

Definition at line 78 of file edgeGraphPart.h.

◆ onEdgeDeleted

Signaler2< NodeId, NodeId > gum::EdgeGraphPart::onEdgeDeleted

Definition at line 79 of file edgeGraphPart.h.


The documentation for this class was generated from the following files: