1 /** 2 * 3 * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_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 discrete time stochastic process. 25 * 26 * @author Jean-Christophe MAGNAN 27 */ 28 #ifndef GUM_ABSTRACT_SIMULATOR_H 29 #define GUM_ABSTRACT_SIMULATOR_H 30 //====================================================================== 31 #include <agrum/tools/multidim/instantiation.h> 32 //====================================================================== 33 #include <agrum/FMDP/fmdp.h> 34 //====================================================================== 35 //====================================================================== 36 37 namespace gum { 38 /** 39 * @class AbstractSimulator abstractSimulator.h 40 * <agrum/FMDP/simulation/abstractSimulator.h> 41 * @brief A class to simulate a reinforcement learning problem. 42 * @ingroup fmdp_group 43 * 44 * 45 * 46 */ 47 class AbstractSimulator { 48 public: 49 // =========================================================================== 50 /// @name Constructors, Destructors. 51 // =========================================================================== 52 /// @{ 53 54 /** 55 * Default constructor. 56 */ 57 AbstractSimulator(); 58 59 /** 60 * Default destructor. 61 */ 62 virtual ~AbstractSimulator(); 63 64 /// @} 65 66 // =========================================================================== 67 /// @name 68 // =========================================================================== 69 /// @{ 70 71 /// Sets the intial statefrom which we begun the simulation setInitialState(const Instantiation & initialState)72 INLINE void setInitialState(const Instantiation& initialState) { currentState_ = initialState; } 73 void setInitialStateRandomly(); 74 75 protected: 76 /// Choses a random state as the first test for a run 77 virtual Instantiation randomState_(); 78 79 public: 80 /// Sets the final states upon which a run is over setEndState(const Instantiation & endState)81 INLINE void setEndState(const Instantiation& endState) { endState_ = endState; } 82 83 /// Tests if end state has been reached 84 virtual bool hasReachEnd(); 85 86 /// currentState()87 INLINE const Instantiation& currentState() { return currentState_; } 88 89 /// 90 virtual double reward() = 0; 91 92 /// 93 virtual void perform(Idx) = 0; 94 95 /// @} 96 97 // =========================================================================== 98 /// @name Variables 99 // =========================================================================== 100 /// @{ 101 102 virtual const DiscreteVariable* primeVar(const DiscreteVariable* mainVar) = 0; 103 104 /// Iteration over the variables of the simulated probleme 105 virtual SequenceIteratorSafe< const DiscreteVariable* > beginVariables() = 0; 106 virtual SequenceIteratorSafe< const DiscreteVariable* > endVariables() = 0; 107 108 /// @} 109 110 // =========================================================================== 111 /// @name Actions 112 // =========================================================================== 113 /// @{ 114 115 virtual const std::string& actionName(Idx) = 0; 116 117 /// Iteration over the variables of the simulated probleme 118 virtual SequenceIteratorSafe< Idx > beginActions() = 0; 119 virtual SequenceIteratorSafe< Idx > endActions() = 0; 120 121 122 /// @} 123 124 /// Tha state in which the system currently is 125 Instantiation currentState_, endState_; 126 }; 127 128 } /* namespace gum */ 129 130 131 #endif // _GUM_ABSTRACT_SIMULATOR_H 132