source: src/RandomNumbers/RandomNumberEngine_Encapsulation.hpp@ 4464ef

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4464ef was 0932c2, checked in by Frederik Heber <heber@…>, 11 years ago

FIX: RandomNumberEngine_Encapsulation::clone() did not set the seed obtained from its prototype.

  • this caused all engines to always start with default seed of 1, irrespective of the set parameter. The engine is always cloned from prototypes in the factory that can be manipulated to change their parameters. Hence, clone needs to set the seed (the engine's only parameter).
  • EmpiricalPotentials now use RandomNumberGenerator to obtain random starting values.
  • TESTFIX: fit-potential regression tests now use fixed seed in order to always take the same amount of time (some test runs in debug mode take very long because of ill-chosen random values).
  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * RandomNumberEngine_Encapsulation.hpp
3 *
4 * Created on: Jan 01, 2011
5 * Author: heber
6 */
7
8#ifndef RANDOMNUMBERENGINE_ENCAPSULATION_HPP_
9#define RANDOMNUMBERENGINE_ENCAPSULATION_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <typeinfo>
17
18#include <boost/nondet_random.hpp>
19#include <boost/random.hpp>
20#include <boost/random/additive_combine.hpp>
21#include <boost/random/discard_block.hpp>
22#include <boost/random/inversive_congruential.hpp>
23#include <boost/random/lagged_fibonacci.hpp>
24#include <boost/random/linear_congruential.hpp>
25#include <boost/random/linear_feedback_shift.hpp>
26#include <boost/random/mersenne_twister.hpp>
27#include <boost/random/random_number_generator.hpp>
28#include <boost/random/ranlux.hpp>
29#include <boost/random/shuffle_output.hpp>
30#include <boost/random/subtract_with_carry.hpp>
31#include <boost/random/xor_combine.hpp>
32
33#include "CodePatterns/ManipulableClone.hpp"
34#include "RandomNumberEngine.hpp"
35
36class RandomNumberEngineFactory;
37
38#include "RandomNumberEngine_Parameters.hpp"
39
40/** Template class that encapsulates the random number engines from
41 * random::boost.
42 *
43 *
44 * We need one template parameters:
45 * -# the engine - generates uniform random numbers
46 */
47template <class engine>
48class RandomNumberEngine_Encapsulation :
49 public RandomNumberEngine,
50 public ManipulableClone<RandomNumberEngine, RandomNumberEngine_Parameters>
51{
52 /**
53 * Factory is friend such that it can access private cstor when filling its
54 * table
55 */
56 friend class RandomNumberEngineFactory;
57
58public:
59 /** Getter for the whole set of possible parameters.
60 *
61 * @return filled instance of RandomNumberEngine_Parameters
62 */
63 RandomNumberEngine_Parameters* getParameterSet() const
64 {
65 RandomNumberEngine_Parameters *params = new RandomNumberEngine_Parameters();
66 params->getParameters(this);
67 return params;
68 }
69
70 /** Set the engine's seed.
71 *
72 * @param _seed seed to set to
73 */
74 void seed(unsigned int _seed) {
75 value_seed = _seed;
76 engine_type.seed(value_seed);
77 }
78
79 /** Getter for the engine's seed.
80 *
81 * @return seed
82 */
83 unsigned int getseed() const {
84 return value_seed;
85 }
86
87 /** Getter for smallest value the engine produces.
88 *
89 * @return smallest value
90 */
91 double min() const {
92 return engine_type.min();
93 }
94
95 /** Getter for largest value the engine produces.
96 *
97 * @return largest value
98 */
99 double max() const {
100 return engine_type.max();
101 }
102
103 /** Getter for the type name of the internal engine.
104 *
105 */
106 std::string name() {
107 return typeid(engine_type).name();
108 }
109
110 /** Getter for the engine instance.
111 *
112 * @return reference to instance
113 */
114 engine& getEngine() {
115 return engine_type;
116 }
117
118 /** Clones the current instance.
119 *
120 * Implementation of Clone pattern.
121 *
122 * @return interface reference to cloned instance
123 */
124 RandomNumberEngine* clone() const {
125 RandomNumberEngine_Parameters *params = getParameterSet();
126 RandomNumberEngine* MyClone = new RandomNumberEngine_Encapsulation<engine>(*params);
127 delete params;
128 MyClone->seed(getseed());
129 return MyClone;
130 }
131
132 /** Clones and manipulates the current instance.
133 *
134 * Implementation of ManipulableClone pattern.
135 *
136 * @param _params set of parameters to instantiate manipulated clone with
137 * @return interface reference to cloned&manipulated instance
138 */
139 ManipulableClone<RandomNumberEngine, RandomNumberEngine_Parameters>*
140 manipulatedclone(const RandomNumberEngine_Parameters &_params) const {
141 RandomNumberEngine_Encapsulation<engine>* MyClone = NULL;
142 MyClone = new RandomNumberEngine_Encapsulation<engine>();
143 MyClone->value_seed = _params.seed;
144 MyClone->seed(_params.seed);
145 return MyClone;
146 }
147
148protected:
149 /** Constructor that instantiates a specific random number generator and
150 * distribution.
151 * @param _engine_type instance of the desired engine
152 */
153 RandomNumberEngine_Encapsulation() :
154 value_seed(1)
155 {}
156
157 /** Constructor that instantiates a specific random number generator and
158 * distribution.
159 * @param _engine_type instance of the desired engine
160 */
161 RandomNumberEngine_Encapsulation(const RandomNumberEngine_Parameters &_params) :
162 value_seed(_params.seed)
163 {}
164
165 /** Destructor of the class.
166 *
167 */
168 virtual ~RandomNumberEngine_Encapsulation() {}
169private:
170 engine engine_type;
171 unsigned int value_seed;
172};
173
174#endif /* RANDOMNUMBERENGINE_ENCAPSULATION_HPP_ */
Note: See TracBrowser for help on using the repository browser.