aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::ArcGraphPart Class Reference

Classes for directed edge sets. More...

#include <arcGraphPart.h>

Inheritance diagram for gum::ArcGraphPart:
Collaboration diagram for gum::ArcGraphPart:

Public Types

using ArcIterator = ArcSetIterator

Public Member Functions

Constructors / Destructors
 ArcGraphPart (Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
 default constructor
 ArcGraphPart (const ArcGraphPart &s)
 copy constructor
virtual ~ArcGraphPart ()
 destructor
Operators
ArcGraphPartoperator= (const ArcGraphPart &s)
 copy operator
bool operator== (const ArcGraphPart &p) const
 tests whether two ArcGraphParts contain the same arcs
Accessors/Modifiers
virtual void addArc (NodeId tail, NodeId head)
 insert a new arc into the ArcGraphPart
virtual void eraseArc (const Arc &arc)
 removes an arc from the ArcGraphPart
bool existsArc (const Arc &arc) const
 indicates whether a given arc exists
bool existsArc (NodeId tail, NodeId head) const
 indicates whether a given arc exists
bool emptyArcs () const
 indicates wether the ArcGraphPart contains any arc
void clearArcs ()
 removes all the arcs from the ArcGraphPart
Size sizeArcs () const
 indicates the number of arcs stored within the ArcGraphPart
const ArcSetarcs () const
 returns the set of arcs stored within the ArcGraphPart
const NodeSetparents (NodeId id) const
 returns the set of nodes with arc ingoing to a given node
NodeSet family (NodeId id) const
 returns the set of nodes which consists in the node and its parents
NodeSet descendants (NodeId id) const
 returns the set of nodes with directed path outgoing from a given node
NodeSet ancestors (NodeId id) const
 returns the set of nodes with directed path ingoing to a given node
NodeSet children (const NodeSet &ids) const
 returns the set of children of a set of nodes
NodeSet parents (const NodeSet &ids) const
 returns the set of parents of a set of nodes
NodeSet family (const NodeSet &ids) const
 returns the set of family nodes of a set of nodes
const NodeSetchildren (NodeId id) const
 returns the set of nodes with arc outgoing from a given node
void eraseParents (NodeId id)
 erase all the parents of a given node
void unvirtualizedEraseParents (NodeId id)
 same function as eraseParents but without any virtual call to an erase
void eraseChildren (NodeId id)
 removes all the children of a given node
void unvirtualizedEraseChildren (NodeId id)
 same function as eraseChildren but without any virtual call to an erase
std::string toString () const
 to friendly display the content of the ArcGraphPart
template<typename VAL>
ArcProperty< VAL > arcsProperty (VAL(*f)(const Arc &), Size size=0) const
 a method to create a hashMap of VAL from a set of arcs (using for every arc, say x, the VAL f(x))
template<typename VAL>
ArcProperty< VAL > arcsProperty (const VAL &a, Size size=0) const
 a method to create a hashMap of VAL from a set of arcs (using for every arc, say x, the VAL a)
template<typename VAL>
List< VAL > listMapArcs (VAL(*f)(const Arc &)) const
 a method to create a list of VAL from a set of arcs (using for every arc, say x, the VAL f(x))
std::vector< NodeIddirectedPath (NodeId node1, NodeId node2) const
 returns a directed path from node1 to node2 belonging to the set of arcs
std::vector< NodeIddirectedUnorientedPath (NodeId node1, NodeId node2) const
 returns an unoriented (directed) path from node1 to node2 in the arc set

Public Attributes

Signaler2< NodeId, NodeIdonArcAdded
Signaler2< NodeId, NodeIdonArcDeleted

Protected Member Functions

void eraseSetOfArcs_ (const ArcSet &set)
 a (virtualized) function to remove a given set of arcs
void unvirtualizedEraseSetOfArcs_ (const ArcSet &set)
 similar to eraseSetOfArcs_ except that it is unvirtualized

Private Member Functions

void _checkParents_ (NodeId id)
 when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entry to parents[id]
void _checkChildren_ (NodeId id)
 when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set entry to children[id]

Private Attributes

Set< Arc_arcs_
 the set of all the arcs contained within the ArcGraphPart
NodeProperty< NodeSet * > _parents_
 for each arc, the sets of its parents
NodeProperty< NodeSet * > _children_
 for each arc, the set of its children

Detailed Description

Classes for directed edge sets.

Author
Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU)
Usage example:
ArcGraphPart arcs1,arcs2,arcs3;
// insert elements into arcs1
arcs1.addArc( 2,3 );
arcs1.addArc( 5,3 );
// copy arcs1 into arcs2
arcs2=arcs1;
// remove some elements from arcs1
arcs1.eraseArc( Arc( 5,3 ) );
arcs1.eraseArc( arc );
if ( arcs1.empty() ) std::cerr<<" arcs1 is empty"<<std::endl;
// checks whether a given arc exists
if ( arcs2.existArc( arc ) )
cerr << "set contains " << arc << endl;
if ( arcs2.existArc( 5,3 ) )
cerr << "set contains " << arc << endl;
std::cerr<<arcs2.toString()<<std::endl;
std::cerr<<arcs2.parents( 3 )<<std::endl;
std::cerr<<arcs2.children( 2 )<<std::endl;
std::cerr<<std::endl<<std::endl;
std::cerr<<std::endl<<std::endl;
virtual void addArc(NodeId tail, NodeId head)
insert a new arc into the ArcGraphPart
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
std::string toString() const
to friendly display the content of the ArcGraphPart
The base class for all directed edges.

Definition at line 98 of file arcGraphPart.h.

Member Typedef Documentation

◆ ArcIterator

Definition at line 100 of file arcGraphPart.h.

Constructor & Destructor Documentation

◆ ArcGraphPart() [1/2]

gum::ArcGraphPart::ArcGraphPart ( Size arcs_size = HashTableConst::default_size,
bool arcs_resize_policy = true )
explicit

default constructor

Parameters
arcs_sizethe size of the hash table used to store all the arcs
arcs_resize_policythe resizing policy of this hash table

Definition at line 58 of file arcGraphPart.cpp.

58 :
59 _arcs_(arcs_size, arcs_resize_policy) {
60 GUM_CONSTRUCTOR(ArcGraphPart);
61 }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart

References ArcGraphPart(), and _arcs_.

Referenced by ArcGraphPart(), ArcGraphPart(), gum::DiGraph::DiGraph(), gum::DiGraph::DiGraph(), ~ArcGraphPart(), operator=(), and operator==().

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

◆ ArcGraphPart() [2/2]

gum::ArcGraphPart::ArcGraphPart ( const ArcGraphPart & s)

copy constructor

Parameters
sthe ArcGraphPart to copy

Definition at line 63 of file arcGraphPart.cpp.

63 : _arcs_(s._arcs_) {
64 GUM_CONS_CPY(ArcGraphPart);
65
66 // copy the sets of parents
67 const NodeProperty< NodeSet* >& pars = s._parents_;
68 _parents_.resize(pars.capacity());
69
70 for (const auto& [key, nodeset]: pars) {
71 NodeSet* newpar = new NodeSet(*nodeset);
72 _parents_.insert(key, newpar);
73 }
74
75 // copy the sets of children
76 const NodeProperty< NodeSet* >& children = s._children_;
77 _children_.resize(children.capacity());
78
79 for (const auto& [key, nodeset]: children) {
80 NodeSet* newchildren = new NodeSet(*nodeset);
81 _children_.insert(key, newchildren);
82 }
83
84 // send signals to indicate that there are new arcs
85 if (onArcAdded.hasListener()) {
86 for (const auto& arc: _arcs_) {
87 GUM_EMIT2(onArcAdded, arc.tail(), arc.head());
88 }
89 }
90 }
Signaler2< NodeId, NodeId > onArcAdded
NodeProperty< NodeSet * > _children_
for each arc, the set of its children
NodeProperty< NodeSet * > _parents_
for each arc, the sets of its parents
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition signaler2.h:61

References ArcGraphPart(), _arcs_, _children_, _parents_, gum::HashTable< Key, Val >::capacity(), children(), GUM_EMIT2, and onArcAdded.

Here is the call graph for this function:

◆ ~ArcGraphPart()

gum::ArcGraphPart::~ArcGraphPart ( )
virtual

destructor

Definition at line 92 of file arcGraphPart.cpp.

92 {
93 GUM_DESTRUCTOR(ArcGraphPart);
94 // be sure to deallocate all the parents and children sets
95 clearArcs();
96 }
void clearArcs()
removes all the arcs from the ArcGraphPart

References ArcGraphPart(), and clearArcs().

Here is the call graph for this function:

Member Function Documentation

◆ _checkChildren_()

INLINE void gum::ArcGraphPart::_checkChildren_ ( NodeId id)
private

when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set entry to children[id]

Parameters
idthe node whose children[id] is checked

Definition at line 71 of file arcGraphPart_inl.h.

71 {
72 if (!_children_.exists(id)) { _children_.insert(id, new NodeSet); }
73 }

References _children_.

Referenced by addArc().

Here is the caller graph for this function:

◆ _checkParents_()

INLINE void gum::ArcGraphPart::_checkParents_ ( NodeId id)
private

when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entry to parents[id]

Parameters
idthe node whose parents[id] is checked

Definition at line 67 of file arcGraphPart_inl.h.

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

References _parents_.

Referenced by addArc().

Here is the caller graph for this function:

◆ addArc()

INLINE void gum::ArcGraphPart::addArc ( NodeId tail,
NodeId head )
virtual

insert a new arc into the ArcGraphPart

Parameters
tailthe id of the tail of the new arc to be inserted
headthe id of the head of the new arc to be inserted
Warning
if the arc already exists, nothing is done. In particular, no exception is raised.

Reimplemented in gum::DAG, gum::DiGraph, gum::PDAG, and gum::prm::gspan::Pattern.

Definition at line 114 of file arcGraphPart_inl.h.

114 {
115 Arc arc(tail, head);
116
117 _arcs_.insert(arc);
118 _checkParents_(head);
119 _checkChildren_(tail);
120 _parents_[head]->insert(tail);
121 _children_[tail]->insert(head);
122
123 GUM_EMIT2(onArcAdded, tail, head);
124 }
void _checkParents_(NodeId id)
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
void _checkChildren_(NodeId id)
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...

References _arcs_, _checkChildren_(), _checkParents_(), _children_, _parents_, GUM_EMIT2, and onArcAdded.

Referenced by gum::DiGraph::addArc().

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

◆ ancestors()

NodeSet gum::ArcGraphPart::ancestors ( NodeId id) const

returns the set of nodes with directed path ingoing to a given node

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is ingoing to the given node.

Parameters
idthe node which is the head of a directed path with the returned nodes

Definition at line 191 of file arcGraphPart.cpp.

191 {
192 NodeSet res;
193 NodeSet tmp;
194 for (auto next: parents(id))
195 tmp.insert(next);
196
197 while (!tmp.empty()) {
198 auto current = *(tmp.begin());
199 tmp.erase(current);
200 res.insert(current);
201 for (auto next: parents(current)) {
202 if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
203 }
204 }
205 return res;
206 }
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 parents().

Referenced by gum::DAGmodel::ancestors().

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

◆ arcs()

INLINE const ArcSet & gum::ArcGraphPart::arcs ( ) const

returns the set of arcs stored within the ArcGraphPart

Definition at line 59 of file arcGraphPart_inl.h.

59{ return _arcs_; }

References _arcs_.

Referenced by gum::EssentialGraph::_buildEssentialGraph_(), gum::prm::ClassBayesNet< GUM_SCALAR >::_init_(), gum::prm::gspan::Pattern::arcs(), gum::learning::SimpleMiic::learnStructure(), gum::DAG::moralGraph(), gum::PDAG::moralGraph(), gum::MeekRules::propagateToCPDAG(), gum::MeekRules::propagateToDAG(), and gum::DiGraph::toDot().

Here is the caller graph for this function:

◆ arcsProperty() [1/2]

template<typename VAL>
ArcProperty< VAL > gum::ArcGraphPart::arcsProperty ( const VAL & a,
Size size = 0 ) const

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

Parameters
athe default value assigned to each arc 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 arcs. If you do not specify this parameter, the method will assign it for you.

◆ arcsProperty() [2/2]

template<typename VAL>
ArcProperty< VAL > gum::ArcGraphPart::arcsProperty ( VAL(* )(const Arc &),
Size size = 0 ) const

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

Parameters
fa function assigning a VAL to any arc
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 arcs. If you do not specify this parameter, the method will assign it for you.

◆ children() [1/2]

INLINE NodeSet gum::ArcGraphPart::children ( const NodeSet & ids) const

returns the set of children of a set of nodes

Definition at line 86 of file arcGraphPart_inl.h.

86 {
87 NodeSet res;
88 for (const auto node: ids)
89 res += children(node);
90 return res;
91 }

References children().

Referenced by ArcGraphPart(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::_addArcs_(), gum::EssentialGraph::_buildEssentialGraph_(), gum::prm::gspan::Pattern::_expandCodeIsMinimal_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::DAG::_minimalCondSetVisitDn_(), gum::DAG::_minimalCondSetVisitUp_(), gum::prm::gspan::Pattern::_not_rec_(), gum::MeekRules::_propagatesOrientationInChainOfRemainingEdges_(), gum::prm::gspan::Pattern::_rec_(), gum::BarrenNodesFinder::barrenNodes(), gum::MixedGraph::boundary(), children(), descendants(), directedUnorientedPath(), eraseChildren(), gum::DiGraph::hasDirectedPath(), gum::PDAG::hasMixedReallyOrientedPath(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::initialize_(), gum::prm::PRMClassElementContainer< double >::isInputNode(), gum::prm::gspan::Pattern::isMinimal(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceNodeToNeighbours_(), gum::DAG::minimalCondSet(), gum::MixedGraph::mixedUnorientedPath(), gum::learning::SimpleMiic::propagatesOrientationInChainOfRemainingEdges_(), gum::rec_hasMixedReallyOrientedPath(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::DAGCycleDetector::setDAG(), gum::MixedGraph::toDot(), gum::PDAG::toDot(), and unvirtualizedEraseChildren().

Here is the call graph for this function:

◆ children() [2/2]

INLINE const NodeSet & gum::ArcGraphPart::children ( NodeId id) const

returns the set of nodes with arc outgoing from a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of the arcs returned

Definition at line 109 of file arcGraphPart_inl.h.

109 {
110 if (_children_.exists(id)) return *_children_[id];
111 else return emptyNodeSet;
112 }
const NodeSet emptyNodeSet
Some typdefs and define for shortcuts ...

References _children_, and gum::emptyNodeSet.

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )

removes all the arcs from the ArcGraphPart

Definition at line 98 of file arcGraphPart.cpp.

98 {
99 for (const auto& elt: _parents_)
100 delete elt.second;
101
102 _parents_.clear();
103
104 for (const auto& elt: _children_)
105 delete elt.second;
106
107 _children_.clear();
108
109 // we need this copy only if at least one onArcDeleted listener exists
110 if (onArcDeleted.hasListener()) {
111 ArcSet tmp = _arcs_;
112 _arcs_.clear();
113
114 for (const auto& arc: tmp)
115 GUM_EMIT2(onArcDeleted, arc.tail(), arc.head());
116 } else {
117 _arcs_.clear();
118 }
119 }
Signaler2< NodeId, NodeId > onArcDeleted
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...

References _arcs_, _children_, _parents_, GUM_EMIT2, and onArcDeleted.

Referenced by ~ArcGraphPart(), gum::DiGraph::clear(), gum::MixedGraph::clear(), operator=(), and gum::MixedGraph::operator=().

Here is the caller graph for this function:

◆ descendants()

NodeSet gum::ArcGraphPart::descendants ( NodeId id) const

returns the set of nodes with directed path outgoing from a given node

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of a directed path with the returned nodes

Definition at line 174 of file arcGraphPart.cpp.

174 {
175 NodeSet res;
176 NodeSet tmp;
177 for (auto next: children(id))
178 tmp.insert(next);
179
180 while (!tmp.empty()) {
181 auto current = *(tmp.begin());
182 tmp.erase(current);
183 res.insert(current);
184 for (auto next: children(current)) {
185 if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
186 }
187 }
188 return res;
189 }

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

Referenced by gum::DAGmodel::descendants().

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

◆ directedPath()

std::vector< NodeId > gum::ArcGraphPart::directedPath ( NodeId node1,
NodeId node2 ) const

returns a directed path from node1 to node2 belonging to the set of arcs

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 208 of file arcGraphPart.cpp.

208 {
209 // not recursive version => use a FIFO for simulating the recursion
210 List< NodeId > nodeFIFO;
211 nodeFIFO.pushBack(n2);
212
213 // mark[node] = successor if visited, else mark[node] does not exist
215 mark.insert(n2, n2);
216
217 NodeId current;
218
219 while (!nodeFIFO.empty()) {
220 current = nodeFIFO.front();
221 nodeFIFO.popFront();
222
223 // check the parents
224
225 for (const auto new_one: parents(current)) {
226 if (mark.exists(new_one)) // if this node is already marked, do not
227 continue; // check it again
228
229 mark.insert(new_one, current);
230
231 if (new_one == n1) {
232 std::vector< NodeId > v;
233
234 for (current = n1; current != n2; current = mark[current])
235 v.push_back(current);
236
237 v.push_back(n2);
238
239 return v;
240 }
241
242 nodeFIFO.pushBack(new_one);
243 }
244 }
245
246 GUM_ERROR(NotFound, "no path found")
247 }
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
Size NodeId
Type for node ids.

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

Referenced by gum::learning::SimpleMiic::orientationLatents_().

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

◆ directedUnorientedPath()

std::vector< NodeId > gum::ArcGraphPart::directedUnorientedPath ( NodeId node1,
NodeId node2 ) const

returns an unoriented (directed) path from node1 to node2 in the arc 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 249 of file arcGraphPart.cpp.

249 {
250 // not recursive version => use a FIFO for simulating the recursion
251 List< NodeId > nodeFIFO;
252 nodeFIFO.pushBack(n2);
253
254 // mark[node] = successor if visited, else mark[node] does not exist
256 mark.insert(n2, n2);
257
258 NodeId current;
259
260 while (!nodeFIFO.empty()) {
261 current = nodeFIFO.front();
262 nodeFIFO.popFront();
263
264 // check the parents
265 for (const auto new_one: parents(current)) {
266 if (mark.exists(new_one)) // the node has already been visited
267 continue;
268
269 mark.insert(new_one, current);
270
271 if (new_one == n1) {
272 std::vector< NodeId > v;
273
274 for (current = n1; current != n2; current = mark[current])
275 v.push_back(current);
276
277 v.push_back(n2);
278
279 return v;
280 }
281
282 nodeFIFO.pushBack(new_one);
283 }
284
285 // check the children
286 for (const auto new_one: children(current)) {
287 if (mark.exists(new_one)) // the node has already been visited
288 continue;
289
290 mark.insert(new_one, current);
291
292 if (new_one == n1) {
293 std::vector< NodeId > v;
294
295 for (current = n1; current != n2; current = mark[current])
296 v.push_back(current);
297
298 v.push_back(n2);
299
300 return v;
301 }
302
303 nodeFIFO.pushBack(new_one);
304 }
305 }
306
307 GUM_ERROR(NotFound, "no path found")
308 }

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

Here is the call graph for this function:

◆ emptyArcs()

INLINE bool gum::ArcGraphPart::emptyArcs ( ) const

indicates wether the ArcGraphPart contains any arc

Definition at line 55 of file arcGraphPart_inl.h.

55{ return _arcs_.empty(); }

References _arcs_.

◆ eraseArc()

INLINE void gum::ArcGraphPart::eraseArc ( const Arc & arc)
virtual

removes an arc from the ArcGraphPart

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

Definition at line 126 of file arcGraphPart_inl.h.

126 {
127 // ASSUMING tail and head exists in _parents_ anf _children_
128 // (if not, it is an error)
129 if (existsArc(arc)) {
130 NodeId tail = arc.tail();
131 NodeId head = arc.head();
132 _parents_[head]->erase(tail);
133 _children_[tail]->erase(head);
134 _arcs_.erase(arc);
135 GUM_EMIT2(onArcDeleted, tail, head);
136 }
137 }
bool existsArc(const Arc &arc) const
indicates whether a given arc exists

References _arcs_, _children_, _parents_, existsArc(), GUM_EMIT2, gum::Arc::head(), onArcDeleted, and gum::Arc::tail().

Referenced by gum::EssentialGraph::_buildEssentialGraph_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::BarrenNodesFinder::barrenNodes(), eraseChildren(), eraseParents(), eraseSetOfArcs_(), gum::learning::IBNLearner::learnDag_(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::learning::SimpleMiic::learnStructure(), gum::learning::SimpleMiic::orientationLatents_(), gum::learning::Miic::orientationMiic_(), gum::learning::SimpleMiic::orientationMiic_(), gum::learning::Miic::orientDoubleHeadedArcs_(), gum::prm::gspan::Pattern::pop_back(), unvirtualizedEraseChildren(), unvirtualizedEraseParents(), and unvirtualizedEraseSetOfArcs_().

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

◆ eraseChildren()

INLINE void gum::ArcGraphPart::eraseChildren ( NodeId id)

removes all the children of a given node

Parameters
idthe node all the children of which will be removed
Warning
although this method is not virtual, it calls method eraseArc( const Arc& arc ) and, as such, has a "virtual" behaviour. If you do not wish it to have this "virtual" behaviour, call instead method unvirtualizedEraseChildren
if no arc is a parent of id, nothing is done. In particular, no exception is thrown.

Definition at line 158 of file arcGraphPart_inl.h.

158 {
159 if (_children_.exists(id)) {
160 const NodeSet& children = *(_children_[id]);
161
162 for (auto iter = children.beginSafe(); // safe iterator needed here
163 iter != children.endSafe();
164 ++iter) {
165 // warning: use this erase so that you actually use the virtualized
166 // arc removal function
167 eraseArc(Arc(id, *iter));
168 }
169 }
170 }

References _children_, children(), and eraseArc().

Here is the call graph for this function:

◆ eraseParents()

INLINE void gum::ArcGraphPart::eraseParents ( NodeId id)

erase all the parents of a given node

Parameters
idthe node all the parents of which will be removed
Warning
although this method is not virtual, it calls method eraseArc( const Arc& arc ) and, as such, has a "virtual" behaviour. If you do not wish it to have this "virtual" behaviour, call instead method unvirtualizedEraseParents
if no arc is a parent of id, nothing is done. In particular, no exception is thrown.

Definition at line 144 of file arcGraphPart_inl.h.

144 {
145 if (_parents_.exists(id)) {
146 const NodeSet& parents = *(_parents_[id]);
147
148 for (auto iter = parents.beginSafe(); // safe iterator needed here
149 iter != parents.endSafe();
150 ++iter) {
151 // warning: use this erase so that you actually use the virtualized
152 // arc removal function
153 eraseArc(Arc(*iter, id));
154 }
155 }
156 }

References _parents_, eraseArc(), and parents().

Here is the call graph for this function:

◆ eraseSetOfArcs_()

INLINE void gum::ArcGraphPart::eraseSetOfArcs_ ( const ArcSet & set)
protected

a (virtualized) function to remove a given set of arcs

Warning
this function uses eraseArc, which is a virtual function. Hence the behaviour of this function is that of a virtual function

Definition at line 139 of file arcGraphPart_inl.h.

139 {
140 for (const auto& arc: set)
141 eraseArc(arc);
142 }

References eraseArc().

Here is the call graph for this function:

◆ existsArc() [1/2]

◆ existsArc() [2/2]

INLINE bool gum::ArcGraphPart::existsArc ( NodeId tail,
NodeId head ) const

indicates whether a given arc exists

Parameters
tailthe tail of the arc we test the existence in the ArcGraphPart
headthe head of the arc we test the existence in the ArcGraphPart

Definition at line 63 of file arcGraphPart_inl.h.

63 {
64 return _parents_.exists(head) && _parents_[head]->exists(tail);
65 }

References _parents_.

◆ family() [1/2]

INLINE NodeSet gum::ArcGraphPart::family ( const NodeSet & ids) const

returns the set of family nodes of a set of nodes

Definition at line 102 of file arcGraphPart_inl.h.

102 {
103 NodeSet res;
104 for (const auto node: ids)
105 res += family(node);
106 return res;
107 }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents

References family().

Here is the call graph for this function:

◆ family() [2/2]

INLINE NodeSet gum::ArcGraphPart::family ( NodeId id) const

returns the set of nodes which consists in the node and its parents

Note that the set of nodes returned may be empty if no path within the ArcGraphPart is outgoing from the given node.

Parameters
idthe node which is the tail of a directed path with the returned nodes

Definition at line 80 of file arcGraphPart_inl.h.

80 {
81 NodeSet res{id};
82 return res + parents(id);
83 }

References parents().

Referenced by family().

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

◆ listMapArcs()

template<typename VAL>
List< VAL > gum::ArcGraphPart::listMapArcs ( VAL(* )(const Arc &)) const

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

Parameters
fa function assigning a VAL to any arc

◆ operator=()

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

copy operator

Parameters
sthe ArcGraphPart to copy

Definition at line 121 of file arcGraphPart.cpp.

121 {
122 // avoid self assignment
123 if (this != &s) {
124 // copy the arcs
125 clearArcs();
126 _arcs_ = s._arcs_;
127
128 // copy the sets of parents
129 _parents_.resize(s._parents_.capacity());
130
131 for (const auto& [key, nodeset]: s._parents_) {
132 NodeSet* newpar = new NodeSet(*nodeset);
133 _parents_.insert(key, newpar);
134 }
135
136 // copy the sets of children
137 _children_.resize(s._children_.capacity());
138
139 for (const auto& [key, nodeset]: s._children_) {
140 NodeSet* newchildren = new NodeSet(*nodeset);
141 _children_.insert(key, newchildren);
142 }
143
144 if (onArcAdded.hasListener()) {
145 for (const auto& arc: _arcs_) {
146 GUM_EMIT2(onArcAdded, arc.tail(), arc.head());
147 }
148 }
149 }
150
151 return *this;
152 }

References ArcGraphPart(), _arcs_, _children_, _parents_, clearArcs(), GUM_EMIT2, and onArcAdded.

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

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

◆ operator==()

INLINE bool gum::ArcGraphPart::operator== ( const ArcGraphPart & p) const

tests whether two ArcGraphParts contain the same arcs

Parameters
pthe ArcGraphPart that we compare with this

Definition at line 201 of file arcGraphPart_inl.h.

201{ return _arcs_ == p._arcs_; }

References ArcGraphPart(), and _arcs_.

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

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

◆ parents() [1/2]

INLINE NodeSet gum::ArcGraphPart::parents ( const NodeSet & ids) const

returns the set of parents of a set of nodes

Definition at line 94 of file arcGraphPart_inl.h.

94 {
95 NodeSet res;
96 for (const auto node: ids)
97 res += parents(node);
98 return res;
99 }

References parents().

Here is the call graph for this function:

◆ parents() [2/2]

INLINE const NodeSet & gum::ArcGraphPart::parents ( NodeId id) const

returns the set of nodes with arc ingoing to a given node

Note that the set of arcs returned may be empty if no arc within the ArcGraphPart is ingoing into the given node.

Parameters
idthe node toward which the arcs returned are pointing

Definition at line 75 of file arcGraphPart_inl.h.

75 {
76 if (_parents_.exists(id)) return *(_parents_[id]);
77 else return emptyNodeSet;
78 }

References _parents_, and gum::emptyNodeSet.

Referenced by gum::MeekRules::_complete_(), gum::MeekRules::_critereMinParents_(), gum::learning::Miic::_existsDirectedPath_(), gum::learning::SimpleMiic::_existsDirectedPath_(), gum::MeekRules::_existsDirectedPath_(), gum::learning::Miic::_existsNonTrivialDirectedPath_(), gum::learning::SimpleMiic::_existsNonTrivialDirectedPath_(), gum::prm::gspan::Pattern::_expandCodeIsMinimal_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClass_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClassDag_(), gum::prm::LayerGenerator< GUM_SCALAR >::_generateClasses_(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::_generateCluster_(), gum::prm::SVE< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVED< GUM_SCALAR >::_initElimOrder_(), gum::prm::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::MeekRules::_isOrientable_(), gum::DAG::_minimalCondSetVisitDn_(), gum::DAG::_minimalCondSetVisitUp_(), gum::prm::gspan::Pattern::_not_rec_(), gum::MeekRules::_orientDoubleHeadedArcs_(), gum::MeekRules::_propagates_(), gum::learning::Miic::_propagatingOrientationMiic_(), gum::learning::SimpleMiic::_propagatingOrientationMiic_(), gum::prm::gspan::Pattern::_rec_(), gum::EssentialGraph::_strongly_protected_(), ancestors(), gum::BarrenNodesFinder::barrenNodes(), gum::MixedGraph::boundary(), directedPath(), directedUnorientedPath(), eraseParents(), family(), gum::MixedGraph::hasMixedOrientedPath(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::initialize_(), gum::prm::PRMClassElementContainer< double >::isInputNode(), gum::learning::Miic::isMaxIndegree_(), gum::prm::gspan::Pattern::isMinimal(), gum::learning::SimpleMiic::isOrientable_(), gum::learning::SimpleMiic::learnPDAG(), gum::learning::SimpleMiic::learnStructure(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::makeInferenceNodeToNeighbours_(), gum::DAG::minimalCondSet(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::DAG::moralGraph(), gum::PDAG::moralGraph(), gum::DAG::moralizedAncestralGraph(), gum::learning::Miic::orientDoubleHeadedArcs_(), gum::prm::gspan::DFSTree< GUM_SCALAR >::parent(), gum::prm::gspan::DFSTree< GUM_SCALAR >::parent(), parents(), gum::rec_ancestral(), gum::BayesBall::relevantTensors(), gum::dSeparationAlgorithm::relevantTensors(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparationAlgorithm::requisiteNodes(), gum::prm::gspan::Pattern::rightmostPath(), gum::DAGCycleDetector::setDAG(), and unvirtualizedEraseParents().

◆ sizeArcs()

INLINE Size gum::ArcGraphPart::sizeArcs ( ) const

indicates the number of arcs stored within the ArcGraphPart

Definition at line 57 of file arcGraphPart_inl.h.

57{ return _arcs_.size(); }

References _arcs_.

Referenced by gum::prm::gspan::Pattern::sizeArcs().

Here is the caller graph for this function:

◆ toString()

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

to friendly display the content of the ArcGraphPart

Definition at line 154 of file arcGraphPart.cpp.

154 {
155 std::stringstream s;
156 bool first = true;
157 s << "{";
158
159 for (const auto& arc: _arcs_) {
160 if (first) {
161 first = false;
162 } else {
163 s << ",";
164 }
165
166 s << arc;
167 }
168
169 s << "}";
170
171 return s.str();
172 }

References _arcs_.

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

Here is the caller graph for this function:

◆ unvirtualizedEraseChildren()

INLINE void gum::ArcGraphPart::unvirtualizedEraseChildren ( NodeId id)

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

Parameters
idthe node whose outgoing arcs will be removed

Definition at line 189 of file arcGraphPart_inl.h.

189 {
190 if (_children_.exists(id)) {
191 const NodeSet& children = *(_children_[id]);
192
193 for (auto iter = children.beginSafe(); // safe iterator needed here
194 iter != children.endSafe();
195 ++iter) {
196 ArcGraphPart::eraseArc(Arc(id, *iter));
197 }
198 }
199 }

References _children_, children(), and eraseArc().

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

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

◆ unvirtualizedEraseParents()

INLINE void gum::ArcGraphPart::unvirtualizedEraseParents ( NodeId id)

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

Parameters
idthe node whose ingoing arcs will be removed

Definition at line 177 of file arcGraphPart_inl.h.

177 {
178 if (_parents_.exists(id)) {
179 const NodeSet& parents = *(_parents_[id]);
180
181 for (auto iter = parents.beginSafe(); // safe iterator needed here
182 iter != parents.endSafe();
183 ++iter) {
184 ArcGraphPart::eraseArc(Arc(*iter, id));
185 }
186 }
187 }

References _parents_, eraseArc(), and parents().

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

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

◆ unvirtualizedEraseSetOfArcs_()

INLINE void gum::ArcGraphPart::unvirtualizedEraseSetOfArcs_ ( const ArcSet & set)
protected

similar to eraseSetOfArcs_ except that it is unvirtualized

Warning
this function uses ArcGraphPart::eraseArc, hence, as compared with eraseSetOfArcs_, it removes the arcs without calling a virtual eraseArc

Definition at line 172 of file arcGraphPart_inl.h.

172 {
173 for (const auto& arc: set)
175 }

References eraseArc().

Here is the call graph for this function:

Member Data Documentation

◆ _arcs_

Set< Arc > gum::ArcGraphPart::_arcs_
private

the set of all the arcs contained within the ArcGraphPart

Definition at line 316 of file arcGraphPart.h.

Referenced by ArcGraphPart(), ArcGraphPart(), addArc(), arcs(), clearArcs(), emptyArcs(), eraseArc(), existsArc(), operator=(), operator==(), sizeArcs(), and toString().

◆ _children_

NodeProperty< NodeSet* > gum::ArcGraphPart::_children_
private

for each arc, the set of its children

Definition at line 322 of file arcGraphPart.h.

Referenced by ArcGraphPart(), _checkChildren_(), addArc(), children(), clearArcs(), eraseArc(), eraseChildren(), operator=(), and unvirtualizedEraseChildren().

◆ _parents_

NodeProperty< NodeSet* > gum::ArcGraphPart::_parents_
private

for each arc, the sets of its parents

Definition at line 319 of file arcGraphPart.h.

Referenced by ArcGraphPart(), _checkParents_(), addArc(), clearArcs(), eraseArc(), eraseParents(), existsArc(), operator=(), parents(), and unvirtualizedEraseParents().

◆ onArcAdded

Signaler2< NodeId, NodeId > gum::ArcGraphPart::onArcAdded

Definition at line 102 of file arcGraphPart.h.

Referenced by ArcGraphPart(), addArc(), and operator=().

◆ onArcDeleted

Signaler2< NodeId, NodeId > gum::ArcGraphPart::onArcDeleted

Definition at line 103 of file arcGraphPart.h.

Referenced by clearArcs(), and eraseArc().


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