aGrUM  0.16.0
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 71 of file DFSTree.h.

Member Typedef Documentation

◆ ArcIterator

Definition at line 81 of file arcGraphPart.h.

◆ node_const_iterator

types for STL compliance

Definition at line 261 of file nodeGraphPart.h.

◆ node_const_iterator_safe

types for STL compliance

Definition at line 263 of file nodeGraphPart.h.

◆ node_iterator

types for STL compliance

Definition at line 260 of file nodeGraphPart.h.

◆ node_iterator_safe

types for STL compliance

Definition at line 262 of file nodeGraphPart.h.

◆ NodeConstIterator

Definition at line 270 of file nodeGraphPart.h.

◆ NodeConstIteratorSafe

◆ NodeIterator

Definition at line 269 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 375 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__strategy.

377  :
378  __graph(&graph),
380  GUM_CONSTRUCTOR(DFSTree);
381 
382  if (!__strategy) __strategy = new FrequenceSearch< GUM_SCALAR >(2);
383 
384  __strategy->setTree(this);
385  }
const InterfaceGraph< GUM_SCALAR > * __graph
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:264
SearchStrategy< GUM_SCALAR > * __strategy
The strategy used to prune the search tree.
Definition: DFSTree.h:277
const InterfaceGraph< GUM_SCALAR > & graph() const
Returns the list of root patterns in this DFSTree.
Definition: DFSTree_tpl.h:500
SearchStrategy< GUM_SCALAR > & strategy()
strategy getter
Definition: DFSTree_tpl.h:530
DFSTree(const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: DFSTree_tpl.h:375

◆ ~DFSTree()

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

Destructor.

Definition at line 37 of file DFSTree_tpl.h.

37  {
38  GUM_DESTRUCTOR(DFSTree);
39 
40  for (const auto& elt : __data) {
41  delete elt.first;
42  delete elt.second;
43  }
44 
45  delete __strategy;
46  }
SearchStrategy< GUM_SCALAR > * __strategy
The strategy used to prune the search tree.
Definition: DFSTree.h:277
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
DFSTree(const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Definition: DFSTree_tpl.h:375

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 161 of file DFSTree_tpl.h.

References gum::NodeGraphPart::addNode(), and gum::prm::gspan::Pattern::code().

162  {
163  // Adding child to the tree
164  NodeId node = DiGraph::addNode();
165  __node_map.insert(node, child);
166  // Adding child in p's children list
167  std::list< NodeId >& children = __data[&p]->children;
168 
169  if (children.empty()) {
170  children.push_back(node);
171  } else {
172  size_t size = children.size();
173 
174  for (std::list< NodeId >::iterator iter = children.begin();
175  iter != children.end();
176  ++iter) {
177  if (child->code() < pattern(*iter).code()) {
178  children.insert(iter, node);
179  break;
180  }
181  }
182 
183  if (size == children.size()) { children.push_back(node); }
184  }
185  }
std::list< NodeId > & children(const Pattern &p)
Returns the list of p children in this DFSTree.
Definition: DFSTree_tpl.h:429
DFSCode & code()
Returns the DFSCode of this Pattern.
Definition: pattern_inl.h:173
Size size() const
alias for sizeNodes
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:448
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
Bijection< NodeId, Pattern *> __node_map
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:271
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ 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 188 of file DFSTree_tpl.h.

References gum::prm::gspan::Pattern::addArc(), gum::prm::gspan::Pattern::addNodeWithLabel(), gum::prm::gspan::Pattern::code(), gum::prm::gspan::DFSCode::codes, gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::edge, gum::prm::gspan::Pattern::edgeCode(), GUM_ERROR, gum::prm::gspan::EdgeCode::isBackward(), gum::prm::gspan::Pattern::isMinimal(), gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::l_v, gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::u, and gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::v.

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

◆ __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 93 of file DFSTree_tpl.h.

References gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNode(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::exists(), gum::Set< Key, Alloc >::insert(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::insert(), gum::prm::gspan::DFSTree< GUM_SCALAR >::PatternData::iso_graph, gum::prm::gspan::DFSTree< GUM_SCALAR >::PatternData::iso_map, gum::prm::gspan::DFSTree< GUM_SCALAR >::PatternData::max_indep_set, and gum::EdgeGraphPart::neighbours().

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

◆ __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 142 of file DFSTree_tpl.h.

144  {
145  for (const auto& elt : iso_map) {
146  bool found = false;
147 
148  for (const auto& inst : seq)
149  if (!(elt.second->exists(inst))) {
150  found = true;
151  break;
152  }
153 
154  if (!found) { return false; }
155  }
156 
157  return true;
158  }
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:476

◆ __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 342 of file DFSTree_tpl.h.

344  {
345  try {
346  for (const auto& elt : x)
347  if (y[elt.first] != elt.second) return false;
348  } catch (NotFound&) { return false; }
349 
350  return true;
351  }

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

References gum::ArcGraphPart::eraseArc().

91  {
92  for (const auto arc : set)
93  eraseArc(arc);
94  }
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
+ Here is the call graph for this function:

◆ _unvirtualizedEraseSetOfArcs()

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

References gum::ArcGraphPart::eraseArc().

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

◆ addArc()

INLINE void gum::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 35 of file diGraph_inl.h.

References gum::ArcGraphPart::addArc(), gum::NodeGraphPart::exists(), and GUM_ERROR.

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::learning::Miic::_orientation_3off2(), gum::learning::Miic::_orientation_latents(), gum::learning::Miic::_orientation_miic(), gum::learning::Miic::_propagatesHead(), gum::prm::gspan::Pattern::addArc(), gum::DAG::addArc(), and gum::DAGCycleDetector::addArc().

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

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

References GUM_EMIT1.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::__addChild(), gum::prm::StructuredInference< GUM_SCALAR >::__addEdgesInReducedGraph(), gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::__addInterface2Dag(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::__addNode(), gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::__addTypes2Dag(), gum::prm::gspan::StrictSearch< GUM_SCALAR >::__buildPatternGraph(), gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__checkAndAddNodesToDag(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::gspan::DFSTree< GUM_SCALAR >::__initialiaze_root(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode(), gum::prm::gspan::DFSTree< GUM_SCALAR >::addRoot(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::IncrementalGraphLearner(), gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::insert(), and gum::LeafAggregator::update().

253  {
254  NodeId newNode;
255 
256  // fill the first hole if holes exist
257  if (__holes && (!__holes->empty())) {
258  newNode = *(__holes->begin());
259  __eraseHole(newNode);
260  } else {
261  newNode = __boundVal;
262  ++__boundVal;
264  }
265 
266  GUM_EMIT1(onNodeAdded, newNode);
267 
268  return newNode;
269  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:707
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:42
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:517
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
Signaler1< NodeId > onNodeAdded
void __eraseHole(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the caller 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 271 of file nodeGraphPart_inl.h.

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

◆ 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 132 of file nodeGraphPart.cpp.

References gum::NodeGraphPart::__boundVal, gum::NodeGraphPart::__eraseHole(), gum::NodeGraphPart::__holes, gum::NodeGraphPart::__holes_resize_policy, gum::NodeGraphPart::__holes_size, gum::NodeGraphPart::__inHoles(), gum::NodeGraphPart::__updateEndIteratorSafe(), GUM_EMIT1, GUM_ERROR, gum::Set< Key, Alloc >::insert(), and gum::NodeGraphPart::onNodeAdded.

Referenced by gum::EssentialGraph::__buildEssentialGraph(), gum::MarkovBlanket::__buildMarkovBlanket(), gum::SpanningForestPrim::__computeInAComponent(), gum::learning::genericBNLearner::__learnDAG(), gum::learning::genericBNLearner::__prepare_miic_3off2(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::InfluenceDiagram< GUM_SCALAR >::_addNode(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::prm::gspan::Pattern::addNodeWithLabel(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::BayesNetFragment< GUM_SCALAR >::installNode(), gum::prm::gspan::InterfaceGraph< GUM_SCALAR >::InterfaceGraph(), gum::learning::Miic::learnStructure(), gum::UndiGraph::partialUndiGraph(), gum::EssentialGraph::skeleton(), and gum::learning::StructuralConstraintDAG::StructuralConstraintDAG().

132  {
133  if (id >= __boundVal) {
134  if (id > __boundVal) { // we have to add holes
136 
137  for (NodeId i = __boundVal; i < id; ++i)
138  __holes->insert(i);
139  }
140 
141  __boundVal = id + 1;
142 
144  } else {
145  if (__inHoles(id)) { // we fill a hole
146  __eraseHole(id);
147  } else {
148  GUM_ERROR(DuplicateElement, "Id " << id << " is already used");
149  }
150  }
151 
152  GUM_EMIT1(onNodeAdded, id);
153  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
#define GUM_EMIT1(signal, arg1)
Definition: signaler1.h:42
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __holes_resize_policy
value for __holes configuration
bool __inHoles(NodeId id) const
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
Size __holes_size
value for __holes configuration
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
Signaler1< NodeId > onNodeAdded
void __eraseHole(NodeId id)
to delete hole.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 49 of file DFSTree_tpl.h.

References gum::prm::gspan::Pattern::addArc(), gum::NodeGraphPart::addNode(), gum::prm::gspan::Pattern::addNodeWithLabel(), and gum::HashTable< Key, Val, Alloc >::insert().

49  {
50  HashTable< Pattern*, std::pair< Idx, Idx > > roots;
51  HashTable< Pattern*, Sequence< EdgeData< GUM_SCALAR >* >* > roots_edges;
52 
53  for (const auto edge : __graph->edges(&label)) {
54  bool u_first = (edge->l_u->id < edge->l_v->id);
55  Idx u_idx = (u_first) ? edge->l_u->id : edge->l_v->id;
56  Idx v_idx = (!u_first) ? edge->l_u->id : edge->l_v->id;
57 
58  bool found = false;
59 
60  for (const auto& elt : roots)
61  if ((elt.second.first == u_idx) && (elt.second.second == v_idx)) {
62  roots_edges[elt.first]->insert(edge);
63  found = true;
64  break;
65  }
66 
68  if (!found) {
69  Pattern* p = new Pattern();
70  roots.insert(p, std::make_pair(u_idx, v_idx));
71  roots_edges.insert(p, new Sequence< EdgeData< GUM_SCALAR >* >());
72  roots_edges[p]->insert(edge);
73  DFSTree< GUM_SCALAR >::PatternData* data =
74  new DFSTree< GUM_SCALAR >::PatternData(p);
75  NodeId u = p->addNodeWithLabel((u_first) ? *edge->l_u : *edge->l_v);
76  NodeId v = p->addNodeWithLabel((!u_first) ? *edge->l_u : *edge->l_v);
77  p->addArc(u, v, label);
78  __node_map.insert(DiGraph::addNode(), p);
79  __data.insert(p, data);
80  __roots.push_back(__node_map.first(p));
81  }
82  }
83 
84  // This is used to compute the max independent set of p->max_indep_set
85  for (const auto& elt : roots_edges) {
86  __initialiaze_root(elt.first, *elt.second);
87  strategy().accept_root(elt.first);
88  delete elt.second;
89  }
90  }
const InterfaceGraph< GUM_SCALAR > * __graph
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:264
std::list< NodeId > __roots
The list of root patterns in this DFSTree.
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:388
SearchStrategy< GUM_SCALAR > & strategy()
strategy getter
Definition: DFSTree_tpl.h:530
void __initialiaze_root(Pattern *p, Sequence< EdgeData< GUM_SCALAR > * > &seq)
This initialize the DSFTree with a new root.
Definition: DFSTree_tpl.h:93
PatternData & data(const Pattern &p)
Definition: DFSTree_tpl.h:519
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
Bijection< NodeId, Pattern *> __node_map
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:271
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ 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 39 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs.

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

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

◆ arcsProperty() [1/2]

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

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

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::getPartialTemporalOrder().

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

◆ begin()

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

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

Definition at line 333 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_validate().

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::parent().

333  {
334  NodeGraphPartIterator it(*this);
335  it._validate(); // stop the iterator at the first not-in-holes
336  return it;
337  }
friend class NodeGraphPartIterator
+ Here is the call graph for this function:
+ Here is the caller 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 319 of file nodeGraphPart_inl.h.

References gum::NodeGraphPartIterator::_validate().

319  {
320  NodeGraphPartIteratorSafe it(*this);
321  it._validate(); // stop the iterator at the first not-in-holes
322  return it;
323  }
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 308 of file nodeGraphPart_inl.h.

Referenced by gum::NodeGraphPart::__clearNodes(), gum::StaticTriangulation::__computeEliminationTree(), gum::NodeGraphPartIterator::_setPos(), and gum::NodeGraphPartIterator::_validate().

308 { return __boundVal; }
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
+ Here is the caller graph for this function:

◆ children() [1/3]

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 429 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data, and GUM_ERROR.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::children().

429  {
430  try {
431  return __data[const_cast< Pattern* >(&p)]->children;
432  } catch (NotFound&) {
433  GUM_ERROR(NotFound, "pattern not found in this DFSTree");
434  }
435  }
std::list< NodeId > & children(const Pattern &p)
Returns the list of p children in this DFSTree.
Definition: DFSTree_tpl.h:429
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller graph for this function:

◆ children() [2/3]

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 439 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data, gum::prm::gspan::DFSTree< GUM_SCALAR >::children(), and GUM_ERROR.

439  {
440  try {
441  return __data[const_cast< Pattern* >(&p)]->children;
442  } catch (NotFound&) {
443  GUM_ERROR(NotFound, "pattern not found in this DFSTree");
444  }
445  }
std::list< NodeId > & children(const Pattern &p)
Returns the list of p children in this DFSTree.
Definition: DFSTree_tpl.h:429
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ children() [3/3]

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

References gum::ArcGraphPart::__checkChildren(), and gum::ArcGraphPart::__children.

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

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

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

References gum::ArcGraphPart::clearArcs(), and gum::NodeGraphPart::clearNodes().

Referenced by gum::DiGraph::operator=().

43  {
46  }
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:
+ Here is the caller graph for this function:

◆ clearArcs()

void gum::ArcGraphPart::clearArcs ( )
inherited

removes all the arcs from the ArcGraphPart

Definition at line 79 of file arcGraphPart.cpp.

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

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

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

◆ clearNodes()

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

remove all the nodes from the NodeGraphPart

Definition at line 310 of file nodeGraphPart_inl.h.

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

310 { __clearNodes(); }
void __clearNodes()
code for clearing nodes (called twice)
+ Here is the caller 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 519 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data.

519  {
520  return *(__data[const_cast< Pattern* >(&p)]);
521  }
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274

◆ 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 525 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data.

525  {
526  return *(__data[const_cast< Pattern* >(&p)]);
527  }
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274

◆ directedPath()

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

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

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

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

◆ directedUnorientedPath()

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

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

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

◆ empty()

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

alias for emptyNodes

Definition at line 306 of file nodeGraphPart_inl.h.

Referenced by gum::prm::gspan::Pattern::remove().

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

◆ emptyArcs()

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

indicates wether the ArcGraphPart contains any arc

Definition at line 35 of file arcGraphPart_inl.h.

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

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

◆ emptyNodes()

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

indicates whether there exists nodes in the NodeGraphPart

Definition at line 304 of file nodeGraphPart_inl.h.

304 { return (sizeNodes() == 0); }
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart

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

339  {
340  return __endIteratorSafe;
341  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)

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

329  {
330  return __endIteratorSafe;
331  }
NodeGraphPartIteratorSafe __endIteratorSafe
the end iterator (used to speed-up parsings of the NodeGraphPart)

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

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

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

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

◆ eraseChildren()

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

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

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

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

References gum::NodeGraphPart::eraseNode(), gum::ArcGraphPart::unvirtualizedEraseChildren(), and gum::ArcGraphPart::unvirtualizedEraseParents().

Referenced by gum::BarrenNodesFinder::barrenNodes(), gum::InfluenceDiagram< GUM_SCALAR >::erase(), gum::prm::gspan::Pattern::pop_back(), gum::prm::gspan::Pattern::remove(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallNode().

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

◆ eraseParents()

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

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

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

◆ exists()

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

alias for existsNode

Definition at line 292 of file nodeGraphPart_inl.h.

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::prm::ClassBayesNet< GUM_SCALAR >::__get(), gum::learning::genericBNLearner::__learnDAG(), gum::prm::StructuredInference< GUM_SCALAR >::__removeNode(), gum::NodeGraphPartIterator::_setPos(), gum::prm::gspan::Pattern::addArc(), gum::DiGraph::addArc(), gum::UndiGraph::addEdge(), gum::prm::gspan::Pattern::exists(), and gum::DiGraph::hasDirectedPath().

292  {
293  return existsNode(node);
294  }
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
+ Here is the caller 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 41 of file arcGraphPart_inl.h.

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

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

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

◆ existsArc() [2/2]

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

References gum::ArcGraphPart::__parents.

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

◆ existsNode()

◆ 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 513 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data, gum::prm::gspan::DFSTree< GUM_SCALAR >::max_indep_set(), and gum::Set< Key, Alloc >::size().

513  {
514  return (double)__data[const_cast< Pattern* >(&p)]->max_indep_set.size();
515  }
Set< NodeId > & max_indep_set(const Pattern &p)
Returns the maximal independent set of p isomorphism graph.
Definition: DFSTree_tpl.h:490
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
+ 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 500 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__graph.

500  {
501  return *__graph;
502  }
const InterfaceGraph< GUM_SCALAR > * __graph
The interface graph on which this DFSTree applies.
Definition: DFSTree.h:264

◆ 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 228 of file DFSTree_tpl.h.

References gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNode(), gum::prm::gspan::Pattern::code(), gum::prm::gspan::DFSCode::codes, GUM_ERROR, gum::Set< Key, Alloc >::insert(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::insert(), gum::prm::gspan::DFSTree< GUM_SCALAR >::PatternData::iso_graph, gum::prm::gspan::DFSTree< GUM_SCALAR >::PatternData::iso_map, gum::prm::gspan::EdgeGrowth< GUM_SCALAR >::matches, gum::prm::gspan::DFSTree< GUM_SCALAR >::PatternData::max_indep_set, gum::EdgeGraphPart::neighbours(), gum::NodeGraphPart::nodes(), and gum::NodeGraphPart::size().

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

References gum::ArcGraphPart::children(), gum::Set< Key, Alloc >::contains(), gum::List< Val, Alloc >::empty(), gum::NodeGraphPart::exists(), gum::List< Val, Alloc >::front(), gum::Set< Key, Alloc >::insert(), gum::List< Val, Alloc >::popFront(), and gum::List< Val, Alloc >::pushBack().

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

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

◆ 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 466 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data, and GUM_ERROR.

466  {
467  try {
468  return __data[const_cast< Pattern* >(&p)]->iso_graph;
469  } catch (NotFound&) {
470  GUM_ERROR(NotFound, "pattern not found in this DFSTree");
471  }
472  }
UndiGraph & iso_graph(const Pattern &p)
Returns the isomorphism graph of p in the interface graph.
Definition: DFSTree_tpl.h:466
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ 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 476 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data, and GUM_ERROR.

476  {
477  try {
478  return *(__data[const_cast< Pattern* >(&p)]->iso_map[node]);
479  } catch (NotFound&) {
480  if (__data.exists(const_cast< Pattern* >(&p))) {
481  GUM_ERROR(NotFound, "node not found in Pattern's isomorphism graph");
482  } else {
483  GUM_ERROR(NotFound, "pattern not found in this DFSTree");
484  }
485  }
486  }
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:476
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ 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 490 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__data, and GUM_ERROR.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::frequency().

490  {
491  try {
492  return __data[const_cast< Pattern* >(&p)]->max_indep_set;
493  } catch (NotFound&) {
494  GUM_ERROR(NotFound, "pattern not found in this DFSTree");
495  }
496  }
Set< NodeId > & max_indep_set(const Pattern &p)
Returns the maximal independent set of p isomorphism graph.
Definition: DFSTree_tpl.h:490
HashTable< Pattern *, PatternData *> __data
Data about patterns in this DFSTree.
Definition: DFSTree.h:274
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the caller 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 226 of file nodeGraphPart_inl.h.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_addNode().

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

◆ nodes()

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

return *this as a NodeGraphPart

Definition at line 373 of file nodeGraphPart_inl.h.

Referenced by gum::MarkovBlanket::__buildMarkovBlanket(), gum::SpanningForestPrim::__compute(), gum::StaticTriangulation::__computeMaxPrimeJunctionTree(), gum::prm::LayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::ClusteredLayerGenerator< GUM_SCALAR >::__generateClassDag(), gum::prm::GSpan< GUM_SCALAR >::__sortPatterns(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__threadUpdate(), gum::InfluenceDiagram< GUM_SCALAR >::_moralGraph(), gum::InfluenceDiagram< GUM_SCALAR >::_removeTables(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), gum::StaticTriangulation::fillIns(), gum::InfluenceDiagram< GUM_SCALAR >::getDecisionGraph(), gum::prm::gspan::DFSTree< GUM_SCALAR >::growPattern(), gum::UndiGraph::hasUndirectedCycle(), gum::DAG::moralGraph(), gum::MarkovBlanket::nodes(), gum::EssentialGraph::nodes(), gum::prm::gspan::Pattern::nodes(), gum::MarkovBlanket::toDot(), gum::EssentialGraph::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), gum::UndiGraph::toDot(), gum::DiGraph::toDot(), and gum::MixedGraph::toDot().

373  {
374  return *(static_cast< const NodeGraphPart* >(this));
375  }
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
+ Here is the caller 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.

Referenced by gum::InfluenceDiagram< GUM_SCALAR >::_getChildrenDecision(), gum::BarrenNodesFinder::barrenNodes(), gum::BinaryJoinTreeConverterDefault::convert(), gum::InfluenceDiagram< GUM_SCALAR >::existsPathBetween(), and gum::UndiGraph::hasUndirectedCycle().

+ Here is the caller graph for this function:

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

References gum::ArcGraphPart::__arcs.

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

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

References gum::DiGraph::operator==().

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

References gum::NodeGraphPartIterator::operator==().

357  {
358  return !operator==(p);
359  }
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 153 of file arcGraphPart_inl.h.

References gum::ArcGraphPart::__arcs.

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

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

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

References gum::ArcGraphPart::operator==(), and gum::NodeGraphPart::operator==().

Referenced by gum::DiGraph::operator!=().

79  {
81  }
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:
+ Here is the caller 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 343 of file nodeGraphPart_inl.h.

References gum::NodeGraphPart::__boundVal, and gum::NodeGraphPart::__holes.

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

343  {
344  if (__boundVal != p.__boundVal) return false;
345 
346  if (__holes)
347  if (p.__holes)
348  return (*__holes == *p.__holes);
349  else
350  return false;
351  else if (p.__holes)
352  return false;
353 
354  return true;
355  }
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 caller 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 398 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__node_map, gum::NodeGraphPart::begin(), GUM_ERROR, and gum::ArcGraphPart::parents().

398  {
399  try {
400  return *(__node_map.second(
401  *(DiGraph::parents(__node_map.first(const_cast< Pattern* >(&p)))
402  .begin())));
403  } catch (NotFound&) {
404  if (__node_map.existsSecond(const_cast< Pattern* >(&p))) {
405  GUM_ERROR(NotFound, "the given pattern is a root node");
406  } else {
407  GUM_ERROR(NotFound, "pattern not found in this DFSTree");
408  }
409  }
410  }
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
const NodeSet & parents(const 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:271
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 413 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__node_map, gum::NodeGraphPart::begin(), GUM_ERROR, and gum::ArcGraphPart::parents().

413  {
414  try {
415  return *(__node_map.second(
416  *(DiGraph::parents(__node_map.first(const_cast< Pattern* >(&p)))
417  .begin())));
418  } catch (NotFound&) {
419  if (__node_map.existsSecond(const_cast< Pattern* >(&p))) {
420  GUM_ERROR(NotFound, "the given pattern is a root node");
421  } else {
422  GUM_ERROR(NotFound, "pattern not found in this DFSTree");
423  }
424  }
425  }
node_iterator begin() const noexcept
a begin iterator to parse the set of nodes contained in the NodeGraphPart
const NodeSet & parents(const 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:271
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ parents()

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

References gum::ArcGraphPart::__checkParents(), and gum::ArcGraphPart::__parents.

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

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

◆ 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 448 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__node_map, and GUM_ERROR.

448  {
449  try {
450  return *(__node_map.second(id));
451  } catch (NotFound&) {
452  GUM_ERROR(NotFound, "no pattern matching the given id");
453  }
454  }
Bijection< NodeId, Pattern *> __node_map
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:271
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ 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 457 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__node_map, and GUM_ERROR.

457  {
458  try {
459  return *(__node_map.second(id));
460  } catch (NotFound&) {
461  GUM_ERROR(NotFound, "no pattern matching the given id");
462  }
463  }
Bijection< NodeId, Pattern *> __node_map
The mapping between nodes in this DFSTree and the patterns they represents.
Definition: DFSTree.h:271
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ 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 64 of file nodeGraphPart.cpp.

References gum::NodeGraphPart::__boundVal, gum::NodeGraphPart::__holes, gum::NodeGraphPart::__holes_resize_policy, gum::NodeGraphPart::__holes_size, gum::NodeGraphPart::__updateEndIteratorSafe(), and gum::NodeGraphPart::clear().

Referenced by gum::DAGmodel::__moralGraph(), and gum::DAG::moralGraph().

64  {
65  clear(); // "virtual" flush of the nodes set
66  __holes_size = s.__holes_size;
67  __holes_resize_policy = s.__holes_resize_policy;
68 
69  if (s.__holes) __holes = new NodeSet(*s.__holes);
70 
71  __boundVal = s.__boundVal;
72 
74  }
NodeSet * __holes
the set of nodes not contained in the NodeGraphPart in the interval 1..__max
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool __holes_resize_policy
value for __holes configuration
NodeId __boundVal
the id below which NodeIds may belong to the NodeGraphPart
Size __holes_size
value for __holes configuration
void __updateEndIteratorSafe()
updating endIterator (always at __max+1)
virtual void clear()
alias for clearNodes
+ Here is the call graph for this function:
+ Here is the caller 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 388 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__roots.

388  {
389  return __roots;
390  }
std::list< NodeId > __roots
The list of root patterns in this DFSTree.
Definition: DFSTree.h:267

◆ 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 393 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__roots.

393  {
394  return __roots;
395  }
std::list< NodeId > __roots
The list of root patterns in this DFSTree.
Definition: DFSTree.h:267

◆ size()

◆ sizeArcs()

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

indicates the number of arcs stored within the ArcGraphPart

Definition at line 37 of file arcGraphPart_inl.h.

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

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

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

◆ sizeNodes()

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

returns the number of nodes in the NodeGraphPart

Definition at line 280 of file nodeGraphPart_inl.h.

Referenced by gum::BinaryJoinTreeConverterDefault::__markConnectedComponent(), gum::BarrenNodesFinder::barrenNodes(), gum::BinaryJoinTreeConverterDefault::convert(), gum::EliminationSequenceStrategy::setGraph(), gum::MarkovBlanket::sizeNodes(), and gum::EssentialGraph::sizeNodes().

280  {
281  return (__holes) ? (__boundVal - __holes->size()) : __boundVal;
282  }
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:701
+ Here is the caller 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 530 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__strategy.

530  {
531  return *__strategy;
532  }
SearchStrategy< GUM_SCALAR > * __strategy
The strategy used to prune the search tree.
Definition: DFSTree.h:277

◆ 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 536 of file DFSTree_tpl.h.

References gum::prm::gspan::DFSTree< GUM_SCALAR >::__strategy.

536  {
537  return *__strategy;
538  }
SearchStrategy< GUM_SCALAR > * __strategy
The strategy used to prune the search tree.
Definition: DFSTree.h:277

◆ toDot()

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

References gum::ArcGraphPart::arcs(), and gum::NodeGraphPart::nodes().

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

References gum::DiGraph::__mutableTopologicalOrder, gum::DiGraph::__topologicalOrder(), and gum::SequenceImplementation< Key, Alloc, Gen >::clear().

Referenced by gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::__setO3ClassCreationOrder(), gum::prm::o3prm::O3InterfaceFactory< GUM_SCALAR >::__setO3InterfaceCreationOrder(), gum::prm::o3prm::O3TypeFactory< GUM_SCALAR >::__setO3TypeCreationOrder(), gum::learning::Miic::learnStructure(), and gum::DAGmodel::topologicalOrder().

91  {
92  if (clear
94  == nullptr)) { // we have to call _topologicalOrder
95  if (__mutableTopologicalOrder == nullptr) {
97  } else {
98  // clear is True
100  }
101 
103  }
104 
106  }
void clear()
Clear the sequence.
Definition: sequence_tpl.h:271
Sequence< NodeId > * __mutableTopologicalOrder
The topology sequence of this Directed Graphical Model.
Definition: diGraph.h:212
void __topologicalOrder() const
Returns a topological order of this DAGModel.
Definition: diGraph.cpp:108
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

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

to friendly display the content of the graph

Reimplemented in gum::MixedGraph.

Definition at line 61 of file diGraph.cpp.

References gum::ArcGraphPart::toString(), and gum::NodeGraphPart::toString().

Referenced by gum::operator<<().

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

◆ unvirtualizedEraseChildren()

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

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

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

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

◆ unvirtualizedEraseParents()

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

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

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

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

Member Data Documentation

◆ __data

◆ __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 264 of file DFSTree.h.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::graph().

◆ __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 271 of file DFSTree.h.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::parent(), and gum::prm::gspan::DFSTree< GUM_SCALAR >::pattern().

◆ __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 267 of file DFSTree.h.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::roots().

◆ __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 277 of file DFSTree.h.

Referenced by gum::prm::gspan::DFSTree< GUM_SCALAR >::DFSTree(), and gum::prm::gspan::DFSTree< GUM_SCALAR >::strategy().

◆ onArcAdded

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

◆ onArcDeleted

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

Definition at line 84 of file arcGraphPart.h.

Referenced by gum::ArcGraphPart::clearArcs(), and gum::ArcGraphPart::eraseArc().

◆ onNodeAdded

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

Definition at line 274 of file nodeGraphPart.h.

Referenced by gum::NodeGraphPart::addNodeWithId().

◆ onNodeDeleted

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

Definition at line 275 of file nodeGraphPart.h.

Referenced by gum::NodeGraphPart::__clearNodes().


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