aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
fmdpSimulator.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Sources of
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  *
29  */
30 // =====================================================================
31 #include <cstdlib>
32 #include <random>
33 //======================================================================
34 #include <agrum/FMDP/io/dat/fmdpDatReader.h>
35 #include <agrum/FMDP/simulation/fmdpSimulator.h>
36 //======================================================================
37 
38 namespace gum {
39 
40  // ===========================================================================
41  // Constructors, Destructors.
42  // ===========================================================================
43 
44  /*
45  * Default constructor.
46  */
47  FMDPSimulator::FMDPSimulator(const FMDP< double >* fmdp) :
48  AbstractSimulator(), _fmdp_(const_cast< FMDP< double >* >(fmdp)), _loaded_(false) {
50  }
51 
54 
55  _fmdp_ = new FMDP< double >(true);
57  reader.trace(false);
58  reader.proceed();
59  }
60 
61  /*
62  * Default destructor.
63  */
66  if (_loaded_) delete _fmdp_;
67  }
68 
69 
70  // ===========================================================================
71  //
72  // ===========================================================================
73 
76  for (auto varIter = this->beginVariables(); varIter != this->endVariables(); ++varIter) {
77  newState.add(**varIter);
79  transit.add(*(this->primeVar(*varIter)));
80 
81  double proba = (double)std::rand() / (double)RAND_MAX;
82  double cdd = 0.0;
85  if (proba <= cdd) {
87  break;
88  }
89  }
90  }
92  }
93 
94 
95 } // End of namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643