aGrUM  0.20.3
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 Attributes

Signaler2< NodeId, NodeIdonArcAdded
 
Signaler2< NodeId, NodeIdonArcDeleted
 

Public Member Functions

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

Public Types

typedef ArcSetIterator ArcIterator
 

Protected Member Functions

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

Detailed Description

Classes for directed edge sets.

Author
Pierre-Henri WUILLEMIN() & Christophe GONZALES()
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;

Definition at line 78 of file arcGraphPart.h.

Member Typedef Documentation

◆ ArcIterator

Definition at line 80 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 38 of file arcGraphPart.cpp.

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

38  :
39  _arcs_(arcs_size, arcs_resize_policy) {
40  GUM_CONSTRUCTOR(ArcGraphPart);
41  }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
+ Here is the call graph for this function:

◆ ArcGraphPart() [2/2]

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

copy constructor

Parameters
sthe ArcGraphPart to copy

Definition at line 43 of file arcGraphPart.cpp.

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

43  : _arcs_(s._arcs_) {
44  GUM_CONS_CPY(ArcGraphPart);
45 
46  // copy the sets of parents
47  const NodeProperty< NodeSet* >& pars = s._parents_;
48  _parents_.resize(pars.capacity());
49 
50  for (const auto& elt: pars) {
51  NodeSet* newpar = new NodeSet(*elt.second);
52  _parents_.insert(elt.first, newpar);
53  }
54 
55  // copy the sets of children
56  const NodeProperty< NodeSet* >& children = s._children_;
57  _children_.resize(children.capacity());
58 
59  for (const auto& elt: children) {
60  NodeSet* newchildren = new NodeSet(*elt.second);
61  _children_.insert(elt.first, newchildren);
62  }
63 
64  // send signals to indicate that there are new arcs
65  if (onArcAdded.hasListener()) {
66  for (const auto& arc: _arcs_) {
67  GUM_EMIT2(onArcAdded, arc.tail(), arc.head());
68  }
69  }
70  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:82
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
+ Here is the call graph for this function:

◆ ~ArcGraphPart()

gum::ArcGraphPart::~ArcGraphPart ( )
virtual

destructor

Definition at line 72 of file arcGraphPart.cpp.

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

72  {
73  GUM_DESTRUCTOR(ArcGraphPart);
74  // be sure to deallocate all the parents and children sets
75  clearArcs();
76  }
void clearArcs()
removes all the arcs from the ArcGraphPart
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
+ Here is the call graph for this function:

Member Function Documentation

◆ _checkChildren_()

INLINE void gum::ArcGraphPart::_checkChildren_ ( NodeId  id) const
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 50 of file arcGraphPart_inl.h.

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

50  {
51  if (!_children_.exists(id)) { _children_.insert(id, new NodeSet); }
52  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
+ Here is the call graph for this function:

◆ _checkParents_()

INLINE void gum::ArcGraphPart::_checkParents_ ( NodeId  id) const
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 46 of file arcGraphPart_inl.h.

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

46  {
47  if (!_parents_.exists(id)) { _parents_.insert(id, new NodeSet); }
48  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call 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::DiGraph, and gum::DAG.

Definition at line 94 of file arcGraphPart_inl.h.

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

94  {
95  Arc arc(tail, head);
96 
97  _arcs_.insert(arc);
98  _checkParents_(head);
99  _checkChildren_(tail);
100  _parents_[head]->insert(tail);
101  _children_[tail]->insert(head);
102 
103  GUM_EMIT2(onArcAdded, tail, head);
104  }
void _checkParents_(NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
void _checkChildren_(NodeId id) const
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:82
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
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:

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

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

172  {
173  NodeSet res;
174  NodeSet tmp;
175  for (auto next: parents(id))
176  tmp.insert(next);
177 
178  while (!tmp.empty()) {
179  auto current = *(tmp.begin());
180  tmp.erase(current);
181  res.insert(current);
182  for (auto next: parents(current)) {
183  if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
184  }
185  }
186  return res;
187  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
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:

◆ arcs()

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

returns the set of arcs stored within the ArcGraphPart

Definition at line 38 of file arcGraphPart_inl.h.

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

38 { return _arcs_; }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ arcsProperty() [1/2]

template<typename VAL >
ArcProperty< VAL > gum::ArcGraphPart::arcsProperty ( VAL(*)(const Arc &)  f,
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.

◆ arcsProperty() [2/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.

◆ 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 66 of file arcGraphPart_inl.h.

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

66  {
67  NodeSet res;
68  for (const auto node: ids)
69  res += children(node);
70  return res;
71  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
+ 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 89 of file arcGraphPart_inl.h.

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

89  {
90  _checkChildren_(id);
91  return *(_children_[id]);
92  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
void _checkChildren_(NodeId id) const
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
+ Here is the call graph for this function:

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )

removes all the arcs from the ArcGraphPart

Definition at line 78 of file arcGraphPart.cpp.

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

78  {
79  for (const auto& elt: _parents_)
80  delete elt.second;
81 
82  _parents_.clear();
83 
84  for (const auto& elt: _children_)
85  delete elt.second;
86 
87  _children_.clear();
88 
89  // we need this copy only if at least one onArcDeleted listener exists
90  if (onArcDeleted.hasListener()) {
91  ArcSet tmp = _arcs_;
92  _arcs_.clear();
93 
94  for (const auto& arc: tmp)
95  GUM_EMIT2(onArcDeleted, arc.tail(), arc.head());
96  } else {
97  _arcs_.clear();
98  }
99  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:83
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
+ Here is the call 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 154 of file arcGraphPart.cpp.

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

154  {
155  NodeSet res;
156  NodeSet tmp;
157  for (auto next: children(id))
158  tmp.insert(next);
159 
160  while (!tmp.empty()) {
161  auto current = *(tmp.begin());
162  tmp.erase(current);
163  res.insert(current);
164  for (auto next: children(current)) {
165  if (!tmp.contains(next) && !res.contains(next)) { tmp.insert(next); }
166  }
167  }
168  return res;
169  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
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:

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

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

190  {
191  // not recursive version => use a FIFO for simulating the recursion
192  List< NodeId > nodeFIFO;
193  nodeFIFO.pushBack(n2);
194 
195  // mark[node] = successor if visited, else mark[node] does not exist
196  NodeProperty< NodeId > mark;
197  mark.insert(n2, n2);
198 
199  NodeId current;
200 
201  while (!nodeFIFO.empty()) {
202  current = nodeFIFO.front();
203  nodeFIFO.popFront();
204 
205  // check the parents
206 
207  for (const auto new_one: parents(current)) {
208  if (mark.exists(new_one)) // if this node is already marked, do not
209  continue; // check it again
210 
211  mark.insert(new_one, current);
212 
213  if (new_one == n1) {
214  std::vector< NodeId > v;
215 
216  for (current = n1; current != n2; current = mark[current])
217  v.push_back(current);
218 
219  v.push_back(n2);
220 
221  return v;
222  }
223 
224  nodeFIFO.pushBack(new_one);
225  }
226  }
227 
228  GUM_ERROR(NotFound, "no path found")
229  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing 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:

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

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

231  {
232  // not recursive version => use a FIFO for simulating the recursion
233  List< NodeId > nodeFIFO;
234  nodeFIFO.pushBack(n2);
235 
236  // mark[node] = successor if visited, else mark[node] does not exist
237  NodeProperty< NodeId > mark;
238  mark.insert(n2, n2);
239 
240  NodeId current;
241 
242  while (!nodeFIFO.empty()) {
243  current = nodeFIFO.front();
244  nodeFIFO.popFront();
245 
246  // check the parents
247  for (const auto new_one: parents(current)) {
248  if (mark.exists(new_one)) // the node has already been visited
249  continue;
250 
251  mark.insert(new_one, current);
252 
253  if (new_one == n1) {
254  std::vector< NodeId > v;
255 
256  for (current = n1; current != n2; current = mark[current])
257  v.push_back(current);
258 
259  v.push_back(n2);
260 
261  return v;
262  }
263 
264  nodeFIFO.pushBack(new_one);
265  }
266 
267  // check the children
268  for (const auto new_one: children(current)) {
269  if (mark.exists(new_one)) // the node has already been visited
270  continue;
271 
272  mark.insert(new_one, current);
273 
274  if (new_one == n1) {
275  std::vector< NodeId > v;
276 
277  for (current = n1; current != n2; current = mark[current])
278  v.push_back(current);
279 
280  v.push_back(n2);
281 
282  return v;
283  }
284 
285  nodeFIFO.pushBack(new_one);
286  }
287  }
288 
289  GUM_ERROR(NotFound, "no path found")
290  }
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
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:

◆ emptyArcs()

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

indicates wether the ArcGraphPart contains any arc

Definition at line 34 of file arcGraphPart_inl.h.

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

34 { return _arcs_.empty(); }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ 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 106 of file arcGraphPart_inl.h.

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

106  {
107  // ASSUMING tail and head exists in _parents_ anf _children_
108  // (if not, it is an error)
109  if (existsArc(arc)) {
110  NodeId tail = arc.tail(), head = arc.head();
111  _parents_[head]->erase(tail);
112  _children_[tail]->erase(head);
113  _arcs_.erase(arc);
114  GUM_EMIT2(onArcDeleted, tail, head);
115  }
116  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:83
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call 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 137 of file arcGraphPart_inl.h.

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

137  {
138  if (_children_.exists(id)) {
139  NodeSet& children = *(_children_[id]);
140 
141  for (auto iter = children.beginSafe(); // safe iterator needed here
142  iter != children.endSafe();
143  ++iter) {
144  // warning: use this erase so that you actually use the vritualized
145  // arc removal function
146  eraseArc(Arc(id, *iter));
147  }
148  }
149  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
+ 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 123 of file arcGraphPart_inl.h.

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

123  {
124  if (_parents_.exists(id)) {
125  NodeSet& parents = *(_parents_[id]);
126 
127  for (auto iter = parents.beginSafe(); // safe iterator needed here
128  iter != parents.endSafe();
129  ++iter) {
130  // warning: use this erase so that you actually use the virtualized
131  // arc removal function
132  eraseArc(Arc(*iter, id));
133  }
134  }
135  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ 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 118 of file arcGraphPart_inl.h.

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

118  {
119  for (const auto& arc: set)
120  eraseArc(arc);
121  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ Here is the call graph for this function:

◆ existsArc() [1/2]

INLINE bool gum::ArcGraphPart::existsArc ( const Arc arc) const

indicates whether a given arc exists

Parameters
arcthe arc we test whether or not it belongs to the ArcGraphPart

Definition at line 40 of file arcGraphPart_inl.h.

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

40 { return _arcs_.contains(arc); }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ 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 42 of file arcGraphPart_inl.h.

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

42  {
43  return _parents_.exists(head) && _parents_[head]->exists(tail);
44  }
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call graph for this function:

◆ family() [1/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 59 of file arcGraphPart_inl.h.

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

59  {
60  _checkParents_(id);
61  NodeSet res{id};
62  return res + parents(id);
63  }
void _checkParents_(NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
+ Here is the call graph for this function:

◆ family() [2/2]

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

returns the set of family nodes of a set of nodes

Definition at line 82 of file arcGraphPart_inl.h.

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

82  {
83  NodeSet res;
84  for (const auto node: ids)
85  res += family(node);
86  return res;
87  }
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
+ Here is the call graph for this function:

◆ listMapArcs()

template<typename VAL >
List< VAL > gum::ArcGraphPart::listMapArcs ( VAL(*)(const Arc &)  f) 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!=()

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

tests whether two ArcGraphParts contain different arcs

Parameters
pthe ArcGraphPart that we compare with this

Definition at line 182 of file arcGraphPart_inl.h.

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

182 { return _arcs_ != p._arcs_; }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ operator=()

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

copy operator

Parameters
sthe ArcGraphPart to copy

Definition at line 101 of file arcGraphPart.cpp.

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

101  {
102  // avoid self assignment
103  if (this != &s) {
104  // copy the arcs
105  clearArcs();
106  _arcs_ = s._arcs_;
107 
108  // copy the sets of parents
109  _parents_.resize(s._parents_.capacity());
110 
111  for (const auto& elt: s._parents_) {
112  NodeSet* newpar = new NodeSet(*elt.second);
113  _parents_.insert(elt.first, newpar);
114  }
115 
116  // copy the sets of children
117  _children_.resize(s._children_.capacity());
118 
119  for (const auto& elt: s._children_) {
120  NodeSet* newchildren = new NodeSet(*elt.second);
121  _children_.insert(elt.first, newchildren);
122  }
123 
124  if (onArcAdded.hasListener()) {
125  for (const auto& arc: _arcs_) {
126  GUM_EMIT2(onArcAdded, arc.tail(), arc.head());
127  }
128  }
129  }
130 
131  return *this;
132  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void clearArcs()
removes all the arcs from the ArcGraphPart
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:41
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:82
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call 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 180 of file arcGraphPart_inl.h.

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

180 { return _arcs_ == p._arcs_; }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ parents() [1/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 54 of file arcGraphPart_inl.h.

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

54  {
55  _checkParents_(id);
56  return *(_parents_[id]);
57  }
void _checkParents_(NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call graph for this function:

◆ parents() [2/2]

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

returns the set of parents of a set of nodes

Definition at line 74 of file arcGraphPart_inl.h.

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

74  {
75  NodeSet res;
76  for (const auto node: ids)
77  res += parents(node);
78  return res;
79  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
+ Here is the call graph for this function:

◆ sizeArcs()

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

indicates the number of arcs stored within the ArcGraphPart

Definition at line 36 of file arcGraphPart_inl.h.

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

36 { return _arcs_.size(); }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
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::ArcGraphPart::toString ( ) const

to friendly display the content of the ArcGraphPart

Definition at line 134 of file arcGraphPart.cpp.

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

134  {
135  std::stringstream s;
136  bool first = true;
137  s << "{";
138 
139  for (const auto& arc: _arcs_) {
140  if (first) {
141  first = false;
142  } else {
143  s << ",";
144  }
145 
146  s << arc;
147  }
148 
149  s << "}";
150 
151  return s.str();
152  }
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call 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 168 of file arcGraphPart_inl.h.

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

168  {
169  if (_children_.exists(id)) {
170  NodeSet& children = *(_children_[id]);
171 
172  for (auto iter = children.beginSafe(); // safe iterator needed here
173  iter != children.endSafe();
174  ++iter) {
175  ArcGraphPart::eraseArc(Arc(id, *iter));
176  }
177  }
178  }
NodeProperty< NodeSet *> _children_
for each arc, the set of its children
Definition: arcGraphPart.h:307
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
+ Here is the call 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 156 of file arcGraphPart_inl.h.

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

156  {
157  if (_parents_.exists(id)) {
158  NodeSet& parents = *(_parents_[id]);
159 
160  for (auto iter = parents.beginSafe(); // safe iterator needed here
161  iter != parents.endSafe();
162  ++iter) {
163  ArcGraphPart::eraseArc(Arc(*iter, id));
164  }
165  }
166  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
NodeProperty< NodeSet *> _parents_
for each arc, the sets of its parents
Definition: arcGraphPart.h:304
+ Here is the call 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 151 of file arcGraphPart_inl.h.

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

151  {
152  for (const auto& arc: set)
154  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ 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 301 of file arcGraphPart.h.

◆ _children_

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

for each arc, the set of its children

Definition at line 307 of file arcGraphPart.h.

◆ _parents_

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

for each arc, the sets of its parents

Definition at line 304 of file arcGraphPart.h.

◆ onArcAdded

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

Definition at line 82 of file arcGraphPart.h.

◆ onArcDeleted

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

Definition at line 83 of file arcGraphPart.h.


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