source: src/RandomNumbers/RandomNumberGeneratorFactory.cpp@ aec098

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
Last change on this file since aec098 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 5.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * RandomNumberGeneratorFactory.cpp
10 *
11 * Created on: Dec 31, 2010
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <utility>
23#include "CodePatterns/Singleton_impl.hpp"
24#include "CodePatterns/Assert.hpp"
25
26#include "TemplatePowerSetGenerator.hpp"
27#include "EmptyPrototypeTable.hpp"
28
29#include <boost/preprocessor/facilities/empty.hpp>
30#include <boost/preprocessor/punctuation/paren.hpp>
31#include <boost/preprocessor/seq/for_each_product.hpp>
32#include <boost/preprocessor/facilities/identity.hpp>
33#include <boost/preprocessor/facilities/expand.hpp>
34#include <boost/preprocessor/seq/seq.hpp>
35
36#include "RandomNumberGenerator_Encapsulation.hpp"
37
38#include "RandomNumberGeneratorFactory.hpp"
39#include "RandomNumberGeneratorFactory.def"
40
41RandomNumberDistributionFactory::TypeList RandomNumberGeneratorFactory::distribution = (RandomNumberDistributionFactory::TypeList) 0;
42RandomNumberEngineFactory::TypeList RandomNumberGeneratorFactory::engine = (RandomNumberEngineFactory::TypeList) 0;
43RandomNumberGeneratorFactory::EngineDistributionTable RandomNumberGeneratorFactory::GeneratorPrototypeTable;
44
45RandomNumberGeneratorFactory::RandomNumberGeneratorFactory()
46{
47 FillPrototypeTable();
48}
49
50RandomNumberGeneratorFactory::~RandomNumberGeneratorFactory()
51{
52 // clear out factories map to allow boost::shared_ptr to do their work (i.e. to release mem)
53 // this is necessary as factories is a object
54 for (EngineDistributionTable::iterator iter = GeneratorPrototypeTable.begin();
55 !GeneratorPrototypeTable.empty();
56 iter = GeneratorPrototypeTable.begin()) {
57 EmptyPrototypeTable< std::map<RandomNumberDistributionFactory::TypeList,RandomNumberGenerator*> > (iter->second);
58 GeneratorPrototypeTable.erase(iter);
59 }
60 GeneratorPrototypeTable.clear();
61}
62
63void RandomNumberGeneratorFactory::FillPrototypeTable()
64{
65 // fill GeneratorPrototypeTable
66#define SequenceElementizer(z,data) (data)
67
68#define distributionengine_seqseq \
69 BOOST_PP_SEQ_FOR_EACH_PRODUCT(SequenceElementizer, (engine_seq)(distribution_seq))
70#define distributionengine_seqseq_a \
71 BOOST_PP_SEQ_FOR_EACH_PRODUCT(SequenceElementizer, (engine_seq_a)(distribution_seq))
72
73#define suffixseq ()(<>)
74#define tableseq (*EnginePrototypeTable)(*DistributionPrototypeTable)
75#define name_spaces_seq (RandomNumberEngineFactory::)(RandomNumberDistributionFactory::)
76
77#define size_tupels BOOST_PP_SEQ_SIZE(tableseq)
78
79#define TableItemPrinter(z,n,sequence) \
80 [ \
81 BOOST_PP_SEQ_ELEM(n,name_spaces_seq) \
82 BOOST_PP_SEQ_ELEM(n,sequence) \
83 ]
84
85#define TemplateItemPrinter(z,n,sequence) \
86 BOOST_PP_COMMA_IF(n) \
87 boost:: \
88 BOOST_PP_SEQ_ELEM(n,sequence) \
89 BOOST_PP_SEQ_ELEM(n,suffixseq)
90
91#define ParamItemPrinter(z,n,sequence)
92
93#define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter)
94#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq)-1 )
95#include BOOST_PP_LOCAL_ITERATE()
96
97#define BOOST_PP_LOCAL_MACRO(n) seqitems_as_enum_key_multidimmap(~, n, size_tupels, distributionengine_seqseq_a, GeneratorPrototypeTable, TableItemPrinter, new RandomNumberGenerator_Encapsulation , TemplateItemPrinter, ParamItemPrinter)
98#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_SEQ_SIZE(distributionengine_seqseq_a)-1 )
99#include BOOST_PP_LOCAL_ITERATE()
100}
101
102RandomNumberGenerator& RandomNumberGeneratorFactory::makeRandomNumberGenerator() const
103{
104 // Instantiate and return (implicitly creates a copy of the stored prototype)
105 RandomNumberEngineFactory::TypeList eng_type =
106 RandomNumberEngineFactory::getInstance().getCurrentTypeEnum();
107 RandomNumberDistributionFactory::TypeList dis_type =
108 RandomNumberDistributionFactory::getInstance().getCurrentTypeEnum();
109
110 return (*GeneratorPrototypeTable[ eng_type ][ dis_type ]);
111}
112
113RandomNumberGenerator& RandomNumberGeneratorFactory::makeRandomNumberGenerator(
114 std::string engine_type,
115 std::string distribution_type
116 ) const
117{
118 RandomNumberEngineFactory::TypeList eng_type;
119 RandomNumberDistributionFactory::TypeList dis_type;
120
121 // Instantiate and return (implicitly creates a copy of the stored prototype)
122 if (!engine_type.empty()) {
123 eng_type = RandomNumberEngineFactory::getInstance().getEnum(engine_type);
124 } else
125 eng_type = RandomNumberEngineFactory::getInstance().getCurrentTypeEnum();
126 if (!distribution_type.empty()) {
127 dis_type = RandomNumberDistributionFactory::getInstance().getEnum(distribution_type);
128 } else
129 dis_type = RandomNumberDistributionFactory::getInstance().getCurrentTypeEnum();
130 return (*GeneratorPrototypeTable[ eng_type ][ dis_type ]);
131
132 return (*GeneratorPrototypeTable[ eng_type ][ dis_type ]);
133}
134
135void RandomNumberGeneratorFactory::setEngine(std::string engine_type)
136{
137 RandomNumberEngineFactory::getInstance().setCurrentType(engine_type);
138}
139
140const std::string &RandomNumberGeneratorFactory::getEngineName() const
141{
142 return RandomNumberEngineFactory::getInstance().getCurrentTypeName();
143}
144
145void RandomNumberGeneratorFactory::setDistribution(std::string distribution_type)
146{
147 RandomNumberDistributionFactory::getInstance().setCurrentType(distribution_type);
148}
149
150const std::string &RandomNumberGeneratorFactory::getDistributionName() const
151{
152 return RandomNumberDistributionFactory::getInstance().getCurrentTypeName();
153}
154
155CONSTRUCT_SINGLETON(RandomNumberGeneratorFactory)
156
157#include "RandomNumberGeneratorFactory.undef"
158
Note: See TracBrowser for help on using the repository browser.