aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::prm::gspan::Pattern Class Reference

This contains all the information we want for a node in a DFSTree. More...

#include <agrum/PRM/gspan/pattern.h>

+ Inheritance diagram for gum::prm::gspan::Pattern:
+ Collaboration diagram for gum::prm::gspan::Pattern:

Public Member Functions

Constructor and destructor.
 Pattern ()
 Default constructor. More...
 
 Pattern (const Pattern &source)
 Copy constructor. More...
 
 ~Pattern ()
 Destructor. More...
 
Graphical getters and setters.
NodeId addNodeWithLabel (LabelData &l)
 Insert a node with the given LabelData. More...
 
LabelDatalabel (NodeId node)
 Returns the LabelData assigned to node. More...
 
const LabelDatalabel (NodeId node) const
 Returns the LabelData assigned to node. More...
 
LabelDatalabel (NodeId i, NodeId j)
 Returns the LabelData assigned to arc. More...
 
const LabelDatalabel (NodeId i, NodeId j) const
 Returns the LabelData assigned to arc. More...
 
LabelDatalabel (const Arc &arc)
 Returns the LabelData assigned to arc. More...
 
const LabelDatalabel (const Arc &arc) const
 Returns the LabelData assigned to arc. More...
 
LabelDatalastAdded ()
 Insert a node with the given LabelData. More...
 
const LabelDatalastAdded () const
 Insert a node with the given LabelData. More...
 
void addArc (NodeId i, NodeId j, LabelData &l)
 Add an arc to this Pattern. More...
 
bool exists (NodeId id) const
 Returns true if id is a node in this Pattern. More...
 
bool exists (NodeId tail, NodeId head) const
 Returns true if (tail, head) is an arc in this Pattern. More...
 
Size size () const
 Returns the number of nodes in this Pattern. More...
 
Size sizeArcs () const
 Returns the number of arcs in this Pattern. More...
 
void rightmostPath (std::list< NodeId > &r_path) const
 Fill r_path with the rightmost path of this Pattern. The list is supposed empty. More...
 
std::string toDot (size_t name) const
 Print the pattern in the DOT syntax. More...
 
Access to topology
const NodeGraphPartnodes () const
 
const ArcSetarcs () const
 
DFSCode related methods.
DFSCodecode ()
 Returns the DFSCode of this Pattern. More...
 
const DFSCodecode () const
 Returns the DFSCode of this Pattern. More...
 
EdgeCodeedgeCode (NodeId tail, NodeId head)
 Returns the EdgeCode of an edge of this Pattern. More...
 
EdgeCodeedgeCode (const Arc &arc)
 Returns the EdgeCode of an edge of this Pattern. More...
 
const EdgeCodeedgeCode (NodeId tail, NodeId head) const
 Returns the EdgeCode of an edge of this Pattern. More...
 
const EdgeCodeedgeCode (const Arc &arc) const
 Returns the EdgeCode of an edge of this Pattern. More...
 
void pop_back ()
 Remove the last EdgeCode of this pattern. More...
 
void remove (NodeId node)
 Remove a node if it has no neighbors, raise an OperationNotAllowed otherwise. More...
 
bool isMinimal ()
 Returns the DFSCode of this Pattern. More...
 

Detailed Description

This contains all the information we want for a node in a DFSTree.

Several rules are used regarding nodes in Pattern::graph. First nodes are added respecting a depth-first search, thus each node is labelled from 1 to n, where n is the number of nodes in Pattern::graph.

Given two nodes id i and j, if i < j then i was discovered before j in the depth first search.

To retrieve the depth first search tree from Pattern::graph simple consider only arcs (u, v) with u < v. The set of arcs { (u,v) | u < v} is called the forward edge set and the set of arcs { (u,v) | u > v} is called the backward edge set.

The orientation in Pattern::graph is only used to differentiate forward edges from backward edges.

Definition at line 72 of file pattern.h.

Member Typedef Documentation

◆ ArcIterator

Definition at line 80 of file arcGraphPart.h.

◆ node_const_iterator

types for STL compliance

Definition at line 258 of file nodeGraphPart.h.

◆ node_const_iterator_safe

types for STL compliance

Definition at line 260 of file nodeGraphPart.h.

◆ node_iterator

types for STL compliance

Definition at line 257 of file nodeGraphPart.h.

◆ node_iterator_safe

types for STL compliance

Definition at line 259 of file nodeGraphPart.h.

◆ NodeConstIterator

Definition at line 267 of file nodeGraphPart.h.

◆ NodeConstIteratorSafe

◆ NodeIterator

Definition at line 266 of file nodeGraphPart.h.

◆ NodeIteratorSafe

Constructor & Destructor Documentation

◆ Pattern() [1/2]

INLINE gum::prm::gspan::Pattern::Pattern ( )

Default constructor.

Definition at line 34 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

34 : DiGraph(), last__(0) { GUM_CONSTRUCTOR(Pattern); }
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Definition: diGraph.cpp:36
Pattern()
Default constructor.
Definition: pattern_inl.h:34
LabelData * last__
The last LabelData added to this pattern.
Definition: pattern.h:215
+ Here is the call graph for this function:

◆ Pattern() [2/2]

gum::prm::gspan::Pattern::Pattern ( const Pattern source)

Copy constructor.

Definition at line 39 of file pattern.cpp.

References gum::prm::gspan::operator<<().

39  : DiGraph(), last__(0) {
40  GUM_CONS_CPY(Pattern);
41  NodeProperty< NodeId > node_map;
42 
43  for (NodeId node = 1; node <= source.size(); ++node) {
44  node_map.insert(
45  node,
46  addNodeWithLabel(const_cast< LabelData& >(source.label(node))));
47  }
48 
49  for (const auto& edge: source.code().codes)
50  addArc(node_map[edge->i],
51  node_map[edge->j],
52  const_cast< LabelData& >(
53  source.label(node_map[edge->i], node_map[edge->j])));
54  }
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Definition: diGraph.cpp:36
Pattern()
Default constructor.
Definition: pattern_inl.h:34
NodeId addNodeWithLabel(LabelData &l)
Insert a node with the given LabelData.
Definition: pattern_inl.h:40
LabelData * last__
The last LabelData added to this pattern.
Definition: pattern.h:215
void addArc(NodeId i, NodeId j, LabelData &l)
Add an arc to this Pattern.
Definition: pattern_inl.h:117
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ ~Pattern()

INLINE gum::prm::gspan::Pattern::~Pattern ( )

Destructor.

Definition at line 37 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

37 { GUM_DESTRUCTOR(Pattern); }
Pattern()
Default constructor.
Definition: pattern_inl.h:34
+ Here is the call graph for this function:

Member Function Documentation

◆ addArc() [1/2]

INLINE void gum::prm::gspan::Pattern::addArc ( NodeId  i,
NodeId  j,
LabelData l 
)

Add an arc to this Pattern.

This create an EdgeCode and check if it respects neighborhood restriction, if not an exception is raised.

Parameters
iThe DFS subscript of the first node in the code.
jThe DFS subscript of the second node in the code.
lThe label data of the added edge.
Exceptions
OperationNotAllowedRaised if the neighborhood restriction is not respected.

Definition at line 117 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

117  {
118  if (!(DiGraph::exists(i) && DiGraph::exists(j))) {
119  GUM_ERROR(NotFound, "node not found in this pattern");
120  }
121 
122  EdgeCode* edge
123  = new EdgeCode(i, j, node_map__[i]->id, l.id, node_map__[j]->id);
124 
125  if ((code().codes.size() == 0)
126  || (DFSCode::validNeighbors(code().codes.back(), edge))) {
127  DiGraph::addArc(i, j);
128  arc_map__.insert(Arc(i, j), std::make_pair(&l, edge));
129  code().codes.push_back(edge);
130  } else {
131  delete edge;
132  GUM_ERROR(OperationNotAllowed,
133  "illegal arc considering neighborhood restriction");
134  }
135  }
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
Definition: diGraph_inl.h:34
DFSCode & code()
Returns the DFSCode of this Pattern.
Definition: pattern_inl.h:172
bool exists(const NodeId id) const
alias for existsNode
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
static bool validNeighbors(EdgeCode *e1, EdgeCode *e2)
Returns true of e2 is a valid neighbor for e1 (i.e.
Definition: DFSCode.h:141
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
NodeProperty< LabelData *> node_map__
Mapping between nodes in this Pattern and their respective LabelData.
Definition: pattern.h:208
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ addArc() [2/2]

INLINE void gum::DiGraph::addArc ( const NodeId  tail,
const NodeId  head 
)
virtualinherited

insert a new arc into the directed graph

Parameters
tailthe id of the tail of the new inserted arc
headthe id of the head of the new inserted arc
Warning
if the arc already exists, nothing is done. In particular, no exception is raised.
Exceptions
InvalidNodeif head or tail does not belong to the graph nodes

Reimplemented from gum::ArcGraphPart.

Reimplemented in gum::DAG.

Definition at line 34 of file diGraph_inl.h.

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

34  {
35  if (!exists(head)) { GUM_ERROR(InvalidNode, "no head node : " << head); }
36 
37  if (!exists(tail)) { GUM_ERROR(InvalidNode, "no tail node : " << tail); }
38 
39  ArcGraphPart::addArc(tail, head);
40  }
bool exists(const NodeId id) const
alias for existsNode
virtual void addArc(NodeId tail, NodeId head)
insert a new arc into the ArcGraphPart
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ addNode()

INLINE NodeId gum::NodeGraphPart::addNode ( )
virtualinherited

insert a new node and return its id

Returns
the id chosen by the internal idFactory

Reimplemented in gum::CliqueGraph.

Definition at line 252 of file nodeGraphPart_inl.h.

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

252  {
253  NodeId newNode;
254 
255  // fill the first hole if holes exist
256  if (holes__ && (!holes__->empty())) {
257  newNode = *(holes__->begin());
258  eraseHole__(newNode);
259  } else {
260  newNode = boundVal__;
261  ++boundVal__;
263  }
264 
265  GUM_EMIT1(onNodeAdded, newNode);
266 
267  return newNode;
268  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:726
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:516
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
Signaler1< NodeId > onNodeAdded
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
void updateEndIteratorSafe__()
updating endIterator (always at max__+1)
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void eraseHole__(NodeId id)
to delete hole.
+ Here is the call graph for this function:

◆ addNodes()

INLINE std::vector< NodeId > gum::NodeGraphPart::addNodes ( Size  n)
inherited

insert n nodes

Parameters
nthe number of nodes to add
Returns
the vector of chosen ids

Definition at line 270 of file nodeGraphPart_inl.h.

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

270  {
271  std::vector< NodeId > v;
272  v.reserve(N);
273  for (Idx i = 0; i < N; i++)
274  v.push_back(this->addNode());
275  return v;
276  }
+ Here is the call graph for this function:

◆ addNodeWithId()

void gum::NodeGraphPart::addNodeWithId ( const NodeId  id)
virtualinherited

try to insert a node with the given id

Warning
This method should be carefully used. Please prefer populateNodes or populateNodesFromProperty when possible
Exceptions
DuplicateElementexception if the id already exists

Definition at line 131 of file nodeGraphPart.cpp.

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

131  {
132  if (id >= boundVal__) {
133  if (id > boundVal__) { // we have to add holes
135 
136  for (NodeId i = boundVal__; i < id; ++i)
137  holes__->insert(i);
138  }
139 
140  boundVal__ = id + 1;
141 
143  } else {
144  if (inHoles__(id)) { // we fill a hole
145  eraseHole__(id);
146  } else {
147  GUM_ERROR(DuplicateElement, "Id " << id << " is already used");
148  }
149  }
150 
151  GUM_EMIT1(onNodeAdded, id);
152  }
bool holes_resize_policy__
value for holes__ configuration
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
Signaler1< NodeId > onNodeAdded
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
void updateEndIteratorSafe__()
updating endIterator (always at max__+1)
bool inHoles__(NodeId id) const
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
void eraseHole__(NodeId id)
to delete hole.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
Size holes_size__
value for holes__ configuration
+ Here is the call graph for this function:

◆ addNodeWithLabel()

INLINE NodeId gum::prm::gspan::Pattern::addNodeWithLabel ( LabelData l)

Insert a node with the given LabelData.

Returns
The id assigned to the inserted node.

Definition at line 40 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

40  {
41  NodeId n = NodeId(size() + 1);
43  node_map__.insert(n, &l);
44  last__ = &l;
45  return n;
46  }
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
Size size() const
Returns the number of nodes in this Pattern.
Definition: pattern_inl.h:146
LabelData * last__
The last LabelData added to this pattern.
Definition: pattern.h:215
Size NodeId
Type for node ids.
Definition: graphElements.h:97
NodeProperty< LabelData *> node_map__
Mapping between nodes in this Pattern and their respective LabelData.
Definition: pattern.h:208
+ Here is the call graph for this function:

◆ ancestors()

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

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:632
+ Here is the call graph for this function:

◆ arcs()

INLINE const ArcSet & gum::prm::gspan::Pattern::arcs ( ) const

Definition at line 169 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

169 { return DiGraph::arcs(); }
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
+ 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
inherited

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
inherited

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.

◆ asNodeSet()

INLINE NodeSet gum::NodeGraphPart::asNodeSet ( ) const
inherited

returns a copy of the set of nodes represented by the NodeGraphPart

Warning
this function is o(n) where n is the number of nodes. In space and in time. Usually, when you need to parse the nodes of a NodeGraphPart, prefer using
for(const auto n : nodes())
rather than
for(const auto n : asNodeSet())
as this is faster and consumes much less memory.

Definition at line 360 of file nodeGraphPart_inl.h.

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

360  {
361  NodeSet son(sizeNodes());
362 
363  if (!empty()) {
364  for (NodeId n = 0; n < boundVal__; ++n) {
365  if (!inHoles__(n)) son.insert(n);
366  }
367  }
368 
369  return son;
370  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool empty() const
alias for emptyNodes
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
bool inHoles__(NodeId id) const
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ begin()

INLINE NodeGraphPartIterator gum::NodeGraphPart::begin ( ) const
noexceptinherited

a begin iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 332 of file nodeGraphPart_inl.h.

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

332  {
333  NodeGraphPartIterator it(*this);
334  it.validate_(); // stop the iterator at the first not-in-holes
335  return it;
336  }
friend class NodeGraphPartIterator
+ Here is the call graph for this function:

◆ beginSafe()

INLINE NodeGraphPartIteratorSafe gum::NodeGraphPart::beginSafe ( ) const
inherited

a begin iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 318 of file nodeGraphPart_inl.h.

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

318  {
319  NodeGraphPartIteratorSafe it(*this);
320  it.validate_(); // stop the iterator at the first not-in-holes
321  return it;
322  }
friend class NodeGraphPartIteratorSafe
+ Here is the call graph for this function:

◆ bound()

INLINE NodeId gum::NodeGraphPart::bound ( ) const
inherited

returns a number n such that all node ids are strictly lower than n

Definition at line 307 of file nodeGraphPart_inl.h.

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

307 { return boundVal__; }
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ children() [1/2]

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

returns the set of children of a set of nodes

Definition at line 68 of file arcGraphPart_inl.h.

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

68  {
69  NodeSet res;
70  for (const auto node: ids)
71  res += children(node);
72  return res;
73  }
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
inherited

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

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

91  {
92  checkChildren__(id);
93  return *(children__[id]);
94  }
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:

◆ clear()

INLINE void gum::DiGraph::clear ( )
virtualinherited

removes all the nodes and arcs from the graph

Reimplemented from gum::NodeGraphPart.

Reimplemented in gum::MixedGraph.

Definition at line 42 of file diGraph_inl.h.

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

42  {
45  }
void clearArcs()
removes all the arcs from the ArcGraphPart
virtual void clearNodes()
remove all the nodes from the NodeGraphPart
+ Here is the call graph for this function:

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )
inherited

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:374
+ Here is the call graph for this function:

◆ clearNodes()

INLINE void gum::NodeGraphPart::clearNodes ( )
virtualinherited

remove all the nodes from the NodeGraphPart

Definition at line 309 of file nodeGraphPart_inl.h.

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

309 { clearNodes__(); }
void clearNodes__()
code for clearing nodes (called twice)
+ Here is the call graph for this function:

◆ code() [1/2]

INLINE DFSCode & gum::prm::gspan::Pattern::code ( )

Returns the DFSCode of this Pattern.

Definition at line 172 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

172 { return code__; }
DFSCode code__
The DFSCode of this Pattern.
Definition: pattern.h:204
+ Here is the call graph for this function:

◆ code() [2/2]

INLINE const DFSCode & gum::prm::gspan::Pattern::code ( ) const

Returns the DFSCode of this Pattern.

Definition at line 175 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

175 { return code__; }
DFSCode code__
The DFSCode of this Pattern.
Definition: pattern.h:204
+ Here is the call graph for this function:

◆ descendants()

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

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:632
+ Here is the call graph for this function:

◆ directedPath()

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

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:54
+ Here is the call graph for this function:

◆ directedUnorientedPath()

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

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

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

◆ edgeCode() [1/4]

INLINE EdgeCode & gum::prm::gspan::Pattern::edgeCode ( NodeId  tail,
NodeId  head 
)

Returns the EdgeCode of an edge of this Pattern.

Definition at line 178 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

178  {
179  try {
180  return *(arc_map__[Arc(tail, head)].second);
181  } catch (NotFound&) { GUM_ERROR(NotFound, "arc not found in Pattern"); }
182  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ edgeCode() [2/4]

INLINE EdgeCode & gum::prm::gspan::Pattern::edgeCode ( const Arc arc)

Returns the EdgeCode of an edge of this Pattern.

Definition at line 185 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

185  {
186  try {
187  return *(arc_map__[arc].second);
188  } catch (NotFound&) { GUM_ERROR(NotFound, "arc not found in Pattern"); }
189  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ edgeCode() [3/4]

INLINE const EdgeCode & gum::prm::gspan::Pattern::edgeCode ( NodeId  tail,
NodeId  head 
) const

Returns the EdgeCode of an edge of this Pattern.

Definition at line 192 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

192  {
193  try {
194  return *(arc_map__[Arc(tail, head)].second);
195  } catch (NotFound&) { GUM_ERROR(NotFound, "arc not found in Pattern"); }
196  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ edgeCode() [4/4]

INLINE const EdgeCode & gum::prm::gspan::Pattern::edgeCode ( const Arc arc) const

Returns the EdgeCode of an edge of this Pattern.

Definition at line 199 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

199  {
200  try {
201  return *(arc_map__[arc].second);
202  } catch (NotFound&) { GUM_ERROR(NotFound, "arc not found in Pattern"); }
203  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ empty()

INLINE bool gum::NodeGraphPart::empty ( ) const
inherited

alias for emptyNodes

Definition at line 305 of file nodeGraphPart_inl.h.

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

305 { return emptyNodes(); }
bool emptyNodes() const
indicates whether there exists nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ emptyArcs()

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

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

◆ emptyNodes()

INLINE bool gum::NodeGraphPart::emptyNodes ( ) const
inherited

indicates whether there exists nodes in the NodeGraphPart

Definition at line 303 of file nodeGraphPart_inl.h.

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

303 { return (sizeNodes() == 0); }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
+ Here is the call graph for this function:

◆ end()

INLINE const NodeGraphPartIterator & gum::NodeGraphPart::end ( ) const
noexceptinherited

the end iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 338 of file nodeGraphPart_inl.h.

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

338  {
339  return endIteratorSafe__;
340  }
NodeGraphPartIteratorSafe endIteratorSafe__
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ endSafe()

INLINE const NodeGraphPartIteratorSafe & gum::NodeGraphPart::endSafe ( ) const
noexceptinherited

the end iterator to parse the set of nodes contained in the NodeGraphPart

Definition at line 328 of file nodeGraphPart_inl.h.

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

328  {
329  return endIteratorSafe__;
330  }
NodeGraphPartIteratorSafe endIteratorSafe__
the end iterator (used to speed-up parsings of the NodeGraphPart)
+ Here is the call graph for this function:

◆ eraseArc()

INLINE void gum::ArcGraphPart::eraseArc ( const Arc arc)
virtualinherited

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

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

108  {
109  // ASSUMING tail and head exists in parents__ anf children__
110  // (if not, it is an error)
111  if (existsArc(arc)) {
112  NodeId tail = arc.tail(), head = arc.head();
113  parents__[head]->erase(tail);
114  children__[tail]->erase(head);
115  arcs__.erase(arc);
116  GUM_EMIT2(onArcDeleted, tail, head);
117  }
118  }
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:675
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)
inherited

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

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

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

◆ eraseNode()

INLINE void gum::DiGraph::eraseNode ( const NodeId  id)
virtualinherited

remove a node and its adjacent arcs from the graph

Parameters
idthe id of the node to be removed
Warning
if the node does not exist, nothing is done. In particular, no exception is raised.

Reimplemented from gum::NodeGraphPart.

Reimplemented in gum::MixedGraph.

Definition at line 68 of file diGraph_inl.h.

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

68  {
69  // warning: to remove the arcs adjacent to id, use the unvirtualized
70  // versions
71  // of arc removals
74 
76  }
void unvirtualizedEraseChildren(NodeId id)
same function as eraseChildren but without any virtual call to an erase
virtual void eraseNode(const NodeId id)
erase the node with the given id
void unvirtualizedEraseParents(NodeId id)
same function as eraseParents but without any virtual call to an erase
+ Here is the call graph for this function:

◆ eraseParents()

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

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

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

125  {
126  if (parents__.exists(id)) {
127  NodeSet& parents = *(parents__[id]);
128 
129  for (auto iter = parents.beginSafe(); // safe iterator needed here
130  iter != parents.endSafe();
131  ++iter) {
132  // warning: use this erase so that you actually use the virtualized
133  // arc removal function
134  eraseArc(Arc(*iter, id));
135  }
136  }
137  }
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)
protectedinherited

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

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

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

◆ exists() [1/2]

INLINE bool gum::prm::gspan::Pattern::exists ( NodeId  id) const

Returns true if id is a node in this Pattern.

Definition at line 138 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

138 { return DiGraph::exists(id); }
bool exists(const NodeId id) const
alias for existsNode
+ Here is the call graph for this function:

◆ exists() [2/2]

INLINE bool gum::prm::gspan::Pattern::exists ( NodeId  tail,
NodeId  head 
) const

Returns true if (tail, head) is an arc in this Pattern.

Definition at line 141 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

141  {
142  return DiGraph::existsArc(tail, head);
143  }
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
+ Here is the call graph for this function:

◆ existsArc() [1/2]

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

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  {
41  return arcs__.contains(arc);
42  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:580
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
inherited

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

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

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

◆ existsNode()

INLINE bool gum::NodeGraphPart::existsNode ( const NodeId  id) const
inherited

returns true iff the NodeGraphPart contains the given nodeId

Definition at line 285 of file nodeGraphPart_inl.h.

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

285  {
286  if (node >= boundVal__) return false;
287 
288  return (!inHoles__(node));
289  }
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
bool inHoles__(NodeId id) const
+ Here is the call graph for this function:

◆ expandCodeIsMinimal__()

bool gum::prm::gspan::Pattern::expandCodeIsMinimal__ ( NodeId  u,
NodeId  v 
)
private

Returns true if the expand code by adding and edge betwenne u and v is minimal with respect to code__.

Parameters
uA node in this Pattern.
vA node in this Pattern.
Returns
true if the expand code by adding and edge betwenne u and v is minimal with respect to code__.

Definition at line 99 of file pattern.cpp.

References gum::prm::gspan::operator<<().

99  {
100  Bijection< NodeId, NodeId > node_map;
101  Pattern p;
102  node_map.insert(u, p.addNodeWithLabel(label(u)));
103  node_map.insert(v, p.addNodeWithLabel(label(v)));
104 
105  try {
106  p.addArc(1, 2, label(u, v));
107  } catch (NotFound&) { p.addArc(1, 2, label(v, u)); }
108 
109  for (const auto nei: children(u))
110  if (nei != v)
111  if (rec__(p, node_map, u, nei)) return true;
112 
113  for (const auto nei: parents(u))
114  if (nei != v)
115  if (rec__(p, node_map, u, nei)) return true;
116 
117  for (const auto nei: children(v))
118  if (nei != u)
119  if (rec__(p, node_map, v, nei)) return true;
120 
121  for (const auto nei: parents(v))
122  if (nei != u)
123  if (rec__(p, node_map, v, nei)) return true;
124 
125  return false;
126  }
Pattern()
Default constructor.
Definition: pattern_inl.h:34
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
bool rec__(Pattern &p, Bijection< NodeId, NodeId > &node_map, NodeId u, NodeId v)
Recurisve method used by expandCodeIsMinimal__.
Definition: pattern.cpp:128
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
Definition: pattern_inl.h:49
+ Here is the call graph for this function:

◆ family() [1/2]

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

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

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

61  {
62  checkParents__(id);
63  NodeSet res{id};
64  return res + parents(id);
65  }
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 checkParents__(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:

◆ family() [2/2]

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

returns the set of family nodes of a set of nodes

Definition at line 84 of file arcGraphPart_inl.h.

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

84  {
85  NodeSet res;
86  for (const auto node: ids)
87  res += family(node);
88  return res;
89  }
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:

◆ hasDirectedPath()

bool gum::DiGraph::hasDirectedPath ( const NodeId  from,
const NodeId  to 
)
inherited

checks whether there exists a directed path from from to to

If from==to, this function checks if a directed cycle containing from exists.

Parameters
from
to
Returns
true if a directed path exists

Definition at line 136 of file diGraph.cpp.

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

136  {
137  if (!exists(from)) return false;
138 
139  // not recursive version => use a FIFO for simulating the recursion
140  List< NodeId > nodeFIFO;
141  nodeFIFO.pushBack(from);
142 
143  NodeSet marked;
144  marked.insert(from);
145 
146  NodeId new_one;
147 
148  while (!nodeFIFO.empty()) {
149  new_one = nodeFIFO.front();
150  // std::cout<<new_one<<std::endl;
151  nodeFIFO.popFront();
152 
153  for (const auto chi: children(new_one)) {
154  if (chi == to) return true;
155 
156  if (!marked.contains(chi)) {
157  nodeFIFO.pushBack(chi);
158  marked.insert(chi);
159  }
160  }
161  }
162 
163  return false;
164  }
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
bool exists(const NodeId id) const
alias for existsNode
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ Here is the call graph for this function:

◆ isMinimal()

bool gum::prm::gspan::Pattern::isMinimal ( )

Returns the DFSCode of this Pattern.

Definition at line 56 of file pattern.cpp.

References gum::prm::gspan::operator<<().

56  {
57  for (const auto node: nodes()) {
58  for (const auto next: parents(node)) {
59  Size u = label(node).id;
60  Size v = label(next).id;
61  EdgeCode edge_code(1, 2, u, label(next, node).id, v);
62 
63  if (edge_code < *(code().codes.front())) {
64  return false;
65  } else if (edge_code == (*code().codes.front())) {
66  if (expandCodeIsMinimal__(node, next)) { return false; }
67  }
68  }
69 
70  for (const auto next: children(node)) {
71  Size u = label(node).id;
72  Size v = label(next).id;
73  EdgeCode edge_code(1, 2, u, label(node, next).id, v);
74 
75  if (edge_code < *(code().codes.front())) {
76  return false;
77  } else if (edge_code == (*code().codes.front())) {
78  if (expandCodeIsMinimal__(node, next)) { return false; }
79  }
80  }
81  }
82 
83  return true;
84  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
DFSCode & code()
Returns the DFSCode of this Pattern.
Definition: pattern_inl.h:172
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
Definition: pattern_inl.h:49
bool expandCodeIsMinimal__(NodeId u, NodeId v)
Returns true if the expand code by adding and edge betwenne u and v is minimal with respect to code__...
Definition: pattern.cpp:99
const NodeGraphPart & nodes() const
Definition: pattern_inl.h:165
Idx id
An unique identifier for this label.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
+ Here is the call graph for this function:

◆ label() [1/6]

INLINE LabelData & gum::prm::gspan::Pattern::label ( NodeId  node)

Returns the LabelData assigned to node.

Definition at line 49 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

49  {
50  try {
51  return *(node_map__[node]);
52  } catch (NotFound&) {
53  GUM_ERROR(NotFound, "node not found in this Pattern");
54  }
55  }
NodeProperty< LabelData *> node_map__
Mapping between nodes in this Pattern and their respective LabelData.
Definition: pattern.h:208
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ label() [2/6]

INLINE const LabelData & gum::prm::gspan::Pattern::label ( NodeId  node) const

Returns the LabelData assigned to node.

Definition at line 58 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

58  {
59  try {
60  return *(node_map__[node]);
61  } catch (NotFound&) {
62  GUM_ERROR(NotFound, "node not found in this Pattern");
63  }
64  }
NodeProperty< LabelData *> node_map__
Mapping between nodes in this Pattern and their respective LabelData.
Definition: pattern.h:208
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ label() [3/6]

INLINE LabelData & gum::prm::gspan::Pattern::label ( NodeId  i,
NodeId  j 
)

Returns the LabelData assigned to arc.

Definition at line 81 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

81  {
82  try {
83  return *(arc_map__[Arc(i, j)].first);
84  } catch (NotFound&) {
85  GUM_ERROR(NotFound, "arc not found in this Pattern");
86  }
87  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ label() [4/6]

INLINE const LabelData & gum::prm::gspan::Pattern::label ( NodeId  i,
NodeId  j 
) const

Returns the LabelData assigned to arc.

Definition at line 90 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

90  {
91  try {
92  return *(arc_map__[Arc(i, j)].first);
93  } catch (NotFound&) {
94  GUM_ERROR(NotFound, "arc not found in this Pattern");
95  }
96  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ label() [5/6]

INLINE LabelData & gum::prm::gspan::Pattern::label ( const Arc arc)

Returns the LabelData assigned to arc.

Definition at line 99 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

99  {
100  try {
101  return *(arc_map__[arc].first);
102  } catch (NotFound&) {
103  GUM_ERROR(NotFound, "arc not found in this Pattern");
104  }
105  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ label() [6/6]

INLINE const LabelData & gum::prm::gspan::Pattern::label ( const Arc arc) const

Returns the LabelData assigned to arc.

Definition at line 108 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

108  {
109  try {
110  return *(arc_map__[arc].first);
111  } catch (NotFound&) {
112  GUM_ERROR(NotFound, "arc not found in this Pattern");
113  }
114  }
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ lastAdded() [1/2]

INLINE LabelData & gum::prm::gspan::Pattern::lastAdded ( )

Insert a node with the given LabelData.

Returns
The id assigned to the inserted node.

Definition at line 67 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

67  {
68  if (last__) return *last__;
69 
70  GUM_ERROR(OperationNotAllowed, "there are no LabelData yet");
71  }
LabelData * last__
The last LabelData added to this pattern.
Definition: pattern.h:215
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ lastAdded() [2/2]

INLINE const LabelData & gum::prm::gspan::Pattern::lastAdded ( ) const

Insert a node with the given LabelData.

Returns
The id assigned to the inserted node.

Definition at line 74 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

74  {
75  if (last__) return *last__;
76 
77  GUM_ERROR(OperationNotAllowed, "there are no LabelData yet");
78  }
LabelData * last__
The last LabelData added to this pattern.
Definition: pattern.h:215
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ listMapArcs()

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

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

◆ listMapNodes()

template<typename VAL >
List< VAL > gum::NodeGraphPart::listMapNodes ( VAL(*)(const NodeId &)  f) const
inherited

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

Parameters
fa function assigning a VAL to any node

◆ nextNodeId()

INLINE NodeId gum::NodeGraphPart::nextNodeId ( ) const
inherited

returns a new node id, not yet used by any node

Warning
a code like
id=nextNodeId();addNode(id);
is basically not thread safe !!
Returns
a node id not yet used by any node within the NodeGraphPart

Definition at line 225 of file nodeGraphPart_inl.h.

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

225  {
226  NodeId next = 0;
227 
228  // return the first hole if holes exist
229  if (holes__ && (!holes__->empty()))
230  next = *(holes__->begin());
231  else // in other case
232  next = boundVal__;
233 
234  return next;
235  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:726
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:516
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ nodes()

INLINE const NodeGraphPart & gum::prm::gspan::Pattern::nodes ( ) const

Definition at line 165 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

165  {
166  return DiGraph::nodes();
167  }
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
+ Here is the call graph for this function:

◆ nodesProperty() [1/2]

template<typename VAL >
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty ( VAL(*)(const NodeId &)  f,
Size  size = 0 
) const
inherited

a method to create a HashTable with key:NodeId and value:VAL

VAL are computed from the nodes using for all node x, VAL f(x). This method is a wrapper of the same method in HashTable.

See also
HashTable::map.
Parameters
fa function assigning a VAL to any node
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 nodes. If you do not specify this parameter, the method will assign it for you.

◆ nodesProperty() [2/2]

template<typename VAL >
NodeProperty< VAL > gum::NodeGraphPart::nodesProperty ( const VAL &  a,
Size  size = 0 
) const
inherited

a method to create a hashMap with key:NodeId and value:VAL

for all nodes, the value stored is a. This method is a wrapper of the same method in HashTable.

See also
HashTable::map.
Parameters
athe default value assigned to each edge in the returned Property
sizean optional parameter enabling to fine-tune the returned Property. Roughly speaking, it is a good practice to have a size equal to half the number of nodes. If you do not specify this parameter, the method will assign it for you.

◆ not_rec__()

bool gum::prm::gspan::Pattern::not_rec__ ( Pattern p,
Bijection< NodeId, NodeId > &  node_map,
NodeId  u,
NodeId  v 
)
private

A non recursive bugged version of rec__.

Definition at line 189 of file pattern.cpp.

References gum::prm::gspan::operator<<().

192  {
193  std::vector< std::pair< NodeId, NodeId > > stack;
194  std::vector< size_t > rec_call;
195  stack.push_back(std::make_pair(a_u, a_v));
196  NodeId u = 0;
197  NodeId v = 0;
198 
199  while (!stack.empty()) {
200  bool go = true;
201  u = stack.back().first;
202  v = stack.back().second;
203  stack.pop_back();
204 
205  if ((u == 0) && (v == 0)) {
206  p.pop_back();
207  } else {
208  if (node_map.existsFirst(v)) {
209  if (node_map.second(u) < node_map.second(v)) {
210  // Invalid forward edge
211  go = false;
212  } else if ((p.existsArc(node_map.second(u), node_map.second(v)))
213  || (p.existsArc(node_map.second(v),
214  node_map.second(u)))) {
215  // Duplicate arc !
216  go = false;
217  }
218  } else {
219  node_map.insert(v, p.addNodeWithLabel(label(v)));
220  }
221 
222  if (go) {
223  // Retrieving arc label data
224  LabelData* data = 0;
225 
226  try {
227  data = &(label(u, v));
228  } catch (NotFound&) { data = &(label(v, u)); }
229 
230  // Adding arc
231  try {
232  p.addArc(node_map.second(u), node_map.second(v), *data);
233  } catch (OperationNotAllowed&) {
234  // Invalid neighbor
235  if (node_map.second(u) < node_map.second(v)) {
236  p.remove(node_map.second(v));
237  node_map.eraseFirst(v);
238  }
239 
240  go = false;
241  }
242 
243  if (go) {
244  // Check if this is minimal or if equal find another growth
245  size_t depth = p.code().codes.size() - 1;
246 
247  if (*(p.code().codes.back()) < *(code().codes[depth])) {
248  return true;
249  } else if (*(p.code().codes.back()) == *(code().codes[depth])) {
250  std::list< NodeId > r_path;
251  p.rightmostPath(r_path);
252  stack.push_back(std::make_pair((NodeId)0, (NodeId)0));
253 
254  for (const auto node: r_path) {
255  for (const auto nei: children(node)) {
256  stack.push_back(std::make_pair(node_map.first(node), nei));
257  ++(rec_call.back());
258  }
259 
260  for (const auto nei: parents(node)) {
261  stack.push_back(std::make_pair(node_map.first(node), nei));
262  ++(rec_call.back());
263  }
264  }
265  }
266 
267  if (p.code().codes.back()->isForward()) node_map.eraseFirst(v);
268  }
269  }
270  }
271  }
272 
273  return false;
274  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
DFSCode & code()
Returns the DFSCode of this Pattern.
Definition: pattern_inl.h:172
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
Definition: pattern_inl.h:49
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ operator!=() [1/3]

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

tests whether two ArcGraphParts contain different arcs

Parameters
pthe ArcGraphPart that we compare with this

Definition at line 186 of file arcGraphPart_inl.h.

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

186  {
187  return arcs__ != p.arcs__;
188  }
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!=() [2/3]

INLINE bool gum::DiGraph::operator!= ( const DiGraph g) const
inherited

tests whether two DiGraphs are different

Parameters
gthe DiGraph with which "this" is compared

Definition at line 82 of file diGraph_inl.h.

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

82  {
83  return !operator==(p);
84  }
bool operator==(const DiGraph &g) const
tests whether two DiGraphs are identical (same nodes, same arcs)
Definition: diGraph_inl.h:78
+ Here is the call graph for this function:

◆ operator!=() [3/3]

INLINE bool gum::NodeGraphPart::operator!= ( const NodeGraphPart p) const
inherited

check whether two NodeGraphParts contain different nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 356 of file nodeGraphPart_inl.h.

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

356  {
357  return !operator==(p);
358  }
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes
+ Here is the call graph for this function:

◆ operator==() [1/3]

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

tests whether two ArcGraphParts contain the same 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  {
183  return arcs__ == p.arcs__;
184  }
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==() [2/3]

INLINE bool gum::DiGraph::operator== ( const DiGraph g) const
inherited

tests whether two DiGraphs are identical (same nodes, same arcs)

Parameters
gthe DiGraph with which "this" is compared

Definition at line 78 of file diGraph_inl.h.

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

78  {
80  }
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs
+ Here is the call graph for this function:

◆ operator==() [3/3]

INLINE bool gum::NodeGraphPart::operator== ( const NodeGraphPart p) const
inherited

check whether two NodeGraphParts contain the same nodes

Parameters
pthe NodeGraphPart to be compared with "this"

Definition at line 342 of file nodeGraphPart_inl.h.

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

342  {
343  if (boundVal__ != p.boundVal__) return false;
344 
345  if (holes__)
346  if (p.holes__)
347  return (*holes__ == *p.holes__);
348  else
349  return false;
350  else if (p.holes__)
351  return false;
352 
353  return true;
354  }
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ parents() [1/2]

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

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

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

56  {
57  checkParents__(id);
58  return *(parents__[id]);
59  }
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
inherited

returns the set of parents of a set of nodes

Definition at line 76 of file arcGraphPart_inl.h.

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

76  {
77  NodeSet res;
78  for (const auto node: ids)
79  res += parents(node);
80  return res;
81  }
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:

◆ pop_back()

INLINE void gum::prm::gspan::Pattern::pop_back ( )

Remove the last EdgeCode of this pattern.

Definition at line 206 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

206  {
207  EdgeCode* edge = code__.codes.back();
208  code__.codes.pop_back();
209 
210  if (edge->isForward()) {
211  node_map__.erase(edge->j);
212  arc_map__.erase(Arc(edge->i, edge->j));
213  DiGraph::eraseArc(Arc(edge->i, edge->j));
214  DiGraph::eraseNode(edge->j);
215  } else {
216  arc_map__.erase(Arc(edge->i, edge->j));
217  DiGraph::eraseArc(Arc(edge->i, edge->j));
218  }
219 
220  delete edge;
221  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
DFSCode code__
The DFSCode of this Pattern.
Definition: pattern.h:204
ArcProperty< std::pair< LabelData *, EdgeCode *> > arc_map__
Mapping between edges in this Pattern and their respective LabelData.
Definition: pattern.h:212
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:68
NodeProperty< LabelData *> node_map__
Mapping between nodes in this Pattern and their respective LabelData.
Definition: pattern.h:208
+ Here is the call graph for this function:

◆ populateNodes()

void gum::NodeGraphPart::populateNodes ( const NodeGraphPart s)
inherited

populateNodes clears *this and fills it with the same nodes as "s"

populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.

Parameters
sthe NodeGraphPart to be copied

Definition at line 63 of file nodeGraphPart.cpp.

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

63  {
64  clear(); // "virtual" flush of the nodes set
65  holes_size__ = s.holes_size__;
66  holes_resize_policy__ = s.holes_resize_policy__;
67 
68  if (s.holes__) holes__ = new NodeSet(*s.holes__);
69 
70  boundVal__ = s.boundVal__;
71 
73  }
bool holes_resize_policy__
value for holes__ configuration
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
virtual void clear()
alias for clearNodes
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
void updateEndIteratorSafe__()
updating endIterator (always at max__+1)
Size holes_size__
value for holes__ configuration
+ Here is the call graph for this function:

◆ populateNodesFromProperty()

template<typename T >
void gum::NodeGraphPart::populateNodesFromProperty ( const NodeProperty< T > &  h)
inherited

populateNodesFromProperty clears *this and fills it with the keys of "h"

populateNodes should basically be the preferred way to insert nodes with IDs not selected by the internal idFactory.

◆ rec__()

bool gum::prm::gspan::Pattern::rec__ ( Pattern p,
Bijection< NodeId, NodeId > &  node_map,
NodeId  u,
NodeId  v 
)
private

Recurisve method used by expandCodeIsMinimal__.

Parameters
pA Pattern.
node_mapA bijection.
uA node in this Pattern.
vA node in this Pattern.
Returns
true if the expansion is minimal.

Definition at line 128 of file pattern.cpp.

References gum::prm::gspan::operator<<().

131  {
132  if (node_map.existsFirst(v)) {
133  if (node_map.second(u) < node_map.second(v)) {
134  // Invalid forward edge
135  return false;
136  } else if ((p.existsArc(node_map.second(u), node_map.second(v)))
137  || (p.existsArc(node_map.second(v), node_map.second(u)))) {
138  // Duplicate arc !
139  return false;
140  }
141  } else {
142  node_map.insert(v, p.addNodeWithLabel(label(v)));
143  }
144 
145  // Retrieving arc label data
146  LabelData* data = 0;
147 
148  try {
149  data = &(label(u, v));
150  } catch (NotFound&) { data = &(label(v, u)); }
151 
152  // Adding arc
153  try {
154  p.addArc(node_map.second(u), node_map.second(v), *data);
155  } catch (OperationNotAllowed&) {
156  // Invalid neighbor
157  if (node_map.second(u) < node_map.second(v)) {
158  p.remove(node_map.second(v));
159  node_map.eraseFirst(v);
160  }
161 
162  return false;
163  }
164 
165  // Check if this is minimal or if equal find another growth
166  size_t depth = p.code().codes.size() - 1;
167 
168  if (*(p.code().codes.back()) < *(code().codes[depth])) {
169  return true;
170  } else if (*(p.code().codes.back()) == *(code().codes[depth])) {
171  std::list< NodeId > r_path;
172  p.rightmostPath(r_path);
173 
174  for (const auto node: r_path) {
175  for (const auto nei: children(node_map.first(node)))
176  if (rec__(p, node_map, node_map.first(node), nei)) return true;
177 
178  for (const auto nei: parents(node_map.first(node)))
179  if (rec__(p, node_map, node_map.first(node), nei)) return true;
180  }
181  }
182 
183  if (p.code().codes.back()->isForward()) node_map.eraseFirst(v);
184 
185  p.pop_back();
186  return false;
187  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
DFSCode & code()
Returns the DFSCode of this Pattern.
Definition: pattern_inl.h:172
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
bool rec__(Pattern &p, Bijection< NodeId, NodeId > &node_map, NodeId u, NodeId v)
Recurisve method used by expandCodeIsMinimal__.
Definition: pattern.cpp:128
std::vector< EdgeCode *> codes
The vector containing the EdgeCode composing this DFSCode.
Definition: DFSCode.h:89
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
Definition: pattern_inl.h:49
+ Here is the call graph for this function:

◆ remove()

INLINE void gum::prm::gspan::Pattern::remove ( NodeId  node)

Remove a node if it has no neighbors, raise an OperationNotAllowed otherwise.

Definition at line 224 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

224  {
225  if (DiGraph::parents(node).empty() && DiGraph::children(node).empty()) {
226  DiGraph::eraseNode(node);
227  node_map__.erase(node);
228  } else {
229  GUM_ERROR(OperationNotAllowed, "the given node has neighbors");
230  }
231  }
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
bool empty() const
alias for emptyNodes
virtual void eraseNode(const NodeId id)
remove a node and its adjacent arcs from the graph
Definition: diGraph_inl.h:68
NodeProperty< LabelData *> node_map__
Mapping between nodes in this Pattern and their respective LabelData.
Definition: pattern.h:208
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
+ Here is the call graph for this function:

◆ rightmostPath()

INLINE void gum::prm::gspan::Pattern::rightmostPath ( std::list< NodeId > &  r_path) const

Fill r_path with the rightmost path of this Pattern. The list is supposed empty.

Definition at line 152 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

152  {
153  r_path.push_back(NodeId(size()));
154 
155  while (r_path.front() != 1) {
156  for (const auto par: parents(r_path.front())) {
157  if (par < r_path.front()) {
158  r_path.push_front(par);
159  break;
160  }
161  }
162  }
163  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
Size size() const
Returns the number of nodes in this Pattern.
Definition: pattern_inl.h:146
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ size()

INLINE Size gum::prm::gspan::Pattern::size ( ) const

Returns the number of nodes in this Pattern.

Definition at line 146 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

146 { return DiGraph::size(); }
Size size() const
alias for sizeNodes
+ Here is the call graph for this function:

◆ sizeArcs()

INLINE Size gum::prm::gspan::Pattern::sizeArcs ( ) const

Returns the number of arcs in this Pattern.

Definition at line 149 of file pattern_inl.h.

References gum::prm::gspan::operator<<().

149 { return DiGraph::sizeArcs(); }
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:

◆ sizeNodes()

INLINE Size gum::NodeGraphPart::sizeNodes ( ) const
inherited

returns the number of nodes in the NodeGraphPart

Definition at line 279 of file nodeGraphPart_inl.h.

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

279  {
280  return (holes__) ? (boundVal__ - holes__->size()) : boundVal__;
281  }
NodeSet * holes__
the set of nodes not contained in the NodeGraphPart in the interval 1..max__
NodeId boundVal__
the id below which NodeIds may belong to the NodeGraphPart
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:720
+ Here is the call graph for this function:

◆ toDot() [1/2]

std::string gum::prm::gspan::Pattern::toDot ( size_t  name) const

Print the pattern in the DOT syntax.

Definition at line 86 of file pattern.cpp.

References gum::prm::gspan::operator<<().

86  {
87  std::stringstream sBuff;
88  sBuff << "digraph " << name << " {\n";
89 
90  for (const auto& arc: arcs()) {
91  sBuff << label(arc.tail()).id << " -> ";
92  sBuff << label(arc.head()).id << ";\n";
93  }
94 
95  sBuff << "}\n";
96  return sBuff.str();
97  }
LabelData & label(NodeId node)
Returns the LabelData assigned to node.
Definition: pattern_inl.h:49
const ArcSet & arcs() const
Definition: pattern_inl.h:169
+ Here is the call graph for this function:

◆ toDot() [2/2]

std::string gum::DiGraph::toDot ( ) const
virtualinherited

to friendly display the content of the graph in the DOT syntax

Parameters
nameThe graph name in the dot syntax. Default is G.
Returns
Returns a string describing the graph in the dot syntax

Reimplemented in gum::MixedGraph.

Definition at line 67 of file diGraph.cpp.

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

67  {
68  std::stringstream strBuff;
69  std::string tab = " ";
70  strBuff << "digraph {" << std::endl;
71 
72  for (const auto node: nodes())
73  strBuff << tab << node << ";" << std::endl;
74 
75  strBuff << std::endl;
76 
77  for (const auto& arc: arcs())
78  strBuff << tab << arc.tail() << " -> " << arc.head() << ";" << std::endl;
79 
80  strBuff << "}" << std::endl << std::endl;
81  return strBuff.str();
82  }
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
+ Here is the call graph for this function:

◆ topologicalOrder()

const Sequence< NodeId > & gum::DiGraph::topologicalOrder ( bool  clear = true) const
inherited

The topological order stays the same as long as no variable or arcs are added or erased src the topology.

Parameters
clearIf false returns the previously created topology.
Exceptions
InvalidDirectedCycleRaised if this DiGraph contains cycles.

Definition at line 90 of file diGraph.cpp.

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

90  {
91  if (clear
93  == nullptr)) { // we have to call topologicalOrder_
94  if (mutableTopologicalOrder__ == nullptr) {
96  } else {
97  // clear is True
99  }
100 
102  }
103 
105  }
void topologicalOrder__() const
Returns a topological order of this DAGModel.
Definition: diGraph.cpp:107
void clear()
Clear the sequence.
Definition: sequence_tpl.h:272
Sequence< NodeId > * mutableTopologicalOrder__
The topology sequence of this Directed Graphical Model.
Definition: diGraph.h:209
+ Here is the call graph for this function:

◆ toString()

std::string gum::DiGraph::toString ( ) const
virtualinherited

to friendly display the content of the graph

Reimplemented from gum::NodeGraphPart.

Reimplemented in gum::MixedGraph.

Definition at line 60 of file diGraph.cpp.

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

60  {
61  std::string s = NodeGraphPart::toString();
62  s += " , ";
64  return s;
65  }
std::string toString() const
to friendly display the content of the ArcGraphPart
virtual std::string toString() const
a function to display the set of nodes
+ Here is the call graph for this function:

◆ unvirtualizedEraseChildren()

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

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

Parameters
idthe node whose outgoing arcs will be removed

Definition at line 170 of file arcGraphPart_inl.h.

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

170  {
171  if (children__.exists(id)) {
172  NodeSet& children = *(children__[id]);
173 
174  for (auto iter = children.beginSafe(); // safe iterator needed here
175  iter != children.endSafe();
176  ++iter) {
177  ArcGraphPart::eraseArc(Arc(id, *iter));
178  }
179  }
180  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet *> children__
for each arc, the set of its children
Definition: arcGraphPart.h:307
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)
inherited

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

Parameters
idthe node whose ingoing arcs will be removed

Definition at line 158 of file arcGraphPart_inl.h.

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

158  {
159  if (parents__.exists(id)) {
160  NodeSet& parents = *(parents__[id]);
161 
162  for (auto iter = parents.beginSafe(); // safe iterator needed here
163  iter != parents.endSafe();
164  ++iter) {
165  ArcGraphPart::eraseArc(Arc(*iter, id));
166  }
167  }
168  }
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)
protectedinherited

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

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

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

Member Data Documentation

◆ arc_map__

ArcProperty< std::pair< LabelData*, EdgeCode* > > gum::prm::gspan::Pattern::arc_map__
private

Mapping between edges in this Pattern and their respective LabelData.

Definition at line 212 of file pattern.h.

◆ code__

DFSCode gum::prm::gspan::Pattern::code__
private

The DFSCode of this Pattern.

Definition at line 204 of file pattern.h.

◆ last__

LabelData* gum::prm::gspan::Pattern::last__
private

The last LabelData added to this pattern.

Definition at line 215 of file pattern.h.

◆ node_map__

NodeProperty< LabelData* > gum::prm::gspan::Pattern::node_map__
private

Mapping between nodes in this Pattern and their respective LabelData.

Definition at line 208 of file pattern.h.

◆ onArcAdded

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

Definition at line 82 of file arcGraphPart.h.

◆ onArcDeleted

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

Definition at line 83 of file arcGraphPart.h.

◆ onNodeAdded

Signaler1< NodeId > gum::NodeGraphPart::onNodeAdded
inherited

Definition at line 271 of file nodeGraphPart.h.

◆ onNodeDeleted

Signaler1< NodeId > gum::NodeGraphPart::onNodeDeleted
inherited

Definition at line 272 of file nodeGraphPart.h.


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