aGrUM  0.16.0
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 (const NodeId tail, const 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 (const NodeId tail, const 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 (const NodeId id) const
 returns the set of nodes with arc ingoing to a given node More...
 
const NodeSetchildren (const NodeId id) const
 returns the set of nodes with arc outgoing from a given node More...
 
void eraseParents (const NodeId id)
 erase all the parents of a given node More...
 
void unvirtualizedEraseParents (const NodeId id)
 same function as eraseParents but without any virtual call to an erase More...
 
void eraseChildren (const NodeId id)
 removes all the children of a given node More...
 
void unvirtualizedEraseChildren (const NodeId id)
 same function as eraseChildren but without any virtual call to an erase More...
 
const 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...
 
const std::vector< NodeIddirectedPath (const NodeId node1, const NodeId node2) const
 returns a directed path from node1 to node2 belonging to the set of arcs More...
 
const std::vector< NodeIddirectedUnorientedPath (const NodeId node1, const 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 and 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 79 of file arcGraphPart.h.

Member Typedef Documentation

◆ ArcIterator

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

39  :
40  __arcs(arcs_size, arcs_resize_policy) {
41  GUM_CONSTRUCTOR(ArcGraphPart);
42  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor

◆ ArcGraphPart() [2/2]

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

copy constructor

Parameters
sthe ArcGraphPart to copy

Definition at line 44 of file arcGraphPart.cpp.

References __arcs, __children, __parents, gum::HashTable< Key, Val, Alloc >::capacity(), children(), GUM_EMIT2, and onArcAdded.

44  : __arcs(s.__arcs) {
45  GUM_CONS_CPY(ArcGraphPart);
46 
47  // copy the sets of parents
48  const NodeProperty< NodeSet* >& pars = s.__parents;
49  __parents.resize(pars.capacity());
50 
51  for (const auto& elt : pars) {
52  NodeSet* newpar = new NodeSet(*elt.second);
53  __parents.insert(elt.first, newpar);
54  }
55 
56  // copy the sets of children
57  const NodeProperty< NodeSet* >& children = s.__children;
58  __children.resize(children.capacity());
59 
60  for (const auto& elt : children) {
61  NodeSet* newchildren = new NodeSet(*elt.second);
62  __children.insert(elt.first, newchildren);
63  }
64 
65  // send signals to indicate that there are new arcs
66  if (onArcAdded.hasListener()) {
67  for (const auto& arc : __arcs) {
68  GUM_EMIT2(onArcAdded, arc.tail(), arc.head());
69  }
70  }
71  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:42
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:83
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
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 73 of file arcGraphPart.cpp.

References clearArcs().

73  {
74  GUM_DESTRUCTOR(ArcGraphPart);
75  // be sure to deallocate all the parents and children sets
76  clearArcs();
77  }
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 ( const 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 53 of file arcGraphPart_inl.h.

References __children.

Referenced by addArc(), and children().

53  {
54  if (!__children.exists(id)) { __children.insert(id, new NodeSet); }
55  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
+ Here is the caller graph for this function:

◆ __checkParents()

INLINE void gum::ArcGraphPart::__checkParents ( const 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 49 of file arcGraphPart_inl.h.

References __parents.

Referenced by addArc(), and parents().

49  {
50  if (!__parents.exists(id)) { __parents.insert(id, new NodeSet); }
51  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
+ Here is the caller 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 91 of file arcGraphPart_inl.h.

References eraseArc().

91  {
92  for (const auto arc : set)
93  eraseArc(arc);
94  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ 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 124 of file arcGraphPart_inl.h.

References eraseArc().

124  {
125  for (const auto& arc : set)
127  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ Here is the call graph for this function:

◆ addArc()

INLINE void gum::ArcGraphPart::addArc ( const NodeId  tail,
const 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 67 of file arcGraphPart_inl.h.

References __arcs, __checkChildren(), __checkParents(), __children, __parents, GUM_EMIT2, gum::Set< Key, Alloc >::insert(), and onArcAdded.

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

67  {
68  Arc arc(tail, head);
69 
70  __arcs.insert(arc);
71  __checkParents(head);
72  __checkChildren(tail);
73  __parents[head]->insert(tail);
74  __children[tail]->insert(head);
75 
76  GUM_EMIT2(onArcAdded, tail, head);
77  }
void __checkParents(const NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
void __checkChildren(const 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:42
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:83
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
+ 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 39 of file arcGraphPart_inl.h.

References __arcs.

Referenced by gum::MarkovBlanket::arcs(), gum::EssentialGraph::arcs(), gum::DAGmodel::arcs(), gum::prm::gspan::Pattern::arcs(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::DAG::moralGraph(), and gum::DiGraph::toDot().

39 { return __arcs; }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
+ Here is the caller 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()

INLINE const NodeSet & gum::ArcGraphPart::children ( const 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 62 of file arcGraphPart_inl.h.

References __checkChildren(), and __children.

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::EssentialGraph::__buildEssentialGraph(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__directedPath(), gum::prm::gspan::Pattern::__expandCodeIsMinimal(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_initialize(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_makeInferenceNodeToNeighbours(), ArcGraphPart(), gum::MarkovBlanket::children(), gum::EssentialGraph::children(), gum::DAGmodel::children(), directedUnorientedPath(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), eraseChildren(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), gum::DiGraph::hasDirectedPath(), gum::prm::gspan::Pattern::isMinimal(), gum::MixedGraph::mixedUnorientedPath(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::MarkovBlanket::toDot(), gum::EssentialGraph::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), gum::MixedGraph::toDot(), and unvirtualizedEraseChildren().

62  {
63  __checkChildren(id);
64  return *(__children[id]);
65  }
void __checkChildren(const NodeId id) const
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
+ Here is the call graph for this function:

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )

removes all the arcs from the ArcGraphPart

Definition at line 79 of file arcGraphPart.cpp.

References __arcs, __children, __parents, gum::Set< Key, Alloc >::clear(), GUM_EMIT2, and onArcDeleted.

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

79  {
80  for (const auto& elt : __parents)
81  delete elt.second;
82 
83  __parents.clear();
84 
85  for (const auto& elt : __children)
86  delete elt.second;
87 
88  __children.clear();
89 
90  // we need this copy only if at least one onArcDeleted listener exists
91  if (onArcDeleted.hasListener()) {
92  ArcSet tmp = __arcs;
93  __arcs.clear();
94 
95  for (const auto& arc : tmp)
96  GUM_EMIT2(onArcDeleted, arc.tail(), arc.head());
97  } else {
98  __arcs.clear();
99  }
100  }
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:42
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:84
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:375
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ directedPath()

const std::vector< NodeId > gum::ArcGraphPart::directedPath ( const NodeId  node1,
const 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 155 of file arcGraphPart.cpp.

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

Referenced by gum::learning::Miic::_orientation_latents().

156  {
157  // not recursive version => use a FIFO for simulating the recursion
158  List< NodeId > nodeFIFO;
159  nodeFIFO.pushBack(n2);
160 
161  // mark[node] = successor if visited, else mark[node] does not exist
162  NodeProperty< NodeId > mark;
163  mark.insert(n2, n2);
164 
165  NodeId current;
166 
167  while (!nodeFIFO.empty()) {
168  current = nodeFIFO.front();
169  nodeFIFO.popFront();
170 
171  // check the parents
172 
173  for (const auto new_one : parents(current)) {
174  if (mark.exists(new_one)) // if this node is already marked, do not
175  continue; // check it again
176 
177  mark.insert(new_one, current);
178 
179  if (new_one == n1) {
180  std::vector< NodeId > v;
181 
182  for (current = n1; current != n2; current = mark[current])
183  v.push_back(current);
184 
185  v.push_back(n2);
186 
187  return v;
188  }
189 
190  nodeFIFO.pushBack(new_one);
191  }
192  }
193 
194  GUM_ERROR(NotFound, "no path found");
195  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ directedUnorientedPath()

const std::vector< NodeId > gum::ArcGraphPart::directedUnorientedPath ( const NodeId  node1,
const 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 198 of file arcGraphPart.cpp.

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

198  {
199  // not recursive version => use a FIFO for simulating the recursion
200  List< NodeId > nodeFIFO;
201  nodeFIFO.pushBack(n2);
202 
203  // mark[node] = successor if visited, else mark[node] does not exist
204  NodeProperty< NodeId > mark;
205  mark.insert(n2, n2);
206 
207  NodeId current;
208 
209  while (!nodeFIFO.empty()) {
210  current = nodeFIFO.front();
211  nodeFIFO.popFront();
212 
213  // check the parents
214  for (const auto new_one : parents(current)) {
215  if (mark.exists(new_one)) // the node has already been visited
216  continue;
217 
218  mark.insert(new_one, current);
219 
220  if (new_one == n1) {
221  std::vector< NodeId > v;
222 
223  for (current = n1; current != n2; current = mark[current])
224  v.push_back(current);
225 
226  v.push_back(n2);
227 
228  return v;
229  }
230 
231  nodeFIFO.pushBack(new_one);
232  }
233 
234  // check the children
235  for (const auto new_one : children(current)) {
236  if (mark.exists(new_one)) // the node has already been visited
237  continue;
238 
239  mark.insert(new_one, current);
240 
241  if (new_one == n1) {
242  std::vector< NodeId > v;
243 
244  for (current = n1; current != n2; current = mark[current])
245  v.push_back(current);
246 
247  v.push_back(n2);
248 
249  return v;
250  }
251 
252  nodeFIFO.pushBack(new_one);
253  }
254  }
255 
256  GUM_ERROR(NotFound, "no path found");
257  }
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 35 of file arcGraphPart_inl.h.

References __arcs, and gum::Set< Key, Alloc >::empty().

35 { return __arcs.empty(); }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:707
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
+ 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 79 of file arcGraphPart_inl.h.

References __arcs, __children, __parents, gum::Set< Key, Alloc >::erase(), existsArc(), GUM_EMIT2, gum::Arc::head(), onArcDeleted, and gum::Arc::tail().

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::learning::genericBNLearner::__learnDAG(), _eraseSetOfArcs(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::BayesNetFragment< GUM_SCALAR >::_uninstallArc(), _unvirtualizedEraseSetOfArcs(), gum::DAGCycleDetector::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), eraseChildren(), eraseParents(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::prm::gspan::Pattern::pop_back(), gum::BayesNet< double >::reverseArc(), unvirtualizedEraseChildren(), and unvirtualizedEraseParents().

79  {
80  // ASSUMING tail and head exists in __parents anf __children
81  // (if not, it is an error)
82  if (existsArc(arc)) {
83  NodeId tail = arc.tail(), head = arc.head();
84  __parents[head]->erase(tail);
85  __children[tail]->erase(head);
86  __arcs.erase(arc);
87  GUM_EMIT2(onArcDeleted, tail, head);
88  }
89  }
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:42
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:84
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eraseChildren()

INLINE void gum::ArcGraphPart::eraseChildren ( const 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 110 of file arcGraphPart_inl.h.

References __children, gum::Set< Key, Alloc >::beginSafe(), children(), gum::Set< Key, Alloc >::endSafe(), and eraseArc().

110  {
111  if (__children.exists(id)) {
112  NodeSet& children = *(__children[id]);
113 
114  for (auto iter = children.beginSafe(); // safe iterator needed here
115  iter != children.endSafe();
116  ++iter) {
117  // warning: use this erase so that you actually use the vritualized
118  // arc removal function
119  eraseArc(Arc(id, *iter));
120  }
121  }
122  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
+ Here is the call graph for this function:

◆ eraseParents()

INLINE void gum::ArcGraphPart::eraseParents ( const 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 96 of file arcGraphPart_inl.h.

References __parents, gum::Set< Key, Alloc >::beginSafe(), gum::Set< Key, Alloc >::endSafe(), eraseArc(), and parents().

96  {
97  if (__parents.exists(id)) {
98  NodeSet& parents = *(__parents[id]);
99 
100  for (auto iter = parents.beginSafe(); // safe iterator needed here
101  iter != parents.endSafe();
102  ++iter) {
103  // warning: use this erase so that you actually use the virtualized
104  // arc removal function
105  eraseArc(Arc(*iter, id));
106  }
107  }
108  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
+ 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 41 of file arcGraphPart_inl.h.

References __arcs, and gum::Set< Key, Alloc >::contains().

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AorR(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__directedPath(), gum::learning::Miic::__existsDirectedPath(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__jump_multi(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__jump_poly(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_updateProbaTriples(), gum::DAGCycleDetector::addArc(), eraseArc(), gum::DAGCycleDetector::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), and gum::prm::gspan::Pattern::exists().

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

◆ existsArc() [2/2]

INLINE bool gum::ArcGraphPart::existsArc ( const NodeId  tail,
const 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 45 of file arcGraphPart_inl.h.

References __parents.

45  {
46  return __parents.exists(head) && __parents[head]->exists(tail);
47  }
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272

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

References __arcs.

157  {
158  return __arcs != p.__arcs;
159  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269

◆ operator=()

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

copy operator

Parameters
sthe ArcGraphPart to copy

Definition at line 102 of file arcGraphPart.cpp.

References __arcs, __children, __parents, clearArcs(), GUM_EMIT2, and onArcAdded.

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

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

References __arcs.

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

153  {
154  return __arcs == p.__arcs;
155  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
+ Here is the caller graph for this function:

◆ parents()

INLINE const NodeSet & gum::ArcGraphPart::parents ( const 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 57 of file arcGraphPart_inl.h.

References __checkParents(), and __parents.

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::learning::Miic::__existsDirectedPath(), gum::prm::gspan::Pattern::__expandCodeIsMinimal(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClass(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClasses(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateCluster(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::gspan::Pattern::__rec(), gum::EssentialGraph::__strongly_protected(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_initialize(), gum::credal::CNLoopyPropagation< GUM_SCALAR >::_makeInferenceNodeToNeighbours(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_propagatesHead(), gum::BarrenNodesFinder::barrenNodes(), directedPath(), directedUnorientedPath(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), eraseParents(), gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder(), gum::prm::gspan::Pattern::isMinimal(), gum::learning::Miic::learnStructure(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), gum::DAG::moralGraph(), gum::prm::gspan::DFSTree< GUM_SCALAR >::parent(), gum::MarkovBlanket::parents(), gum::EssentialGraph::parents(), gum::DAGmodel::parents(), gum::BayesBall::relevantPotentials(), gum::dSeparation::relevantPotentials(), gum::prm::gspan::Pattern::remove(), gum::BayesBall::requisiteNodes(), gum::dSeparation::requisiteNodes(), gum::prm::gspan::Pattern::rightmostPath(), and unvirtualizedEraseParents().

57  {
58  __checkParents(id);
59  return *(__parents[id]);
60  }
void __checkParents(const 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:272
+ 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 37 of file arcGraphPart_inl.h.

References __arcs, and gum::Set< Key, Alloc >::size().

Referenced by gum::MarkovBlanket::sizeArcs(), gum::EssentialGraph::sizeArcs(), gum::DAGmodel::sizeArcs(), gum::prm::gspan::Pattern::sizeArcs(), and gum::InfluenceDiagram< GUM_SCALAR >::toString().

37 { return __arcs.size(); }
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

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

to friendly display the content of the ArcGraphPart

Definition at line 135 of file arcGraphPart.cpp.

References __arcs.

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

135  {
136  std::stringstream s;
137  bool first = true;
138  s << "{";
139 
140  for (const auto& arc : __arcs) {
141  if (first) {
142  first = false;
143  } else {
144  s << ",";
145  }
146 
147  s << arc;
148  }
149 
150  s << "}";
151 
152  return s.str();
153  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:269
+ Here is the caller graph for this function:

◆ unvirtualizedEraseChildren()

INLINE void gum::ArcGraphPart::unvirtualizedEraseChildren ( const 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 141 of file arcGraphPart_inl.h.

References __children, gum::Set< Key, Alloc >::beginSafe(), children(), gum::Set< Key, Alloc >::endSafe(), and eraseArc().

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

141  {
142  if (__children.exists(id)) {
143  NodeSet& children = *(__children[id]);
144 
145  for (auto iter = children.beginSafe(); // safe iterator needed here
146  iter != children.endSafe();
147  ++iter) {
148  ArcGraphPart::eraseArc(Arc(id, *iter));
149  }
150  }
151  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const NodeSet & children(const NodeId id) const
returns the set of nodes with arc outgoing from a given node
NodeProperty< NodeSet *> __children
for each arc, the set of its children
Definition: arcGraphPart.h:275
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unvirtualizedEraseParents()

INLINE void gum::ArcGraphPart::unvirtualizedEraseParents ( const 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 129 of file arcGraphPart_inl.h.

References __parents, gum::Set< Key, Alloc >::beginSafe(), gum::Set< Key, Alloc >::endSafe(), eraseArc(), and parents().

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

129  {
130  if (__parents.exists(id)) {
131  NodeSet& parents = *(__parents[id]);
132 
133  for (auto iter = parents.beginSafe(); // safe iterator needed here
134  iter != parents.endSafe();
135  ++iter) {
136  ArcGraphPart::eraseArc(Arc(*iter, id));
137  }
138  }
139  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
const NodeSet & parents(const NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeProperty< NodeSet *> __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:272
+ Here is the call graph for this function:
+ Here is the caller 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 269 of file arcGraphPart.h.

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

◆ __children

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

for each arc, the set of its children

Definition at line 275 of file arcGraphPart.h.

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

◆ __parents

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

for each arc, the sets of its parents

Definition at line 272 of file arcGraphPart.h.

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

◆ onArcAdded

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

Definition at line 83 of file arcGraphPart.h.

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

◆ onArcDeleted

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

Definition at line 84 of file arcGraphPart.h.

Referenced by clearArcs(), and eraseArc().


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