aGrUM  0.16.0
abstractSimulator.cpp
Go to the documentation of this file.
1 
30 // =====================================================================
31 #include <cstdlib>
32 #include <random>
33 //======================================================================
35 //======================================================================
36 
37 namespace gum {
38 
39  // ===========================================================================
40  // Constructors, Destructors.
41  // ===========================================================================
42 
43  /*
44  * Default constructor.
45  */
47 
48  /*
49  * Default destructor.
50  */
52 
53 
54  // ===========================================================================
55  //
56  // ===========================================================================
57 
59  bool hre = true;
60  while (hre) {
62  hre = hasReachEnd();
63  }
64  }
65 
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  }
77 
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  }
88 
89 
90 } // End of namespace gum
virtual bool hasReachEnd()
Tests if end state has been reached.
<agrum/FMDP/simulation/abstractSimulator.h>
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
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 ~AbstractSimulator()
Default destructor.
void setInitialStateRandomly()
Sets the intial statefrom which we begun the simulation.
virtual SequenceIteratorSafe< const DiscreteVariable *> beginVariables()=0
Iteration over the variables of the simulated probleme.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual bool empty() const final
Returns true if the instantiation is empty.
virtual Instantiation _randomState()
Choses a random state as the first test for a run.
virtual SequenceIteratorSafe< const DiscreteVariable *> endVariables()=0
Iteration over the variables of the simulated probleme.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
Size Idx
Type for indexes.
Definition: types.h:53
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
AbstractSimulator()
Default constructor.