aGrUM 2.3.2
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 62 of file variableselector.cpp.

62 :
63 _remainingVars_(startingSet) {
64 GUM_CONSTRUCTOR(VariableSelector)
65 _remainingScores_.insert(0.0, 0.0);
67
68 for (auto varIter = _remainingVars_.cbeginSafe(); varIter != _remainingVars_.cendSafe();
69 ++varIter) {
70 _remainingVarsScore_.insert(*varIter, 0.0);
71 _remainingVarsOtherScore_.insert(*varIter, 0.0);
72 }
73 }
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 78 of file variableselector.cpp.

78{ 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 127 of file variableselector.cpp.

127 {
128 double varScore = _remainingVarsScore_[var];
129
130 if (!_remainingVarsByScore_.exists(varScore)) {
131 _remainingVarsByScore_.insert(varScore, new gum::VariableSet());
132 _remainingScores_.insert(varScore, varScore);
133 }
134 _remainingVarsByScore_[varScore]->insert(var);
135 }

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 140 of file variableselector.cpp.

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

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()

void gum::VariableSelector::begin ( )
inline

The set of remaining vars to select among.

Definition at line 109 of file variableselector.h.

109{ _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()

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

The set of remaining vars to select among.

Definition at line 115 of file variableselector.h.

115{ 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 95 of file variableselector.cpp.

97 {
98 _removeVar_(var);
99 _remainingVarsScore_[var] -= score;
100 _addVar_(var);
101 _remainingVarsOtherScore_[var] -= secondaryscore;
102 }
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()

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

The set of remaining vars to select among.

Definition at line 111 of file variableselector.h.

111{ 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()

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

The set of remaining vars to select among.

Definition at line 107 of file variableselector.h.

107{ return _remainingVars_.empty(); }

References _remainingVars_.

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

Here is the caller graph for this function:

◆ next()

void gum::VariableSelector::next ( )
inline

The set of remaining vars to select among.

Definition at line 113 of file variableselector.h.

113{ ++_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 107 of file variableselector.cpp.

107 {
108 double bestScore = _remainingScores_.top();
109 const gum::VariableSet* bestSet = _remainingVarsByScore_[bestScore];
110 const DiscreteVariable* bestVar = nullptr;
111
112 for (auto varIter = bestSet->beginSafe(); varIter != bestSet->endSafe(); ++varIter) {
113 if (bestVar == nullptr
116 && bestVar->domainSize() < (*varIter)->domainSize()))
117 bestVar = *varIter;
118 }
119 _removeVar_(bestVar);
120 _remainingVars_ >> bestVar;
121 return bestVar;
122 }
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition set_tpl.h:414
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition set_tpl.h:426

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 83 of file variableselector.cpp.

85 {
86 _removeVar_(var);
87 _remainingVarsScore_[var] += score;
88 _addVar_(var);
89 _remainingVarsOtherScore_[var] += secondaryscore;
90 }

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: