aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::prm::gspan::DFSTree< GUM_SCALAR > Class Template Reference

A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph. More...

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

+ Inheritance diagram for gum::prm::gspan::DFSTree< GUM_SCALAR >:
+ Collaboration diagram for gum::prm::gspan::DFSTree< GUM_SCALAR >:

Public Member Functions

Constructor and destructor.
 DFSTree (const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
 Default constructor. More...
 
 ~DFSTree ()
 Destructor. More...
 
DFSTree getters and setters.
const InterfaceGraph< GUM_SCALAR > & graph () const
 Returns the list of root patterns in this DFSTree. More...
 
std::list< NodeId > & roots ()
 Returns the list of root patterns in this DFSTree. More...
 
const std::list< NodeId > & roots () const
 Returns the list of root patterns in this DFSTree. More...
 
Patternparent (const Pattern &p)
 Returns the parent of p in this DFSTree. More...
 
const Patternparent (const Pattern &p) const
 Returns the parent of p in this DFSTree. More...
 
std::list< NodeId > & children (const Pattern &p)
 Returns the list of p children in this DFSTree. More...
 
const std::list< NodeId > & children (const Pattern &p) const
 Returns the list of p children in this DFSTree. More...
 
Patternpattern (NodeId id)
 Returns the pattern represented by id in this DFSTree. More...
 
const Patternpattern (NodeId id) const
 Returns the pattern represented by id in this DFSTree. More...
 
void addRoot (LabelData &data)
 Add a one edge Pattern in this DFSTree. More...
 
PatterngrowPattern (Pattern &p, EdgeGrowth< GUM_SCALAR > &edge_growth, Size min_freq)
 Add a one edge growth of p as one of its child. More...
 
Isomorphisms for patterns in this DFSTree.
UndiGraphiso_graph (const Pattern &p)
 Returns the isomorphism graph of p in the interface graph. More...
 
Sequence< PRMInstance< GUM_SCALAR > *> & iso_map (const Pattern &p, NodeId node)
 Given a pattern and a node in its isomorphism graph, this methods returns the sequence of instance matching p in the interface graph. More...
 
Set< NodeId > & max_indep_set (const Pattern &p)
 Returns the maximal independent set of p isomorphism graph. More...
 
double frequency (const Pattern &p) const
 Returns the frequency of p respecting it's maximal independent set. More...
 
PatternDatadata (const Pattern &p)
 
const PatternDatadata (const Pattern &p) const
 
SearchStrategy< GUM_SCALAR > & strategy ()
 strategy getter More...
 
const SearchStrategy< GUM_SCALAR > & strategy () const
 strategy getter More...
 

Classes

class  NeighborDegreeSort
 This is used to generate the max_indep_set of a Pattern. More...
 
struct  PatternData
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::gspan::DFSTree< GUM_SCALAR >

A DFSTree is used by gspan to sort lexicographically patterns discovered in an interface graph.

Definition at line 70 of file DFSTree.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

◆ DFSTree()

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::DFSTree< GUM_SCALAR >::DFSTree ( const InterfaceGraph< GUM_SCALAR > &  graph,
gspan::SearchStrategy< GUM_SCALAR > *  strategy = 0 
)

Default constructor.

Definition at line 366 of file DFSTree_tpl.h.

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

367  :
368  _graph_(&graph),
370  GUM_CONSTRUCTOR(DFSTree);
371 
372  if (!_strategy_) _strategy_ = new FrequenceSearch< GUM_SCALAR >(2);
373 
374  _strategy_->setTree(this);
375  }
const InterfaceGraph< GUM_SCALAR > * _graph_
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:260
const InterfaceGraph< GUM_SCALAR > & graph() const
Returns the list of root patterns in this DFSTree.
Definition: DFSTree_tpl.h:472
SearchStrategy< GUM_SCALAR > * _strategy_
The strategy used to prune the search tree.
Definition: DFSTree.h:273
SearchStrategy< GUM_SCALAR > & strategy()
strategy getter
Definition: DFSTree_tpl.h:500
DFSTree(const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: DFSTree_tpl.h:366
+ Here is the call graph for this function:

◆ ~DFSTree()

template<typename GUM_SCALAR >
gum::prm::gspan::DFSTree< GUM_SCALAR >::~DFSTree ( )

Destructor.

Definition at line 36 of file DFSTree_tpl.h.

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

36  {
37  GUM_DESTRUCTOR(DFSTree);
38 
39  for (const auto& elt: _data_) {
40  delete elt.first;
41  delete elt.second;
42  }
43 
44  delete _strategy_;
45  }
SearchStrategy< GUM_SCALAR > * _strategy_
The strategy used to prune the search tree.
Definition: DFSTree.h:273
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
DFSTree(const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: DFSTree_tpl.h:366
+ Here is the call graph for this function:

Member Function Documentation

◆ _addChild_()

template<typename GUM_SCALAR >
void gum::prm::gspan::DFSTree< GUM_SCALAR >::_addChild_ ( Pattern p,
Pattern child,
EdgeGrowth< GUM_SCALAR > &  edge_growth 
)
private

Add a child to this DFSTree.

Definition at line 159 of file DFSTree_tpl.h.

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

161  {
162  // Adding child to the tree
163  NodeId node = DiGraph::addNode();
164  _node_map_.insert(node, child);
165  // Adding child in p's children list
166  std::list< NodeId >& children = _data_[&p]->children;
167 
168  if (children.empty()) {
169  children.push_back(node);
170  } else {
171  size_t size = children.size();
172 
173  for (std::list< NodeId >::iterator iter = children.begin(); iter != children.end();
174  ++iter) {
175  if (child->code() < pattern(*iter).code()) {
176  children.insert(iter, node);
177  break;
178  }
179  }
180 
181  if (size == children.size()) { children.push_back(node); }
182  }
183  }
std::list< NodeId > & children(const Pattern &p)
Returns the list of p children in this DFSTree.
Definition: DFSTree_tpl.h:416
DFSCode & code()
Returns the DFSCode of this Pattern.
Definition: pattern_inl.h:161
Size size() const
alias for sizeNodes
Bijection< NodeId, Pattern *> _node_map_
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:267
virtual NodeId addNode()
insert a new node and return its id
Pattern & pattern(NodeId id)
Returns the pattern represented by id in this DFSTree.
Definition: DFSTree_tpl.h:430
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ _checkGrowth_()

template<typename GUM_SCALAR >
void gum::prm::gspan::DFSTree< GUM_SCALAR >::_checkGrowth_ ( Pattern p,
Pattern child,
EdgeGrowth< GUM_SCALAR > &  edge_growth 
)
private

Raise different exceptions if child is invalid or illegal.

Definition at line 186 of file DFSTree_tpl.h.

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

188  {
189  NodeId v = edge_growth.v;
190 
191  // First we check if the edge is legal
192  if (v == 0) { v = child->addNodeWithLabel(*(edge_growth.l_v)); }
193 
194  child->addArc(edge_growth.u, v, *(edge_growth.edge));
195  // Neighborhood restriction is checked by the Pattern class
196  EdgeCode& edge = child->edgeCode(edge_growth.u, v);
197 
198  // Then we check if the edge we added is valid
199  if (edge < *(child->code().codes.front())) {
200  GUM_ERROR(OperationNotAllowed,
201  "added edge code is lesser than the first "
202  "one in the pattern's DFSCode");
203  }
204 
205  if (edge.isBackward()) {
206  typedef std::vector< EdgeCode* >::iterator EdgeIter;
207 
208  for (EdgeIter iter = child->code().codes.begin(); (iter + 1) != child->code().codes.end();
209  ++iter) {
210  if ((((**iter).i == v) || ((**iter).j == v)) && edge < (**iter)) {
211  GUM_ERROR(OperationNotAllowed,
212  "added backward edge is lesser than an existing edge on v");
213  }
214  }
215  }
216 
217  // Finally we check if child is minimal.
218  if (!child->isMinimal()) {
219  GUM_ERROR(OperationNotAllowed, "the DFSCode for this growth is not minimal")
220  }
221  }
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ _initialiaze_root_()

template<typename GUM_SCALAR >
void gum::prm::gspan::DFSTree< GUM_SCALAR >::_initialiaze_root_ ( Pattern p,
Sequence< EdgeData< GUM_SCALAR > * > &  seq 
)
private

This initialize the DSFTree with a new root.

Parameters
pA Pattern.
seqA sequence of EdgeData<GUM_SCALAR>.

Definition at line 92 of file DFSTree_tpl.h.

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

93  {
94  DFSTree< GUM_SCALAR >::PatternData* data = _data_[p];
95  std::vector< NodeId > degree_list;
96 
97  for (auto iter = edge_seq.begin(); iter != edge_seq.end(); ++iter) {
98  const auto& edge = *iter;
99  Sequence< PRMInstance< GUM_SCALAR >* >* seq
100  = new Sequence< PRMInstance< GUM_SCALAR >* >();
101 
102  // Creating the multiset of instances matching p
103  bool u_first = (edge->l_u->id < edge->l_v->id);
104  seq->insert((u_first) ? edge->u : edge->v);
105  seq->insert((!u_first) ? edge->u : edge->v);
106 
107  NodeId an_id = data->iso_graph.addNode();
108  data->iso_map.insert(an_id, seq);
109  degree_list.push_back(an_id);
110 
111  // Adding edges between two isomorphisms of p sharing at least one
112  // instance
113  for (const auto& elt: data->iso_map)
114  if (elt.first != an_id)
115  for (auto iter = elt.second->begin(); iter != elt.second->end(); ++iter)
116  if (seq->exists(*iter)) {
117  data->iso_graph.addEdge(an_id, elt.first);
118  break;
119  }
120  }
121 
122  // Computing p->max_indep_set using a greedy algorithm
123  DFSTree< GUM_SCALAR >::NeighborDegreeSort my_operator(data->iso_graph);
124  std::sort(degree_list.begin(), degree_list.end(), my_operator);
125  Set< NodeId > removed;
126 
127  for (const auto node: degree_list) {
128  if (!removed.exists(node)) {
129  removed.insert(node);
130 
131  for (const auto neighbor: data->iso_graph.neighbours(node))
132  removed.insert(neighbor);
133 
134  data->max_indep_set.insert(node);
135  }
136  }
137  }
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
PatternData & data(const Pattern &p)
Definition: DFSTree_tpl.h:489
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:606
+ Here is the call graph for this function:

◆ _is_new_seq_()

template<typename GUM_SCALAR >
bool gum::prm::gspan::DFSTree< GUM_SCALAR >::_is_new_seq_ ( Sequence< PRMInstance< GUM_SCALAR > * > &  seq,
NodeProperty< Sequence< PRMInstance< GUM_SCALAR > * > * > &  iso_map 
)
private

Check if an instance match is redundant.

Definition at line 140 of file DFSTree_tpl.h.

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

142  {
143  for (const auto& elt: iso_map) {
144  bool found = false;
145 
146  for (const auto& inst: seq)
147  if (!(elt.second->exists(inst))) {
148  found = true;
149  break;
150  }
151 
152  if (!found) { return false; }
153  }
154 
155  return true;
156  }
Sequence< PRMInstance< GUM_SCALAR > *> & iso_map(const Pattern &p, NodeId node)
Given a pattern and a node in its isomorphism graph, this methods returns the sequence of instance ma...
Definition: DFSTree_tpl.h:452
+ Here is the call graph for this function:

◆ _test_equality_()

template<typename GUM_SCALAR >
bool gum::prm::gspan::DFSTree< GUM_SCALAR >::_test_equality_ ( HashTable< PRMClassElement< GUM_SCALAR > *, Size > &  x,
HashTable< PRMClassElement< GUM_SCALAR > *, Size > &  y 
)
private

Definition at line 335 of file DFSTree_tpl.h.

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

337  {
338  try {
339  for (const auto& elt: x)
340  if (y[elt.first] != elt.second) return false;
341  } catch (NotFound&) { return false; }
342 
343  return true;
344  }
+ Here is the call graph for this function:

◆ addArc()

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:51
+ 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 238 of file nodeGraphPart_inl.h.

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

238  {
239  NodeId newNode;
240 
241  // fill the first hole if holes exist
242  if (_holes_ && (!_holes_->empty())) {
243  newNode = *(_holes_->begin());
244  _eraseHole_(newNode);
245  } else {
246  newNode = _boundVal_;
247  ++_boundVal_;
249  }
250 
251  GUM_EMIT1(onNodeAdded, newNode);
252 
253  return newNode;
254  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
#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:498
Signaler1< NodeId > onNodeAdded
void _eraseHole_(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 256 of file nodeGraphPart_inl.h.

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

256  {
257  std::vector< NodeId > v;
258  v.reserve(N);
259  for (Idx i = 0; i < N; i++)
260  v.push_back(this->addNode());
261  return v;
262  }
+ 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  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:41
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size _holes_size_
value for holes configuration
Signaler1< NodeId > onNodeAdded
bool _inHoles_(NodeId id) const
void _eraseHole_(NodeId id)
to delete hole.
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:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
bool _holes_resize_policy_
value for holes configuration
+ Here is the call graph for this function:

◆ addRoot()

template<typename GUM_SCALAR >
void gum::prm::gspan::DFSTree< GUM_SCALAR >::addRoot ( LabelData data)

Add a one edge Pattern in this DFSTree.

Parameters
dataData over the edge used to create a root of this DFSTree.
Returns
Returns the Pattern added as a root of this DFSTree.

Definition at line 48 of file DFSTree_tpl.h.

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

48  {
49  HashTable< Pattern*, std::pair< Idx, Idx > > roots;
50  HashTable< Pattern*, Sequence< EdgeData< GUM_SCALAR >* >* > roots_edges;
51 
52  for (const auto& edge: _graph_->edges(&label)) {
53  bool u_first = (edge->l_u->id < edge->l_v->id);
54  Idx u_idx = (u_first) ? edge->l_u->id : edge->l_v->id;
55  Idx v_idx = (!u_first) ? edge->l_u->id : edge->l_v->id;
56 
57  bool found = false;
58 
59  for (const auto& elt: roots)
60  if ((elt.second.first == u_idx) && (elt.second.second == v_idx)) {
61  roots_edges[elt.first]->insert(edge);
62  found = true;
63  break;
64  }
65 
67  if (!found) {
68  Pattern* p = new Pattern();
69  roots.insert(p, std::make_pair(u_idx, v_idx));
70  roots_edges.insert(p, new Sequence< EdgeData< GUM_SCALAR >* >());
71  roots_edges[p]->insert(edge);
72  DFSTree< GUM_SCALAR >::PatternData* data = new DFSTree< GUM_SCALAR >::PatternData(p);
73  NodeId u = p->addNodeWithLabel((u_first) ? *edge->l_u : *edge->l_v);
74  NodeId v = p->addNodeWithLabel((!u_first) ? *edge->l_u : *edge->l_v);
75  p->addArc(u, v, label);
76  _node_map_.insert(DiGraph::addNode(), p);
77  _data_.insert(p, data);
78  _roots_.push_back(_node_map_.first(p));
79  }
80  }
81 
82  // This is used to compute the max independent set of p->max_indep_set
83  for (const auto& elt: roots_edges) {
84  _initialiaze_root_(elt.first, *elt.second);
85  strategy().accept_root(elt.first);
86  delete elt.second;
87  }
88  }
const InterfaceGraph< GUM_SCALAR > * _graph_
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:260
Bijection< NodeId, Pattern *> _node_map_
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:267
virtual NodeId addNode()
insert a new node and return its id
std::list< NodeId > & roots()
Returns the list of root patterns in this DFSTree.
Definition: DFSTree_tpl.h:378
void _initialiaze_root_(Pattern *p, Sequence< EdgeData< GUM_SCALAR > * > &seq)
This initialize the DSFTree with a new root.
Definition: DFSTree_tpl.h:92
SearchStrategy< GUM_SCALAR > & strategy()
strategy getter
Definition: DFSTree_tpl.h:500
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
PatternData & data(const Pattern &p)
Definition: DFSTree_tpl.h:489
std::list< NodeId > _roots_
The list of root patterns in this DFSTree.
Definition: DFSTree.h:263
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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:606
+ Here is the call graph for this function:

◆ arcs()

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

returns the set of arcs stored within the ArcGraphPart

Definition at line 38 of file arcGraphPart_inl.h.

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

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

◆ arcsProperty() [1/2]

template<typename VAL >
ArcProperty< VAL > gum::ArcGraphPart::arcsProperty ( VAL(*)(const Arc &)  f,
Size  size = 0 
) const
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 340 of file nodeGraphPart_inl.h.

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

340  {
341  NodeSet son(sizeNodes());
342 
343  if (!empty()) {
344  for (NodeId n = 0; n < _boundVal_; ++n) {
345  if (!_inHoles_(n)) son.insert(n);
346  }
347  }
348 
349  return son;
350  }
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
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
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 314 of file nodeGraphPart_inl.h.

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

314  {
315  NodeGraphPartIterator it(*this);
316  it.validate_(); // stop the iterator at the first not-in-holes
317  return it;
318  }
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 302 of file nodeGraphPart_inl.h.

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

302  {
303  NodeGraphPartIteratorSafe it(*this);
304  it.validate_(); // stop the iterator at the first not-in-holes
305  return it;
306  }
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 291 of file nodeGraphPart_inl.h.

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

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

◆ children() [1/4]

template<typename GUM_SCALAR >
INLINE std::list< NodeId > & gum::prm::gspan::DFSTree< GUM_SCALAR >::children ( const Pattern p)

Returns the list of p children in this DFSTree.

Definition at line 416 of file DFSTree_tpl.h.

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

416  {
417  try {
418  return _data_[const_cast< Pattern* >(&p)]->children;
419  } catch (NotFound&) { GUM_ERROR(NotFound, "pattern not found in this DFSTree") }
420  }
std::list< NodeId > & children(const Pattern &p)
Returns the list of p children in this DFSTree.
Definition: DFSTree_tpl.h:416
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ children() [2/4]

template<typename GUM_SCALAR >
INLINE const std::list< NodeId > & gum::prm::gspan::DFSTree< GUM_SCALAR >::children ( const Pattern p) const

Returns the list of p children in this DFSTree.

Definition at line 423 of file DFSTree_tpl.h.

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

423  {
424  try {
425  return _data_[const_cast< Pattern* >(&p)]->children;
426  } catch (NotFound&) { GUM_ERROR(NotFound, "pattern not found in this DFSTree") }
427  }
std::list< NodeId > & children(const Pattern &p)
Returns the list of p children in this DFSTree.
Definition: DFSTree_tpl.h:416
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ children() [3/4]

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

returns the set of children of a set of nodes

Definition at line 66 of file arcGraphPart_inl.h.

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

66  {
67  NodeSet res;
68  for (const auto node: ids)
69  res += children(node);
70  return res;
71  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
+ Here is the call graph for this function:

◆ children() [4/4]

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

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

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

◆ 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:361
+ 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 293 of file nodeGraphPart_inl.h.

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

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

◆ data() [1/2]

template<typename GUM_SCALAR >
INLINE DFSTree< GUM_SCALAR >::PatternData & gum::prm::gspan::DFSTree< GUM_SCALAR >::data ( const Pattern p)
Parameters
pThe pattern

Definition at line 489 of file DFSTree_tpl.h.

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

489  {
490  return *(_data_[const_cast< Pattern* >(&p)]);
491  }
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
+ Here is the call graph for this function:

◆ data() [2/2]

template<typename GUM_SCALAR >
INLINE const DFSTree< GUM_SCALAR >::PatternData & gum::prm::gspan::DFSTree< GUM_SCALAR >::data ( const Pattern p) const
Parameters
pThe pattern

Definition at line 495 of file DFSTree_tpl.h.

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

495  {
496  return *(_data_[const_cast< Pattern* >(&p)]);
497  }
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
+ 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:606
+ 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:51
+ 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().

231  {
232  // not recursive version => use a FIFO for simulating the recursion
233  List< NodeId > nodeFIFO;
234  nodeFIFO.pushBack(n2);
235 
236  // mark[node] = successor if visited, else mark[node] does not exist
237  NodeProperty< NodeId > mark;
238  mark.insert(n2, n2);
239 
240  NodeId current;
241 
242  while (!nodeFIFO.empty()) {
243  current = nodeFIFO.front();
244  nodeFIFO.popFront();
245 
246  // check the parents
247  for (const auto new_one: parents(current)) {
248  if (mark.exists(new_one)) // the node has already been visited
249  continue;
250 
251  mark.insert(new_one, current);
252 
253  if (new_one == n1) {
254  std::vector< NodeId > v;
255 
256  for (current = n1; current != n2; current = mark[current])
257  v.push_back(current);
258 
259  v.push_back(n2);
260 
261  return v;
262  }
263 
264  nodeFIFO.pushBack(new_one);
265  }
266 
267  // check the children
268  for (const auto new_one: children(current)) {
269  if (mark.exists(new_one)) // the node has already been visited
270  continue;
271 
272  mark.insert(new_one, current);
273 
274  if (new_one == n1) {
275  std::vector< NodeId > v;
276 
277  for (current = n1; current != n2; current = mark[current])
278  v.push_back(current);
279 
280  v.push_back(n2);
281 
282  return v;
283  }
284 
285  nodeFIFO.pushBack(new_one);
286  }
287  }
288 
289  GUM_ERROR(NotFound, "no path found")
290  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ empty()

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

alias for emptyNodes

Definition at line 289 of file nodeGraphPart_inl.h.

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

289 { 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:700
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ emptyNodes()

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

indicates whether there exists nodes in the NodeGraphPart

Definition at line 287 of file nodeGraphPart_inl.h.

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

287 { 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 320 of file nodeGraphPart_inl.h.

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

320  {
321  return _endIteratorSafe_;
322  }
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 310 of file nodeGraphPart_inl.h.

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

310  {
311  return _endIteratorSafe_;
312  }
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 106 of file arcGraphPart_inl.h.

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

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

◆ eraseChildren()

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

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

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

◆ 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 67 of file diGraph_inl.h.

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

67  {
68  // warning: to remove the arcs adjacent to id, use the unvirtualized
69  // versions
70  // of arc removals
73 
75  }
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 123 of file arcGraphPart_inl.h.

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

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

◆ eraseSetOfArcs_()

INLINE void gum::ArcGraphPart::eraseSetOfArcs_ ( const ArcSet set)
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 118 of file arcGraphPart_inl.h.

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

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

◆ exists()

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

alias for existsNode

Definition at line 277 of file nodeGraphPart_inl.h.

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

277 { return existsNode(node); }
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
+ 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 { return _arcs_.contains(arc); }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:558
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
Definition: arcGraphPart.h:301
+ Here is the call graph for this function:

◆ existsArc() [2/2]

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

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

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

◆ existsNode()

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

returns true iff the NodeGraphPart contains the given nodeId

Definition at line 271 of file nodeGraphPart_inl.h.

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

271  {
272  if (node >= _boundVal_) return false;
273 
274  return (!_inHoles_(node));
275  }
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:

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

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

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

◆ family() [2/2]

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

returns the set of family nodes of a set of nodes

Definition at line 82 of file arcGraphPart_inl.h.

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

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

◆ frequency()

template<typename GUM_SCALAR >
INLINE double gum::prm::gspan::DFSTree< GUM_SCALAR >::frequency ( const Pattern p) const

Returns the frequency of p respecting it's maximal independent set.

Parameters
pThe pattern

Definition at line 483 of file DFSTree_tpl.h.

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

483  {
484  return (double)_data_[const_cast< Pattern* >(&p)]->max_indep_set.size();
485  }
Set< NodeId > & max_indep_set(const Pattern &p)
Returns the maximal independent set of p isomorphism graph.
Definition: DFSTree_tpl.h:465
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
+ Here is the call graph for this function:

◆ graph()

template<typename GUM_SCALAR >
INLINE const InterfaceGraph< GUM_SCALAR > & gum::prm::gspan::DFSTree< GUM_SCALAR >::graph ( ) const

Returns the list of root patterns in this DFSTree.

Definition at line 472 of file DFSTree_tpl.h.

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

472  {
473  return *_graph_;
474  }
const InterfaceGraph< GUM_SCALAR > * _graph_
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:260
+ Here is the call graph for this function:

◆ growPattern()

template<typename GUM_SCALAR >
Pattern & gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern ( Pattern p,
EdgeGrowth< GUM_SCALAR > &  edge_growth,
Size  min_freq 
)

Add a one edge growth of p as one of its child.

The child is inserted lexicographically among the children of p. However if the child is found to be not minimal an OperationNotAllowed is raised.

Parameters
pThe Pattern from which a one edge growth is spawned.
edge_growthThe data about the edge growth of p.
min_freqminimum number of occurrence to be used as a pattern
Exceptions
FatalErrorRaised if the grow is an illegal backedge growth.
OperationNotAllowedRaised if the grow is found to be not minimal.

Definition at line 224 of file DFSTree_tpl.h.

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

226  {
227  Pattern* child = new Pattern(p);
228 
229  try {
230  _checkGrowth_(p, child, edge_growth);
231  } catch (OperationNotAllowed&) {
232  delete child;
233  throw;
234  }
235 
236  // Now we need to build the pattern data about child
237  DFSTree< GUM_SCALAR >::PatternData* data = new DFSTree< GUM_SCALAR >::PatternData(child);
238  std::vector< NodeId > degree_list;
239  NodeProperty< Sequence< PRMInstance< GUM_SCALAR >* >* >& p_iso_map = _data_[&p]->iso_map;
240  typename NodeProperty< std::pair< PRMInstance< GUM_SCALAR >*,
241  PRMInstance< GUM_SCALAR >* > >::iterator_safe match;
242  // Using p information to build child's isomorphism graph
243  NodeId id = 0;
244 
245  for (const auto& elt: p_iso_map) {
246  auto match = edge_growth.matches.begin();
247 
248  for (; match != edge_growth.matches.end(); ++match) {
249  // Adding the isomorphism in the iso_graph and building the iso_map.
250  if (child->code().codes.back()->isForward()) {
251  if (elt.second->exists(match.val().first)
252  && !(elt.second->exists(match.val().second))) {
253  // Let's see if the new match is already matched
254  Sequence< PRMInstance< GUM_SCALAR >* >* new_seq
255  = new Sequence< PRMInstance< GUM_SCALAR >* >(*elt.second);
256  new_seq->insert(match.val().second);
257 
258  if (_is_new_seq_(*new_seq, data->iso_map)) {
259  id = data->iso_graph.addNode();
260  data->iso_map.insert(id, new_seq);
261  } else {
262  delete new_seq;
263  }
264 
265  break;
266  }
267  } else {
268  if (elt.second->exists(match.val().first) && elt.second->exists(match.val().second)) {
269  Sequence< PRMInstance< GUM_SCALAR >* >* new_seq
270  = new Sequence< PRMInstance< GUM_SCALAR >* >(*elt.second);
271 
272  if (_is_new_seq_(*new_seq, data->iso_map)) {
273  id = data->iso_graph.addNode();
274  data->iso_map.insert(id, new_seq);
275  } else {
276  delete new_seq;
277  }
278 
279  break;
280  }
281  }
282  }
283 
284  if (match != edge_growth.matches.end()) {
285  // Adding edges in the iso_graph
286  for (const auto node: data->iso_graph.nodes())
287  if (node != id)
288  for (const auto m: *data->iso_map[id])
289  if (data->iso_map[node]->exists(m)) {
290  data->iso_graph.addEdge(node, id);
291  break;
292  }
293 
294  degree_list.push_back(id);
295  edge_growth.matches.erase(match.key());
296  }
297  }
298 
299  if (data->iso_graph.size() < min_freq) {
300  delete data;
301  delete child;
302  GUM_ERROR(OperationNotAllowed, "child is not frequent enough")
303  }
304 
305  // Now we can compute the maximal independent set of child
306  DFSTree< GUM_SCALAR >::NeighborDegreeSort my_operator(data->iso_graph);
307  std::sort(degree_list.begin(), degree_list.end(), my_operator);
308  Set< NodeId > removed;
309 
310  for (const auto node: degree_list) {
311  if (!removed.exists(node)) {
312  removed.insert(node);
313 
314  for (const auto neighbor: data->iso_graph.neighbours(node))
315  removed.insert(neighbor);
316 
317  data->max_indep_set.insert(node);
318  }
319  }
320 
321  _data_.insert(child, data);
322 
323  if (!_strategy_->accept_growth(&p, child, edge_growth)) {
324  _data_.erase(child);
325  delete data;
326  delete child;
327  GUM_ERROR(OperationNotAllowed, "child is not frequent enough")
328  }
329 
330  _addChild_(p, child, edge_growth);
331  return *child;
332  }
SearchStrategy< GUM_SCALAR > * _strategy_
The strategy used to prune the search tree.
Definition: DFSTree.h:273
void _addChild_(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Add a child to this DFSTree.
Definition: DFSTree_tpl.h:159
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
void _checkGrowth_(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Raise different exceptions if child is invalid or illegal.
Definition: DFSTree_tpl.h:186
PatternData & data(const Pattern &p)
Definition: DFSTree_tpl.h:489
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:606
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
bool _is_new_seq_(Sequence< PRMInstance< GUM_SCALAR > * > &seq, NodeProperty< Sequence< PRMInstance< GUM_SCALAR > * > * > &iso_map)
Check if an instance match is redundant.
Definition: DFSTree_tpl.h:140
+ 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 131 of file diGraph.cpp.

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

131  {
132  if (!exists(from)) return false;
133 
134  // not recursive version => use a FIFO for simulating the recursion
135  List< NodeId > nodeFIFO;
136  nodeFIFO.pushBack(from);
137 
138  NodeSet marked;
139  marked.insert(from);
140 
141  NodeId new_one;
142 
143  while (!nodeFIFO.empty()) {
144  new_one = nodeFIFO.front();
145  // std::cout<<new_one<<std::endl;
146  nodeFIFO.popFront();
147 
148  for (const auto chi: children(new_one)) {
149  if (chi == to) return true;
150 
151  if (!marked.contains(chi)) {
152  nodeFIFO.pushBack(chi);
153  marked.insert(chi);
154  }
155  }
156  }
157 
158  return false;
159  }
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:606
+ Here is the call graph for this function:

◆ iso_graph()

template<typename GUM_SCALAR >
INLINE UndiGraph & gum::prm::gspan::DFSTree< GUM_SCALAR >::iso_graph ( const Pattern p)

Returns the isomorphism graph of p in the interface graph.

The isomorphism graph is a undirected graph in which each node represents a set of PRMInstance<GUM_SCALAR> matching p in the interface graph.

If there exists an edge between two nodes in the isomorphism graph, then the two respective set of instances are not disjoint.

Parameters
pThe pattern for which we want the isomorphism graph.
Returns
The isomorphism graph of p.
Exceptions
NotFoundRaised if p is not a node in this DFSTree.

Definition at line 444 of file DFSTree_tpl.h.

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

444  {
445  try {
446  return _data_[const_cast< Pattern* >(&p)]->iso_graph;
447  } catch (NotFound&) { GUM_ERROR(NotFound, "pattern not found in this DFSTree") }
448  }
UndiGraph & iso_graph(const Pattern &p)
Returns the isomorphism graph of p in the interface graph.
Definition: DFSTree_tpl.h:444
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ iso_map()

template<typename GUM_SCALAR >
INLINE Sequence< PRMInstance< GUM_SCALAR > *> & gum::prm::gspan::DFSTree< GUM_SCALAR >::iso_map ( const Pattern p,
NodeId  node 
)

Given a pattern and a node in its isomorphism graph, this methods returns the sequence of instance matching p in the interface graph.

The sequence of instances respect DSF subscripting. Each node in the pattern's graph have a DSF subscript from 1 to n, where n is the number of nodes in the pattern's graph.

If for a given match you want the k-th instance repecting p's DFS subscripting, then it will be the (k - 1)th element in the sequence.

Parameters
pThe pattern for which we want a match in the interface graph.
nodeThe node in p isomorphism graph for which we want the matching set if instances.
Returns
Returns the sequence of instances matching p and node.
Exceptions
NotFoundRaised if p or node does not exists.

Definition at line 452 of file DFSTree_tpl.h.

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

452  {
453  try {
454  return *(_data_[const_cast< Pattern* >(&p)]->iso_map[node]);
455  } catch (NotFound&) {
456  if (_data_.exists(const_cast< Pattern* >(&p))) {
457  GUM_ERROR(NotFound, "node not found in Pattern's isomorphism graph")
458  } else {
459  GUM_ERROR(NotFound, "pattern not found in this DFSTree")
460  }
461  }
462  }
Sequence< PRMInstance< GUM_SCALAR > *> & iso_map(const Pattern &p, NodeId node)
Given a pattern and a node in its isomorphism graph, this methods returns the sequence of instance ma...
Definition: DFSTree_tpl.h:452
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ 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

◆ max_indep_set()

template<typename GUM_SCALAR >
INLINE Set< NodeId > & gum::prm::gspan::DFSTree< GUM_SCALAR >::max_indep_set ( const Pattern p)

Returns the maximal independent set of p isomorphism graph.

Parameters
pThe pattern for which we want its maximal independent set.
Exceptions
NotFoundRaised if p is not a node in this DFSTree.

Definition at line 465 of file DFSTree_tpl.h.

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

465  {
466  try {
467  return _data_[const_cast< Pattern* >(&p)]->max_indep_set;
468  } catch (NotFound&) { GUM_ERROR(NotFound, "pattern not found in this DFSTree") }
469  }
Set< NodeId > & max_indep_set(const Pattern &p)
Returns the maximal independent set of p isomorphism graph.
Definition: DFSTree_tpl.h:465
HashTable< Pattern *, PatternData *> _data_
Data about patterns in this DFSTree.
Definition: DFSTree.h:270
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ 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 211 of file nodeGraphPart_inl.h.

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

211  {
212  NodeId next = 0;
213 
214  // return the first hole if holes exist
215  if (_holes_ && (!_holes_->empty()))
216  next = *(_holes_->begin());
217  else // in other case
218  next = _boundVal_;
219 
220  return next;
221  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:498
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ nodes()

INLINE const NodeGraphPart & gum::NodeGraphPart::nodes ( ) const
inherited

return *this as a NodeGraphPart

Definition at line 352 of file nodeGraphPart_inl.h.

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

352  {
353  return *(static_cast< const NodeGraphPart* >(this));
354  }
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
+ 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.

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

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

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

◆ operator!=() [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 81 of file diGraph_inl.h.

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

81 { return !operator==(p); }
bool operator==(const DiGraph &g) const
tests whether two DiGraphs are identical (same nodes, same arcs)
Definition: diGraph_inl.h:77
+ 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 338 of file nodeGraphPart_inl.h.

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

338 { return !operator==(p); }
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 180 of file arcGraphPart_inl.h.

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

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

◆ 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 77 of file diGraph_inl.h.

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

77  {
79  }
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 324 of file nodeGraphPart_inl.h.

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

324  {
325  if (_boundVal_ != p._boundVal_) return false;
326 
327  if (_holes_)
328  if (p._holes_)
329  return (*_holes_ == *p._holes_);
330  else
331  return false;
332  else if (p._holes_)
333  return false;
334 
335  return true;
336  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the call graph for this function:

◆ parent() [1/2]

template<typename GUM_SCALAR >
INLINE Pattern & gum::prm::gspan::DFSTree< GUM_SCALAR >::parent ( const Pattern p)

Returns the parent of p in this DFSTree.

Definition at line 388 of file DFSTree_tpl.h.

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

388  {
389  try {
390  return *(_node_map_.second(
391  *(DiGraph::parents(_node_map_.first(const_cast< Pattern* >(&p))).begin())));
392  } catch (NotFound&) {
393  if (_node_map_.existsSecond(const_cast< Pattern* >(&p))) {
394  GUM_ERROR(NotFound, "the given pattern is a root node")
395  } else {
396  GUM_ERROR(NotFound, "pattern not found in this DFSTree")
397  }
398  }
399  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
Bijection< NodeId, Pattern *> _node_map_
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:267
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ parent() [2/2]

template<typename GUM_SCALAR >
INLINE const Pattern & gum::prm::gspan::DFSTree< GUM_SCALAR >::parent ( const Pattern p) const

Returns the parent of p in this DFSTree.

Definition at line 402 of file DFSTree_tpl.h.

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

402  {
403  try {
404  return *(_node_map_.second(
405  *(DiGraph::parents(_node_map_.first(const_cast< Pattern* >(&p))).begin())));
406  } catch (NotFound&) {
407  if (_node_map_.existsSecond(const_cast< Pattern* >(&p))) {
408  GUM_ERROR(NotFound, "the given pattern is a root node")
409  } else {
410  GUM_ERROR(NotFound, "pattern not found in this DFSTree")
411  }
412  }
413  }
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
Bijection< NodeId, Pattern *> _node_map_
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:267
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ 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 54 of file arcGraphPart_inl.h.

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

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

◆ parents() [2/2]

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

returns the set of parents of a set of nodes

Definition at line 74 of file arcGraphPart_inl.h.

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

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

◆ pattern() [1/2]

template<typename GUM_SCALAR >
INLINE Pattern & gum::prm::gspan::DFSTree< GUM_SCALAR >::pattern ( NodeId  id)

Returns the pattern represented by id in this DFSTree.

Definition at line 430 of file DFSTree_tpl.h.

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

430  {
431  try {
432  return *(_node_map_.second(id));
433  } catch (NotFound&) { GUM_ERROR(NotFound, "no pattern matching the given id") }
434  }
Bijection< NodeId, Pattern *> _node_map_
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:267
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ pattern() [2/2]

template<typename GUM_SCALAR >
INLINE const Pattern & gum::prm::gspan::DFSTree< GUM_SCALAR >::pattern ( NodeId  id) const

Returns the pattern represented by id in this DFSTree.

Definition at line 437 of file DFSTree_tpl.h.

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

437  {
438  try {
439  return *(_node_map_.second(id));
440  } catch (NotFound&) { GUM_ERROR(NotFound, "no pattern matching the given id") }
441  }
Bijection< NodeId, Pattern *> _node_map_
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:267
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ 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  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
NodeId _boundVal_
the id below which NodeIds may belong to the NodeGraphPart
void _updateEndIteratorSafe_()
updating endIterator (always at max+1)
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size _holes_size_
value for holes configuration
virtual void clear()
alias for clearNodes
bool _holes_resize_policy_
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.

◆ roots() [1/2]

template<typename GUM_SCALAR >
INLINE std::list< NodeId > & gum::prm::gspan::DFSTree< GUM_SCALAR >::roots ( )

Returns the list of root patterns in this DFSTree.

Definition at line 378 of file DFSTree_tpl.h.

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

378  {
379  return _roots_;
380  }
std::list< NodeId > _roots_
The list of root patterns in this DFSTree.
Definition: DFSTree.h:263
+ Here is the call graph for this function:

◆ roots() [2/2]

template<typename GUM_SCALAR >
INLINE const std::list< NodeId > & gum::prm::gspan::DFSTree< GUM_SCALAR >::roots ( ) const

Returns the list of root patterns in this DFSTree.

Definition at line 383 of file DFSTree_tpl.h.

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

383  {
384  return _roots_;
385  }
std::list< NodeId > _roots_
The list of root patterns in this DFSTree.
Definition: DFSTree.h:263
+ Here is the call graph for this function:

◆ size()

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

alias for sizeNodes

Definition at line 269 of file nodeGraphPart_inl.h.

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

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

◆ sizeArcs()

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

indicates the number of arcs stored within the ArcGraphPart

Definition at line 36 of file arcGraphPart_inl.h.

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

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

◆ sizeNodes()

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

returns the number of nodes in the NodeGraphPart

Definition at line 265 of file nodeGraphPart_inl.h.

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

265  {
266  return (_holes_) ? (_boundVal_ - _holes_->size()) : _boundVal_;
267  }
NodeSet * _holes_
the set of nodes not contained in the NodeGraphPart in the interval 1.
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:694
+ Here is the call graph for this function:

◆ strategy() [1/2]

template<typename GUM_SCALAR >
INLINE SearchStrategy< GUM_SCALAR > & gum::prm::gspan::DFSTree< GUM_SCALAR >::strategy ( )

strategy getter

Definition at line 500 of file DFSTree_tpl.h.

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

500  {
501  return *_strategy_;
502  }
SearchStrategy< GUM_SCALAR > * _strategy_
The strategy used to prune the search tree.
Definition: DFSTree.h:273
+ Here is the call graph for this function:

◆ strategy() [2/2]

template<typename GUM_SCALAR >
INLINE const SearchStrategy< GUM_SCALAR > & gum::prm::gspan::DFSTree< GUM_SCALAR >::strategy ( ) const

strategy getter

Definition at line 505 of file DFSTree_tpl.h.

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

505  {
506  return *_strategy_;
507  }
SearchStrategy< GUM_SCALAR > * _strategy_
The strategy used to prune the search tree.
Definition: DFSTree.h:273
+ Here is the call graph for this function:

◆ toDot()

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 65 of file diGraph.cpp.

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

65  {
66  std::stringstream strBuff;
67  std::string tab = " ";
68  strBuff << "digraph {" << std::endl;
69 
70  for (const auto node: nodes())
71  strBuff << tab << node << ";" << std::endl;
72 
73  strBuff << std::endl;
74 
75  for (const auto& arc: arcs())
76  strBuff << tab << arc.tail() << " -> " << arc.head() << ";" << std::endl;
77 
78  strBuff << "}" << std::endl << std::endl;
79  return strBuff.str();
80  }
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 88 of file diGraph.cpp.

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

88  {
89  if (clear || (_mutableTopologicalOrder_ == nullptr)) { // we have to call topologicalOrder_
90  if (_mutableTopologicalOrder_ == nullptr) {
92  } else {
93  // clear is True
95  }
96 
98  }
99 
101  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:264
Sequence< NodeId > * _mutableTopologicalOrder_
The topology sequence of this Directed Graphical Model.
Definition: diGraph.h:209
void _topologicalOrder_() const
Returns a topological order of this DAGModel.
Definition: diGraph.cpp:103
+ 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 58 of file diGraph.cpp.

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

58  {
59  std::string s = NodeGraphPart::toString();
60  s += " , ";
62  return s;
63  }
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 168 of file arcGraphPart_inl.h.

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

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

◆ unvirtualizedEraseParents()

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

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

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

◆ unvirtualizedEraseSetOfArcs_()

INLINE void gum::ArcGraphPart::unvirtualizedEraseSetOfArcs_ ( const ArcSet set)
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 151 of file arcGraphPart_inl.h.

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

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

Member Data Documentation

◆ _data_

template<typename GUM_SCALAR >
HashTable< Pattern*, PatternData* > gum::prm::gspan::DFSTree< GUM_SCALAR >::_data_
private

Data about patterns in this DFSTree.

Definition at line 270 of file DFSTree.h.

◆ _graph_

template<typename GUM_SCALAR >
const InterfaceGraph< GUM_SCALAR >* gum::prm::gspan::DFSTree< GUM_SCALAR >::_graph_
private

The interface graph on which this DFSTree applies.

Definition at line 260 of file DFSTree.h.

◆ _node_map_

template<typename GUM_SCALAR >
Bijection< NodeId, Pattern* > gum::prm::gspan::DFSTree< GUM_SCALAR >::_node_map_
private

The mapping between nodes in this DFSTree and the patterns they represents.

Definition at line 267 of file DFSTree.h.

◆ _roots_

template<typename GUM_SCALAR >
std::list< NodeId > gum::prm::gspan::DFSTree< GUM_SCALAR >::_roots_
private

The list of root patterns in this DFSTree.

Definition at line 263 of file DFSTree.h.

◆ _strategy_

template<typename GUM_SCALAR >
SearchStrategy< GUM_SCALAR >* gum::prm::gspan::DFSTree< GUM_SCALAR >::_strategy_
private

The strategy used to prune the search tree.

Definition at line 273 of file DFSTree.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: