aGrUM  0.13.2
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 45 of file abstractSimulator.h.

Constructor & Destructor Documentation

gum::AbstractSimulator::AbstractSimulator ( )

Default constructor.

Definition at line 43 of file abstractSimulator.cpp.

43 {GUM_CONSTRUCTOR(AbstractSimulator)}
AbstractSimulator()
Default constructor.
gum::AbstractSimulator::~AbstractSimulator ( )
virtual

Default destructor.

Definition at line 48 of file abstractSimulator.cpp.

48  {
49  GUM_DESTRUCTOR(AbstractSimulator)
50  }
AbstractSimulator()
Default constructor.

Member Function Documentation

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 65 of file abstractSimulator.cpp.

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

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

65  {
66  Instantiation retState;
67  for (auto varIter = this->beginVariables(); varIter != this->endVariables();
68  ++varIter) {
69  retState.add(**varIter);
70  retState.chgVal(*varIter,
71  (Idx)(((double)std::rand() / (double)RAND_MAX)
72  * (double)(*varIter)->domainSize()));
73  }
74  return retState;
75  }
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.
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

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:

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:

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

Sets the intial statefrom which we begun the simulation.

Definition at line 89 of file abstractSimulator.h.

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

89 { return _currentState; }
Instantiation _currentState
Tha state in which the system currently is.

+ Here is the call graph for this function:

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:

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:

bool gum::AbstractSimulator::hasReachEnd ( )
virtual

Tests if end state has been reached.

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

Definition at line 78 of file abstractSimulator.cpp.

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

Referenced by setEndState(), and setInitialStateRandomly().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

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:

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:

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

Sets the final states upon which a run is over.

Definition at line 81 of file abstractSimulator.h.

References _endState, and hasReachEnd().

81  {
82  _endState = endState;
83  }

+ Here is the call graph for this function:

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

Sets the intial statefrom which we begun the simulation.

Definition at line 70 of file abstractSimulator.h.

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

70  {
71  _currentState = initialState;
72  }
Instantiation _currentState
Tha state in which the system currently is.

+ Here is the call graph for this function:

void gum::AbstractSimulator::setInitialStateRandomly ( )

Sets the intial statefrom which we begun the simulation.

Definition at line 57 of file abstractSimulator.cpp.

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

Referenced by setInitialState().

57  {
58  bool hre = true;
59  while (hre) {
61  hre = hasReachEnd();
62  }
63  }
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

Instantiation gum::AbstractSimulator::_endState

Definition at line 127 of file abstractSimulator.h.

Referenced by hasReachEnd(), and setEndState().


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