aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::VariableSelector Class Reference

<agrum/FMDP/planning/FunctionGraph/variableselector.h> More...

#include <variableselector.h>

Collaboration diagram for gum::VariableSelector:

Public Member Functions

Constructor & destructor.
 VariableSelector (const gum::VariableSet &startingSet)
 Default constructor.
 ~VariableSelector ()
 Default destructor.
gum::VariableSet _remainingVars_
 The set of remaining vars to select among.
SetIteratorSafe< const DiscreteVariable * > _rvi_
 The set of remaining vars to select among.
MultiPriorityQueue< double, double, std::greater< double > > _remainingScores_
 Heap keeping best score on top for immediate access.
HashTable< double, gum::VariableSet * > _remainingVarsByScore_
 HashTable associating to each score the set of variable having that score.
HashTable< const DiscreteVariable *, double_remainingVarsScore_
 HashTable associating to each variable its score.
HashTable< const DiscreteVariable *, double_remainingVarsOtherScore_
 HashTable associating to each variable its 2nd score.
void updateScore (const DiscreteVariable *var, double score, double secondaryscore)
 The set of remaining vars to select among.
void downdateScore (const DiscreteVariable *var, double score, double secondaryscore)
 The set of remaining vars to select among.
const DiscreteVariableselect ()
 Select the most relevant variable.
bool isEmpty () const
 The set of remaining vars to select among.
void begin ()
 The set of remaining vars to select among.
bool hasNext () const
 The set of remaining vars to select among.
void next ()
 The set of remaining vars to select among.
const DiscreteVariablecurrent () const
 The set of remaining vars to select among.
void _addVar_ (const DiscreteVariable *var)
 The set of remaining vars to select among.
void _removeVar_ (const DiscreteVariable *var)
 The set of remaining vars to select among.

Detailed Description

<agrum/FMDP/planning/FunctionGraph/variableselector.h>

Definition at line 71 of file variableselector.h.

Constructor & Destructor Documentation

◆ VariableSelector()

gum::VariableSelector::VariableSelector ( const gum::VariableSet & startingSet)
explicit

Default constructor.

Definition at line 66 of file variableselector.cpp.

66 :
67 _remainingVars_(startingSet) {
68 GUM_CONSTRUCTOR(VariableSelector)
69 _remainingScores_.insert(0.0, 0.0);
71
72 for (auto varIter = _remainingVars_.cbeginSafe(); varIter != _remainingVars_.cendSafe();
73 ++varIter) {
74 _remainingVarsScore_.insert(*varIter, 0.0);
75 _remainingVarsOtherScore_.insert(*varIter, 0.0);
76 }
77 }
HashTable< const DiscreteVariable *, double > _remainingVarsScore_
HashTable associating to each variable its score.
VariableSelector(const gum::VariableSet &startingSet)
Default constructor.
gum::VariableSet _remainingVars_
The set of remaining vars to select among.
HashTable< const DiscreteVariable *, double > _remainingVarsOtherScore_
HashTable associating to each variable its 2nd score.
MultiPriorityQueue< double, double, std::greater< double > > _remainingScores_
Heap keeping best score on top for immediate access.
HashTable< double, gum::VariableSet * > _remainingVarsByScore_
HashTable associating to each score the set of variable having that score.
Set< const DiscreteVariable * > VariableSet

References VariableSelector(), _remainingScores_, _remainingVars_, _remainingVarsByScore_, _remainingVarsOtherScore_, and _remainingVarsScore_.

Referenced by VariableSelector(), and ~VariableSelector().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~VariableSelector()

gum::VariableSelector::~VariableSelector ( )

Default destructor.

Definition at line 82 of file variableselector.cpp.

82{ GUM_DESTRUCTOR(VariableSelector) }

References VariableSelector().

Here is the call graph for this function:

Member Function Documentation

◆ _addVar_()

void gum::VariableSelector::_addVar_ ( const DiscreteVariable * var)
private

The set of remaining vars to select among.

Definition at line 131 of file variableselector.cpp.

131 {
132 double varScore = _remainingVarsScore_[var];
133
134 if (!_remainingVarsByScore_.exists(varScore)) {
135 _remainingVarsByScore_.insert(varScore, new gum::VariableSet());
136 _remainingScores_.insert(varScore, varScore);
137 }
138 _remainingVarsByScore_[varScore]->insert(var);
139 }

References _remainingScores_, _remainingVarsByScore_, and _remainingVarsScore_.

Referenced by downdateScore(), and updateScore().

Here is the caller graph for this function:

◆ _removeVar_()

void gum::VariableSelector::_removeVar_ ( const DiscreteVariable * var)
private

The set of remaining vars to select among.

Definition at line 144 of file variableselector.cpp.

144 {
145 double varScore = _remainingVarsScore_[var];
146 gum::VariableSet* varSet = _remainingVarsByScore_[varScore];
147 *varSet >> var;
148 if (varSet->empty()) {
149 _remainingScores_.erase(varScore);
150 _remainingVarsByScore_.erase(varScore);
151 delete varSet;
152 }
153 }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition set_tpl.h:613

References _remainingScores_, _remainingVarsByScore_, _remainingVarsScore_, and gum::Set< Key >::empty().

Referenced by downdateScore(), select(), and updateScore().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin()

INLINE void gum::VariableSelector::begin ( )

The set of remaining vars to select among.

Definition at line 50 of file variableselector_inl.h.

50{ _rvi_ = _remainingVars_.beginSafe(); }
SetIteratorSafe< const DiscreteVariable * > _rvi_
The set of remaining vars to select among.

References _remainingVars_, and _rvi_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), and gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

Here is the caller graph for this function:

◆ current()

INLINE const DiscreteVariable * gum::VariableSelector::current ( ) const

The set of remaining vars to select among.

Definition at line 56 of file variableselector_inl.h.

56{ return *_rvi_; }

References _rvi_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), and gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

Here is the caller graph for this function:

◆ downdateScore()

void gum::VariableSelector::downdateScore ( const DiscreteVariable * var,
double score,
double secondaryscore )

The set of remaining vars to select among.

Definition at line 99 of file variableselector.cpp.

101 {
102 _removeVar_(var);
103 _remainingVarsScore_[var] -= score;
104 _addVar_(var);
105 _remainingVarsOtherScore_[var] -= secondaryscore;
106 }
void _removeVar_(const DiscreteVariable *var)
The set of remaining vars to select among.
void _addVar_(const DiscreteVariable *var)
The set of remaining vars to select among.

References _addVar_(), _remainingVarsOtherScore_, _remainingVarsScore_, and _removeVar_().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_downdateScore_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasNext()

INLINE bool gum::VariableSelector::hasNext ( ) const

The set of remaining vars to select among.

Definition at line 52 of file variableselector_inl.h.

52{ return _rvi_ != _remainingVars_.endSafe(); }

References _remainingVars_, and _rvi_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), and gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

Here is the caller graph for this function:

◆ isEmpty()

INLINE bool gum::VariableSelector::isEmpty ( ) const

The set of remaining vars to select among.

Definition at line 48 of file variableselector_inl.h.

48{ return _remainingVars_.empty(); }

References _remainingVars_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

Here is the caller graph for this function:

◆ next()

INLINE void gum::VariableSelector::next ( )

The set of remaining vars to select among.

Definition at line 54 of file variableselector_inl.h.

54{ ++_rvi_; }

References _rvi_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), and gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

Here is the caller graph for this function:

◆ select()

const DiscreteVariable * gum::VariableSelector::select ( )

Select the most relevant variable.

Definition at line 111 of file variableselector.cpp.

111 {
112 double bestScore = _remainingScores_.top();
113 const gum::VariableSet* bestSet = _remainingVarsByScore_[bestScore];
114 const DiscreteVariable* bestVar = nullptr;
115
116 for (auto varIter = bestSet->beginSafe(); varIter != bestSet->endSafe(); ++varIter) {
117 if (bestVar == nullptr
120 && bestVar->domainSize() < (*varIter)->domainSize()))
121 bestVar = *varIter;
122 }
123 _removeVar_(bestVar);
124 _remainingVars_ >> bestVar;
125 return bestVar;
126 }
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition set_tpl.h:385
static const iterator_safe & endSafe() noexcept
The usual safe end iterator to parse the set.
Definition set_tpl.h:397

References _remainingScores_, _remainingVars_, _remainingVarsByScore_, _remainingVarsOtherScore_, _removeVar_(), gum::Set< Key >::beginSafe(), gum::DiscreteVariable::domainSize(), and gum::Set< Key >::endSafe().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateScore()

void gum::VariableSelector::updateScore ( const DiscreteVariable * var,
double score,
double secondaryscore )

The set of remaining vars to select among.

Definition at line 87 of file variableselector.cpp.

89 {
90 _removeVar_(var);
91 _remainingVarsScore_[var] += score;
92 _addVar_(var);
93 _remainingVarsOtherScore_[var] += secondaryscore;
94 }

References _addVar_(), _remainingVarsOtherScore_, _remainingVarsScore_, and _removeVar_().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateScore_().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _remainingScores_

MultiPriorityQueue< double, double, std::greater< double > > gum::VariableSelector::_remainingScores_
private

Heap keeping best score on top for immediate access.

Definition at line 126 of file variableselector.h.

Referenced by VariableSelector(), _addVar_(), _removeVar_(), and select().

◆ _remainingVars_

gum::VariableSet gum::VariableSelector::_remainingVars_
private

The set of remaining vars to select among.

Definition at line 122 of file variableselector.h.

Referenced by VariableSelector(), begin(), hasNext(), isEmpty(), and select().

◆ _remainingVarsByScore_

HashTable< double, gum::VariableSet* > gum::VariableSelector::_remainingVarsByScore_
private

HashTable associating to each score the set of variable having that score.

Definition at line 130 of file variableselector.h.

Referenced by VariableSelector(), _addVar_(), _removeVar_(), and select().

◆ _remainingVarsOtherScore_

HashTable< const DiscreteVariable*, double > gum::VariableSelector::_remainingVarsOtherScore_
private

HashTable associating to each variable its 2nd score.

Definition at line 136 of file variableselector.h.

Referenced by VariableSelector(), downdateScore(), select(), and updateScore().

◆ _remainingVarsScore_

HashTable< const DiscreteVariable*, double > gum::VariableSelector::_remainingVarsScore_
private

HashTable associating to each variable its score.

Definition at line 133 of file variableselector.h.

Referenced by VariableSelector(), _addVar_(), _removeVar_(), downdateScore(), and updateScore().

◆ _rvi_

SetIteratorSafe< const DiscreteVariable* > gum::VariableSelector::_rvi_
private

The set of remaining vars to select among.

Definition at line 123 of file variableselector.h.

Referenced by begin(), current(), hasNext(), and next().


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