aGrUM  0.16.0
variableselector.cpp
Go to the documentation of this file.
1 
29 // =========================================================================
31 // =========================================================================
32 
33 namespace gum {
34 
35  // ==========================================================================
36  // Constructor & destructor.
37  // ==========================================================================
38 
39  // ###################################################################
40  // Default constructor
41  // ###################################################################
43  __remainingVars(startingSet) {
44  GUM_CONSTRUCTOR(VariableSelector);
45  __remainingScores.insert(0.0, 0.0);
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  }
56 
57  // ###################################################################
58  // Default constructor
59  // ###################################################################
61 
62 
63  // ###################################################################
64  //
65  // ###################################################################
67  double score,
68  double secondaryscore) {
69  __removeVar(var);
70  __remainingVarsScore[var] += score;
71  __addVar(var);
72  __remainingVarsOtherScore[var] += secondaryscore;
73  }
74 
75 
76  // ###################################################################
77  //
78  // ###################################################################
80  double score,
81  double secondaryscore) {
82  __removeVar(var);
83  __remainingVarsScore[var] -= score;
84  __addVar(var);
85  __remainingVarsOtherScore[var] -= secondaryscore;
86  }
87 
88 
89  // ###################################################################
90  // Select the most relevant variable
91  // ###################################################################
93  double bestScore = __remainingScores.top();
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  }
111 
112 
113  // ###################################################################
114  // Select the most relevant variable
115  // ###################################################################
117  double varScore = __remainingVarsScore[var];
118 
119  if (!__remainingVarsByScore.exists(varScore)) {
120  __remainingVarsByScore.insert(varScore,
122  __remainingScores.insert(varScore, varScore);
123  }
124  __remainingVarsByScore[varScore]->insert(var);
125  }
126 
127 
128  // ###################################################################
129  // Select the most relevant variable
130  // ###################################################################
132  double varScore = __remainingVarsScore[var];
134  *varSet >> var;
135  if (varSet->empty()) {
136  __remainingScores.erase(varScore);
137  __remainingVarsByScore.erase(varScore);
138  delete varSet;
139  }
140  }
141 } // namespace gum
HashTable< const DiscreteVariable *, double > __remainingVarsScore
HashTable associating to each variable its score.
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:707
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.
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
void downdateScore(const DiscreteVariable *var, double score, double secondaryscore)
The set of remaining vars to select among.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
MultiPriorityQueue< double, double, std::greater< double > > __remainingScores
Heap keeping best score on top for immediate access.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition: set_tpl.h:502
virtual Size domainSize() const =0
~VariableSelector()
Default destructor.
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.
const DiscreteVariable * select()
Select the most relevant variable.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
void __addVar(const DiscreteVariable *var)
The set of remaining vars to select among.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/FMDP/planning/FunctionGraph/variableselector.h>
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition: set_tpl.h:488
void updateScore(const DiscreteVariable *var, double score, double secondaryscore)
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.
VariableSelector(Set< const DiscreteVariable * > &startingSet)
Default constructor.