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

Detailed Description

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

Definition at line 51 of file variableselector.h.

Constructor & Destructor Documentation

◆ VariableSelector()

gum::VariableSelector::VariableSelector ( Set< const DiscreteVariable * > &  startingSet)

Default constructor.

Definition at line 41 of file variableselector.cpp.

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

41  :
42  _remainingVars_(startingSet) {
43  GUM_CONSTRUCTOR(VariableSelector);
44  _remainingScores_.insert(0.0, 0.0);
45  _remainingVarsByScore_.insert(0.0, new Set< const DiscreteVariable* >(_remainingVars_));
46 
47  for (auto varIter = _remainingVars_.cbeginSafe(); varIter != _remainingVars_.cendSafe();
48  ++varIter) {
49  _remainingVarsScore_.insert(*varIter, 0.0);
50  _remainingVarsOtherScore_.insert(*varIter, 0.0);
51  }
52  }
Set< const DiscreteVariable *> _remainingVars_
The set of remaining vars to select among.
HashTable< const DiscreteVariable *, double > _remainingVarsOtherScore_
HashTable associating to each variable its 2nd score.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
HashTable< const DiscreteVariable *, double > _remainingVarsScore_
HashTable associating to each variable its score.
HashTable< double, Set< const DiscreteVariable *> *> _remainingVarsByScore_
HashTable associating to each score the set of variable having that score.
MultiPriorityQueue< double, double, std::greater< double > > _remainingScores_
Heap keeping best score on top for immediate access.
VariableSelector(Set< const DiscreteVariable * > &startingSet)
Default constructor.
+ Here is the call graph for this function:

◆ ~VariableSelector()

gum::VariableSelector::~VariableSelector ( )

Default destructor.

Definition at line 57 of file variableselector.cpp.

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

57  {
58  GUM_DESTRUCTOR(VariableSelector);
59  ;
60  }
VariableSelector(Set< const DiscreteVariable * > &startingSet)
Default constructor.
+ 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 113 of file variableselector.cpp.

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

113  {
114  double varScore = _remainingVarsScore_[var];
115 
116  if (!_remainingVarsByScore_.exists(varScore)) {
117  _remainingVarsByScore_.insert(varScore, new Set< const DiscreteVariable* >());
118  _remainingScores_.insert(varScore, varScore);
119  }
120  _remainingVarsByScore_[varScore]->insert(var);
121  }
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
HashTable< const DiscreteVariable *, double > _remainingVarsScore_
HashTable associating to each variable its score.
HashTable< double, Set< const DiscreteVariable *> *> _remainingVarsByScore_
HashTable associating to each score the set of variable having that score.
MultiPriorityQueue< double, double, std::greater< double > > _remainingScores_
Heap keeping best score on top for immediate access.
+ Here is the call graph for this function:

◆ _removeVar_()

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

The set of remaining vars to select among.

Definition at line 127 of file variableselector.cpp.

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

127  {
128  double varScore = _remainingVarsScore_[var];
129  Set< const DiscreteVariable* >* varSet = _remainingVarsByScore_[varScore];
130  *varSet >> var;
131  if (varSet->empty()) {
132  _remainingScores_.erase(varScore);
133  _remainingVarsByScore_.erase(varScore);
134  delete varSet;
135  }
136  }
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
HashTable< const DiscreteVariable *, double > _remainingVarsScore_
HashTable associating to each variable its score.
HashTable< double, Set< const DiscreteVariable *> *> _remainingVarsByScore_
HashTable associating to each score the set of variable having that score.
MultiPriorityQueue< double, double, std::greater< double > > _remainingScores_
Heap keeping best score on top for immediate access.
+ Here is the call graph for this function:

◆ begin()

void gum::VariableSelector::begin ( )
inline

The set of remaining vars to select among.

Definition at line 89 of file variableselector.h.

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

◆ current()

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

The set of remaining vars to select among.

Definition at line 92 of file variableselector.h.

92 { return *_rvi_; }
SetIteratorSafe< const DiscreteVariable *> _rvi_
The set of remaining vars to select among.

◆ downdateScore()

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

The set of remaining vars to select among.

Definition at line 79 of file variableselector.cpp.

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

81  {
82  _removeVar_(var);
83  _remainingVarsScore_[var] -= score;
84  _addVar_(var);
85  _remainingVarsOtherScore_[var] -= secondaryscore;
86  }
HashTable< const DiscreteVariable *, double > _remainingVarsOtherScore_
HashTable associating to each variable its 2nd score.
HashTable< const DiscreteVariable *, double > _remainingVarsScore_
HashTable associating to each variable its score.
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.
+ Here is the call graph for this function:

◆ hasNext()

bool gum::VariableSelector::hasNext ( )
inline

The set of remaining vars to select among.

Definition at line 90 of file variableselector.h.

90 { return _rvi_ != _remainingVars_.endSafe(); }
Set< const DiscreteVariable *> _remainingVars_
The set of remaining vars to select among.
SetIteratorSafe< const DiscreteVariable *> _rvi_
The set of remaining vars to select among.

◆ isEmpty()

bool gum::VariableSelector::isEmpty ( )
inline

The set of remaining vars to select among.

Definition at line 87 of file variableselector.h.

87 { return _remainingVars_.empty(); }
Set< const DiscreteVariable *> _remainingVars_
The set of remaining vars to select among.

◆ next()

void gum::VariableSelector::next ( )
inline

The set of remaining vars to select among.

Definition at line 91 of file variableselector.h.

91 { ++_rvi_; }
SetIteratorSafe< const DiscreteVariable *> _rvi_
The set of remaining vars to select among.

◆ select()

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

Select the most relevant variable.

Definition at line 92 of file variableselector.cpp.

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

92  {
93  double bestScore = _remainingScores_.top();
94  Set< const DiscreteVariable* >* bestSet = _remainingVarsByScore_[bestScore];
95  const DiscreteVariable* bestVar = nullptr;
96 
97  for (auto varIter = bestSet->beginSafe(); varIter != bestSet->endSafe(); ++varIter) {
98  if (bestVar == nullptr
100  || (_remainingVarsOtherScore_[bestVar] == _remainingVarsOtherScore_[*varIter]
101  && bestVar->domainSize() < (*varIter)->domainSize()))
102  bestVar = *varIter;
103  }
104  _removeVar_(bestVar);
105  _remainingVars_ >> bestVar;
106  return bestVar;
107  }
const Val & top() const
Returns the element at the top of the priority queue.
Set< const DiscreteVariable *> _remainingVars_
The set of remaining vars to select among.
HashTable< const DiscreteVariable *, double > _remainingVarsOtherScore_
HashTable associating to each variable its 2nd score.
HashTable< double, Set< const DiscreteVariable *> *> _remainingVarsByScore_
HashTable associating to each score the set of variable having that score.
void _removeVar_(const DiscreteVariable *var)
The set of remaining vars to select among.
MultiPriorityQueue< double, double, std::greater< double > > _remainingScores_
Heap keeping best score on top for immediate access.
+ Here is the call 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 66 of file variableselector.cpp.

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

68  {
69  _removeVar_(var);
70  _remainingVarsScore_[var] += score;
71  _addVar_(var);
72  _remainingVarsOtherScore_[var] += secondaryscore;
73  }
HashTable< const DiscreteVariable *, double > _remainingVarsOtherScore_
HashTable associating to each variable its 2nd score.
HashTable< const DiscreteVariable *, double > _remainingVarsScore_
HashTable associating to each variable its score.
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.
+ Here is the call 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 103 of file variableselector.h.

◆ _remainingVars_

Set< const DiscreteVariable* > gum::VariableSelector::_remainingVars_
private

The set of remaining vars to select among.

Definition at line 99 of file variableselector.h.

◆ _remainingVarsByScore_

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

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

Definition at line 107 of file variableselector.h.

◆ _remainingVarsOtherScore_

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

HashTable associating to each variable its 2nd score.

Definition at line 113 of file variableselector.h.

◆ _remainingVarsScore_

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

HashTable associating to each variable its score.

Definition at line 110 of file variableselector.h.

◆ _rvi_

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

The set of remaining vars to select among.

Definition at line 100 of file variableselector.h.


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