aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
taxiSimulator.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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  }
134  return taxiVars__.endSafe();
135  }
136 
137  /// @}
138 
139  // ===========================================================================
140  /// @name Actions
141  // ===========================================================================
142  /// @{
143 
144  const std::string& actionName(Idx actionId) { return *actionMap__[actionId]; }
145 
146  /// Iteration over the variables of the simulated probleme
148  return taxiActions__.beginSafe();
149  }
150  SequenceIteratorSafe< Idx > endActions() { return taxiActions__.endSafe(); }
151 
152 
153  void perform(Idx);
154 
155  private:
156  void performGoNorth__();
157  void performGoEast__();
158  void performGoSouth__();
159  void performGoWest__();
160  void performPickUp__();
161  void performPutDown__();
162  void performFillUp__();
163 
164  /// @}
165 
166  // ===========================================================================
167  /// @name Rewards
168  // ===========================================================================
169  /// @{
170  public:
171  double reward();
172 
173  private:
174  void evalReward__();
176  TaxiSimulationLandmarkX xCurPos,
177  TaxiSimulationLandmarkY yCurPos);
179  TaxiSimulationLandmarkX xCurPos,
180  TaxiSimulationLandmarkY yCurPos);
181 
182  /// @}
183 
184  /// Variables data structures
192 
193  /// Actions
195  HashTable< Idx, std::string* > actionMap__; //__actionMap.insert ( actionId,
196  // new std::string ( action ) );
198 
199  /// Reward
200  double reward__;
201  };
202 
203 } /* namespace gum */
204 
205 
206 #endif // GUM_TAXI_SIMULATOR_H
void perform(Idx)
Iteration over the variables of the simulated probleme.
Instantiation randomState_()
Choses a random state as the first test for a run.
TaxiSimulationAction lastAction__
void performPutDown__()
Iteration over the variables of the simulated probleme.
double reward__
Reward.
Bijection< const DiscreteVariable *, const DiscreteVariable *> primeMap__
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:669
TaxiSimulationLandmarkX
Definition: taxiSimulator.h:52
LabelizedVariable * passengerDest__
SequenceIteratorSafe< const DiscreteVariable *> endVariables()
Iteration over the variables of the simulated probleme.
LabelizedVariable * yPos__
void performGoEast__()
Iteration over the variables of the simulated probleme.
bool isAtMeetPoint__(TaxiSimulationLandmark passpos, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
TaxiSimulationLandmark
Definition: taxiSimulator.h:44
SequenceIteratorSafe< Idx > beginActions()
Iteration over the variables of the simulated probleme.
TaxiSimulationLandmarkY
Definition: taxiSimulator.h:60
bool hasReachEnd()
Choses a random state as the first test for a run.
double reward()
Sets the intial statefrom which we begun the simulation.
LabelizedVariable * fuelLevel__
void performGoWest__()
Iteration over the variables of the simulated probleme.
A class to simulate the Taxi problem.
Definition: taxiSimulator.h:87
void performFillUp__()
Iteration over the variables of the simulated probleme.
~TaxiSimulator()
Default destructor.
const std::string & actionName(Idx actionId)
Iteration over the variables of the simulated probleme.
void performPickUp__()
Iteration over the variables of the simulated probleme.
LabelizedVariable * xPos__
HashTable< Idx, std::string *> actionMap__
Sequence< Idx > taxiActions__
Actions.
SequenceIteratorSafe< Idx > endActions()
Iteration over the variables of the simulated probleme.
void performGoNorth__()
Iteration over the variables of the simulated probleme.
TaxiSimulator()
Default constructor.
Sequence< const DiscreteVariable *> taxiVars__
Variables data structures.
void performGoSouth__()
Iteration over the variables of the simulated probleme.
bool isAtDestination__(TaxiSimulationLandmark passDest, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
LabelizedVariable * passengerPos__