aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
gum::AbstractSimulator Class Referenceabstract

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

#include <abstractSimulator.h>

Inheritance diagram for gum::AbstractSimulator:
[legend]
Collaboration diagram for gum::AbstractSimulator:
[legend]

Public Member Functions

Constructors, Destructors.
 AbstractSimulator ()
 Default constructor.
virtual ~AbstractSimulator ()
 Default destructor.
Variables
virtual const DiscreteVariable * primeVar (const DiscreteVariable *mainVar)=0
 Iteration over the variables of the simulated probleme.
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.
Actions
virtual const std::string & actionName (Idx)=0
 Iteration over the variables of the simulated probleme.
virtual SequenceIteratorSafe< Idx > beginActions ()=0
 Iteration over the variables of the simulated probleme.
virtual SequenceIteratorSafe< Idx > endActions ()=0
 Iteration over the variables of the simulated probleme.

Public Attributes

Instantiation currentState_
 Tha state in which the system currently is.
Instantiation endState_
void setInitialState (const Instantiation &initialState)
 Sets the intial statefrom which we begun the simulation.
void setInitialStateRandomly ()
 Sets the intial statefrom which we begun the simulation.
void setEndState (const Instantiation &endState)
 Sets the final states upon which a run is over.
virtual bool hasReachEnd ()
 Tests if end state has been reached.
const Instantiation & currentState ()
 Sets the intial statefrom which we begun the simulation.
virtual double reward ()=0
 Sets the intial statefrom which we begun the simulation.
virtual void perform (Idx)=0
 Sets the intial statefrom which we begun the simulation.
virtual Instantiation randomState_ ()
 Choses a random state as the first test for a run.

Detailed Description

<agrum/FMDP/simulation/abstractSimulator.h>

A class to simulate a reinforcement learning problem.

Definition at line 67 of file abstractSimulator.h.

Constructor & Destructor Documentation

◆ AbstractSimulator()

gum::AbstractSimulator::AbstractSimulator ( )

Default constructor.

Definition at line 69 of file abstractSimulator.cpp.

69 {
70 GUM_CONSTRUCTOR(AbstractSimulator);
71 ;
72 }
AbstractSimulator()
Default constructor.

References AbstractSimulator().

Referenced by AbstractSimulator(), gum::FMDPSimulator::FMDPSimulator(), gum::FMDPSimulator::FMDPSimulator(), gum::TaxiSimulator::TaxiSimulator(), and ~AbstractSimulator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~AbstractSimulator()

gum::AbstractSimulator::~AbstractSimulator ( )
virtual

Default destructor.

Definition at line 77 of file abstractSimulator.cpp.

77 {
78 GUM_DESTRUCTOR(AbstractSimulator);
79 ;
80 }

References AbstractSimulator().

Here is the call graph for this function:

Member Function Documentation

◆ actionName()

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

Iteration over the variables of the simulated probleme.

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

◆ beginActions()

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

Iteration over the variables of the simulated probleme.

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

◆ beginVariables()

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

Iteration over the variables of the simulated probleme.

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

Referenced by randomState_().

Here is the caller graph for this function:

◆ currentState()

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

Sets the intial statefrom which we begun the simulation.

Definition at line 56 of file abstractSimulator_inl.h.

56{ return currentState_; }
Instantiation currentState_
Tha state in which the system currently is.

References currentState_.

◆ endActions()

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

Iteration over the variables of the simulated probleme.

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

◆ endVariables()

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

Iteration over the variables of the simulated probleme.

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

Referenced by randomState_().

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

104 {
105 if (endState_.empty()) return false;
106
107 for (auto varIter = endState_.variablesSequence().beginSafe();
108 varIter != endState_.variablesSequence().endSafe();
109 ++varIter)
110 if (endState_.val(**varIter) != currentState_.val(**varIter)) return false;
111 return true;
112 }
const Sequence< const DiscreteVariable * > & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
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.

References currentState_, gum::Instantiation::empty(), endState_, gum::Instantiation::val(), and gum::Instantiation::variablesSequence().

Referenced by setInitialStateRandomly().

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::FactorySimulator, gum::FMDPSimulator, and gum::TaxiSimulator.

◆ 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::FMDPSimulator, and gum::TaxiSimulator.

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

94 {
95 Instantiation retState;
96 for (auto varIter = this->beginVariables(); varIter != this->endVariables(); ++varIter) {
97 retState.add(**varIter);
98 retState.chgVal(**varIter, randomValue((*varIter)->domainSize()));
99 }
100 return retState;
101 }
virtual SequenceIteratorSafe< const DiscreteVariable * > endVariables()=0
Iteration over the variables of the simulated probleme.
virtual SequenceIteratorSafe< const DiscreteVariable * > beginVariables()=0
Iteration over the variables of the simulated probleme.
GUM_SHARED_PUBLIC Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.

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

Referenced by gum::TaxiSimulator::randomState_(), and setInitialStateRandomly().

Here is the call graph for this function:
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::FactorySimulator, gum::FMDPSimulator, and gum::TaxiSimulator.

◆ setEndState()

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

Sets the final states upon which a run is over.

Definition at line 52 of file abstractSimulator_inl.h.

52 {
53 endState_ = endState;
54 }

References endState_.

◆ setInitialState()

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

Sets the intial statefrom which we begun the simulation.

Definition at line 48 of file abstractSimulator_inl.h.

48 {
49 currentState_ = initialState;
50 }

References currentState_.

◆ setInitialStateRandomly()

void gum::AbstractSimulator::setInitialStateRandomly ( )

Sets the intial statefrom which we begun the simulation.

Definition at line 86 of file abstractSimulator.cpp.

86 {
87 bool hre = true;
88 while (hre) {
90 hre = hasReachEnd();
91 }
92 }
virtual Instantiation randomState_()
Choses a random state as the first test for a run.
virtual bool hasReachEnd()
Tests if end state has been reached.

References currentState_, hasReachEnd(), and randomState_().

Here is the call graph for this function:

Member Data Documentation

◆ currentState_

◆ endState_

Instantiation gum::AbstractSimulator::endState_

Definition at line 146 of file abstractSimulator.h.

Referenced by hasReachEnd(), and setEndState().


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