aGrUM  0.16.0
gum::AbstractSimulator Class Referenceabstract

<agrum/FMDP/simulation/abstractSimulator.h> More...

#include <abstractSimulator.h>

+ Inheritance diagram for gum::AbstractSimulator:
+ Collaboration diagram for gum::AbstractSimulator:

Public Attributes

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

Public Member Functions

Constructors, Destructors.
 AbstractSimulator ()
 Default constructor. More...
 
virtual ~AbstractSimulator ()
 Default destructor. More...
 
Variables
virtual const DiscreteVariableprimeVar (const DiscreteVariable *mainVar)=0
 Iteration over the variables of the simulated probleme. More...
 
virtual SequenceIteratorSafe< const DiscreteVariable *> beginVariables ()=0
 Iteration over the variables of the simulated probleme. More...
 
virtual SequenceIteratorSafe< const DiscreteVariable *> endVariables ()=0
 Iteration over the variables of the simulated probleme. More...
 
Actions
virtual const std::string & actionName (Idx)=0
 Iteration over the variables of the simulated probleme. More...
 
virtual SequenceIteratorSafe< IdxbeginActions ()=0
 Iteration over the variables of the simulated probleme. More...
 
virtual SequenceIteratorSafe< IdxendActions ()=0
 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...
 
virtual bool hasReachEnd ()
 Tests if end state has been reached. More...
 
INLINE const InstantiationcurrentState ()
 Sets the intial statefrom which we begun the simulation. More...
 
virtual double reward ()=0
 Sets the intial statefrom which we begun the simulation. More...
 
virtual void perform (Idx)=0
 Sets the intial statefrom which we begun the simulation. More...
 
virtual Instantiation _randomState ()
 Choses a random state as the first test for a run. More...
 

Detailed Description

<agrum/FMDP/simulation/abstractSimulator.h>

A class to simulate a reinforcement learning problem.

Definition at line 48 of file abstractSimulator.h.

Constructor & Destructor Documentation

◆ AbstractSimulator()

gum::AbstractSimulator::AbstractSimulator ( )

Default constructor.

Definition at line 46 of file abstractSimulator.cpp.

46 { GUM_CONSTRUCTOR(AbstractSimulator); }
AbstractSimulator()
Default constructor.

◆ ~AbstractSimulator()

gum::AbstractSimulator::~AbstractSimulator ( )
virtual

Default destructor.

Definition at line 51 of file abstractSimulator.cpp.

51 { GUM_DESTRUCTOR(AbstractSimulator); }
AbstractSimulator()
Default constructor.

Member Function Documentation

◆ _randomState()

Instantiation gum::AbstractSimulator::_randomState ( )
protectedvirtual

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

Reimplemented in gum::FactorySimulator, and gum::TaxiSimulator.

Definition at line 66 of file abstractSimulator.cpp.

References gum::Instantiation::add(), beginVariables(), gum::Instantiation::chgVal(), and endVariables().

Referenced by gum::TaxiSimulator::_randomState(), setInitialState(), and setInitialStateRandomly().

66  {
67  Instantiation retState;
68  for (auto varIter = this->beginVariables(); varIter != this->endVariables();
69  ++varIter) {
70  retState.add(**varIter);
71  retState.chgVal(*varIter,
72  (Idx)(((double)std::rand() / (double)RAND_MAX)
73  * (double)(*varIter)->domainSize()));
74  }
75  return retState;
76  }
virtual SequenceIteratorSafe< const DiscreteVariable *> beginVariables()=0
Iteration over the variables of the simulated probleme.
virtual SequenceIteratorSafe< const DiscreteVariable *> endVariables()=0
Iteration over the variables of the simulated probleme.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ actionName()

virtual const std::string& gum::AbstractSimulator::actionName ( Idx  )
pure virtual

Iteration over the variables of the simulated probleme.

Implemented in gum::FactorySimulator, gum::TaxiSimulator, and gum::FMDPSimulator.

Referenced by currentState().

+ Here is the caller graph for this function:

◆ beginActions()

virtual SequenceIteratorSafe< Idx > gum::AbstractSimulator::beginActions ( )
pure virtual

Iteration over the variables of the simulated probleme.

Implemented in gum::FactorySimulator, gum::TaxiSimulator, and gum::FMDPSimulator.

Referenced by currentState().

+ Here is the caller graph for this function:

◆ beginVariables()

virtual SequenceIteratorSafe< const DiscreteVariable* > gum::AbstractSimulator::beginVariables ( )
pure virtual

Iteration over the variables of the simulated probleme.

Implemented in gum::FactorySimulator, gum::TaxiSimulator, and gum::FMDPSimulator.

Referenced by _randomState(), and currentState().

+ Here is the caller graph for this function:

◆ currentState()

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

Sets the intial statefrom which we begun the simulation.

Definition at line 92 of file abstractSimulator.h.

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

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

◆ endActions()

virtual SequenceIteratorSafe< Idx > gum::AbstractSimulator::endActions ( )
pure virtual

Iteration over the variables of the simulated probleme.

Implemented in gum::FactorySimulator, gum::TaxiSimulator, and gum::FMDPSimulator.

Referenced by currentState().

+ Here is the caller graph for this function:

◆ endVariables()

virtual SequenceIteratorSafe< const DiscreteVariable* > gum::AbstractSimulator::endVariables ( )
pure virtual

Iteration over the variables of the simulated probleme.

Implemented in gum::FactorySimulator, gum::TaxiSimulator, and gum::FMDPSimulator.

Referenced by _randomState(), and currentState().

+ Here is the caller graph for this function:

◆ hasReachEnd()

bool gum::AbstractSimulator::hasReachEnd ( )
virtual

Tests if end state has been reached.

Reimplemented in gum::FactorySimulator, and gum::TaxiSimulator.

Definition at line 79 of file abstractSimulator.cpp.

References _currentState, _endState, gum::Instantiation::empty(), gum::Instantiation::val(), and gum::Instantiation::variablesSequence().

Referenced by setEndState(), and setInitialStateRandomly().

79  {
80  if (_endState.empty()) return false;
81 
82  for (auto varIter = _endState.variablesSequence().beginSafe();
83  varIter != _endState.variablesSequence().endSafe();
84  ++varIter)
85  if (_endState.val(**varIter) != _currentState.val(**varIter)) return false;
86  return true;
87  }
const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
Idx val(Idx i) const
Returns the current value of the variable at position i.
Instantiation _currentState
Tha state in which the system currently is.
virtual bool empty() const final
Returns true if the instantiation is empty.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ perform()

virtual void gum::AbstractSimulator::perform ( Idx  )
pure virtual

Sets the intial statefrom which we begun the simulation.

Implemented in gum::TaxiSimulator, gum::FactorySimulator, and gum::FMDPSimulator.

Referenced by currentState().

+ Here is the caller graph for this function:

◆ primeVar()

virtual const DiscreteVariable* gum::AbstractSimulator::primeVar ( const DiscreteVariable mainVar)
pure virtual

Iteration over the variables of the simulated probleme.

Implemented in gum::FactorySimulator, gum::TaxiSimulator, and gum::FMDPSimulator.

Referenced by currentState().

+ Here is the caller graph for this function:

◆ reward()

virtual double gum::AbstractSimulator::reward ( )
pure virtual

Sets the intial statefrom which we begun the simulation.

Implemented in gum::TaxiSimulator, gum::FactorySimulator, and gum::FMDPSimulator.

Referenced by currentState().

+ Here is the caller graph for this function:

◆ setEndState()

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

Sets the final states upon which a run is over.

Definition at line 84 of file abstractSimulator.h.

References _endState, and hasReachEnd().

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

◆ setInitialState()

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

Sets the intial statefrom which we begun the simulation.

Definition at line 73 of file abstractSimulator.h.

References _currentState, _randomState(), and 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 ( )

Sets the intial statefrom which we begun the simulation.

Definition at line 58 of file abstractSimulator.cpp.

References _currentState, _randomState(), and hasReachEnd().

Referenced by 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

◆ _currentState

◆ _endState

Instantiation gum::AbstractSimulator::_endState

Definition at line 130 of file abstractSimulator.h.

Referenced by hasReachEnd(), and setEndState().


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