aGrUM  0.13.2
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 76 of file arcGraphPart.h.

Member Typedef Documentation

Definition at line 78 of file arcGraphPart.h.

Constructor & Destructor Documentation

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

36  :
37  __arcs(arcs_size, arcs_resize_policy) {
38  GUM_CONSTRUCTOR(ArcGraphPart);
39  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
gum::ArcGraphPart::ArcGraphPart ( const ArcGraphPart s)

copy constructor

Parameters
sthe ArcGraphPart to copy

Definition at line 41 of file arcGraphPart.cpp.

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

41  : __arcs(s.__arcs) {
42  GUM_CONS_CPY(ArcGraphPart);
43 
44  // copy the sets of parents
45  const NodeProperty< NodeSet* >& pars = s.__parents;
46  __parents.resize(pars.capacity());
47 
48  for (const auto& elt : pars) {
49  NodeSet* newpar = new NodeSet(*elt.second);
50  __parents.insert(elt.first, newpar);
51  }
52 
53  // copy the sets of children
54  const NodeProperty< NodeSet* >& children = s.__children;
55  __children.resize(children.capacity());
56 
57  for (const auto& elt : children) {
58  NodeSet* newchildren = new NodeSet(*elt.second);
59  __children.insert(elt.first, newchildren);
60  }
61 
62  // send signals to indicate that there are new arcs
63  if (onArcAdded.hasListener()) {
64  for (const auto& arc : __arcs) {
65  GUM_EMIT2(onArcAdded, arc.tail(), arc.head());
66  }
67  }
68  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:40
NodeProperty< NodeSet * > __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:80
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:272
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor

+ Here is the call graph for this function:

gum::ArcGraphPart::~ArcGraphPart ( )
virtual

destructor

Definition at line 70 of file arcGraphPart.cpp.

References clearArcs().

70  {
71  GUM_DESTRUCTOR(ArcGraphPart);
72  // be sure to deallocate all the parents and children sets
73  clearArcs();
74  }
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

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

References __children.

Referenced by addArc(), and children().

50  {
51  if (!__children.exists(id)) { __children.insert(id, new NodeSet); }
52  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet * > __children
for each arc, the set of its children
Definition: arcGraphPart.h:272

+ Here is the caller graph for this function:

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

References __parents.

Referenced by addArc(), and parents().

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:269

+ Here is the caller graph for this function:

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

References eraseArc().

88  {
89  for (const auto arc : set)
90  eraseArc(arc);
91  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart

+ Here is the call graph for this function:

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

References eraseArc().

121  {
122  for (const auto& arc : set)
124  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart

+ Here is the call graph for this function:

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 64 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().

64  {
65  Arc arc(tail, head);
66 
67  __arcs.insert(arc);
68  __checkParents(head);
69  __checkChildren(tail);
70  __parents[head]->insert(tail);
71  __children[tail]->insert(head);
72 
73  GUM_EMIT2(onArcAdded, tail, head);
74  }
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:40
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 * > __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:80
NodeProperty< NodeSet * > __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
void __checkParents(const NodeId id) const
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
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:

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

returns the set of arcs stored within the ArcGraphPart

Definition at line 36 of file arcGraphPart_inl.h.

References __arcs.

Referenced by gum::MarkovBlanket::arcs(), gum::EssentialGraph::arcs(), gum::DAGmodel::arcs(), gum::prm::gspan::Pattern::arcs(), and gum::DiGraph::toDot().

36 { return __arcs; }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266

+ Here is the caller graph for this function:

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

References __checkChildren(), and __children.

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__AR(), gum::EssentialGraph::__buildEssentialGraph(), gum::prm::PRMClass< GUM_SCALAR >::__checkInterface(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__connect(), gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__directedPath(), gum::prm::gspan::Pattern::__expandCodeIsMinimal(), gum::DAG::__hasDirectedPath(), gum::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitDn(), gum::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitUp(), gum::prm::gspan::Pattern::__not_rec(), gum::prm::PRMClass< GUM_SCALAR >::__overloadReference(), 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::prm::gspan::Pattern::isMinimal(), gum::IBayesNet< GUM_SCALAR >::minimalCondSet(), 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().

59  {
60  __checkChildren(id);
61  return *(__children[id]);
62  }
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:272

+ Here is the call graph for this function:

void gum::ArcGraphPart::clearArcs ( )

removes all the arcs from the ArcGraphPart

Definition at line 76 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().

76  {
77  for (const auto& elt : __parents)
78  delete elt.second;
79 
80  __parents.clear();
81 
82  for (const auto& elt : __children)
83  delete elt.second;
84 
85  __children.clear();
86 
87  // we need this copy only if at least one onArcDeleted listener exists
88  if (onArcDeleted.hasListener()) {
89  ArcSet tmp = __arcs;
90  __arcs.clear();
91 
92  for (const auto& arc : tmp)
93  GUM_EMIT2(onArcDeleted, arc.tail(), arc.head());
94  } else {
95  __arcs.clear();
96  }
97  }
Set< Arc > ArcSet
Some typdefs and define for shortcuts ...
#define GUM_EMIT2(signal, arg1, arg2)
Definition: signaler2.h:40
NodeProperty< NodeSet * > __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
NodeProperty< NodeSet * > __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:81
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:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 152 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().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 195 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().

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

+ Here is the call graph for this function:

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

indicates wether the ArcGraphPart contains any arc

Definition at line 32 of file arcGraphPart_inl.h.

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

32 { 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:266

+ Here is the call graph for this function:

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 76 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(), gum::BayesNet< GUM_SCALAR >::eraseArc(), eraseChildren(), eraseParents(), gum::learning::GreedyHillClimbing::learnStructure(), gum::learning::LocalSearchWithTabuList::learnStructure(), gum::prm::gspan::Pattern::pop_back(), gum::BayesNet< GUM_SCALAR >::reverseArc(), unvirtualizedEraseChildren(), and unvirtualizedEraseParents().

76  {
77  // ASSUMING tail and head exists in __parents anf __children
78  // (if not, it is an error)
79  if (existsArc(arc)) {
80  NodeId tail = arc.tail(), head = arc.head();
81  __parents[head]->erase(tail);
82  __children[tail]->erase(head);
83  __arcs.erase(arc);
84  GUM_EMIT2(onArcDeleted, tail, head);
85  }
86  }
unsigned int NodeId
Type for node ids.
Definition: graphElements.h:97
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:40
NodeProperty< NodeSet * > __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
NodeProperty< NodeSet * > __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
Signaler2< NodeId, NodeId > onArcDeleted
Definition: arcGraphPart.h:81
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

107  {
108  if (__children.exists(id)) {
109  NodeSet& children = *(__children[id]);
110 
111  for (auto iter = children.beginSafe(); // safe iterator needed here
112  iter != children.endSafe();
113  ++iter) {
114  // warning: use this erase so that you actually use the vritualized
115  // arc removal function
116  eraseArc(Arc(id, *iter));
117  }
118  }
119  }
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:272

+ Here is the call graph for this function:

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

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

Referenced by gum::prm::PRMClass< GUM_SCALAR >::__overloadAttribute().

93  {
94  if (__parents.exists(id)) {
95  NodeSet& parents = *(__parents[id]);
96 
97  for (auto iter = parents.beginSafe(); // safe iterator needed here
98  iter != parents.endSafe();
99  ++iter) {
100  // warning: use this erase so that you actually use the virtualized
101  // arc removal function
102  eraseArc(Arc(*iter, id));
103  }
104  }
105  }
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:269

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 38 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::prm::PRMClass< GUM_SCALAR >::addArc(), gum::DAGCycleDetector::addArc(), eraseArc(), gum::DAGCycleDetector::eraseArc(), gum::InfluenceDiagram< GUM_SCALAR >::eraseArc(), gum::prm::gspan::Pattern::exists(), and gum::BayesNet< GUM_SCALAR >::reverseArc().

38  {
39  return __arcs.contains(arc);
40  }
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:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References __parents.

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:269
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
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 154 of file arcGraphPart_inl.h.

References __arcs.

154  {
155  return __arcs != p.__arcs;
156  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266
ArcGraphPart & gum::ArcGraphPart::operator= ( const ArcGraphPart s)

copy operator

Parameters
sthe ArcGraphPart to copy

Definition at line 99 of file arcGraphPart.cpp.

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

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

99  {
100  // avoid self assignment
101  if (this != &s) {
102  // copy the arcs
103  clearArcs();
104  __arcs = s.__arcs;
105 
106  // copy the sets of parents
107  __parents.resize(s.__parents.capacity());
108 
109  for (const auto& elt : s.__parents) {
110  NodeSet* newpar = new NodeSet(*elt.second);
111  __parents.insert(elt.first, newpar);
112  }
113 
114  // copy the sets of children
115  __children.resize(s.__children.capacity());
116 
117  for (const auto& elt : s.__children) {
118  NodeSet* newchildren = new NodeSet(*elt.second);
119  __children.insert(elt.first, newchildren);
120  }
121 
122  if (onArcAdded.hasListener()) {
123  for (const auto& arc : __arcs) {
124  GUM_EMIT2(onArcAdded, arc.tail(), arc.head());
125  }
126  }
127  }
128 
129  return *this;
130  }
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:40
NodeProperty< NodeSet * > __parents
for each arc, the sets of its parents
Definition: arcGraphPart.h:269
Signaler2< NodeId, NodeId > onArcAdded
Definition: arcGraphPart.h:80
NodeProperty< NodeSet * > __children
for each arc, the set of its children
Definition: arcGraphPart.h:272
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

References __arcs.

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

150  {
151  return __arcs == p.__arcs;
152  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266

+ Here is the caller graph for this function:

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 54 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::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitDn(), gum::IBayesNet< GUM_SCALAR >::__minimalCondSetVisitUp(), 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::IBayesNet< GUM_SCALAR >::minimalCondSet(), gum::MixedGraph::mixedOrientedPath(), gum::MixedGraph::mixedUnorientedPath(), 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().

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

+ Here is the call graph for this function:

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

indicates the number of arcs stored within the ArcGraphPart

Definition at line 34 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(), gum::InfluenceDiagram< GUM_SCALAR >::toString(), and gum::IBayesNet< GUM_SCALAR >::toString().

34 { 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:266

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

to friendly display the content of the ArcGraphPart

Definition at line 132 of file arcGraphPart.cpp.

References __arcs.

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

132  {
133  std::stringstream s;
134  bool first = true;
135  s << "{";
136 
137  for (const auto& arc : __arcs) {
138  if (first) {
139  first = false;
140  } else {
141  s << ",";
142  }
143 
144  s << arc;
145  }
146 
147  s << "}";
148 
149  return s.str();
150  }
Set< Arc > __arcs
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:266

+ Here is the caller graph for this function:

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 138 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().

138  {
139  if (__children.exists(id)) {
140  NodeSet& children = *(__children[id]);
141 
142  for (auto iter = children.beginSafe(); // safe iterator needed here
143  iter != children.endSafe();
144  ++iter) {
145  ArcGraphPart::eraseArc(Arc(id, *iter));
146  }
147  }
148  }
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:272

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 126 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().

126  {
127  if (__parents.exists(id)) {
128  NodeSet& parents = *(__parents[id]);
129 
130  for (auto iter = parents.beginSafe(); // safe iterator needed here
131  iter != parents.endSafe();
132  ++iter) {
133  ArcGraphPart::eraseArc(Arc(*iter, id));
134  }
135  }
136  }
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:269

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

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

the set of all the arcs contained within the ArcGraphPart

Definition at line 266 of file arcGraphPart.h.

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

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

for each arc, the set of its children

Definition at line 272 of file arcGraphPart.h.

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

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

for each arc, the sets of its parents

Definition at line 269 of file arcGraphPart.h.

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

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

Definition at line 80 of file arcGraphPart.h.

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

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

Definition at line 81 of file arcGraphPart.h.

Referenced by clearArcs(), and eraseArc().


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