aGrUM  0.20.3
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:
+ 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 47 of file abstractSimulator.h.

Constructor & Destructor Documentation

◆ AbstractSimulator()

gum::AbstractSimulator::AbstractSimulator ( )

Default constructor.

Definition at line 46 of file abstractSimulator.cpp.

References gum::Set< Key, Alloc >::emplace().

46  {
47  GUM_CONSTRUCTOR(AbstractSimulator);
48  ;
49  }
AbstractSimulator()
Default constructor.
+ Here is the call graph for this function:

◆ ~AbstractSimulator()

gum::AbstractSimulator::~AbstractSimulator ( )
virtual

Default destructor.

Definition at line 54 of file abstractSimulator.cpp.

References gum::Set< Key, Alloc >::emplace().

54  {
55  GUM_DESTRUCTOR(AbstractSimulator);
56  ;
57  }
AbstractSimulator()
Default constructor.
+ 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::TaxiSimulator, and gum::FMDPSimulator.

◆ 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.

◆ 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.

◆ currentState()

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

Sets the intial statefrom which we begun the simulation.

Definition at line 87 of file abstractSimulator.h.

References reward().

87 { 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.

◆ 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.

◆ hasReachEnd()

bool gum::AbstractSimulator::hasReachEnd ( )
virtual

Tests if end state has been reached.

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

Definition at line 84 of file abstractSimulator.cpp.

References gum::Set< Key, Alloc >::emplace().

84  {
85  if (endState_.empty()) return false;
86 
87  for (auto varIter = endState_.variablesSequence().beginSafe();
88  varIter != endState_.variablesSequence().endSafe();
89  ++varIter)
90  if (endState_.val(**varIter) != currentState_.val(**varIter)) return false;
91  return true;
92  }
Instantiation currentState_
Tha state in which the system currently is.
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.
virtual bool empty() const final
Returns true if the instantiation is empty.
+ Here is the call 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.

◆ 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.

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

References gum::Set< Key, Alloc >::emplace().

72  {
73  Instantiation retState;
74  for (auto varIter = this->beginVariables(); varIter != this->endVariables(); ++varIter) {
75  retState.add(**varIter);
76  retState.chgVal(
77  *varIter,
78  (Idx)(((double)std::rand() / (double)RAND_MAX) * (double)(*varIter)->domainSize()));
79  }
80  return retState;
81  }
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:

◆ 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(), setEndState(), and setInitialState().

+ 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 81 of file abstractSimulator.h.

References reward().

81 { endState_ = endState; }
+ 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 72 of file abstractSimulator.h.

References reward().

72 { currentState_ = initialState; }
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 64 of file abstractSimulator.cpp.

References gum::Set< Key, Alloc >::emplace().

64  {
65  bool hre = true;
66  while (hre) {
68  hre = hasReachEnd();
69  }
70  }
virtual bool hasReachEnd()
Tests if end state has been reached.
virtual Instantiation randomState_()
Choses a random state as the first test for a run.
Instantiation currentState_
Tha state in which the system currently is.
+ Here is the call graph for this function:

Member Data Documentation

◆ currentState_

Instantiation gum::AbstractSimulator::currentState_

Tha state in which the system currently is.

Definition at line 125 of file abstractSimulator.h.

◆ endState_

Instantiation gum::AbstractSimulator::endState_

Definition at line 125 of file abstractSimulator.h.


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