aGrUM  0.16.0
structuredPlaner.h
Go to the documentation of this file.
1 
30 // =========================================================================
31 #ifndef GUM_STRUCTURED_PLANNING_H
32 #define GUM_STRUCTURED_PLANNING_H
33 // =========================================================================
34 #include <thread>
35 // =========================================================================
36 #include <agrum/core/argMaxSet.h>
37 #include <agrum/core/functors.h>
38 #include <agrum/core/inline.h>
40 // =========================================================================
43 // =========================================================================
45 #include <agrum/FMDP/fmdp.h>
50 // =========================================================================
51 
52 namespace gum {
53 
69  template < typename GUM_SCALAR >
70  class StructuredPlaner : public IPlanningStrategy< GUM_SCALAR > {
71  // ###################################################################
73  // ###################################################################
75  public:
76  // ==========================================================================
78  // ==========================================================================
80  spumddInstance(GUM_SCALAR discountFactor = 0.9,
81  GUM_SCALAR epsilon = 0.00001,
82  bool verbose = true) {
85  discountFactor,
86  epsilon,
87  verbose);
88  }
89 
90  // ==========================================================================
92  // ==========================================================================
94  sviInstance(GUM_SCALAR discountFactor = 0.9,
95  GUM_SCALAR epsilon = 0.00001,
96  bool verbose = true) {
99  discountFactor,
100  epsilon,
101  verbose);
102  }
103 
105 
106  // ###################################################################
108  // ###################################################################
110  protected:
111  // ==========================================================================
113  // ==========================================================================
115  GUM_SCALAR discountFactor,
116  GUM_SCALAR epsilon,
117  bool verbose);
118 
119  // ==========================================================================
121  // ==========================================================================
122  public:
123  virtual ~StructuredPlaner();
124 
126 
127  // ###################################################################
129  // ###################################################################
131 
132  public:
133  // ==========================================================================
136  // ==========================================================================
137  INLINE const FMDP< GUM_SCALAR >* fmdp() { return _fmdp; }
138 
139  // ==========================================================================
141  // ==========================================================================
143  return _vFunction;
144  }
145 
146  // ==========================================================================
148  // ==========================================================================
149  virtual Size vFunctionSize() {
150  return _vFunction != nullptr ? _vFunction->realSize() : 0;
151  }
152 
153  // ==========================================================================
155  // ==========================================================================
158  return _optimalPolicy;
159  }
160 
161  // ==========================================================================
163  // ==========================================================================
165  return _optimalPolicy != nullptr ? _optimalPolicy->realSize() : 0;
166  }
167 
168  // ==========================================================================
172  // ==========================================================================
173  std::string optimalPolicy2String();
174 
176 
177 
178  // ###################################################################
180  // ###################################################################
182 
183  public:
184  // ==========================================================================
190  // ==========================================================================
191  virtual void initialize(const FMDP< GUM_SCALAR >* fmdp);
192 
193 
194  // ==========================================================================
203  // ==========================================================================
204  virtual void makePlanning(Idx nbStep = 1000000);
205 
207 
208 
209  // ###################################################################
211  // ###################################################################
213 
214  protected:
215  // ==========================================================================
217  // ==========================================================================
218  virtual void _initVFunction();
219 
220  // ==========================================================================
222  // ==========================================================================
224 
225  // ==========================================================================
227  // ==========================================================================
230 
231  // ==========================================================================
234  // ==========================================================================
237 
238  // ==========================================================================
241  // ==========================================================================
244 
245  // ==========================================================================
248  // ==========================================================================
250  _addReward(MultiDimFunctionGraph< GUM_SCALAR >* function, Idx actionId = 0);
251 
253 
254 
255  // ###################################################################
257  // ###################################################################
259 
260  protected:
261  // ==========================================================================
263  // ==========================================================================
264  virtual void _evalPolicy();
265 
266  // ==========================================================================
277  // ==========================================================================
280  Idx actionId);
281 
282  private:
283  // ==========================================================================
285  // ==========================================================================
287  Idx,
292 
293  protected:
294  // ==========================================================================
297  // ==========================================================================
302  SetTerminalNodePolicy >* >&);
303 
304  // ==========================================================================
309  // ==========================================================================
312  SetTerminalNodePolicy >* optimalValueFunction);
313 
314  private:
315  // ==========================================================================
317  // ==========================================================================
319  NodeId,
323 
324  // ==========================================================================
326  // ==========================================================================
328 
329 
331 
332  protected:
333  // ==========================================================================
337  // ==========================================================================
339 
340  // ==========================================================================
342  // ==========================================================================
344 
345  // ==========================================================================
352  // ==========================================================================
354 
355  // ==========================================================================
357  // ==========================================================================
359 
360  // ==========================================================================
362  // ==========================================================================
363  GUM_SCALAR _discountFactor;
364 
366 
367  // ==========================================================================
370  // ==========================================================================
371  bool _verbose;
372 
373 
374  private:
375  // ==========================================================================
378  // ==========================================================================
379  GUM_SCALAR __threshold;
381  };
382 
383 } /* namespace gum */
384 
385 
387 
388 #endif // GUM_STRUCTURED_PLANNING_H
static StructuredPlaner< GUM_SCALAR > * sviInstance(GUM_SCALAR discountFactor=0.9, GUM_SCALAR epsilon=0.00001, bool verbose=true)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/FMDP/planning/structuredPlaner.h>
virtual ~StructuredPlaner()
Default destructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
A class to store the optimal actions.
Definition: actionSet.h:88
virtual Size realSize() const
Returns the real number of parameters used for this table.
virtual MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > * _argmaximiseQactions(std::vector< MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > * > &)
Performs argmax_a Q(s,a)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeId __recurExtractOptPol(NodeId, const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *, HashTable< NodeId, NodeId > &)
Recursion part for the createArgMaxCopy.
GUM_SCALAR _discountFactor
Discount Factor used for infinite horizon planning.
virtual void _evalPolicy()
Perform the required tasks to extract an optimal policy.
IOperatorStrategy< GUM_SCALAR > * _operator
<agrum/FMDP/SDyna/IOperatorStrategy.h>
bool _verbose
Boolean used to indcates whether or not iteration informations should be displayed on terminal...
virtual MultiDimFunctionGraph< GUM_SCALAR > * _valueIteration()
Performs a single step of value iteration.
void _extractOptimalPolicy(const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *optimalValueFunction)
From V(s)* = argmax_a Q*(s,a), this function extract pi*(s) This function mainly consists in extracti...
This class is used to implement factored decision process.
Definition: fmdp.h:57
<agrum/FMDP/planning/mddOperatorStrategy.h>
void __transferActionIds(const ArgMaxSet< GUM_SCALAR, Idx > &, ActionSet &)
Extract from an ArgMaxSet the associated ActionSet.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
const FMDP< GUM_SCALAR > * _fmdp
The Factored Markov Decision Process describing our planning situation (NB : this one must have funct...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Class to handle efficiently argMaxSet.
Definition: argMaxSet.h:57
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
StructuredPlaner(IOperatorStrategy< GUM_SCALAR > *opi, GUM_SCALAR discountFactor, GUM_SCALAR epsilon, bool verbose)
Default constructor.
<agrum/FMDP/planning/treeOperatorStrategy.h>
virtual void _initVFunction()
Performs a single step of value iteration.
virtual MultiDimFunctionGraph< GUM_SCALAR > * _evalQaction(const MultiDimFunctionGraph< GUM_SCALAR > *, Idx)
Performs the P(s&#39;|s,a).V^{t-1}(s&#39;) part of the value itération.
GUM_SCALAR __threshold
The threshold value Whenever | V^{n} - V^{n+1} | < threshold, we consider that V ~ V*...
Set< const DiscreteVariable *> _elVarSeq
A Set to eleminate primed variables.
MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * _optimalPolicy
The associated optimal policy.
virtual Size vFunctionSize()
Returns vFunction computed so far current size.
std::string optimalPolicy2String()
Provide a better toDot for the optimal policy where the leaves have the action name instead of its id...
MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > * _makeArgMax(const MultiDimFunctionGraph< GUM_SCALAR > *Qaction, Idx actionId)
Creates a copy of given Qaction that can be exploit by a Argmax.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void initialize(const FMDP< GUM_SCALAR > *fmdp)
Initializes data structure needed for making the planning.
Implementation of a Terminal Node Policy that maps nodeid to a set of value.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual Size optimalPolicySize()
Returns optimalPolicy computed so far current size.
NodeId __recurArgMaxCopy(NodeId, Idx, const MultiDimFunctionGraph< GUM_SCALAR > *, MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *, HashTable< NodeId, NodeId > &)
Recursion part for the createArgMaxCopy.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
INLINE const FMDP< GUM_SCALAR > * fmdp()
Returns a const ptr on the Factored Markov Decision Process on which we&#39;re planning.
virtual MultiDimFunctionGraph< GUM_SCALAR > * _addReward(MultiDimFunctionGraph< GUM_SCALAR > *function, Idx actionId=0)
Perform the R(s) + gamma . function.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size Idx
Type for indexes.
Definition: types.h:53
<agrum/FMDP/SDyna/IPlanningStrategy.h>
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
virtual MultiDimFunctionGraph< GUM_SCALAR > * _minimiseFunctions(std::vector< MultiDimFunctionGraph< GUM_SCALAR > * > &)
Performs min_i F_i.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
static StructuredPlaner< GUM_SCALAR > * spumddInstance(GUM_SCALAR discountFactor=0.9, GUM_SCALAR epsilon=0.00001, bool verbose=true)
MultiDimFunctionGraph< GUM_SCALAR > * _vFunction
The Value Function computed iteratively.
virtual MultiDimFunctionGraph< GUM_SCALAR > * _maximiseQactions(std::vector< MultiDimFunctionGraph< GUM_SCALAR > * > &)
Performs max_a Q(s,a)
INLINE const MultiDimFunctionGraph< GUM_SCALAR > * vFunction()
Returns a const ptr on the value function computed so far.
INLINE const MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * optimalPolicy()
Returns the best policy obtained so far.
virtual void makePlanning(Idx nbStep=1000000)
Performs a value iteration.