aGrUM  0.16.0
gum::TaxiSimulator Class Reference

A class to simulate the Taxi problem. More...

#include <agrum/FMDP/simulation/taxiSimulator.h>

+ Inheritance diagram for gum::TaxiSimulator:
+ Collaboration diagram for gum::TaxiSimulator:

Public Attributes

Instantiation _currentState
 Tha state in which the system currently is. More...
 
Instantiation _endState
 

Public Member Functions

Constructors, Destructors.
 TaxiSimulator ()
 Default constructor. More...
 
 ~TaxiSimulator ()
 Default destructor. More...
 
Variables
const DiscreteVariableprimeVar (const DiscreteVariable *mainVar)
 Iteration over the variables of the simulated probleme. More...
 
SequenceIteratorSafe< const DiscreteVariable *> beginVariables ()
 Iteration over the variables of the simulated probleme. More...
 
SequenceIteratorSafe< const DiscreteVariable *> endVariables ()
 Iteration over the variables of the simulated probleme. More...
 
INLINE void setInitialState (const Instantiation &initialState)
 Sets the intial statefrom which we begun the simulation. More...
 
void setInitialStateRandomly ()
 Sets the intial statefrom which we begun the simulation. More...
 
INLINE void setEndState (const Instantiation &endState)
 Sets the final states upon which a run is over. More...
 
INLINE const InstantiationcurrentState ()
 Sets the intial statefrom which we begun the simulation. More...
 

States

bool hasReachEnd ()
 Choses a random state as the first test for a run. More...
 
Instantiation _randomState ()
 Choses a random state as the first test for a run. More...
 

Actions

const std::string & actionName (Idx actionId)
 Iteration over the variables of the simulated probleme. More...
 
SequenceIteratorSafe< IdxbeginActions ()
 Iteration over the variables of the simulated probleme. More...
 
SequenceIteratorSafe< IdxendActions ()
 Iteration over the variables of the simulated probleme. More...
 
void perform (Idx)
 Iteration over the variables of the simulated probleme. More...
 
void __performGoNorth ()
 Iteration over the variables of the simulated probleme. More...
 
void __performGoEast ()
 Iteration over the variables of the simulated probleme. More...
 
void __performGoSouth ()
 Iteration over the variables of the simulated probleme. More...
 
void __performGoWest ()
 Iteration over the variables of the simulated probleme. More...
 
void __performPickUp ()
 Iteration over the variables of the simulated probleme. More...
 
void __performPutDown ()
 Iteration over the variables of the simulated probleme. More...
 
void __performFillUp ()
 Iteration over the variables of the simulated probleme. More...
 

Rewards

double reward ()
 Sets the intial statefrom which we begun the simulation. More...
 
void __evalReward ()
 
bool __isAtDestination (TaxiSimulationLandmark passDest, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
 
bool __isAtMeetPoint (TaxiSimulationLandmark passpos, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
 

Detailed Description

A class to simulate the Taxi problem.

Definition at line 83 of file taxiSimulator.h.

Constructor & Destructor Documentation

◆ TaxiSimulator()

gum::TaxiSimulator::TaxiSimulator ( )

Default constructor.

Definition at line 39 of file taxiSimulator.cpp.

References __actionMap, __fuelLevel, __passengerDest, __passengerPos, __primeMap, __taxiActions, __taxiVars, __xPos, __yPos, gum::LabelizedVariable::addLabel(), beginVariables(), gum::LabelizedVariable::changeLabel(), gum::DiscreteVariable::clone(), gum::CLUB, endVariables(), gum::LabelizedVariable::eraseLabels(), gum::FillUp, gum::GoEast, gum::GoNorth, gum::GoSouth, gum::GoWest, gum::HOME, gum::SequenceImplementation< Key, Alloc, Gen >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), gum::PickUp, primeVar(), gum::PutDown, gum::Variable::setName(), gum::TAXI, gum::THEATER, and gum::WORK.

39  : AbstractSimulator() {
40  GUM_CONSTRUCTOR(TaxiSimulator);
41 
42  // *****************************************************************************************
43  // Défintion des variables du problème
44 
45  // Position TaxiSimulator
46  __xPos =
47  new LabelizedVariable("xPos", "Position horizontale du TaxiSimulator");
48  __yPos = new LabelizedVariable("yPos", "Position verticale du TaxiSimulator");
51  for (Idx pos = 0; pos < 5; pos++) {
52  std::stringstream ss;
53  ss << pos;
54  __xPos->addLabel(ss.str());
55  __yPos->addLabel(ss.str());
56  }
57 
58  // Position et destination passager
60  new LabelizedVariable("PassengerPos", "Position du Passager", 5);
62  new LabelizedVariable("PassengerDest", "Destination du Passager", 4);
67  __passengerPos->changeLabel(THEATER, "Theater");
68  __passengerDest->changeLabel(THEATER, "Theater");
72 
73  __fuelLevel = new LabelizedVariable("FuelLevel", "Niveau du réservoir", 14);
74 
75  // Ajout à séquence
76  __taxiVars.insert(__xPos);
77  __taxiVars.insert(__yPos);
78  __taxiVars.insert(__passengerPos);
80  __taxiVars.insert(__fuelLevel);
81 
82  // Prime version creation
83  for (SequenceIteratorSafe< const DiscreteVariable* > varIter =
84  this->beginVariables();
85  varIter != this->endVariables();
86  ++varIter) {
87  DiscreteVariable* primeVar = (*varIter)->clone();
88  primeVar->setName((*varIter)->name() + "'");
89  __primeMap.insert((*varIter), primeVar);
90  }
91 
92  // *****************************************************************************************
93 
94  // *****************************************************************************************
95  // Défintion des actions du problème
97  __actionMap.insert(GoNorth, new std::string("Go North"));
99  __actionMap.insert(GoEast, new std::string("Go East"));
101  __actionMap.insert(GoSouth, new std::string("Go South"));
103  __actionMap.insert(GoWest, new std::string("Go West"));
105  __actionMap.insert(PickUp, new std::string("Pick Up"));
107  __actionMap.insert(PutDown, new std::string("Put Down"));
109  __actionMap.insert(FillUp, new std::string("FillUp"));
110  }
void setName(const std::string &theValue)
sets the name of the variable
void changeLabel(Idx pos, const std::string &aLabel) const
change a label for this index
SequenceIteratorSafe< const DiscreteVariable *> beginVariables()
Iteration over the variables of the simulated probleme.
LabelizedVariable * __passengerDest
const DiscreteVariable * primeVar(const DiscreteVariable *mainVar)
Iteration over the variables of the simulated probleme.
LabelizedVariable * __xPos
SequenceIteratorSafe< const DiscreteVariable *> endVariables()
Iteration over the variables of the simulated probleme.
virtual DiscreteVariable * clone() const =0
Copy Factory.
LabelizedVariable * __yPos
void eraseLabels()
erase all the labels
Bijection< const DiscreteVariable *, const DiscreteVariable *> __primeMap
LabelizedVariable * __fuelLevel
HashTable< Idx, std::string *> __actionMap
Sequence< const DiscreteVariable *> __taxiVars
Variables data structures.
LabelizedVariable * __passengerPos
Sequence< Idx > __taxiActions
Actions.
TaxiSimulator()
Default constructor.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
LabelizedVariable & addLabel(const std::string &aLabel)
add a label with a new index (we assume that we will NEVER remove a label)
AbstractSimulator()
Default constructor.
void insert(const Key &k)
Insert an element at the end of the sequence.
Definition: sequence_tpl.h:408
+ Here is the call graph for this function:

◆ ~TaxiSimulator()

gum::TaxiSimulator::~TaxiSimulator ( )

Default destructor.

Definition at line 112 of file taxiSimulator.cpp.

References __primeMap.

112  {
113  GUM_DESTRUCTOR(TaxiSimulator);
114 
115  for (BijectionIteratorSafe< const DiscreteVariable*, const DiscreteVariable* >
116  varIter = __primeMap.beginSafe();
117  varIter != __primeMap.endSafe();
118  ++varIter) {
119  delete varIter.first();
120  delete varIter.second();
121  }
122  }
Bijection< const DiscreteVariable *, const DiscreteVariable *> __primeMap
TaxiSimulator()
Default constructor.

Member Function Documentation

◆ __evalReward()

void gum::TaxiSimulator::__evalReward ( )
private

Definition at line 337 of file taxiSimulator.cpp.

References __fuelLevel, __isAtDestination(), __isAtMeetPoint(), __lastAction, __passengerDest, __passengerPos, __reward, __xPos, __yPos, gum::AbstractSimulator::_currentState, gum::FillUp, gum::PickUp, gum::PutDown, gum::STATIONX, gum::STATIONY, gum::TAXI, and gum::Instantiation::valFromPtr().

Referenced by endActions(), and perform().

337  {
338  TaxiSimulationLandmarkX xCurPos =
340  TaxiSimulationLandmarkY yCurPos =
342  TaxiSimulationLandmark passPos =
344  TaxiSimulationLandmark passDest =
346 
347  if (__lastAction == PutDown) {
348  if (passPos == TAXI) {
349  if (__isAtDestination(passDest, xCurPos, yCurPos))
350  __reward = 30.0;
351  else
352  __reward = 0.0;
353  return;
354  }
355  __reward = 0;
356  return;
357  }
358 
359  if (__lastAction == PickUp) {
360  if (__isAtMeetPoint(passPos, xCurPos, yCurPos))
361  __reward = 20.0;
362  else
363  __reward = 0.0;
364  return;
365  }
366 
368  __reward = 0.0;
369  return;
370  }
371 
372  if (__lastAction == FillUp && (xCurPos != STATIONX || yCurPos != STATIONY)) {
373  __reward = 0.0;
374  return;
375  }
376 
377  __reward = 10.0; //-1.0;
378  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
LabelizedVariable * __passengerDest
TaxiSimulationLandmarkX
Definition: taxiSimulator.h:51
LabelizedVariable * __xPos
LabelizedVariable * __yPos
TaxiSimulationLandmark
Definition: taxiSimulator.h:44
TaxiSimulationLandmarkY
Definition: taxiSimulator.h:58
Instantiation _currentState
Tha state in which the system currently is.
LabelizedVariable * __fuelLevel
bool __isAtMeetPoint(TaxiSimulationLandmark passpos, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
double __reward
Reward.
LabelizedVariable * __passengerPos
bool __isAtDestination(TaxiSimulationLandmark passDest, TaxiSimulationLandmarkX xCurPos, TaxiSimulationLandmarkY yCurPos)
TaxiSimulationAction __lastAction
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __isAtDestination()

bool gum::TaxiSimulator::__isAtDestination ( TaxiSimulationLandmark  passDest,
TaxiSimulationLandmarkX  xCurPos,
TaxiSimulationLandmarkY  yCurPos 
)
private

Definition at line 380 of file taxiSimulator.cpp.

References gum::CLUB, gum::CLUBX, gum::CLUBY, gum::HOME, gum::HOMEX, gum::HOMEY, gum::TAXI, gum::THEATER, gum::THEATERX, gum::THEATERY, gum::WORK, gum::WORKX, and gum::WORKY.

Referenced by __evalReward(), and endActions().

382  {
383  switch (passDest) {
384  case HOME: {
385  if (xCurPos == HOMEX && yCurPos == HOMEY) return true;
386  break;
387  }
388  case WORK: {
389  if (xCurPos == WORKX && yCurPos == WORKY) return true;
390  break;
391  }
392  case THEATER: {
393  if (xCurPos == THEATERX && yCurPos == THEATERY) return true;
394  break;
395  }
396  case CLUB: {
397  if (xCurPos == CLUBX && yCurPos == CLUBY) return true;
398  break;
399  }
400  case TAXI: return false;
401  }
402  return false;
403  }
+ Here is the caller graph for this function:

◆ __isAtMeetPoint()

bool gum::TaxiSimulator::__isAtMeetPoint ( TaxiSimulationLandmark  passpos,
TaxiSimulationLandmarkX  xCurPos,
TaxiSimulationLandmarkY  yCurPos 
)
private

Definition at line 405 of file taxiSimulator.cpp.

References gum::CLUB, gum::CLUBX, gum::CLUBY, gum::HOME, gum::HOMEX, gum::HOMEY, gum::TAXI, gum::THEATER, gum::THEATERX, gum::THEATERY, gum::WORK, gum::WORKX, and gum::WORKY.

Referenced by __evalReward(), and endActions().

407  {
408  switch (passPos) {
409  case HOME: {
410  if (xCurPos == HOMEX && yCurPos == HOMEY) return true;
411  break;
412  }
413  case WORK: {
414  if (xCurPos == WORKX && yCurPos == WORKY) return true;
415  break;
416  }
417  case THEATER: {
418  if (xCurPos == THEATERX && yCurPos == THEATERY) return true;
419  break;
420  }
421  case CLUB: {
422  if (xCurPos == CLUBX && yCurPos == CLUBY) return true;
423  break;
424  }
425  case TAXI: return false;
426  }
427  return false;
428  }
+ Here is the caller graph for this function:

◆ __performFillUp()

void gum::TaxiSimulator::__performFillUp ( )
private

Iteration over the variables of the simulated probleme.

Definition at line 323 of file taxiSimulator.cpp.

References __fuelLevel, __xPos, __yPos, gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), gum::STATIONX, gum::STATIONY, and gum::Instantiation::valFromPtr().

Referenced by endActions(), and perform().

323  {
324  TaxiSimulationLandmarkX xCurPos =
326  TaxiSimulationLandmarkY yCurPos =
328 
329  if (xCurPos == STATIONX && yCurPos == STATIONY)
331  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
TaxiSimulationLandmarkX
Definition: taxiSimulator.h:51
LabelizedVariable * __xPos
LabelizedVariable * __yPos
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
TaxiSimulationLandmarkY
Definition: taxiSimulator.h:58
Instantiation _currentState
Tha state in which the system currently is.
LabelizedVariable * __fuelLevel
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __performGoEast()

void gum::TaxiSimulator::__performGoEast ( )
private

Iteration over the variables of the simulated probleme.

Definition at line 204 of file taxiSimulator.cpp.

References __xPos, __yPos, gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), and gum::Instantiation::valFromPtr().

Referenced by endActions(), and perform().

204  {
205  Idx xCurPos = this->_currentState.valFromPtr(__xPos);
206  Idx yCurPos = this->_currentState.valFromPtr(__yPos);
207 
208  if (xCurPos == 4) return;
209  if (xCurPos == 0 || xCurPos == 2)
210  if (yCurPos == 0 || yCurPos == 1) return;
211  if (xCurPos == 1)
212  if (yCurPos == 3 || yCurPos == 4) return;
213 
214  _currentState.chgVal(__xPos, ++xCurPos);
215  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
LabelizedVariable * __xPos
LabelizedVariable * __yPos
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Instantiation _currentState
Tha state in which the system currently is.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __performGoNorth()

void gum::TaxiSimulator::__performGoNorth ( )
private

Iteration over the variables of the simulated probleme.

Definition at line 195 of file taxiSimulator.cpp.

References __yPos, gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), and gum::Instantiation::valFromPtr().

Referenced by endActions(), and perform().

195  {
196  Idx curPos = this->_currentState.valFromPtr(__yPos);
197  if (curPos < 4) _currentState.chgVal(__yPos, ++curPos);
198  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
LabelizedVariable * __yPos
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Instantiation _currentState
Tha state in which the system currently is.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __performGoSouth()

void gum::TaxiSimulator::__performGoSouth ( )
private

Iteration over the variables of the simulated probleme.

Definition at line 221 of file taxiSimulator.cpp.

References __yPos, gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), and gum::Instantiation::valFromPtr().

Referenced by endActions(), and perform().

221  {
222  Idx curPos = this->_currentState.valFromPtr(__yPos);
223  if (curPos > 0) _currentState.chgVal(__yPos, --curPos);
224  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
LabelizedVariable * __yPos
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Instantiation _currentState
Tha state in which the system currently is.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __performGoWest()

void gum::TaxiSimulator::__performGoWest ( )
private

Iteration over the variables of the simulated probleme.

Definition at line 230 of file taxiSimulator.cpp.

References __xPos, __yPos, gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), and gum::Instantiation::valFromPtr().

Referenced by endActions(), and perform().

230  {
231  Idx xCurPos = this->_currentState.valFromPtr(__xPos);
232  Idx yCurPos = this->_currentState.valFromPtr(__yPos);
233 
234  if (xCurPos == 0) return;
235  if (xCurPos == 1 || xCurPos == 3)
236  if (yCurPos == 0 || yCurPos == 1) return;
237  if (xCurPos == 2)
238  if (yCurPos == 3 || yCurPos == 4) return;
239 
240  _currentState.chgVal(__xPos, --xCurPos);
241  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
LabelizedVariable * __xPos
LabelizedVariable * __yPos
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Instantiation _currentState
Tha state in which the system currently is.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __performPickUp()

void gum::TaxiSimulator::__performPickUp ( )
private

Iteration over the variables of the simulated probleme.

Definition at line 247 of file taxiSimulator.cpp.

References __passengerPos, __xPos, __yPos, gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), gum::CLUB, gum::CLUBX, gum::CLUBY, gum::HOME, gum::HOMEX, gum::HOMEY, gum::TAXI, gum::THEATER, gum::THEATERX, gum::THEATERY, gum::Instantiation::valFromPtr(), gum::WORK, gum::WORKX, and gum::WORKY.

Referenced by endActions(), and perform().

247  {
248  TaxiSimulationLandmarkX xCurPos =
250  TaxiSimulationLandmarkY yCurPos =
252  TaxiSimulationLandmark passPos =
254  switch (passPos) {
255  case HOME: {
256  if (xCurPos == HOMEX && yCurPos == HOMEY)
258  return;
259  }
260  case WORK: {
261  if (xCurPos == WORKX && yCurPos == WORKY)
263  return;
264  }
265  case THEATER: {
266  if (xCurPos == THEATERX && yCurPos == THEATERY)
268  return;
269  }
270  case CLUB: {
271  if (xCurPos == CLUBX && yCurPos == CLUBY)
273  return;
274  }
275  case TAXI: return;
276  }
277  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
TaxiSimulationLandmarkX
Definition: taxiSimulator.h:51
LabelizedVariable * __xPos
LabelizedVariable * __yPos
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
TaxiSimulationLandmark
Definition: taxiSimulator.h:44
TaxiSimulationLandmarkY
Definition: taxiSimulator.h:58
Instantiation _currentState
Tha state in which the system currently is.
LabelizedVariable * __passengerPos
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __performPutDown()

void gum::TaxiSimulator::__performPutDown ( )
private

Iteration over the variables of the simulated probleme.

Definition at line 283 of file taxiSimulator.cpp.

References __passengerDest, __passengerPos, __xPos, __yPos, gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), gum::CLUB, gum::CLUBX, gum::CLUBY, gum::HOME, gum::HOMEX, gum::HOMEY, gum::TAXI, gum::THEATER, gum::THEATERX, gum::THEATERY, gum::Instantiation::valFromPtr(), gum::WORK, gum::WORKX, and gum::WORKY.

Referenced by endActions(), and perform().

283  {
284  TaxiSimulationLandmarkX xCurPos =
286  TaxiSimulationLandmarkY yCurPos =
288  TaxiSimulationLandmark passPos =
290  TaxiSimulationLandmark passDest =
292  if (passPos == TAXI) {
293  switch (passDest) {
294  case HOME: {
295  if (xCurPos == HOMEX && yCurPos == HOMEY)
297  return;
298  }
299  case WORK: {
300  if (xCurPos == WORKX && yCurPos == WORKY)
302  return;
303  }
304  case THEATER: {
305  if (xCurPos == THEATERX && yCurPos == THEATERY)
307  return;
308  }
309  case CLUB: {
310  if (xCurPos == CLUBX && yCurPos == CLUBY)
312  return;
313  }
314  case TAXI: return;
315  }
316  }
317  }
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
LabelizedVariable * __passengerDest
TaxiSimulationLandmarkX
Definition: taxiSimulator.h:51
LabelizedVariable * __xPos
LabelizedVariable * __yPos
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
TaxiSimulationLandmark
Definition: taxiSimulator.h:44
TaxiSimulationLandmarkY
Definition: taxiSimulator.h:58
Instantiation _currentState
Tha state in which the system currently is.
LabelizedVariable * __passengerPos
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _randomState()

Instantiation gum::TaxiSimulator::_randomState ( )
protectedvirtual

Choses a random state as the first test for a run.

Reimplemented from gum::AbstractSimulator.

Definition at line 128 of file taxiSimulator.cpp.

References gum::AbstractSimulator::_randomState().

128  {
129  Instantiation randy = AbstractSimulator::_randomState();
130  // Idx curFuelLevel = randy.valFromPtr(__fuelLevel);
131  // while(curFuelLevel > 12 || curFuelLevel < 5)
132  // curFuelLevel = (Idx)(((double)std::rand( ) / (double)RAND_MAX) *
133  // 7.0) + 5;
134  // randy.chgVal(__fuelLevel, curFuelLevel);
135 
136  // TaxiSimulationLandmark passPos = (TaxiSimulationLandmark)
137  // randy.valFromPtr(__passengerPos);
138  // TaxiSimulationLandmark passDest = (TaxiSimulationLandmark)
139  // randy.valFromPtr(__passengerDest);
140  // while( passPos == passDest || passPos == TAXI )
141  // passPos = (TaxiSimulationLandmark) (((double)std::rand( ) /
142  // (double)RAND_MAX) * 3.0);
143  // randy.chgVal(__passengerPos, passPos);
144 
145  return randy;
146  }
virtual Instantiation _randomState()
Choses a random state as the first test for a run.
+ Here is the call graph for this function:

◆ actionName()

const std::string& gum::TaxiSimulator::actionName ( Idx  actionId)
inlinevirtual

Iteration over the variables of the simulated probleme.

Implements gum::AbstractSimulator.

Definition at line 140 of file taxiSimulator.h.

References __actionMap.

140 { return *__actionMap[actionId]; }
HashTable< Idx, std::string *> __actionMap

◆ beginActions()

SequenceIteratorSafe< Idx > gum::TaxiSimulator::beginActions ( )
inlinevirtual

Iteration over the variables of the simulated probleme.

Implements gum::AbstractSimulator.

Definition at line 143 of file taxiSimulator.h.

References __taxiActions, and gum::SequenceImplementation< Key, Alloc, Gen >::beginSafe().

143  {
144  return __taxiActions.beginSafe();
145  }
iterator_safe beginSafe() const
Returns a safe begin iterator.
Definition: sequence_tpl.h:627
Sequence< Idx > __taxiActions
Actions.
+ Here is the call graph for this function:

◆ beginVariables()

SequenceIteratorSafe< const DiscreteVariable* > gum::TaxiSimulator::beginVariables ( )
inlinevirtual

Iteration over the variables of the simulated probleme.

Implements gum::AbstractSimulator.

Definition at line 126 of file taxiSimulator.h.

References __taxiVars.

Referenced by TaxiSimulator().

126  {
127  return __taxiVars.beginSafe();
128  }
Sequence< const DiscreteVariable *> __taxiVars
Variables data structures.
+ Here is the caller graph for this function:

◆ currentState()

INLINE const Instantiation& gum::AbstractSimulator::currentState ( )
inlineinherited

Sets the intial statefrom which we begun the simulation.

Definition at line 92 of file abstractSimulator.h.

References gum::AbstractSimulator::_currentState, gum::AbstractSimulator::actionName(), gum::AbstractSimulator::beginActions(), gum::AbstractSimulator::beginVariables(), gum::AbstractSimulator::endActions(), gum::AbstractSimulator::endVariables(), gum::AbstractSimulator::perform(), gum::AbstractSimulator::primeVar(), and gum::AbstractSimulator::reward().

92 { return _currentState; }
Instantiation _currentState
Tha state in which the system currently is.
+ Here is the call graph for this function:

◆ endActions()

SequenceIteratorSafe< Idx > gum::TaxiSimulator::endActions ( )
inlinevirtual

Iteration over the variables of the simulated probleme.

Implements gum::AbstractSimulator.

Definition at line 146 of file taxiSimulator.h.

References __evalReward(), __isAtDestination(), __isAtMeetPoint(), __performFillUp(), __performGoEast(), __performGoNorth(), __performGoSouth(), __performGoWest(), __performPickUp(), __performPutDown(), __taxiActions, gum::SequenceImplementation< Key, Alloc, Gen >::endSafe(), perform(), and reward().

146 { return __taxiActions.endSafe(); }
const iterator_safe & endSafe() const noexcept
Returns the safe end iterator.
Definition: sequence_tpl.h:634
Sequence< Idx > __taxiActions
Actions.
+ Here is the call graph for this function:

◆ endVariables()

SequenceIteratorSafe< const DiscreteVariable* > gum::TaxiSimulator::endVariables ( )
inlinevirtual

Iteration over the variables of the simulated probleme.

Implements gum::AbstractSimulator.

Definition at line 129 of file taxiSimulator.h.

References __taxiVars.

Referenced by TaxiSimulator().

129  {
130  return __taxiVars.endSafe();
131  }
Sequence< const DiscreteVariable *> __taxiVars
Variables data structures.
+ Here is the caller graph for this function:

◆ hasReachEnd()

bool gum::TaxiSimulator::hasReachEnd ( )
virtual

Choses a random state as the first test for a run.

Reimplemented from gum::AbstractSimulator.

Definition at line 152 of file taxiSimulator.cpp.

152  {
153  // if( _currentState.valFromPtr(__passengerPos) ==
154  // _currentState.valFromPtr(__passengerDest) )
155  // return true;
156 
157  // if( _currentState.valFromPtr(__fuelLevel) == 0 )
158  // return true;
159 
160  return false;
161  }

◆ perform()

void gum::TaxiSimulator::perform ( Idx  actionId)
virtual

Iteration over the variables of the simulated probleme.

Implements gum::AbstractSimulator.

Definition at line 172 of file taxiSimulator.cpp.

References __evalReward(), __fuelLevel, __lastAction, __performFillUp(), __performGoEast(), __performGoNorth(), __performGoSouth(), __performGoWest(), __performPickUp(), __performPutDown(), gum::AbstractSimulator::_currentState, gum::Instantiation::chgVal(), gum::FillUp, gum::GoEast, gum::GoNorth, gum::GoSouth, gum::GoWest, gum::PickUp, gum::PutDown, and gum::Instantiation::valFromPtr().

Referenced by endActions().

172  {
174 
175  __evalReward();
176 
177  Idx curFuelLevel = _currentState.valFromPtr(__fuelLevel);
178  if (curFuelLevel > 0) _currentState.chgVal(__fuelLevel, --curFuelLevel);
179 
180  switch (actionId) {
181  case GoNorth: return __performGoNorth();
182  case GoEast: return __performGoEast();
183  case GoSouth: return __performGoSouth();
184  case GoWest: return __performGoWest();
185  case PickUp: return __performPickUp();
186  case PutDown: return __performPutDown();
187  case FillUp: return __performFillUp();
188  }
189  }
void __performFillUp()
Iteration over the variables of the simulated probleme.
void __performGoEast()
Iteration over the variables of the simulated probleme.
Idx valFromPtr(const DiscreteVariable *pvar) const
Returns the current value of a given variable.
void __performGoNorth()
Iteration over the variables of the simulated probleme.
TaxiSimulationAction
Definition: taxiSimulator.h:65
void __performGoWest()
Iteration over the variables of the simulated probleme.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Instantiation _currentState
Tha state in which the system currently is.
LabelizedVariable * __fuelLevel
void __performGoSouth()
Iteration over the variables of the simulated probleme.
void __performPutDown()
Iteration over the variables of the simulated probleme.
void __performPickUp()
Iteration over the variables of the simulated probleme.
TaxiSimulationAction __lastAction
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ primeVar()

const DiscreteVariable* gum::TaxiSimulator::primeVar ( const DiscreteVariable mainVar)
inlinevirtual

Iteration over the variables of the simulated probleme.

Implements gum::AbstractSimulator.

Definition at line 121 of file taxiSimulator.h.

References __primeMap.

Referenced by TaxiSimulator().

121  {
122  return __primeMap.second(mainVar);
123  }
Bijection< const DiscreteVariable *, const DiscreteVariable *> __primeMap
+ Here is the caller graph for this function:

◆ reward()

double gum::TaxiSimulator::reward ( )
virtual

Sets the intial statefrom which we begun the simulation.

Implements gum::AbstractSimulator.

Definition at line 167 of file taxiSimulator.cpp.

References __reward.

Referenced by endActions().

167 { return __reward; }
double __reward
Reward.
+ Here is the caller graph for this function:

◆ setEndState()

INLINE void gum::AbstractSimulator::setEndState ( const Instantiation endState)
inlineinherited

Sets the final states upon which a run is over.

Definition at line 84 of file abstractSimulator.h.

References gum::AbstractSimulator::_endState, and gum::AbstractSimulator::hasReachEnd().

84  {
85  _endState = endState;
86  }
+ Here is the call graph for this function:

◆ setInitialState()

INLINE void gum::AbstractSimulator::setInitialState ( const Instantiation initialState)
inlineinherited

Sets the intial statefrom which we begun the simulation.

Definition at line 73 of file abstractSimulator.h.

References gum::AbstractSimulator::_currentState, gum::AbstractSimulator::_randomState(), and gum::AbstractSimulator::setInitialStateRandomly().

73  {
74  _currentState = initialState;
75  }
Instantiation _currentState
Tha state in which the system currently is.
+ Here is the call graph for this function:

◆ setInitialStateRandomly()

void gum::AbstractSimulator::setInitialStateRandomly ( )
inherited

Sets the intial statefrom which we begun the simulation.

Definition at line 58 of file abstractSimulator.cpp.

References gum::AbstractSimulator::_currentState, gum::AbstractSimulator::_randomState(), and gum::AbstractSimulator::hasReachEnd().

Referenced by gum::AbstractSimulator::setInitialState().

58  {
59  bool hre = true;
60  while (hre) {
62  hre = hasReachEnd();
63  }
64  }
virtual bool hasReachEnd()
Tests if end state has been reached.
Instantiation _currentState
Tha state in which the system currently is.
virtual Instantiation _randomState()
Choses a random state as the first test for a run.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ __actionMap

HashTable< Idx, std::string* > gum::TaxiSimulator::__actionMap
private

Definition at line 191 of file taxiSimulator.h.

Referenced by actionName(), and TaxiSimulator().

◆ __fuelLevel

LabelizedVariable* gum::TaxiSimulator::__fuelLevel
private

Definition at line 187 of file taxiSimulator.h.

Referenced by __evalReward(), __performFillUp(), perform(), and TaxiSimulator().

◆ __lastAction

TaxiSimulationAction gum::TaxiSimulator::__lastAction
private

Definition at line 193 of file taxiSimulator.h.

Referenced by __evalReward(), and perform().

◆ __passengerDest

LabelizedVariable* gum::TaxiSimulator::__passengerDest
private

Definition at line 186 of file taxiSimulator.h.

Referenced by __evalReward(), __performPutDown(), and TaxiSimulator().

◆ __passengerPos

LabelizedVariable* gum::TaxiSimulator::__passengerPos
private

Definition at line 185 of file taxiSimulator.h.

Referenced by __evalReward(), __performPickUp(), __performPutDown(), and TaxiSimulator().

◆ __primeMap

Bijection< const DiscreteVariable*, const DiscreteVariable* > gum::TaxiSimulator::__primeMap
private

Definition at line 182 of file taxiSimulator.h.

Referenced by primeVar(), TaxiSimulator(), and ~TaxiSimulator().

◆ __reward

double gum::TaxiSimulator::__reward
private

Reward.

Definition at line 196 of file taxiSimulator.h.

Referenced by __evalReward(), and reward().

◆ __taxiActions

Sequence< Idx > gum::TaxiSimulator::__taxiActions
private

Actions.

Definition at line 190 of file taxiSimulator.h.

Referenced by beginActions(), endActions(), and TaxiSimulator().

◆ __taxiVars

Sequence< const DiscreteVariable* > gum::TaxiSimulator::__taxiVars
private

Variables data structures.

Definition at line 181 of file taxiSimulator.h.

Referenced by beginVariables(), endVariables(), and TaxiSimulator().

◆ __xPos

LabelizedVariable* gum::TaxiSimulator::__xPos
private

◆ __yPos

◆ _currentState

◆ _endState

Instantiation gum::AbstractSimulator::_endState
inherited

The documentation for this class was generated from the following files: