56 template <
typename GUM_SCALAR >
60 for (
const auto& elt:
_data_) {
68 template <
typename GUM_SCALAR >
73 for (
const auto& edge:
_graph_->edges(&label)) {
74 bool u_first = (edge->l_u->id < edge->l_v->id);
75 Idx u_idx = (u_first) ? edge->l_u->id : edge->l_v->id;
76 Idx v_idx = (!u_first) ? edge->l_u->id : edge->l_v->id;
80 for (
const auto& elt:
roots)
81 if ((elt.second.first == u_idx) && (elt.second.second == v_idx)) {
82 roots_edges[elt.first]->
insert(edge);
90 roots.insert(p, std::make_pair(u_idx, v_idx));
92 roots_edges[p]->
insert(edge);
104 for (
const auto& elt: roots_edges) {
111 template <
typename GUM_SCALAR >
116 std::vector< NodeId > degree_list;
118 for (
auto iter = edge_seq.begin(); iter != edge_seq.end(); ++iter) {
119 const auto& edge = *iter;
124 bool u_first = (edge->l_u->id < edge->l_v->id);
125 seq->
insert((u_first) ? edge->u : edge->v);
126 seq->
insert((!u_first) ? edge->u : edge->v);
129 data->iso_map.insert(an_id, seq);
130 degree_list.push_back(an_id);
134 for (
const auto& elt:
data->iso_map)
135 if (elt.first != an_id)
136 for (
auto iter = elt.second->begin(); iter != elt.second->end(); ++iter)
138 data->iso_graph.addEdge(an_id, elt.first);
145 std::sort(degree_list.begin(), degree_list.end(), my_operator);
148 for (
const auto node: degree_list) {
149 if (!removed.
exists(node)) {
152 for (
const auto neighbor:
data->iso_graph.neighbours(node))
155 data->max_indep_set.insert(node);
160 template <
typename GUM_SCALAR >
164 for (
const auto& elt:
iso_map) {
167 for (
const auto& inst: seq)
168 if (!(elt.second->exists(inst))) {
173 if (!found) {
return false; }
179 template <
typename GUM_SCALAR >
194 for (std::list< NodeId >::iterator iter =
children.begin(); iter !=
children.end();
206 template <
typename GUM_SCALAR >
215 child->
addArc(edge_growth.
u, v, *(edge_growth.
edge));
220 if (edge < *(child->
code().
codes.front())) {
222 "added edge code is lesser than the first "
223 "one in the pattern's DFSCode");
227 for (
auto iter = child->
code().
codes.begin(); (iter + 1) != child->
code().
codes.end();
229 if ((((**iter).i == v) || ((**iter).j == v)) && edge < (**iter)) {
231 "added backward edge is lesser than an existing edge on v");
242 template <
typename GUM_SCALAR >
257 std::vector< NodeId > degree_list;
264 for (
const auto& elt: p_iso_map) {
265 auto match = edge_growth.
matches.begin();
267 for (; match != edge_growth.
matches.end(); ++match) {
269 if (child->code().codes.back()->isForward()) {
270 if (elt.second->exists(match.val().first)
271 && !(elt.second->exists(match.val().second))) {
274 new_seq->
insert(match.val().second);
277 id =
data->iso_graph.addNode();
278 data->iso_map.insert(
id, new_seq);
286 if (elt.second->exists(match.val().first) && elt.second->exists(match.val().second)) {
291 id =
data->iso_graph.addNode();
292 data->iso_map.insert(
id, new_seq);
302 if (match != edge_growth.
matches.end()) {
304 for (
const auto node:
data->iso_graph.nodes())
306 for (
const auto m: *
data->iso_map[
id])
307 if (
data->iso_map[node]->exists(m)) {
308 data->iso_graph.addEdge(node,
id);
312 degree_list.push_back(
id);
313 edge_growth.
matches.erase(match.key());
317 if (
data->iso_graph.size() < min_freq) {
325 std::sort(degree_list.begin(), degree_list.end(), my_operator);
328 for (
const auto node: degree_list) {
329 if (!removed.
exists(node)) {
332 for (
const auto neighbor:
data->iso_graph.neighbours(node))
335 data->max_indep_set.insert(node);
341 if (!
_strategy_->accept_growth(&p, child, edge_growth)) {
352 template <
typename GUM_SCALAR >
357 for (
const auto& elt: x)
358 if (y[elt.first] != elt.second)
return false;
359 }
catch (
NotFound const&) {
return false; }
365 template <
typename GUM_SCALAR >
371 for (
const auto& elt: from.
iso_map)
375 template <
typename GUM_SCALAR >
383 template <
typename GUM_SCALAR >
394 template <
typename GUM_SCALAR >
399 template <
typename GUM_SCALAR >
404 template <
typename GUM_SCALAR >
418 template <
typename GUM_SCALAR >
432 template <
typename GUM_SCALAR >
439 template <
typename GUM_SCALAR >
446 template <
typename GUM_SCALAR >
453 template <
typename GUM_SCALAR >
460 template <
typename GUM_SCALAR >
467 template <
typename GUM_SCALAR >
481 template <
typename GUM_SCALAR >
488 template <
typename GUM_SCALAR >
493 template <
typename GUM_SCALAR >
495 out << edge.
u <<
", " << *(edge.
edge) <<
", " << *(edge.
l_v) <<
", " << edge.
v;
499 template <
typename GUM_SCALAR >
504 template <
typename GUM_SCALAR >
510 template <
typename GUM_SCALAR >
516 template <
typename GUM_SCALAR >
521 template <
typename GUM_SCALAR >
528 template <
typename GUM_SCALAR >
534 template <
typename GUM_SCALAR >
540 template <
typename GUM_SCALAR >
545 template <
typename GUM_SCALAR >
547 return g.neighbours(i).size() <
g.neighbours(j).size();
552 template <
typename GUM_SCALAR >
Headers of the DFSTree class.
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size size() const
alias for sizeNodes
virtual NodeId addNode()
insert a new node and return its id
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
bool exists(const Key &k) const
Check the existence of k in the sequence.
void insert(const Key &k)
Insert an element at the end of the sequence.
The generic class for storing (ordered) sequences of objects.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
Base class for undirected graphs.
Abstract class representing an element of PRM class.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
std::vector< EdgeCode * > codes
The vector containing the EdgeCode composing this DFSCode.
Set< NodeId > & max_indep_set(const Pattern &p)
Returns the maximal independent set of p isomorphism graph.
Pattern & pattern(NodeId id)
Returns the pattern represented by id in this DFSTree.
std::list< NodeId > & children(const Pattern &p)
Returns the list of p children in this DFSTree.
const InterfaceGraph< GUM_SCALAR > & graph() const
Returns the list of root patterns in this DFSTree.
SearchStrategy< GUM_SCALAR > * _strategy_
The strategy used to prune the search tree.
void _checkGrowth_(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Raise different exceptions if child is invalid or illegal.
std::list< NodeId > & roots()
Returns the list of root patterns in this DFSTree.
bool _test_equality_(HashTable< PRMClassElement< GUM_SCALAR > *, Size > &x, HashTable< PRMClassElement< GUM_SCALAR > *, Size > &y)
Pattern & parent(const Pattern &p)
Returns the parent of p in this DFSTree.
PatternData & data(const Pattern &p)
UndiGraph & iso_graph(const Pattern &p)
Returns the isomorphism graph of p in the interface graph.
void addRoot(LabelData &data)
Add a one edge Pattern in this DFSTree.
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...
Pattern & growPattern(Pattern &p, EdgeGrowth< GUM_SCALAR > &edge_growth, Size min_freq)
Add a one edge growth of p as one of its child.
void _addChild_(Pattern &p, Pattern *child, EdgeGrowth< GUM_SCALAR > &edge_growth)
Add a child to this DFSTree.
void _initialiaze_root_(Pattern *p, Sequence< EdgeData< GUM_SCALAR > * > &seq)
This initialize the DSFTree with a new root.
HashTable< Pattern *, PatternData * > _data_
Data about patterns in this DFSTree.
bool _is_new_seq_(Sequence< PRMInstance< GUM_SCALAR > * > &seq, NodeProperty< Sequence< PRMInstance< GUM_SCALAR > * > * > &iso_map)
Check if an instance match is redundant.
double frequency(const Pattern &p) const
Returns the frequency of p respecting it's maximal independent set.
SearchStrategy< GUM_SCALAR > & strategy()
strategy getter
Bijection< NodeId, Pattern * > _node_map_
The mapping between nodes in this DFSTree and the patterns they represents.
const InterfaceGraph< GUM_SCALAR > * _graph_
The interface graph on which this DFSTree applies.
std::list< NodeId > _roots_
The list of root patterns in this DFSTree.
DFSTree(const InterfaceGraph< GUM_SCALAR > &graph, SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Inner class to handle data about edges in graph.
This class is used to define an edge growth of a pattern in this DFSTree.
NodeId u
The id of the node from which we grow an edge.
NodeProperty< std::pair< PRMInstance< GUM_SCALAR > *, PRMInstance< GUM_SCALAR > * > > matches
The mapping between the u and v for each match in the interface graph.
NodeId v
If the growth is backward you must assigned the subscript of v, otherwise 0 is assigned (recall that ...
LabelData * edge
The LabelData over the edge of this edge growth.
LabelData * l_v
The LabelData over the node of this edge growth.
This is class is an implementation of a simple serach strategy for the gspan algorithm: it accept a g...
This class represent the interface graph of a given gum::prm::PRMSystem<GUM_SCALAR>.
This contains all the information we want for a node in a DFSTree.
bool isMinimal()
Returns the DFSCode of this Pattern.
NodeId addNodeWithLabel(LabelData &l)
Insert a node with the given LabelData.
DFSCode & code()
Returns the DFSCode of this Pattern.
void addArc(NodeId i, NodeId j, LabelData &l)
Add an arc to this Pattern.
EdgeCode & edgeCode(NodeId tail, NodeId head)
Returns the EdgeCode of an edge of this Pattern.
This is an abstract class used to tune search strategies in the gspan algorithm.
Headers of the DFSTree class.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
std::ostream & operator<<(std::ostream &out, const DFSCode &code)
Print code in out.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities
This is used to generate the max_indep_set of a Pattern.
~NeighborDegreeSort()
Destructor.
NeighborDegreeSort(UndiGraph &graph)
Constructor.
bool operator()(NodeId i, NodeId j)
The operator used to sort stuff.
UndiGraph & g
The isomorphism graph.
~PatternData()
Destructor.
Pattern * pattern
The pattern.
Size cost
The cost of this Pattern.
Size gain
The gain of this Pattern.
NodeProperty< Sequence< PRMInstance< GUM_SCALAR > * > * > iso_map
The instances matching p in the interface graph.
UndiGraph iso_graph
The isomorphism graph of the pattern.
PatternData(Pattern *p)
Constructor.
Set< NodeId > max_indep_set
The maximal independent set of p.
std::list< NodeId > children
The list of the pattern's children, sorted lexicographically.
represent a DFS code used by gspan.
bool isBackward() const
Returns true if this EdgeCode is a backward edge.
Inner class to handle data about labels in this interface graph.