aGrUM  0.16.0
gum::prm::gspan::TreeWidthSearch< GUM_SCALAR > Class Template Reference

A growth is accepted if and only if the new growth has a tree width less large or equal than its father. More...

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

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

Public Member Functions

Constructor and destructor.
 TreeWidthSearch ()
 Default constructor. More...
 
 TreeWidthSearch (const TreeWidthSearch &from)
 Copy constructor. More...
 
virtual ~TreeWidthSearch ()
 Destructor. More...
 
TreeWidthSearchoperator= (const TreeWidthSearch &from)
 Copy operator. More...
 
Search methods.
double cost (const Pattern &p)
 
virtual bool accept_root (const Pattern *r)
 
virtual bool accept_growth (const Pattern *parent, const Pattern *child, const EdgeGrowth< GUM_SCALAR > &growth)
 
virtual bool operator() (LabelData *i, LabelData *j)
 
virtual bool operator() (Pattern *i, Pattern *j)
 
Search methods.
void setTree (DFSTree< GUM_SCALAR > *tree)
 

Protected Attributes

DFSTree< GUM_SCALAR > * _tree
 

Protected Member Functions

double _computeCost (const Pattern &p)
 

Detailed Description

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

A growth is accepted if and only if the new growth has a tree width less large or equal than its father.

Definition at line 263 of file searchStrategy.h.

Constructor & Destructor Documentation

◆ TreeWidthSearch() [1/2]

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( )

Default constructor.

Definition at line 405 of file searchStrategy_tpl.h.

405  :
406  SearchStrategy< GUM_SCALAR >() {
407  GUM_CONSTRUCTOR(TreeWidthSearch);
408  }
TreeWidthSearch()
Default constructor.

◆ TreeWidthSearch() [2/2]

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::TreeWidthSearch ( const TreeWidthSearch< GUM_SCALAR > &  from)

Copy constructor.

Definition at line 411 of file searchStrategy_tpl.h.

412  :
413  SearchStrategy< GUM_SCALAR >(from) {
414  GUM_CONS_CPY(TreeWidthSearch);
415  }
TreeWidthSearch()
Default constructor.

◆ ~TreeWidthSearch()

template<typename GUM_SCALAR >
INLINE gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::~TreeWidthSearch ( )
virtual

Destructor.

Definition at line 418 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator=().

418  {
419  GUM_DESTRUCTOR(TreeWidthSearch);
420  }
TreeWidthSearch()
Default constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ _computeCost()

template<typename GUM_SCALAR >
double gum::prm::gspan::SearchStrategy< GUM_SCALAR >::_computeCost ( const Pattern p)
protectedinherited

Definition at line 36 of file searchStrategy_tpl.h.

References gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::exists(), and gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::insert().

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::__compute_costs(), and gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost().

36  {
37  double cost = 0;
38  const Sequence< PRMInstance< GUM_SCALAR >* >& seq =
39  *(this->_tree->data(p).iso_map.begin().val());
40  Sequence< PRMClassElement< GUM_SCALAR >* > input_set;
41 
42  for (const auto inst : seq) {
43  for (const auto input : inst->type().slotChains())
44  for (const auto inst2 : inst->getInstances(input->id()))
45  if ((!seq.exists(inst2))
46  && (!input_set.exists(
47  &(inst2->get(input->lastElt().safeName()))))) {
48  cost += std::log(input->type().variable().domainSize());
49  input_set.insert(&(inst2->get(input->lastElt().safeName())));
50  }
51 
52  for (auto vec = inst->beginInvRef(); vec != inst->endInvRef(); ++vec)
53  for (const auto inverse : *vec.val())
54  if (!seq.exists(inverse.first)) {
55  cost +=
56  std::log(inst->get(vec.key()).type().variable().domainSize());
57  break;
58  }
59  }
60 
61  return cost;
62  }
DFSTree< GUM_SCALAR > * _tree
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ accept_growth()

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_growth ( const Pattern parent,
const Pattern child,
const EdgeGrowth< GUM_SCALAR > &  growth 
)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 449 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost().

452  {
453  return cost(*parent) >= cost(*child);
454  }
+ Here is the call graph for this function:

◆ accept_root()

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_root ( const Pattern r)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 439 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost(), gum::prm::gspan::Pattern::label(), gum::prm::gspan::Pattern::nodes(), and gum::prm::gspan::LabelData::tree_width.

439  {
440  Size tree_width = 0;
441 
442  for (const auto n : r->nodes())
443  tree_width += r->label(n).tree_width;
444 
445  return tree_width >= cost(*r);
446  }
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:

◆ cost()

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

Definition at line 429 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::__map, and gum::prm::gspan::SearchStrategy< GUM_SCALAR >::_computeCost().

Referenced by gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_growth(), gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::accept_root(), and gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator()().

429  {
430  try {
431  return __map[&p];
432  } catch (NotFound&) {
433  __map.insert(&p, this->_computeCost(p));
434  return __map[&p];
435  }
436  }
HashTable< const Pattern *, double > __map
double _computeCost(const Pattern &p)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator()() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( LabelData i,
LabelData j 
)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 463 of file searchStrategy_tpl.h.

References gum::prm::gspan::LabelData::tree_width.

464  {
465  return i->tree_width < j->tree_width;
466  }

◆ operator()() [2/2]

template<typename GUM_SCALAR >
INLINE bool gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator() ( gspan::Pattern i,
gspan::Pattern j 
)
virtual

Implements gum::prm::gspan::SearchStrategy< GUM_SCALAR >.

Definition at line 457 of file searchStrategy_tpl.h.

References gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::cost().

458  {
459  return cost(*i) < cost(*j);
460  }
+ Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR >
INLINE TreeWidthSearch< GUM_SCALAR > & gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::operator= ( const TreeWidthSearch< GUM_SCALAR > &  from)

Copy operator.

Definition at line 424 of file searchStrategy_tpl.h.

Referenced by gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::~TreeWidthSearch().

424  {
425  return *this;
426  }
+ Here is the caller graph for this function:

◆ setTree()

template<typename GUM_SCALAR >
INLINE void gum::prm::gspan::SearchStrategy< GUM_SCALAR >::setTree ( DFSTree< GUM_SCALAR > *  tree)
inherited

Definition at line 233 of file searchStrategy_tpl.h.

References gum::prm::gspan::SearchStrategy< GUM_SCALAR >::_tree.

233  {
234  this->_tree = tree;
235  }
DFSTree< GUM_SCALAR > * _tree

Member Data Documentation

◆ __map

template<typename GUM_SCALAR>
HashTable< const Pattern*, double > gum::prm::gspan::TreeWidthSearch< GUM_SCALAR >::__map
private

◆ _tree


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