aGrUM  0.16.0
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 52 of file variableselector.h.

Constructor & Destructor Documentation

◆ VariableSelector()

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

Default constructor.

Definition at line 42 of file variableselector.cpp.

References __remainingScores, __remainingVars, __remainingVarsByScore, __remainingVarsOtherScore, __remainingVarsScore, and gum::MultiPriorityQueue< Val, Priority, Cmp, Alloc >::insert().

42  :
43  __remainingVars(startingSet) {
44  GUM_CONSTRUCTOR(VariableSelector);
45  __remainingScores.insert(0.0, 0.0);
47  0.0, new Set< const DiscreteVariable* >(__remainingVars));
48 
49  for (auto varIter = __remainingVars.cbeginSafe();
50  varIter != __remainingVars.cendSafe();
51  ++varIter) {
52  __remainingVarsScore.insert(*varIter, 0.0);
53  __remainingVarsOtherScore.insert(*varIter, 0.0);
54  }
55  }
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.
MultiPriorityQueue< double, double, std::greater< double > > __remainingScores
Heap keeping best score on top for immediate access.
Set< const DiscreteVariable *> __remainingVars
The set of remaining vars to select among.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
HashTable< double, Set< const DiscreteVariable *> *> __remainingVarsByScore
HashTable associating to each score the set of variable having that score.
VariableSelector(Set< const DiscreteVariable * > &startingSet)
Default constructor.
+ Here is the call graph for this function:

◆ ~VariableSelector()

gum::VariableSelector::~VariableSelector ( )

Default destructor.

Definition at line 60 of file variableselector.cpp.

60 { GUM_DESTRUCTOR(VariableSelector); }
VariableSelector(Set< const DiscreteVariable * > &startingSet)
Default constructor.

Member Function Documentation

◆ __addVar()

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

The set of remaining vars to select among.

Definition at line 116 of file variableselector.cpp.

References __remainingScores, __remainingVarsByScore, __remainingVarsScore, and gum::MultiPriorityQueue< Val, Priority, Cmp, Alloc >::insert().

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

116  {
117  double varScore = __remainingVarsScore[var];
118 
119  if (!__remainingVarsByScore.exists(varScore)) {
120  __remainingVarsByScore.insert(varScore,
121  new Set< const DiscreteVariable* >());
122  __remainingScores.insert(varScore, varScore);
123  }
124  __remainingVarsByScore[varScore]->insert(var);
125  }
HashTable< const DiscreteVariable *, double > __remainingVarsScore
HashTable associating to each variable its score.
MultiPriorityQueue< double, double, std::greater< double > > __remainingScores
Heap keeping best score on top for immediate access.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
HashTable< double, Set< const DiscreteVariable *> *> __remainingVarsByScore
HashTable associating to each score the set of variable having that score.
+ Here is the call graph for this function:
+ 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 131 of file variableselector.cpp.

References __remainingScores, __remainingVarsByScore, __remainingVarsScore, gum::Set< Key, Alloc >::empty(), and gum::MultiPriorityQueue< Val, Priority, Cmp, Alloc >::erase().

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

131  {
132  double varScore = __remainingVarsScore[var];
133  Set< const DiscreteVariable* >* varSet = __remainingVarsByScore[varScore];
134  *varSet >> var;
135  if (varSet->empty()) {
136  __remainingScores.erase(varScore);
137  __remainingVarsByScore.erase(varScore);
138  delete varSet;
139  }
140  }
HashTable< const DiscreteVariable *, double > __remainingVarsScore
HashTable associating to each variable its score.
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
MultiPriorityQueue< double, double, std::greater< double > > __remainingScores
Heap keeping best score on top for immediate access.
HashTable< double, Set< const DiscreteVariable *> *> __remainingVarsByScore
HashTable associating to each score the set of variable having that score.
+ 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 94 of file variableselector.h.

References __remainingVars, and __rvi.

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

94 { __rvi = __remainingVars.beginSafe(); }
SetIteratorSafe< const DiscreteVariable *> __rvi
The set of remaining vars to select among.
Set< const DiscreteVariable *> __remainingVars
The set of remaining vars to select among.
+ Here is the caller graph for this function:

◆ current()

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

The set of remaining vars to select among.

Definition at line 97 of file variableselector.h.

References __addVar(), __removeVar(), and __rvi.

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

97 { return *__rvi; }
SetIteratorSafe< const DiscreteVariable *> __rvi
The set of remaining vars to select among.
+ Here is the call graph for this function:
+ 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 79 of file variableselector.cpp.

References __addVar(), __remainingVarsOtherScore, __remainingVarsScore, and __removeVar().

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

81  {
82  __removeVar(var);
83  __remainingVarsScore[var] -= score;
84  __addVar(var);
85  __remainingVarsOtherScore[var] -= secondaryscore;
86  }
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 __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:
+ Here is the caller graph for this function:

◆ hasNext()

bool gum::VariableSelector::hasNext ( )
inline

The set of remaining vars to select among.

Definition at line 95 of file variableselector.h.

References __remainingVars, and __rvi.

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

95 { return __rvi != __remainingVars.endSafe(); }
SetIteratorSafe< const DiscreteVariable *> __rvi
The set of remaining vars to select among.
Set< const DiscreteVariable *> __remainingVars
The set of remaining vars to select among.
+ Here is the caller graph for this function:

◆ isEmpty()

bool gum::VariableSelector::isEmpty ( )
inline

The set of remaining vars to select among.

Definition at line 92 of file variableselector.h.

References __remainingVars.

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

92 { return __remainingVars.empty(); }
Set< const DiscreteVariable *> __remainingVars
The set of remaining vars to select among.
+ 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 96 of file variableselector.h.

References __rvi.

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

96 { ++__rvi; }
SetIteratorSafe< const DiscreteVariable *> __rvi
The set of remaining vars to select among.
+ Here is the caller graph for this function:

◆ select()

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

Select the most relevant variable.

Definition at line 92 of file variableselector.cpp.

References __remainingScores, __remainingVars, __remainingVarsByScore, __remainingVarsOtherScore, __removeVar(), gum::Set< Key, Alloc >::beginSafe(), gum::DiscreteVariable::domainSize(), gum::Set< Key, Alloc >::endSafe(), and gum::MultiPriorityQueue< Val, Priority, Cmp, Alloc >::top().

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

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();
98  ++varIter) {
99  if (bestVar == nullptr
100  || __remainingVarsOtherScore[bestVar]
101  < __remainingVarsOtherScore[*varIter]
102  || (__remainingVarsOtherScore[bestVar]
103  == __remainingVarsOtherScore[*varIter]
104  && bestVar->domainSize() < (*varIter)->domainSize()))
105  bestVar = *varIter;
106  }
107  __removeVar(bestVar);
108  __remainingVars >> bestVar;
109  return bestVar;
110  }
HashTable< const DiscreteVariable *, double > __remainingVarsOtherScore
HashTable associating to each variable its 2nd score.
const Val & top() const
Returns the element at the top of the priority queue.
MultiPriorityQueue< double, double, std::greater< double > > __remainingScores
Heap keeping best score on top for immediate access.
Set< const DiscreteVariable *> __remainingVars
The set of remaining vars to select among.
void __removeVar(const DiscreteVariable *var)
The set of remaining vars to select among.
HashTable< double, Set< const DiscreteVariable *> *> __remainingVarsByScore
HashTable associating to each score the set of variable having that score.
+ 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 66 of file variableselector.cpp.

References __addVar(), __remainingVarsOtherScore, __remainingVarsScore, and __removeVar().

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

68  {
69  __removeVar(var);
70  __remainingVarsScore[var] += score;
71  __addVar(var);
72  __remainingVarsOtherScore[var] += secondaryscore;
73  }
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 __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:
+ 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 108 of file variableselector.h.

Referenced by __addVar(), __removeVar(), select(), and VariableSelector().

◆ __remainingVars

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

The set of remaining vars to select among.

Definition at line 104 of file variableselector.h.

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

◆ __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 112 of file variableselector.h.

Referenced by __addVar(), __removeVar(), select(), and VariableSelector().

◆ __remainingVarsOtherScore

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

HashTable associating to each variable its 2nd score.

Definition at line 118 of file variableselector.h.

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

◆ __remainingVarsScore

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

HashTable associating to each variable its score.

Definition at line 115 of file variableselector.h.

Referenced by __addVar(), __removeVar(), downdateScore(), updateScore(), and VariableSelector().

◆ __rvi

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

The set of remaining vars to select among.

Definition at line 105 of file variableselector.h.

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


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