aGrUM 2.3.2
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 Types

using EdgeIterator = EdgeSetIterator

Public Member Functions

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

Public Attributes

Signaler2< NodeId, NodeIdonEdgeAdded
Signaler2< NodeId, NodeIdonEdgeDeleted

Private Member Functions

void _checkNeighbours_ (NodeId id)
 when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set entry to neighbours[id]
void _clearEdges_ ()

Private Attributes

EdgeSet _edges_
 the set of all the edges contained within the EdgeGraphPart
NodeProperty< NodeSet * > _neighbours_
 for each node, the set of its adjacent edges

Detailed Description

Classes for undirected edge sets.

Author
Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU)
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;
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
virtual void addEdge(NodeId n1, NodeId n2)
insert a new edge into the EdgeGraphPart
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
virtual std::string toString() const
to friendly display the content of the EdgeGraphPart
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
The base class for all undirected edges.

Definition at line 94 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 58 of file edgeGraphPart.cpp.

58 :
59 _edges_(edges_size, edges_resize_policy) {
60 GUM_CONSTRUCTOR(EdgeGraphPart);
61 }
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart

References EdgeGraphPart(), and _edges_.

Referenced by EdgeGraphPart(), EdgeGraphPart(), gum::UndiGraph::UndiGraph(), gum::UndiGraph::UndiGraph(), ~EdgeGraphPart(), operator=(), and operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EdgeGraphPart() [2/2]

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

copy constructor

Parameters
sthe EdgeGraphPart to copy

Definition at line 63 of file edgeGraphPart.cpp.

63 : _edges_(s._edges_) {
64 GUM_CONS_CPY(EdgeGraphPart)
65
66 // copy the set of neighbours
67 _neighbours_.resize(s._neighbours_.capacity());
68
69 for (const auto& [key, nodeset]: s._neighbours_) {
70 NodeSet* newneigh = new NodeSet(*nodeset);
71 _neighbours_.insert(key, newneigh);
72 }
73
74 // send signals to indicate that there are new edges
75 if (onEdgeAdded.hasListener())
76 for (const auto& edge: _edges_)
77 GUM_EMIT2(onEdgeAdded, edge.first(), edge.second());
78 }
NodeProperty< NodeSet * > _neighbours_
for each node, the set of its adjacent edges
Signaler2< NodeId, NodeId > onEdgeAdded
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition signaler2.h:61

References EdgeGraphPart(), _edges_, _neighbours_, GUM_EMIT2, and onEdgeAdded.

Here is the call graph for this function:

◆ ~EdgeGraphPart()

gum::EdgeGraphPart::~EdgeGraphPart ( )
virtual

destructor

Definition at line 80 of file edgeGraphPart.cpp.

80 {
81 GUM_DESTRUCTOR(EdgeGraphPart)
82 // be sure to deallocate all the neighbours sets
84 }

References EdgeGraphPart(), and _clearEdges_().

Here is the call graph for this function:

Member Function Documentation

◆ _checkNeighbours_()

INLINE void gum::EdgeGraphPart::_checkNeighbours_ ( NodeId id)
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 67 of file edgeGraphPart_inl.h.

67 {
68 if (!_neighbours_.exists(id)) { _neighbours_.insert(id, new NodeSet); }
69 }

References _neighbours_.

Referenced by addEdge().

Here is the caller graph for this function:

◆ _clearEdges_()

void gum::EdgeGraphPart::_clearEdges_ ( )
private

Definition at line 88 of file edgeGraphPart.cpp.

88 {
89 for (const auto& elt: _neighbours_)
90 delete elt.second;
91
92 _neighbours_.clear();
93
94 if (onEdgeDeleted.hasListener()) {
95 EdgeSet tmp = _edges_;
96 _edges_.clear();
97
98 for (const auto& edge: tmp)
99 GUM_EMIT2(onEdgeDeleted, edge.first(), edge.second());
100 } else {
101 _edges_.clear();
102 }
103 }
Signaler2< NodeId, NodeId > onEdgeDeleted
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...

References _edges_, _neighbours_, GUM_EMIT2, and onEdgeDeleted.

Referenced by ~EdgeGraphPart(), and clearEdges().

Here is the caller graph for this function:

◆ addEdge()

INLINE void gum::EdgeGraphPart::addEdge ( NodeId n1,
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::CliqueGraph, gum::PDAG, and gum::UndiGraph.

Definition at line 71 of file edgeGraphPart_inl.h.

71 {
72 Edge edge(first, second);
73 _edges_.insert(edge);
74 _checkNeighbours_(first);
75 _checkNeighbours_(second);
76 _neighbours_[first]->insert(second);
77 _neighbours_[second]->insert(first);
78
79 GUM_EMIT2(onEdgeAdded, first, second);
80 }
void _checkNeighbours_(NodeId id)
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...

References _checkNeighbours_(), _edges_, _neighbours_, GUM_EMIT2, and onEdgeAdded.

Referenced by gum::PDAG::addEdge(), and gum::UndiGraph::addEdge().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearEdges()

void gum::EdgeGraphPart::clearEdges ( )
virtual

removes all the edges from the EdgeGraphPart

Reimplemented in gum::CliqueGraph.

Definition at line 86 of file edgeGraphPart.cpp.

86{ _clearEdges_(); }

References _clearEdges_().

Referenced by gum::MixedGraph::clear(), gum::UndiGraph::clear(), operator=(), and gum::MixedGraph::operator=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ edges()

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

◆ edgesProperty() [1/2]

template<typename VAL>
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( const VAL & val,
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.

◆ edgesProperty() [2/2]

template<typename VAL>
EdgeProperty< VAL > gum::EdgeGraphPart::edgesProperty ( VAL(* )(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))

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.

◆ emptyEdges()

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

indicates wether the EdgeGraphPart contains any edge

Definition at line 55 of file edgeGraphPart_inl.h.

55{ return _edges_.empty(); }

References _edges_.

◆ 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 82 of file edgeGraphPart_inl.h.

82 {
83 if (existsEdge(edge)) {
84 // ASSUMING first and second exists in _neighbours_ (if not, it is an
85 // error)
86 NodeId id1 = edge.first();
87 NodeId id2 = edge.second();
88
89 _neighbours_[id1]->erase(id2);
90 _neighbours_[id2]->erase(id1);
91 _edges_.erase(edge);
92 GUM_EMIT2(onEdgeDeleted, id1, id2);
93 }
94 }
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
Size NodeId
Type for node ids.

References _edges_, _neighbours_, existsEdge(), gum::Edge::first(), GUM_EMIT2, onEdgeDeleted, and gum::Edge::second().

Referenced by gum::MeekRules::_applyMeekRules_(), gum::learning::Miic::_orientingVstructureMiic_(), gum::learning::SimpleMiic::_orientingVstructureMiic_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::learning::Miic::_propagatingOrientationMiic_(), gum::learning::SimpleMiic::_propagatingOrientationMiic_(), gum::prm::GSpan< GUM_SCALAR >::discoverPatterns(), eraseNeighbours(), gum::learning::Miic::initiation_(), gum::learning::SimpleMiic::initiation_(), gum::learning::Miic::iteration_(), gum::learning::SimpleMiic::iteration_(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::learning::SimpleMiic::orientationLatents_(), gum::learning::Miic::orientationMiic_(), gum::learning::SimpleMiic::orientationMiic_(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::learning::SimpleMiic::propagatesRemainingOrientableEdges_(), and unvirtualizedEraseNeighbours().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ eraseNeighbours()

INLINE void gum::EdgeGraphPart::eraseNeighbours ( 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 101 of file edgeGraphPart_inl.h.

101 {
102 if (_neighbours_.exists(id)) {
103 const NodeSet& set = *(_neighbours_[id]);
104
105 for (auto iter = set.beginSafe(); iter != set.endSafe();
106 ++iter) { // safe iterator needed here
107 // warning: use this erases so that you actually use the virtualized
108 // edge removal function
109 eraseEdge(Edge(*iter, id));
110 }
111 }
112 }

References _neighbours_, gum::Set< Key >::beginSafe(), gum::Set< Key >::endSafe(), and eraseEdge().

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 61 of file edgeGraphPart_inl.h.

61{ return _edges_.contains(edge); }

References _edges_.

Referenced by gum::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::EssentialGraph::_strongly_protected_(), gum::StaticTriangulation::_triangulate_(), eraseEdge(), gum::learning::Miic::orientationMiic_(), gum::learning::SimpleMiic::orientationMiic_(), gum::learning::Miic::unshieldedTriples_(), gum::learning::SimpleMiic::unshieldedTriples_(), gum::learning::Miic::unshieldedTriplesMiic_(), and gum::learning::SimpleMiic::unshieldedTriplesMiic_().

Here is the caller graph for this function:

◆ existsEdge() [2/2]

INLINE bool gum::EdgeGraphPart::existsEdge ( NodeId n1,
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 63 of file edgeGraphPart_inl.h.

63 {
64 return _neighbours_.exists(first) && _neighbours_[first]->exists(second);
65 }

References _neighbours_.

◆ hasUndirectedPath() [1/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 222 of file edgeGraphPart.cpp.

224 {
225 NodeSet visited;
226 NodeSet temp;
227
228 for (auto n: n1)
229 temp.insert(n);
230
231 while (!temp.empty()) {
232 NodeId current = *(temp.begin());
233 if (n2.contains(current)) return true;
234 temp.erase(current);
235 visited.insert(current);
236 for (auto next: neighbours(current)) {
237 if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
238 temp.insert(next);
239 }
240 }
241 return false;
242 }
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:539

References gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and neighbours().

Here is the call graph for this function:

◆ hasUndirectedPath() [2/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( NodeId n1,
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 185 of file edgeGraphPart.cpp.

185 {
186 NodeSet visited;
187 NodeSet temp;
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)) temp.insert(next);
197 }
198 }
199 return false;
200 }

References gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and neighbours().

Referenced by gum::UGmodel::isIndependent(), and gum::UGmodel::isIndependent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasUndirectedPath() [3/3]

bool gum::EdgeGraphPart::hasUndirectedPath ( NodeId n1,
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 202 of file edgeGraphPart.cpp.

202 {
203 NodeSet visited;
204 NodeSet temp;
205
206 if (except.contains(n2)) return false;
207
208 temp.insert(n1);
209 while (!temp.empty()) {
210 NodeId current = *(temp.begin());
211 if (current == n2) return true;
212 temp.erase(current);
213 visited.insert(current);
214 for (auto next: neighbours(current)) {
215 if (!temp.contains(next) && !visited.contains(next) && !except.contains(next))
216 temp.insert(next);
217 }
218 }
219 return false;
220 }

References gum::Set< Key >::begin(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::Set< Key >::erase(), gum::Set< Key >::insert(), and neighbours().

Here is the call graph for this function:

◆ listMapEdges()

template<typename VAL>
List< VAL > gum::EdgeGraphPart::listMapEdges ( VAL(* )(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))

Parameters
fa function assigning a VAL to any edge

◆ neighbours()

INLINE const NodeSet & gum::EdgeGraphPart::neighbours ( 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 96 of file edgeGraphPart_inl.h.

96 {
97 if (_neighbours_.exists(id)) return *(_neighbours_[id]);
98 else return emptyNodeSet;
99 }
const NodeSet emptyNodeSet
Some typdefs and define for shortcuts ...

References _neighbours_, and gum::emptyNodeSet.

Referenced by gum::MeekRules::_applyMeekRules_(), gum::BinaryJoinTreeConverterDefault::_convertClique_(), gum::BinaryJoinTreeConverterDefault::_convertConnectedComponent_(), gum::MeekRules::_critereMinParents_(), gum::BinaryJoinTreeConverterDefault::_markConnectedComponent_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::prm::StructuredInference< GUM_SCALAR >::_removeBarrenNodes_(), gum::prm::GSpan< GUM_SCALAR >::_sortPatterns_(), gum::prm::GSpan< GUM_SCALAR >::_subgraph_mining_(), gum::StaticTriangulation::_triangulate_(), gum::MixedGraph::boundary(), gum::MixedGraph::chainComponent(), gum::MixedGraph::hasMixedOrientedPath(), gum::PDAG::hasMixedReallyOrientedPath(), gum::UndiGraph::hasUndirectedCycle(), hasUndirectedPath(), hasUndirectedPath(), hasUndirectedPath(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::PDAG::moralGraph(), gum::UndiGraph::nodes2ConnectedComponent(), gum::UndiGraph::partialUndiGraph(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::learning::SimpleMiic::propagatesRemainingOrientableEdges_(), gum::rec_ancestral(), gum::rec_hasMixedReallyOrientedPath(), gum::MixedGraph::toDot(), gum::PDAG::toDot(), gum::UndiGraph::toDot(), undirectedPath(), gum::learning::Miic::unshieldedTriples_(), gum::learning::SimpleMiic::unshieldedTriples_(), gum::learning::Miic::unshieldedTriplesMiic_(), and gum::learning::SimpleMiic::unshieldedTriplesMiic_().

◆ operator=()

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

copy operator

Parameters
sthe EdgeGraphPart to copy

Definition at line 105 of file edgeGraphPart.cpp.

105 {
106 // avoid self assignment
107 if (this != &s) {
108 clearEdges();
109
110 _edges_ = s._edges_;
111
112 // copy the set of neighbours
113 _neighbours_.resize(s._neighbours_.capacity());
114
115 for (const auto& [key, nodeset]: s._neighbours_) {
116 NodeSet* newneigh = new NodeSet(*nodeset);
117 _neighbours_.insert(key, newneigh);
118 }
119
120 if (onEdgeAdded.hasListener())
121 for (const auto& edge: _edges_)
122 GUM_EMIT2(onEdgeAdded, edge.first(), edge.second());
123 }
124
125 return *this;
126 }
virtual void clearEdges()
removes all the edges from the EdgeGraphPart

References EdgeGraphPart(), _edges_, _neighbours_, clearEdges(), GUM_EMIT2, and onEdgeAdded.

Referenced by gum::MixedGraph::operator=(), and gum::UndiGraph::operator=().

Here is the call graph for this function:
Here is the caller 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 125 of file edgeGraphPart_inl.h.

125 {
126 return _edges_ == p._edges_;
127 }

References EdgeGraphPart(), and _edges_.

Referenced by gum::MixedGraph::operator==(), and gum::UndiGraph::operator==().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sizeEdges()

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

indicates the number of edges stored within the EdgeGraphPart

Definition at line 57 of file edgeGraphPart_inl.h.

57{ return _edges_.size(); }

References _edges_.

◆ toString()

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

to friendly display the content of the EdgeGraphPart

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

Definition at line 128 of file edgeGraphPart.cpp.

128 {
129 std::stringstream s;
130 bool first = true;
131 s << "{";
132
133 for (const auto& edge: _edges_) {
134 if (first) first = false;
135 else s << ",";
136
137 s << edge;
138 }
139
140 s << "}";
141
142 return s.str();
143 }

References _edges_.

Referenced by gum::operator<<(), gum::MixedGraph::toString(), and gum::UndiGraph::toString().

Here is the caller graph for this function:

◆ undirectedPath()

std::vector< NodeId > gum::EdgeGraphPart::undirectedPath ( NodeId node1,
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 145 of file edgeGraphPart.cpp.

145 {
146 // not recursive version => use a FIFO for simulating the recursion
147 List< NodeId > nodeFIFO;
148 nodeFIFO.pushBack(n2);
149
150 // mark[node] = predecessor if visited, else mark[node] does not exist
152 mark.insert(n2, n2);
153
154 NodeId current;
155
156 while (!nodeFIFO.empty()) {
157 current = nodeFIFO.front();
158 nodeFIFO.popFront();
159
160 // check the neighbour
161 for (const auto new_one: neighbours(current)) {
162 if (mark.exists(new_one)) // if this node is already marked, stop
163 continue;
164
165 mark.insert(new_one, current);
166
167 if (new_one == n1) {
168 std::vector< NodeId > v;
169
170 for (current = n1; current != n2; current = mark[current])
171 v.push_back(current);
172
173 v.push_back(n2);
174
175 return v;
176 }
177
178 nodeFIFO.pushBack(new_one);
179 }
180 }
181
182 GUM_ERROR(NotFound, "no path found")
183 }
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.

References gum::List< Val >::empty(), gum::HashTable< Key, Val >::exists(), gum::List< Val >::front(), GUM_ERROR, gum::HashTable< Key, Val >::insert(), neighbours(), gum::List< Val >::popFront(), and gum::List< Val >::pushBack().

Here is the call graph for this function:

◆ unvirtualizedEraseNeighbours()

INLINE void gum::EdgeGraphPart::unvirtualizedEraseNeighbours ( 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 114 of file edgeGraphPart_inl.h.

114 {
115 if (_neighbours_.exists(id)) {
116 const NodeSet& set = *(_neighbours_[id]);
117
118 for (auto iter = set.beginSafe(); iter != set.endSafe();
119 ++iter) { // safe iterator needed here
120 EdgeGraphPart::eraseEdge(Edge(*iter, id));
121 }
122 }
123 }

References _neighbours_, gum::Set< Key >::beginSafe(), gum::Set< Key >::endSafe(), and eraseEdge().

Referenced by gum::MixedGraph::eraseNode(), and gum::UndiGraph::eraseNode().

Here is the call graph for this function:
Here is the caller 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 266 of file edgeGraphPart.h.

Referenced by EdgeGraphPart(), EdgeGraphPart(), _clearEdges_(), addEdge(), edges(), emptyEdges(), eraseEdge(), existsEdge(), operator=(), operator==(), sizeEdges(), and toString().

◆ _neighbours_

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

for each node, the set of its adjacent edges

Definition at line 269 of file edgeGraphPart.h.

Referenced by EdgeGraphPart(), _checkNeighbours_(), _clearEdges_(), addEdge(), eraseEdge(), eraseNeighbours(), existsEdge(), neighbours(), operator=(), and unvirtualizedEraseNeighbours().

◆ onEdgeAdded

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

Definition at line 98 of file edgeGraphPart.h.

Referenced by EdgeGraphPart(), addEdge(), and operator=().

◆ onEdgeDeleted

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

Definition at line 99 of file edgeGraphPart.h.

Referenced by _clearEdges_(), and eraseEdge().


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