- Timestamp:
- Feb 3, 2011, 9:51:19 AM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 1d5a871
- Parents:
- 3f9eba
- git-author:
- Frederik Heber <heber@…> (01/03/11 14:01:22)
- git-committer:
- Frederik Heber <heber@…> (02/03/11 09:51:19)
- Location:
- src
- Files:
-
- 18 added
- 1 deleted
- 13 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/RandomNumbersAction/SetRandomNumbersDistributionAction.cpp
r3f9eba rc9bc2b7 45 45 CommandSetRandomNumbersDistributionState *state = 46 46 new CommandSetRandomNumbersDistributionState( 47 RandomNumberGeneratorFactory::getInstance().getDistribution (),47 RandomNumberGeneratorFactory::getInstance().getDistributionName(), 48 48 params); 49 49 RandomNumberGeneratorFactory::getInstance().setDistribution(params.distribution_type); 50 50 51 51 DoLog(0) && (Log() << Verbose(0) << "Distribution of random number generator is now: " 52 << RandomNumberGeneratorFactory::getInstance().getDistribution () << std::endl);52 << RandomNumberGeneratorFactory::getInstance().getDistributionName() << std::endl); 53 53 54 54 return Action::state_ptr(state); … … 60 60 CommandSetRandomNumbersDistributionState *newstate = 61 61 new CommandSetRandomNumbersDistributionState( 62 RandomNumberGeneratorFactory::getInstance().getDistribution (),62 RandomNumberGeneratorFactory::getInstance().getDistributionName(), 63 63 state->params); 64 64 RandomNumberGeneratorFactory::getInstance().setDistribution(state->old_distribution_type); 65 65 66 66 DoLog(0) && (Log() << Verbose(0) << "Distribution of random number generator is undone to: " 67 << RandomNumberGeneratorFactory::getInstance().getDistribution () << std::endl);67 << RandomNumberGeneratorFactory::getInstance().getDistributionName() << std::endl); 68 68 69 69 return Action::state_ptr(newstate); -
src/Actions/RandomNumbersAction/SetRandomNumbersEngineAction.cpp
r3f9eba rc9bc2b7 45 45 CommandSetRandomNumbersEngineState *state = 46 46 new CommandSetRandomNumbersEngineState( 47 RandomNumberGeneratorFactory::getInstance().getEngine (),47 RandomNumberGeneratorFactory::getInstance().getEngineName(), 48 48 params); 49 49 RandomNumberGeneratorFactory::getInstance().setEngine(params.engine_type); 50 50 51 51 DoLog(0) && (Log() << Verbose(0) << "Engine of random number generator is now: " 52 << RandomNumberGeneratorFactory::getInstance().getEngine () << std::endl);52 << RandomNumberGeneratorFactory::getInstance().getEngineName() << std::endl); 53 53 54 54 return Action::state_ptr(state); … … 60 60 CommandSetRandomNumbersEngineState *newstate = 61 61 new CommandSetRandomNumbersEngineState( 62 RandomNumberGeneratorFactory::getInstance().getEngine (),62 RandomNumberGeneratorFactory::getInstance().getEngineName(), 63 63 state->params); 64 64 RandomNumberGeneratorFactory::getInstance().setEngine(state->old_engine_type); 65 65 66 66 DoLog(0) && (Log() << Verbose(0) << "Engine of random number generator is undone to: " 67 << RandomNumberGeneratorFactory::getInstance().getEngine () << std::endl);67 << RandomNumberGeneratorFactory::getInstance().getEngineName() << std::endl); 68 68 69 69 return Action::state_ptr(newstate); -
src/Makefile.am
r3f9eba rc9bc2b7 123 123 124 124 RANDOMSOURCE = \ 125 RandomNumbers/RandomNumberDistributionFactory.cpp \ 126 RandomNumbers/RandomNumberEngineFactory.cpp \ 125 127 RandomNumbers/RandomNumberGeneratorFactory.cpp 126 128 127 129 RANDOMHEADER = \ 130 RandomNumbers/RandomNumberDistribution.hpp \ 131 RandomNumbers/RandomNumberDistribution_Creator.hpp \ 132 RandomNumbers/RandomNumberDistribution_Encapsulation.hpp \ 133 RandomNumbers/RandomNumberDistributionFactory.hpp \ 134 RandomNumbers/RandomNumberEngine.hpp \ 135 RandomNumbers/RandomNumberEngine_Creator.hpp \ 136 RandomNumbers/RandomNumberEngine_Encapsulation.hpp \ 137 RandomNumbers/RandomNumberEngineFactory.hpp \ 128 138 RandomNumbers/RandomNumberGenerator.hpp \ 139 RandomNumbers/RandomNumberGenerator_Creator.hpp \ 140 RandomNumbers/RandomNumberGenerator_Encapsulation.hpp \ 141 RandomNumbers/RandomNumberGeneratorFactory.hpp \ 129 142 RandomNumbers/TemplatePowerSetGenerator.hpp \ 130 RandomNumbers/RandomNumberGenerator_Encapsulation.hpp \ 131 RandomNumbers/RandomNumberGeneratorFactory.hpp 143 RandomNumbers/EmptyPrototypeTable.hpp 132 144 133 145 THERMOSTATSOURCE = \ -
src/RandomNumbers/RandomNumberDistribution_Encapsulation.hpp
r3f9eba rc9bc2b7 15 15 16 16 #include <typeinfo> 17 18 #include "RandomNumberDistribution.hpp"19 #include "RandomNumberGeneratorFactory.hpp"20 17 21 18 #include <boost/nondet_random.hpp> … … 38 35 #include <boost/random/uniform_smallint.hpp> 39 36 37 #include "RandomNumberDistribution_Creator.hpp" 38 #include "RandomNumberDistribution.hpp" 39 #include "RandomNumberGeneratorFactory.hpp" 40 40 41 #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" 41 42 … … 48 49 */ 49 50 template <class distribution> 50 class RandomNumberDistribution_Encapsulation : public RandomNumberDistribution 51 class RandomNumberDistribution_Encapsulation : public RandomNumberDistribution, public RandomNumberDistribution_Creator< RandomNumberDistribution_Encapsulation<distribution> > 51 52 { 52 53 /** … … 83 84 * 84 85 */ 85 ~RandomNumberDistribution_Encapsulation() {}86 virtual ~RandomNumberDistribution_Encapsulation() {} 86 87 private: 87 88 distribution distribution_type; -
src/RandomNumbers/RandomNumberEngineFactory.def
r3f9eba rc9bc2b7 1 #ifndef RANDOMNUMBER GENERATORFACTORY_DEF_2 #define RANDOMNUMBER GENERATORFACTORY_DEF_1 #ifndef RANDOMNUMBERENGINEFACTORY_DEF_ 2 #define RANDOMNUMBERENGINEFACTORY_DEF_ 3 3 4 4 /** BOOST_PP_SEQ of all random::boost engine types, … … 42 42 #define engine_seq_a_size BOOST_PP_SEQ_SIZE(engine_seq_a) 43 43 44 /** BOOST_PP_SEQ of all random::boost distribution types, 45 * see see http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/reference.html#boost_random.reference.concepts 46 */ 47 #define distribution_seq \ 48 (uniform_smallint)\ 49 (uniform_int) 50 51 /* 52 (uniform_01)\ 53 (uniform_real)\ 54 (bernoulli_distribution)\ 55 (binomial_distribution)\ 56 (cauchy_distribution)\ 57 (gamma_distribution)\ 58 (poisson_distribution)\ 59 (geometric_distribution)\ 60 (triangle_distribution)\ 61 (exponential_distribution)\ 62 (normal_distribution)\ 63 (lognormal_distribution)\ 64 (uniform_on_sphere) 65 */ 66 #define distribution_seq_size BOOST_PP_SEQ_SIZE(distribution_seq) 67 68 #endif /* RANDOMNUMBERGENERATORFACTORY_DEF_ */ 44 #endif /* RANDOMNUMBERENGINEFACTORY_DEF_ */ -
src/RandomNumbers/RandomNumberEngine_Encapsulation.hpp
r3f9eba rc9bc2b7 16 16 #include <typeinfo> 17 17 18 #include "RandomNumberEngine.hpp"19 #include "RandomNumberGeneratorFactory.hpp"20 21 18 #include <boost/nondet_random.hpp> 22 19 #include <boost/random.hpp> … … 34 31 #include <boost/random/xor_combine.hpp> 35 32 33 #include "RandomNumberEngine_Creator.hpp" 34 #include "RandomNumberEngine.hpp" 35 36 #include "RandomNumberGeneratorFactory.hpp" 36 37 #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" 37 38 … … 44 45 */ 45 46 template <class engine> 46 class RandomNumberEngine_Encapsulation : public RandomNumberEngine 47 class RandomNumberEngine_Encapsulation : public RandomNumberEngine, public RandomNumberEngine_Creator< RandomNumberEngine_Encapsulation<engine> > 47 48 { 48 49 /** … … 86 87 * 87 88 */ 88 ~RandomNumberEngine_Encapsulation() {}89 virtual ~RandomNumberEngine_Encapsulation() {} 89 90 private: 90 91 engine engine_type; -
src/RandomNumbers/RandomNumberGeneratorFactory.cpp
r3f9eba rc9bc2b7 25 25 26 26 #include "TemplatePowerSetGenerator.hpp" 27 #include "EmptyPrototypeTable.hpp" 27 28 28 #include "RandomNumberEngine _Encapsulation.hpp"29 #include "RandomNumberDistribution _Encapsulation.hpp"29 #include "RandomNumberEngineFactory.hpp" 30 #include "RandomNumberDistributionFactory.hpp" 30 31 #include "RandomNumberGenerator_Encapsulation.hpp" 31 32 32 33 #include <boost/preprocessor/facilities/empty.hpp> 33 34 #include <boost/preprocessor/punctuation/paren.hpp> 35 #include <boost/preprocessor/seq/for_each_product.hpp> 36 #include <boost/preprocessor/facilities/identity.hpp> 37 #include <boost/preprocessor/facilities/expand.hpp> 38 #include <boost/preprocessor/seq/seq.hpp> 39 34 40 35 41 #include "RandomNumberGeneratorFactory.hpp" 36 #include "RandomNumberGeneratorFactory.def" 42 #include "RandomNumberDistributionFactory.def" 43 #include "RandomNumberEngineFactory.def" 37 44 38 enum RandomNumberGeneratorFactory::Engine RandomNumberGeneratorFactory::engine = (enum RandomNumberGeneratorFactory::Engine) 0; 39 enum RandomNumberGeneratorFactory::Distribution RandomNumberGeneratorFactory::distribution = (enum RandomNumberGeneratorFactory::Distribution) 0; 40 RandomNumberGeneratorFactory::EngineMap RandomNumberGeneratorFactory::engines; 41 RandomNumberGeneratorFactory::EngineNamesMap RandomNumberGeneratorFactory::engineNames; 42 RandomNumberGeneratorFactory::DistributionMap RandomNumberGeneratorFactory::distributions; 43 RandomNumberGeneratorFactory::DistributionNamesMap RandomNumberGeneratorFactory::distributionNames; 44 RandomNumberGeneratorFactory::EngineTable RandomNumberGeneratorFactory::EnginePrototypeTable; 45 RandomNumberGeneratorFactory::DistributionTable RandomNumberGeneratorFactory::DistributionPrototypeTable; 45 enum RandomNumberDistributionFactory::Distribution RandomNumberGeneratorFactory::distribution = (enum RandomNumberDistributionFactory::Distribution) 0; 46 enum RandomNumberEngineFactory::Engine RandomNumberGeneratorFactory::engine = (enum RandomNumberEngineFactory::Engine) 0; 46 47 RandomNumberGeneratorFactory::EngineDistributionTable RandomNumberGeneratorFactory::GeneratorPrototypeTable; 47 48 48 49 49 RandomNumberGeneratorFactory::RandomNumberGeneratorFactory() 50 50 { 51 // insert all known engines 52 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, engine_seq, engines) 53 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq)-1 ) 54 #include BOOST_PP_LOCAL_ITERATE() 55 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, engine_seq_a, engines) 56 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq_a)-1 ) 57 #include BOOST_PP_LOCAL_ITERATE() 58 for (EngineMap::const_iterator iter = engines.begin(); 59 iter != engines.end(); 60 ++iter) { 61 engineNames.insert(make_pair(iter->second, iter->first)); 62 } 63 64 // insert all known distributions 65 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_string_enum_map(~, n, distribution_seq, distributions) 66 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distribution_seq)-1 ) 67 #include BOOST_PP_LOCAL_ITERATE() 68 for (DistributionMap::const_iterator iter = distributions.begin(); 69 iter != distributions.end(); 70 ++iter) { 71 distributionNames.insert(make_pair(iter->second, iter->first)); 72 } 73 74 FillPrototypeTables(); 51 FillPrototypeTable(); 75 52 } 76 77 /** Removes all pointers to instances from a table while free'ing memory.78 *79 * I.e. we assume class T to be a map of some key with its values pointers to80 * some classes that have to be free'd.81 *82 * \param _PrototypeTable table to empty83 */84 template <class T>85 void EmptyPrototypeTable(T &_PrototypeTable)86 {87 for (typename T::iterator iter = _PrototypeTable.begin();88 !_PrototypeTable.empty();89 iter = _PrototypeTable.begin()) {90 delete (iter->second);91 _PrototypeTable.erase(iter);92 }93 _PrototypeTable.clear();94 }95 96 97 53 98 54 RandomNumberGeneratorFactory::~RandomNumberGeneratorFactory() … … 100 56 // clear out factories map to allow boost::shared_ptr to do their work (i.e. to release mem) 101 57 // this is necessary as factories is a object 102 engines.clear();103 engineNames.clear();104 EmptyPrototypeTable<EngineTable> (EnginePrototypeTable);105 distributions.clear();106 distributionNames.clear();107 EmptyPrototypeTable<DistributionTable> (DistributionPrototypeTable);108 58 for (EngineDistributionTable::iterator iter = GeneratorPrototypeTable.begin(); 109 59 !GeneratorPrototypeTable.empty(); 110 60 iter = GeneratorPrototypeTable.begin()) { 111 EmptyPrototypeTable< std::map<enum Distribution,RandomNumberGenerator *> > (iter->second);61 EmptyPrototypeTable< std::map<enum RandomNumberDistributionFactory::Distribution,IRandomNumberGenerator_Creator *> > (iter->second); 112 62 GeneratorPrototypeTable.erase(iter); 113 63 } … … 115 65 } 116 66 117 void RandomNumberGeneratorFactory::FillPrototypeTable s()67 void RandomNumberGeneratorFactory::FillPrototypeTable() 118 68 { 119 // fill EnginePrototypeTable 120 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, engine_seq, EnginePrototypeTable, new RandomNumberEngine_Encapsulation, boost::, ) 121 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq)-1 ) 122 #include BOOST_PP_LOCAL_ITERATE() 123 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, engine_seq_a, EnginePrototypeTable, new RandomNumberEngine_Encapsulation, boost::, ) 124 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(engine_seq_a)-1 ) 125 #include BOOST_PP_LOCAL_ITERATE() 69 // fill GeneratorPrototypeTable 70 #define SequenceElementizer(z,data) (data) 126 71 127 // fill DistributionPrototypeTable 128 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_map(~, n, distribution_seq, DistributionPrototypeTable, new RandomNumberDistribution_Encapsulation, boost::, <>)129 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distribution_seq)-1 )130 #include BOOST_PP_LOCAL_ITERATE()72 #define distributionengine_seqseq \ 73 BOOST_PP_SEQ_FOR_EACH_PRODUCT(SequenceElementizer, (engine_seq)(distribution_seq)) 74 #define distributionengine_seqseq_a \ 75 BOOST_PP_SEQ_FOR_EACH_PRODUCT(SequenceElementizer, (engine_seq_a)(distribution_seq)) 131 76 132 // fill GeneratorPrototypeTable 133 #define DoubleElementSequenceElementizer(z,data,elem) ((data)(elem)) 77 #define suffixseq ()(<> > ) 78 #define tableseq (*EnginePrototypeTable)(*DistributionPrototypeTable) 79 #define name_spaces_seq (RandomNumberEngineFactory::)(RandomNumberDistributionFactory::) 134 80 135 #define seqseqiterate(z,n,seq) BOOST_PP_SEQ_FOR_EACH(DoubleElementSequenceElementizer, BOOST_PP_SEQ_ELEM(n,seq), distribution_seq) 136 137 #define distributionengine_seqseq BOOST_PP_REPEAT( \ 138 BOOST_PP_SEQ_SIZE(engine_seq), seqseqiterate, engine_seq ) 139 140 #define distributionengine_seqseq_a BOOST_PP_REPEAT( \ 141 BOOST_PP_SEQ_SIZE(engine_seq_a), seqseqiterate, engine_seq_a ) 142 143 #define suffixseq ()(<>) 144 #define tableseq (*EnginePrototypeTable)(*DistributionPrototypeTable) 81 #define size_tupels BOOST_PP_SEQ_SIZE(tableseq) 145 82 146 83 #define TableItemPrinter(z,n,sequence) \ 84 [ \ 85 BOOST_PP_SEQ_ELEM(n,name_spaces_seq) \ 86 BOOST_PP_SEQ_ELEM(n,sequence) \ 87 ] 88 89 #define TemplateItemPrinter(z,n,sequence) \ 147 90 BOOST_PP_COMMA_IF(n) \ 148 91 boost:: \ … … 150 93 BOOST_PP_SEQ_ELEM(n,suffixseq) 151 94 152 #define ParamItemPrinter(z,n,sequence) \ 153 BOOST_PP_COMMA_IF(n) \ 154 BOOST_PP_SEQ_ELEM(n,tableseq) \ 155 [ \ 156 BOOST_PP_SEQ_ELEM(n,sequence) \ 157 ] 95 #define ParamItemPrinter(z,n,sequence) 158 96 159 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, distributionengine_seqseq, GeneratorPrototypeTable, new RandomNumberGenerator_Encapsulation, TableItemPrinter, ParamItemPrinter)97 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Creator< RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter) 160 98 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq)-1 ) 161 99 #include BOOST_PP_LOCAL_ITERATE() 162 100 163 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, distributionengine_seqseq_a, GeneratorPrototypeTable, new RandomNumberGenerator_Encapsulation, TableItemPrinter, ParamItemPrinter)101 #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq_a, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Creator< RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter) 164 102 #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq_a)-1 ) 165 103 #include BOOST_PP_LOCAL_ITERATE() 166 104 } 167 105 168 RandomNumberGenerator &RandomNumberGeneratorFactory::makeRandomNumberGenerator() const106 RandomNumberGenerator* RandomNumberGeneratorFactory::makeRandomNumberGenerator() const 169 107 { 170 108 // Instantiate and return (implicitly creates a copy of the stored prototype) 171 return *GeneratorPrototypeTable[engine][distribution];109 return (GeneratorPrototypeTable[engine][distribution]->create()); 172 110 } 173 111 174 RandomNumberGenerator& RandomNumberGeneratorFactory::makeRandomNumberGenerator(std::string engine_type, std::string distribution_type) const 112 RandomNumberGenerator* RandomNumberGeneratorFactory::makeRandomNumberGenerator( 113 std::string engine_type, 114 std::string distribution_type 115 ) const 175 116 { 176 enum Engine eng_type;177 enum Distribution dis_type;117 enum RandomNumberEngineFactory::Engine eng_type; 118 enum RandomNumberDistributionFactory::Distribution dis_type; 178 119 179 120 // Instantiate and return (implicitly creates a copy of the stored prototype) 180 121 if (!engine_type.empty()) { 181 ASSERT(engines.count(engine_type) != 0, 182 "RandomNumberGeneratorFactory::makeRandomNumberGenerator() - Selected engine "+engine_type+"is not registered."); 183 eng_type = engines[engine_type]; 122 eng_type = RandomNumberEngineFactory::getInstance().getEnum(engine_type); 184 123 } else 185 124 eng_type = engine; 186 125 if (!distribution_type.empty()) { 187 ASSERT(distributions.count(distribution_type) != 0, 188 "RandomNumberGeneratorFactory::makeRandomNumberGenerator() - Selected distribution "+distribution_type+"is not registered."); 189 dis_type = distributions[distribution_type]; 126 dis_type = RandomNumberDistributionFactory::getInstance().getEnum(distribution_type); 190 127 } else 191 128 dis_type = distribution; 192 return *GeneratorPrototypeTable[ eng_type ][ dis_type ];129 return (GeneratorPrototypeTable[ eng_type ][ dis_type ]->create()); 193 130 } 194 131 195 132 void RandomNumberGeneratorFactory::setEngine(std::string engine_type) 196 133 { 197 ASSERT(engines.count(engine_type) != 0,"Selected engine "+engine_type+"is not registered."); 198 engine = engines[engine_type]; 134 engine = RandomNumberEngineFactory::getInstance().getEnum(engine_type); 199 135 } 200 136 201 const std::string &RandomNumberGeneratorFactory::getEngine () const137 const std::string &RandomNumberGeneratorFactory::getEngineName() const 202 138 { 203 return engineNames[engine];139 return RandomNumberEngineFactory::getInstance().getName(engine); 204 140 } 205 141 206 142 void RandomNumberGeneratorFactory::setDistribution(std::string distribution_type) 207 143 { 208 ASSERT(distributions.count(distribution_type) != 0 ,"Selected distribution "+distribution_type+"is not registered."); 209 distribution = distributions[distribution_type]; 144 distribution = RandomNumberDistributionFactory::getInstance().getEnum(distribution_type); 210 145 } 211 146 212 const std::string &RandomNumberGeneratorFactory::getDistribution () const147 const std::string &RandomNumberGeneratorFactory::getDistributionName() const 213 148 { 214 return distributionNames[distribution];149 return RandomNumberDistributionFactory::getInstance().getName(distribution); 215 150 } 216 151 217 152 CONSTRUCT_SINGLETON(RandomNumberGeneratorFactory) 218 153 219 #include "RandomNumberGeneratorFactory.undef" 154 #include "RandomNumberDistributionFactory.undef" 155 #include "RandomNumberEngineFactory.undef" 220 156 -
src/RandomNumbers/RandomNumberGeneratorFactory.hpp
r3f9eba rc9bc2b7 16 16 #include "CodePatterns/Singleton.hpp" 17 17 18 #include "RandomNumberDistribution.hpp" 19 #include "RandomNumberEngine.hpp" 20 #include "RandomNumberGenerator.hpp" 18 #include "RandomNumberDistributionFactory.hpp" 19 #include "RandomNumberEngineFactory.hpp" 21 20 22 21 #include <map> 23 22 24 #include "TemplatePowerSetGenerator.hpp" 25 #include "RandomNumberGeneratorFactory.def" 23 #include "RandomNumberGenerator_Creator.hpp" 26 24 27 25 #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" 26 27 class RandomNumberGenerator; 28 28 29 29 /** This is the abstract factory class for random number generators. … … 40 40 friend class Singleton<RandomNumberGeneratorFactory>; 41 41 friend class RandomNumberGeneratorFactoryTest; 42 42 43 public: 43 44 … … 47 48 48 49 public: 49 /** Enumeration of all (pseudo-)random number engines implemented in50 * boost::random, see51 * http://www.boost.org/doc/libs/1_45_0/doc/html/boost_random/reference.html#boost_random.reference.concepts52 */53 enum Engine {54 BOOST_PP_REPEAT( engine_seq_size, seqitems_as_enum, engine_seq)55 ,56 BOOST_PP_REPEAT( engine_seq_a_size, seqitems_as_enum, engine_seq_a)57 };58 59 /** Enumeration of all distribution implemented in random::boost.60 */61 enum Distribution {62 BOOST_PP_REPEAT( distribution_seq_size, seqitems_as_enum, distribution_seq)63 };64 65 50 /** Create a Generator of previously set type. 66 51 * 67 52 * \return random number generator instance 68 53 */ 69 RandomNumberGenerator &makeRandomNumberGenerator() const;54 RandomNumberGenerator* makeRandomNumberGenerator() const; 70 55 71 56 /** Create a Generator of desired combination of engine and distribution. … … 75 60 * 76 61 * \param engine_type name of engine, give empty string for current default 77 * \param distribution_type name of distribution, give empty string for current default 62 * \param distribution_type name of distribution, give empty string for 63 * current default 78 64 * \return random number generator instance 79 65 */ 80 RandomNumberGenerator &makeRandomNumberGenerator(std::string engine_type, std::string distribution_type) const;66 RandomNumberGenerator* makeRandomNumberGenerator(std::string engine_type, std::string distribution_type) const; 81 67 82 68 /** Specify the precise type of the engine to build … … 86 72 void setEngine(std::string engine_type); 87 73 88 /** Getter for current type of engine.74 /** Getter for the name of the current type of engine. 89 75 * 90 76 * @return name of engine 91 77 */ 92 const std::string &getEngine () const;78 const std::string &getEngineName() const; 93 79 94 80 /** Specify the precise type of the distribution to build … … 98 84 void setDistribution(std::string distribution_type); 99 85 100 /** Getter for current type of distribution.86 /** Getter for the name of the current type of distribution. 101 87 * 102 88 * @return name of distribution 103 89 */ 104 const std::string &getDistribution () const;90 const std::string &getDistributionName() const; 105 91 106 92 protected: … … 109 95 * and stores them in \a PrototypeTable. 110 96 */ 111 void FillPrototypeTable s();97 void FillPrototypeTable(); 112 98 113 99 typedef std::map< 114 std::string, 115 enum Engine 116 > EngineMap; 117 typedef std::map< 118 enum Engine, 119 RandomNumberEngine * 120 > EngineTable; 121 typedef std::map< 122 enum Engine, 123 std::string 124 > EngineNamesMap; 125 126 typedef std::map< 127 std::string, 128 enum Distribution 129 > DistributionMap; 130 typedef std::map< 131 enum Distribution, 132 RandomNumberDistribution * 133 > DistributionTable; 134 typedef std::map< 135 enum Distribution, 136 std::string 137 > DistributionNamesMap; 138 139 typedef std::map< 140 enum Engine, 100 enum RandomNumberEngineFactory::Engine, 141 101 std::map< 142 enum Distribution,143 RandomNumberGenerator *>102 enum RandomNumberDistributionFactory::Distribution, 103 IRandomNumberGenerator_Creator *> 144 104 > EngineDistributionTable; 145 105 146 static enum Engine engine; 147 static enum Distribution distribution; 148 static EngineMap engines; 149 static EngineTable EnginePrototypeTable; 150 static EngineNamesMap engineNames; 151 static DistributionMap distributions; 152 static DistributionTable DistributionPrototypeTable; 153 static DistributionNamesMap distributionNames; 106 static enum RandomNumberDistributionFactory::Distribution distribution; 107 static enum RandomNumberEngineFactory::Engine engine; 154 108 static EngineDistributionTable GeneratorPrototypeTable; 155 109 }; 156 110 157 #include "RandomNumberGeneratorFactory.undef"158 159 111 #endif /* RANDOMNUMBERGENERATORFACTORY_HPP_ */ -
src/RandomNumbers/RandomNumberGenerator_Encapsulation.hpp
r3f9eba rc9bc2b7 14 14 #endif 15 15 16 #include "RandomNumberDistribution.hpp" 17 #include "RandomNumberEngine.hpp" 16 #include <boost/nondet_random.hpp> 17 #include <boost/random.hpp> 18 #include <boost/random/bernoulli_distribution.hpp> 19 #include <boost/random/binomial_distribution.hpp> 20 #include <boost/random/cauchy_distribution.hpp> 21 #include <boost/random/exponential_distribution.hpp> 22 #include <boost/random/gamma_distribution.hpp> 23 #include <boost/random/geometric_distribution.hpp> 24 #include <boost/random/linear_congruential.hpp> 25 #include <boost/random/lognormal_distribution.hpp> 26 #include <boost/random/normal_distribution.hpp> 27 #include <boost/random/poisson_distribution.hpp> 28 #include <boost/random/triangle_distribution.hpp> 29 #include <boost/random/uniform_01.hpp> 30 #include <boost/random/uniform_int.hpp> 31 #include <boost/random/uniform_on_sphere.hpp> 32 #include <boost/random/uniform_real.hpp> 33 #include <boost/random/uniform_smallint.hpp> 34 #include <boost/random/additive_combine.hpp> 35 #include <boost/random/discard_block.hpp> 36 #include <boost/random/inversive_congruential.hpp> 37 #include <boost/random/lagged_fibonacci.hpp> 38 #include <boost/random/linear_congruential.hpp> 39 #include <boost/random/linear_feedback_shift.hpp> 40 #include <boost/random/mersenne_twister.hpp> 41 #include <boost/random/random_number_generator.hpp> 42 #include <boost/random/ranlux.hpp> 43 #include <boost/random/shuffle_output.hpp> 44 #include <boost/random/subtract_with_carry.hpp> 45 #include <boost/random/xor_combine.hpp> 46 #include <boost/random/variate_generator.hpp> 47 48 #include <typeinfo> 49 50 #include "RandomNumberGenerator_Creator.hpp" 18 51 #include "RandomNumberGenerator.hpp" 52 19 53 #include "RandomNumberGeneratorFactory.hpp" 20 21 54 #include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp" 22 55 … … 36 69 */ 37 70 template <class engine, class distribution> 38 class RandomNumberGenerator_Encapsulation : public RandomNumberGenerator 71 class RandomNumberGenerator_Encapsulation : public RandomNumberGenerator, public RandomNumberGenerator_Creator< RandomNumberGenerator_Encapsulation<engine, distribution> > 39 72 { 40 73 /** … … 43 76 friend class RandomNumberGeneratorFactory; 44 77 friend class RandomNumberGeneratorFactoryTest; 78 79 friend class RandomNumberGenerator_Creator< RandomNumberGenerator_Encapsulation<engine, distribution> >; 45 80 46 81 public: … … 64 99 */ 65 100 std::string EngineName() { 66 return engine_type.name();101 return typeid(engine_type).name(); 67 102 } 68 103 … … 71 106 */ 72 107 std::string DistributionName() { 73 return distribution_type.name();108 return typeid(distribution_type).name(); 74 109 } 75 110 111 protected: 76 112 /** Constructor that instantiates a specific random number generator and 77 113 * distribution. … … 79 115 * @param _distribution_type instance of the desired distribution 80 116 */ 81 RandomNumberGenerator_Encapsulation( 82 RandomNumberEngine &_engine_type, 83 RandomNumberDistribution &_distribution_type 84 ) : 85 engine_type(static_cast<RandomNumberEngine_Encapsulation<engine> &>(_engine_type)), 86 distribution_type(static_cast<RandomNumberDistribution_Encapsulation<distribution> &>(_distribution_type)), 87 randomgenerator(boost::variate_generator<engine, distribution> ( 88 engine_type.getEngine(), 89 distribution_type.getDistribution() 90 )) 117 RandomNumberGenerator_Encapsulation() : 118 randomgenerator( 119 boost::variate_generator<engine, distribution> ( 120 engine_type, 121 distribution_type) 122 ) 91 123 { 92 124 // note that we instantiate the variate_generator with the copied instances! … … 96 128 * 97 129 */ 98 ~RandomNumberGenerator_Encapsulation() {}130 virtual ~RandomNumberGenerator_Encapsulation() {} 99 131 private: 100 RandomNumberEngine_Encapsulation<engine>engine_type;101 RandomNumberDistribution_Encapsulation<distribution>distribution_type;132 engine engine_type; 133 distribution distribution_type; 102 134 mutable boost::variate_generator<engine, distribution> randomgenerator; 103 135 }; -
src/RandomNumbers/TemplatePowerSetGenerator.hpp
r3f9eba rc9bc2b7 25 25 #include <boost/preprocessor/seq/enum.hpp> 26 26 #include <boost/preprocessor/seq/for_each.hpp> 27 #include <boost/preprocessor/seq/for_each_i.hpp> 27 28 #include <boost/preprocessor/stringize.hpp> 28 29 #include <boost/preprocessor/tuple/elem.hpp> … … 36 37 * [test] 37 38 */ 38 #define SquareBracketize(r, data, elem) \39 #define SquareBracketize(r, data, i, elem) \ 39 40 [ \ 41 BOOST_PP_SEQ_ELEM(i, data) \ 40 42 elem \ 41 43 ] … … 142 144 * then we use 143 145 * #define tableprinter(z,n,seq) BOOST_PP_SEQ_ELEM(n,seq) 144 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(seqsize, n, seqseq, MultiMap, test::, tableprinter)146 * #define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(seqsize, n, seqseq, bla::, MultiMap, test::testfunction, test_printer, tableprinter) 145 147 * #define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(seqseq)-1 ) 146 148 * #include BOOST_PP_LOCAL_ITERATE() … … 152 154 153 155 */ 154 #define seqitems_as_enum_key_multidimmap(z,n, seq_of_tupels, map, template_function, template_arg_printer, param_arg_printer) \156 #define seqitems_as_enum_key_multidimmap(z,n, size_tupels, seq_of_tupels, map, tableitems_arg_printer, template_function, template_arg_printer, param_arg_printer) \ 155 157 map \ 156 BOOST_PP_ SEQ_FOR_EACH(SquareBracketize, ~, BOOST_PP_SEQ_ELEM(n, seq_of_tupels)) \158 BOOST_PP_REPEAT (size_tupels, tableitems_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) \ 157 159 = template_function \ 158 < BOOST_PP_REPEAT( BOOST_PP_SEQ_SIZE(tableseq), template_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) > (\159 BOOST_PP_REPEAT( BOOST_PP_SEQ_SIZE(tableseq), param_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) );160 < BOOST_PP_REPEAT(size_tupels, template_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) > (\ 161 BOOST_PP_REPEAT(size_tupels, param_arg_printer, BOOST_PP_SEQ_ELEM(n, seq_of_tupels) ) ); 160 162 161 163 -
src/RandomNumbers/unittests/Makefile.am
r3f9eba rc9bc2b7 8 8 9 9 TESTS = \ 10 RandomNumberGeneratorFactoryUnitTest 10 RandomNumberDistributionFactoryUnitTest \ 11 RandomNumberEngineFactoryUnitTest \ 12 RandomNumberGeneratorFactoryUnitTest \ 13 RandomNumberGeneratorUnitTest 11 14 12 15 … … 31 34 PARSERLIBS = ../../Parser/libMolecuilderParser.la 32 35 36 RandomNumberDistributionFactoryUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 37 RandomNumberDistributionFactoryUnitTest.cpp \ 38 RandomNumberDistributionFactoryUnitTest.hpp \ 39 $(srcdir)/../RandomNumberDistributionFactory.cpp \ 40 $(srcdir)/../RandomNumberDistributionFactory.hpp 41 RandomNumberDistributionFactoryUnitTest_LDADD = ${GSLLIBS} 42 43 RandomNumberEngineFactoryUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 44 RandomNumberEngineFactoryUnitTest.cpp \ 45 RandomNumberEngineFactoryUnitTest.hpp \ 46 $(srcdir)/../RandomNumberEngineFactory.cpp \ 47 $(srcdir)/../RandomNumberEngineFactory.hpp 48 RandomNumberEngineFactoryUnitTest_LDADD = ${GSLLIBS} 49 33 50 RandomNumberGeneratorFactoryUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 34 51 RandomNumberGeneratorFactoryUnitTest.cpp \ 35 52 RandomNumberGeneratorFactoryUnitTest.hpp \ 53 $(srcdir)/../RandomNumberDistributionFactory.cpp \ 54 $(srcdir)/../RandomNumberDistributionFactory.hpp \ 55 $(srcdir)/../RandomNumberEngineFactory.cpp \ 56 $(srcdir)/../RandomNumberEngineFactory.hpp \ 36 57 $(srcdir)/../RandomNumberGeneratorFactory.cpp \ 37 58 $(srcdir)/../RandomNumberGeneratorFactory.hpp 38 59 RandomNumberGeneratorFactoryUnitTest_LDADD = ${GSLLIBS} 39 60 61 RandomNumberGeneratorUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \ 62 RandomNumberGeneratorUnitTest.cpp \ 63 RandomNumberGeneratorUnitTest.hpp \ 64 $(srcdir)/../RandomNumberDistributionFactory.cpp \ 65 $(srcdir)/../RandomNumberDistributionFactory.hpp \ 66 $(srcdir)/../RandomNumberEngineFactory.cpp \ 67 $(srcdir)/../RandomNumberEngineFactory.hpp \ 68 $(srcdir)/../RandomNumberGeneratorFactory.cpp \ 69 $(srcdir)/../RandomNumberGeneratorFactory.hpp 70 RandomNumberGeneratorUnitTest_LDADD = ${GSLLIBS} 71 40 72 41 73 #AUTOMAKE_OPTIONS = parallel-tests -
src/RandomNumbers/unittests/RandomNumberGeneratorFactoryUnitTest.cpp
r3f9eba rc9bc2b7 9 9 * RandomNumberGeneratorFactoryUnitTest.cpp 10 10 * 11 * Created on: Dec 31, 201011 * Created on: Jan 03, 2011 12 12 * Author: heber 13 13 */ … … 26 26 #include "RandomNumberGeneratorFactoryUnitTest.hpp" 27 27 28 #include "RandomNumbers/RandomNumber Distribution_Encapsulation.hpp"29 #include "RandomNumbers/RandomNumberEngine _Encapsulation.hpp"30 #include "RandomNumbers/RandomNumber Generator_Encapsulation.hpp"28 #include "RandomNumbers/RandomNumberGenerator.hpp" 29 #include "RandomNumbers/RandomNumberEngineFactory.hpp" 30 #include "RandomNumbers/RandomNumberDistributionFactory.hpp" 31 31 #include "RandomNumbers/RandomNumberGeneratorFactory.hpp" 32 32 … … 80 80 void RandomNumberGeneratorFactoryTest::tearDown() 81 81 { 82 RandomNumberDistributionFactory::purgeInstance(); 83 RandomNumberEngineFactory::purgeInstance(); 82 84 RandomNumberGeneratorFactory::purgeInstance(); 83 }84 85 void RandomNumberGeneratorFactoryTest::EngineTest()86 {87 // check default value88 CPPUNIT_ASSERT_EQUAL(89 std::string("minstd_rand0"),90 RandomNumberGeneratorFactory::getInstance().getEngine());91 92 // check one of the engines in the table93 CPPUNIT_ASSERT_EQUAL(94 std::string(typeid(boost::minstd_rand0).name()),95 RandomNumberGeneratorFactory::getInstance().96 EnginePrototypeTable[RandomNumberGeneratorFactory::minstd_rand0]->name()97 );98 }99 100 void RandomNumberGeneratorFactoryTest::DistributionTest()101 {102 // check default value103 CPPUNIT_ASSERT_EQUAL(104 std::string("uniform_smallint"),105 RandomNumberGeneratorFactory::getInstance().getDistribution());106 107 // check one of the distributions in the table108 CPPUNIT_ASSERT_EQUAL(109 std::string(typeid(boost::uniform_smallint<> ).name()),110 RandomNumberGeneratorFactory::getInstance().111 DistributionPrototypeTable[RandomNumberGeneratorFactory::uniform_smallint]->name()112 );113 85 } 114 86 115 87 void RandomNumberGeneratorFactoryTest::GeneratorTest() 116 88 { 89 RandomNumberGenerator *rng = NULL; 117 90 // check one of the engines and distributions 91 rng = RandomNumberGeneratorFactory::getInstance(). 92 GeneratorPrototypeTable[RandomNumberEngineFactory::minstd_rand0] 93 [RandomNumberDistributionFactory::uniform_smallint]->create(); 118 94 CPPUNIT_ASSERT_EQUAL( 119 95 std::string(typeid(boost::minstd_rand0).name()), 120 RandomNumberGeneratorFactory::getInstance(). 121 GeneratorPrototypeTable[RandomNumberGeneratorFactory::minstd_rand0][RandomNumberGeneratorFactory::uniform_smallint] 122 ->EngineName() 96 rng->EngineName() 123 97 ); 124 98 CPPUNIT_ASSERT_EQUAL( 125 99 std::string(typeid(boost::uniform_smallint<> ).name()), 126 RandomNumberGeneratorFactory::getInstance(). 127 GeneratorPrototypeTable[RandomNumberGeneratorFactory::minstd_rand0][RandomNumberGeneratorFactory::uniform_smallint] 128 ->DistributionName() 100 rng->DistributionName() 129 101 ); 102 delete rng; 130 103 131 // obtain some random values for uniform_smallint132 RandomNumberGeneratorFactory::getInstance().setDistribution("uniform_smallint");133 RandomNumberGenerator &rng = RandomNumberGeneratorFactory::getInstance().makeRandomNumberGenerator();134 for (size_t i=0; i < 1000; ++i) {135 const int testint = rng();136 CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint >= 0);137 CPPUNIT_ASSERT_MESSAGE("randon number from uniform_smallint is out of [0:9]!", testint <= 9);138 }139 104 } 140 105 -
src/RandomNumbers/unittests/RandomNumberGeneratorFactoryUnitTest.hpp
r3f9eba rc9bc2b7 2 2 * RandomNumberGeneratorFactoryUnitTest.hpp 3 3 * 4 * Created on: Dec 31, 20104 * Created on: Jan 03, 2011 5 5 * Author: heber 6 6 */ … … 20 20 { 21 21 CPPUNIT_TEST_SUITE( RandomNumberGeneratorFactoryTest ); 22 CPPUNIT_TEST ( EngineTest );23 CPPUNIT_TEST ( DistributionTest );24 22 CPPUNIT_TEST ( GeneratorTest ); 25 23 CPPUNIT_TEST_SUITE_END(); … … 29 27 void tearDown(); 30 28 31 void EngineTest();32 void DistributionTest();33 29 void GeneratorTest(); 34 30 -
src/builder_init.cpp
r3f9eba rc9bc2b7 169 169 void cleanUp() 170 170 { 171 RandomNumberDistributionFactory::purgeInstance(); 172 RandomNumberEngineFactory::purgeInstance(); 171 173 RandomNumberGeneratorFactory::purgeInstance(); 172 174 FormatParserStorage::purgeInstance();
Note:
See TracChangeset
for help on using the changeset viewer.