aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
fmdpSimulator.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Class for simulating a markov decision process.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 #ifndef GUM_FMDP_SIMULATOR_H
30 #define GUM_FMDP_SIMULATOR_H
31 //======================================================================
32 #include <agrum/tools/multidim/instantiation.h>
33 //======================================================================
34 #include <agrum/FMDP/fmdp.h>
35 #include <agrum/FMDP/simulation/abstractSimulator.h>
36 //======================================================================
37 
38 namespace gum {
39  /**
40  * @class FMDPSimulator fmdpSimulator.h
41  * <agrum/FMDP/simulation/fmdpSimulator.h>
42  * @brief A class to simulate a Factored Markov Decision Process.
43  * @ingroup fmdp_group
44  *
45  *
46  *
47  */
49  public:
50  // ===========================================================================
51  /// @name Constructors, Destructors.
52  // ===========================================================================
53  /// @{
54 
55  /**
56  * Default constructor.
57  */
58  FMDPSimulator(const FMDP< double >* fmdp);
59  FMDPSimulator(const std::string& resource);
60 
61  /**
62  * Default destructor.
63  */
64  ~FMDPSimulator();
65 
66  /// @}
67 
68  // ===========================================================================
69  /// @name
70  // ===========================================================================
71  /// @{
72 
73  ///
74  double reward() { return _fmdp_->reward()->get(this->currentState_); }
75 
76  void perform(Idx);
77 
78  /// @}
79 
80  // ===========================================================================
81  /// @name
82  // ===========================================================================
83  /// @{
84 
86  return _fmdp_->main2prime(mainVar);
87  }
88 
89  /// Iteration over the variables of the simulated probleme
91  return _fmdp_->beginVariables();
92  }
94  return _fmdp_->endVariables();
95  }
96 
97  /// @}
98 
99  // ===========================================================================
100  /// @name
101  // ===========================================================================
102  /// @{
103 
104  virtual const std::string& actionName(Idx actionId) { return _fmdp_->actionName(actionId); }
105 
106  /// Iteration over the variables of the simulated probleme
107  SequenceIteratorSafe< Idx > beginActions() { return _fmdp_->beginActions(); }
108  SequenceIteratorSafe< Idx > endActions() { return _fmdp_->endActions(); }
109  /// @}
110 
111  protected:
112  virtual double transitionProbability_(const DiscreteVariable* var,
113  const Instantiation& transit,
114  Idx actionId) {
115  return reinterpret_cast< const MultiDimFunctionGraph< double >* >(
116  _fmdp_->transition(actionId, var))
117  ->get(transit);
118  }
119 
120  private:
121  /// The Factored Markov Decision Process that describes how the system
122  /// evolves
123  FMDP< double >* _fmdp_;
124 
125  /// Just to know if it should be deleted in the end
126  const bool _loaded_;
127  };
128 
129 } /* namespace gum */
130 
131 
132 #endif // GUM_FMDP_SIMULATOR_H
FMDP< double > * _fmdp_
The Factored Markov Decision Process that describes how the system evolves.
void perform(Idx)
Sets the intial statefrom which we begun the simulation.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
const DiscreteVariable * primeVar(const DiscreteVariable *mainVar)
Iteration over the variables of the simulated probleme.
Definition: fmdpSimulator.h:85
<agrum/FMDP/simulation/fmdpSimulator.h>
Definition: fmdpSimulator.h:48
const bool _loaded_
Just to know if it should be deleted in the end.
FMDPSimulator(const std::string &resource)
Default constructor.
SequenceIteratorSafe< const DiscreteVariable *> endVariables()
Iteration over the variables of the simulated probleme.
Definition: fmdpSimulator.h:93
FMDPSimulator(const FMDP< double > *fmdp)
Default constructor.
SequenceIteratorSafe< const DiscreteVariable *> beginVariables()
Iteration over the variables of the simulated probleme.
Definition: fmdpSimulator.h:90
virtual const std::string & actionName(Idx actionId)
Iteration over the variables of the simulated probleme.
double reward()
Sets the intial statefrom which we begun the simulation.
Definition: fmdpSimulator.h:74
virtual double transitionProbability_(const DiscreteVariable *var, const Instantiation &transit, Idx actionId)
SequenceIteratorSafe< Idx > endActions()
Iteration over the variables of the simulated probleme.
SequenceIteratorSafe< Idx > beginActions()
Iteration over the variables of the simulated probleme.
~FMDPSimulator()
Default destructor.