aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
taxiSimulator.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
49
#ifndef GUM_TAXI_SIMULATOR_H
50
#define GUM_TAXI_SIMULATOR_H
51
//======================================================================
52
//======================================================================
53
//======================================================================
54
#include <
agrum/FMDP/simulation/abstractSimulator.h
>
55
//======================================================================
56
#include <
agrum/base/variables/labelizedVariable.h
>
57
58
//======================================================================
59
60
namespace
gum
{
61
62
63
enum
TaxiSimulationLandmark
:
Idx
{
HOME
= 0,
WORK
= 1,
THEATER
= 2,
CLUB
= 3,
TAXI
= 4 };
64
65
enum
TaxiSimulationLandmarkX
:
Idx
{
66
HOMEX
= 0,
67
WORKX
= 0,
68
THEATERX
= 3,
69
CLUBX
= 4,
70
STATIONX
= 2
71
};
72
73
enum
TaxiSimulationLandmarkY
:
Idx
{
74
HOMEY
= 0,
75
WORKY
= 4,
76
THEATERY
= 0,
77
CLUBY
= 4,
78
STATIONY
= 1
79
};
80
81
enum
TaxiSimulationAction
:
Idx
{
82
GoNorth
= 1,
83
GoEast
= 2,
84
GoSouth
= 3,
85
GoWest
= 4,
86
PickUp
= 5,
87
PutDown
= 6,
88
FillUp
= 7
89
};
90
91
// clang-format off
98
// clang-format on
99
100
class
TaxiSimulator
:
public
AbstractSimulator
{
101
public
:
102
// ===========================================================================
104
// ===========================================================================
106
110
TaxiSimulator
();
111
115
~TaxiSimulator
()
override
;
116
118
119
// ===========================================================================
121
// ===========================================================================
123
124
protected
:
126
Instantiation
randomState_
()
override
;
127
128
public
:
129
bool
hasReachEnd
()
override
;
130
132
133
// ===========================================================================
135
// ===========================================================================
137
138
const
DiscreteVariable
*
primeVar
(
const
DiscreteVariable
* mainVar)
override
;
139
141
SequenceIteratorSafe< const DiscreteVariable* >
beginVariables
()
override
;
142
143
SequenceIteratorSafe< const DiscreteVariable* >
endVariables
()
override
;
144
146
147
// ===========================================================================
149
// ===========================================================================
151
152
const
std::string&
actionName
(
Idx
actionId)
override
;
153
154
SequenceIteratorSafe< Idx >
beginActions
()
override
;
155
156
SequenceIteratorSafe< Idx >
endActions
()
override
;
157
158
void
perform
(
Idx
)
override
;
159
160
private
:
161
void
_performGoNorth_
();
162
void
_performGoEast_
();
163
void
_performGoSouth_
();
164
void
_performGoWest_
();
165
void
_performPickUp_
();
166
void
_performPutDown_
();
167
void
_performFillUp_
();
168
170
171
// ===========================================================================
173
// ===========================================================================
175
176
public
:
177
double
reward
()
override
;
178
179
private
:
180
void
_evalReward_
();
181
bool
_isAtDestination_
(
TaxiSimulationLandmark
passDest,
182
TaxiSimulationLandmarkX
xCurPos,
183
TaxiSimulationLandmarkY
yCurPos);
184
bool
_isAtMeetPoint_
(
TaxiSimulationLandmark
passpos,
185
TaxiSimulationLandmarkX
xCurPos,
186
TaxiSimulationLandmarkY
yCurPos);
187
189
191
Sequence< const DiscreteVariable* >
_taxiVars_
;
192
Bijection< const DiscreteVariable*, const DiscreteVariable* >
_primeMap_
;
193
LabelizedVariable
*
_xPos_
;
194
LabelizedVariable
*
_yPos_
;
195
LabelizedVariable
*
_passengerPos_
;
196
LabelizedVariable
*
_passengerDest_
;
197
LabelizedVariable
*
_fuelLevel_
;
198
200
Sequence< Idx >
_taxiActions_
;
201
HashTable< Idx, std::string* >
_actionMap_
;
// __actionMap.insert ( actionId,
202
// new std::string ( action ) );
203
TaxiSimulationAction
_lastAction_
;
204
206
double
_reward_
;
207
};
208
209
}
/* namespace gum */
210
211
#ifndef GUM_NO_INLINE
212
# include <
agrum/FMDP/simulation/taxiSimulator_inl.h
>
213
#endif
// GUM_NO_INLINE
214
#endif
// GUM_TAXI_SIMULATOR_H
abstractSimulator.h
Class for simulating a discrete time stochastic process.
gum::AbstractSimulator::AbstractSimulator
AbstractSimulator()
Default constructor.
Definition
abstractSimulator.cpp:69
gum::Bijection
Set of pairs of elements with fast search for both elements.
Definition
bijection.h:1640
gum::DiscreteVariable
Base class for discrete random variable.
Definition
discreteVariable.h:80
gum::HashTable
The class for generic Hash Tables.
Definition
hashTable.h:640
gum::Instantiation
Class for assigning/browsing values to tuples of discrete variables.
Definition
instantiation.h:102
gum::LabelizedVariable
class LabelizedVariable
Definition
labelizedVariable.h:71
gum::SequenceIteratorSafe
Safe iterators for Sequence.
Definition
sequence.h:1148
gum::Sequence
The generic class for storing (ordered) sequences of objects.
Definition
sequence.h:994
gum::TaxiSimulator::actionName
const std::string & actionName(Idx actionId) override
Iteration over the variables of the simulated probleme.
Definition
taxiSimulator_inl.h:60
gum::TaxiSimulator::_taxiActions_
Sequence< Idx > _taxiActions_
Actions.
Definition
taxiSimulator.h:200
gum::TaxiSimulator::_isAtDestination_
bool _isAtDestination_(TaxiSimulationLandmark passDest, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
Definition
taxiSimulator.cpp:374
gum::TaxiSimulator::_yPos_
LabelizedVariable * _yPos_
Definition
taxiSimulator.h:194
gum::TaxiSimulator::_evalReward_
void _evalReward_()
Definition
taxiSimulator.cpp:335
gum::TaxiSimulator::_primeMap_
Bijection< const DiscreteVariable *, const DiscreteVariable * > _primeMap_
Definition
taxiSimulator.h:192
gum::TaxiSimulator::_performFillUp_
void _performFillUp_()
Definition
taxiSimulator.cpp:323
gum::TaxiSimulator::_performGoEast_
void _performGoEast_()
Definition
taxiSimulator.cpp:216
gum::TaxiSimulator::_performGoWest_
void _performGoWest_()
Definition
taxiSimulator.cpp:240
gum::TaxiSimulator::_xPos_
LabelizedVariable * _xPos_
Definition
taxiSimulator.h:193
gum::TaxiSimulator::TaxiSimulator
TaxiSimulator()
Default constructor.
Definition
taxiSimulator.cpp:61
gum::TaxiSimulator::reward
double reward() override
Sets the intial statefrom which we begun the simulation.
Definition
taxiSimulator.cpp:181
gum::TaxiSimulator::perform
void perform(Idx) override
Sets the intial statefrom which we begun the simulation.
Definition
taxiSimulator.cpp:186
gum::TaxiSimulator::hasReachEnd
bool hasReachEnd() override
Choses a random state as the first test for a run.
Definition
taxiSimulator.cpp:167
gum::TaxiSimulator::_taxiVars_
Sequence< const DiscreteVariable * > _taxiVars_
Variables data structures.
Definition
taxiSimulator.h:191
gum::TaxiSimulator::primeVar
const DiscreteVariable * primeVar(const DiscreteVariable *mainVar) override
Iteration over the variables of the simulated probleme.
Definition
taxiSimulator_inl.h:48
gum::TaxiSimulator::_lastAction_
TaxiSimulationAction _lastAction_
Definition
taxiSimulator.h:203
gum::TaxiSimulator::beginActions
SequenceIteratorSafe< Idx > beginActions() override
Iteration over the variables of the simulated probleme.
Definition
taxiSimulator_inl.h:64
gum::TaxiSimulator::_passengerDest_
LabelizedVariable * _passengerDest_
Definition
taxiSimulator.h:196
gum::TaxiSimulator::_performGoSouth_
void _performGoSouth_()
Definition
taxiSimulator.cpp:232
gum::TaxiSimulator::_performGoNorth_
void _performGoNorth_()
Definition
taxiSimulator.cpp:208
gum::TaxiSimulator::_passengerPos_
LabelizedVariable * _passengerPos_
Definition
taxiSimulator.h:195
gum::TaxiSimulator::_performPickUp_
void _performPickUp_()
Definition
taxiSimulator.cpp:256
gum::TaxiSimulator::beginVariables
SequenceIteratorSafe< const DiscreteVariable * > beginVariables() override
Iteration over the variables of the simulated probleme.
Definition
taxiSimulator_inl.h:52
gum::TaxiSimulator::endVariables
SequenceIteratorSafe< const DiscreteVariable * > endVariables() override
Iteration over the variables of the simulated probleme.
Definition
taxiSimulator_inl.h:56
gum::TaxiSimulator::_reward_
double _reward_
Reward.
Definition
taxiSimulator.h:206
gum::TaxiSimulator::_fuelLevel_
LabelizedVariable * _fuelLevel_
Definition
taxiSimulator.h:197
gum::TaxiSimulator::_actionMap_
HashTable< Idx, std::string * > _actionMap_
Definition
taxiSimulator.h:201
gum::TaxiSimulator::randomState_
Instantiation randomState_() override
Choses a random state as the first test for a run.
Definition
taxiSimulator.cpp:144
gum::TaxiSimulator::endActions
SequenceIteratorSafe< Idx > endActions() override
Iteration over the variables of the simulated probleme.
Definition
taxiSimulator_inl.h:68
gum::TaxiSimulator::_performPutDown_
void _performPutDown_()
Definition
taxiSimulator.cpp:287
gum::TaxiSimulator::_isAtMeetPoint_
bool _isAtMeetPoint_(TaxiSimulationLandmark passpos, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
Definition
taxiSimulator.cpp:399
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
labelizedVariable.h
Base class for labelized discrete random variables.
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::TaxiSimulationLandmarkX
TaxiSimulationLandmarkX
Definition
taxiSimulator.h:65
gum::WORKX
@ WORKX
Definition
factorySimulator.h:66
gum::STATIONX
@ STATIONX
Definition
factorySimulator.h:69
gum::CLUBX
@ CLUBX
Definition
factorySimulator.h:68
gum::HOMEX
@ HOMEX
Definition
factorySimulator.h:65
gum::THEATERX
@ THEATERX
Definition
factorySimulator.h:67
gum::TaxiSimulationLandmark
TaxiSimulationLandmark
Definition
taxiSimulator.h:63
gum::HOME
@ HOME
Definition
factorySimulator.h:62
gum::THEATER
@ THEATER
Definition
factorySimulator.h:62
gum::WORK
@ WORK
Definition
factorySimulator.h:62
gum::TAXI
@ TAXI
Definition
taxiSimulator.h:63
gum::CLUB
@ CLUB
Definition
factorySimulator.h:62
gum::TaxiSimulationLandmarkY
TaxiSimulationLandmarkY
Definition
taxiSimulator.h:73
gum::STATIONY
@ STATIONY
Definition
factorySimulator.h:77
gum::THEATERY
@ THEATERY
Definition
factorySimulator.h:75
gum::WORKY
@ WORKY
Definition
factorySimulator.h:74
gum::HOMEY
@ HOMEY
Definition
factorySimulator.h:73
gum::CLUBY
@ CLUBY
Definition
factorySimulator.h:76
gum::TaxiSimulationAction
TaxiSimulationAction
Definition
taxiSimulator.h:81
gum::PickUp
@ PickUp
Definition
factorySimulator.h:85
gum::GoSouth
@ GoSouth
Definition
factorySimulator.h:83
gum::GoWest
@ GoWest
Definition
factorySimulator.h:84
gum::GoEast
@ GoEast
Definition
factorySimulator.h:82
gum::PutDown
@ PutDown
Definition
factorySimulator.h:86
gum::GoNorth
@ GoNorth
Definition
factorySimulator.h:81
gum::FillUp
@ FillUp
Definition
factorySimulator.h:87
taxiSimulator_inl.h
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0