aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
taxiSimulator.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_TAXI_SIMULATOR_H
30 #define GUM_TAXI_SIMULATOR_H
31 //======================================================================
32 #include <agrum/tools/multidim/instantiation.h>
33 //======================================================================
34 #include <agrum/FMDP/fmdp.h>
35 //======================================================================
36 #include <agrum/FMDP/simulation/abstractSimulator.h>
37 //======================================================================
38 #include <agrum/tools/variables/labelizedVariable.h>
39 //======================================================================
40 
41 namespace gum {
42 
43 
45  {
46  HOME = 0,
47  WORK = 1,
48  THEATER = 2,
49  CLUB = 3,
50  TAXI = 4
51  };
53  {
54  HOMEX = 0,
55  WORKX = 0,
56  THEATERX = 3,
57  CLUBX = 4,
58  STATIONX = 2
59  };
61  {
62  HOMEY = 0,
63  WORKY = 4,
64  THEATERY = 0,
65  CLUBY = 4,
66  STATIONY = 1
67  };
69  {
70  GoNorth = 1,
71  GoEast = 2,
72  GoSouth = 3,
73  GoWest = 4,
74  PickUp = 5,
75  PutDown = 6,
76  FillUp = 7
77  };
78 
79  // clang-format off
80  /**
81 * @class TaxiSimulator
82 * @headerfile taxiSimulator.h <agrum/FMDP/simulation/taxiSimulator.h>
83  * @brief A class to simulate the Taxi problem
84  * @ingroup fmdp_group
85  */
86  // clang-format on
88  public:
89  // ===========================================================================
90  /// @name Constructors, Destructors.
91  // ===========================================================================
92  /// @{
93 
94  /**
95  * Default constructor.
96  */
97  TaxiSimulator();
98 
99  /**
100  * Default destructor.
101  */
102  ~TaxiSimulator();
103 
104  /// @}
105 
106  // ===========================================================================
107  /// @name States
108  // ===========================================================================
109  /// @{
110 
111  protected:
112  /// Choses a random state as the first test for a run
114 
115  public:
116  bool hasReachEnd();
117 
118  /// @}
119 
120  // ===========================================================================
121  /// @name Variables
122  // ===========================================================================
123  /// @{
124 
126  return _primeMap_.second(mainVar);
127  }
128 
129  /// Iteration over the variables of the simulated probleme
131  return _taxiVars_.beginSafe();
132  }
133  SequenceIteratorSafe< const DiscreteVariable* > endVariables() { return _taxiVars_.endSafe(); }
134 
135  /// @}
136 
137  // ===========================================================================
138  /// @name Actions
139  // ===========================================================================
140  /// @{
141 
142  const std::string& actionName(Idx actionId) { return *_actionMap_[actionId]; }
143 
144  /// Iteration over the variables of the simulated probleme
145  SequenceIteratorSafe< Idx > beginActions() { return _taxiActions_.beginSafe(); }
146  SequenceIteratorSafe< Idx > endActions() { return _taxiActions_.endSafe(); }
147 
148 
149  void perform(Idx);
150 
151  private:
152  void _performGoNorth_();
153  void _performGoEast_();
154  void _performGoSouth_();
155  void _performGoWest_();
156  void _performPickUp_();
157  void _performPutDown_();
158  void _performFillUp_();
159 
160  /// @}
161 
162  // ===========================================================================
163  /// @name Rewards
164  // ===========================================================================
165  /// @{
166  public:
167  double reward();
168 
169  private:
170  void _evalReward_();
172  TaxiSimulationLandmarkX xCurPos,
173  TaxiSimulationLandmarkY yCurPos);
175  TaxiSimulationLandmarkX xCurPos,
176  TaxiSimulationLandmarkY yCurPos);
177 
178  /// @}
179 
180  /// Variables data structures
188 
189  /// Actions
191  HashTable< Idx, std::string* > _actionMap_; // __actionMap.insert ( actionId,
192  // new std::string ( action ) );
194 
195  /// Reward
196  double _reward_;
197  };
198 
199 } /* namespace gum */
200 
201 
202 #endif // GUM_TAXI_SIMULATOR_H
void perform(Idx)
Iteration over the variables of the simulated probleme.
LabelizedVariable * _passengerPos_
void _performGoSouth_()
Iteration over the variables of the simulated probleme.
void _performFillUp_()
Iteration over the variables of the simulated probleme.
void _performGoEast_()
Iteration over the variables of the simulated probleme.
LabelizedVariable * _yPos_
Instantiation randomState_()
Choses a random state as the first test for a run.
void _performGoNorth_()
Iteration over the variables of the simulated probleme.
double _reward_
Reward.
bool _isAtDestination_(TaxiSimulationLandmark passDest, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
SequenceIteratorSafe< const DiscreteVariable *> beginVariables()
Iteration over the variables of the simulated probleme.
TaxiSimulationAction
Definition: taxiSimulator.h:68
const DiscreteVariable * primeVar(const DiscreteVariable *mainVar)
Iteration over the variables of the simulated probleme.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
TaxiSimulationAction _lastAction_
TaxiSimulationLandmarkX
Definition: taxiSimulator.h:52
SequenceIteratorSafe< const DiscreteVariable *> endVariables()
Iteration over the variables of the simulated probleme.
LabelizedVariable * _xPos_
TaxiSimulationLandmark
Definition: taxiSimulator.h:44
Sequence< const DiscreteVariable *> _taxiVars_
Variables data structures.
SequenceIteratorSafe< Idx > beginActions()
Iteration over the variables of the simulated probleme.
bool _isAtMeetPoint_(TaxiSimulationLandmark passpos, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
TaxiSimulationLandmarkY
Definition: taxiSimulator.h:60
void _performGoWest_()
Iteration over the variables of the simulated probleme.
bool hasReachEnd()
Choses a random state as the first test for a run.
void _performPickUp_()
Iteration over the variables of the simulated probleme.
double reward()
Sets the intial statefrom which we begun the simulation.
void _performPutDown_()
Iteration over the variables of the simulated probleme.
A class to simulate the Taxi problem.
Definition: taxiSimulator.h:87
~TaxiSimulator()
Default destructor.
LabelizedVariable * _passengerDest_
const std::string & actionName(Idx actionId)
Iteration over the variables of the simulated probleme.
Sequence< Idx > _taxiActions_
Actions.
Bijection< const DiscreteVariable *, const DiscreteVariable *> _primeMap_
HashTable< Idx, std::string *> _actionMap_
LabelizedVariable * _fuelLevel_
SequenceIteratorSafe< Idx > endActions()
Iteration over the variables of the simulated probleme.
TaxiSimulator()
Default constructor.