aGrUM  0.20.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 (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 *, doubleremainingVarsScore__
 HashTable associating to each variable its score. More...
 
HashTable< const DiscreteVariable *, doubleremainingVarsOtherScore__
 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);
46  0.0,
47  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  }
Set< const DiscreteVariable *> remainingVars__
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.
MultiPriorityQueue< double, double, std::greater< double > > remainingScores__
Heap keeping best score on top for immediate access.
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.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
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.

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

60 { GUM_DESTRUCTOR(VariableSelector); }
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 116 of file variableselector.cpp.

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

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< 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.
HashTable< const DiscreteVariable *, double > remainingVarsScore__
HashTable associating to each variable its score.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
+ 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 93 of file variableselector.h.

93 { 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 96 of file variableselector.h.

96 { 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  }
void removeVar__(const DiscreteVariable *var)
The set of remaining vars to select among.
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 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 94 of file variableselector.h.

94 { 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 91 of file variableselector.h.

91 { 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 95 of file variableselector.h.

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

◆ 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 gum::Set< Key, Alloc >::emplace().

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  }
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
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.
HashTable< const DiscreteVariable *, double > remainingVarsScore__
HashTable associating to each variable its score.
+ Here is the call graph for this function:

◆ 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();
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  }
Set< const DiscreteVariable *> remainingVars__
The set of remaining vars to select among.
const Val & top() const
Returns the element at the top of the priority queue.
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.
MultiPriorityQueue< double, double, std::greater< double > > remainingScores__
Heap keeping best score on top for immediate access.
HashTable< const DiscreteVariable *, double > remainingVarsOtherScore__
HashTable associating to each variable its 2nd score.
+ 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  }
void removeVar__(const DiscreteVariable *var)
The set of remaining vars to select among.
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 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 107 of file variableselector.h.

◆ remainingVars__

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

The set of remaining vars to select among.

Definition at line 103 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 111 of file variableselector.h.

◆ remainingVarsOtherScore__

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

HashTable associating to each variable its 2nd score.

Definition at line 117 of file variableselector.h.

◆ remainingVarsScore__

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

HashTable associating to each variable its score.

Definition at line 114 of file variableselector.h.

◆ rvi__

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

The set of remaining vars to select among.

Definition at line 104 of file variableselector.h.


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