Ignore:
Timestamp:
Feb 3, 2011, 9:51:19 AM (14 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Bigger rewrite of RandomNumbers ... due to cloning of prototypes.

  • in order to copy the prototypes and not use the original instance, we have implemented a new pattern called "Creator" that wraps a templated class in a creation interface class such that this abstract class can instaniate the particular types (see here http://stackoverflow.com/questions/3506026/c-clone-abstract-base-class-without-meddling-with-derived). This is also wrapped up in ..._Creator.hpp files.
  • meanwhile we also tried to have factories for Engine and Distribution but this failed due to boost::variate_operator<> having to know the particular types of engine and distribution. One could go forth with some cast's but this is very unclean and not what we want. ... Downside is that we can't set global options for engines or distributions as of now.
  • For the moment Engine- and DistributionFactory both have a prototype table, i.e. the same wrapped ones as above, but they are not used for the GeneratorFactory.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/RandomNumbers/RandomNumberGenerator_Encapsulation.hpp

    r3f9eba rc9bc2b7  
    1414#endif
    1515
    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"
    1851#include "RandomNumberGenerator.hpp"
     52
    1953#include "RandomNumberGeneratorFactory.hpp"
    20 
    2154#include "unittests/RandomNumberGeneratorFactoryUnitTest.hpp"
    2255
     
    3669 */
    3770template <class engine, class distribution>
    38 class RandomNumberGenerator_Encapsulation : public RandomNumberGenerator
     71class RandomNumberGenerator_Encapsulation : public RandomNumberGenerator, public RandomNumberGenerator_Creator< RandomNumberGenerator_Encapsulation<engine, distribution> >
    3972{
    4073  /**
     
    4376  friend class RandomNumberGeneratorFactory;
    4477  friend class RandomNumberGeneratorFactoryTest;
     78
     79  friend class RandomNumberGenerator_Creator< RandomNumberGenerator_Encapsulation<engine, distribution> >;
    4580
    4681public:
     
    6499   */
    65100  std::string EngineName() {
    66     return engine_type.name();
     101    return typeid(engine_type).name();
    67102  }
    68103
     
    71106   */
    72107  std::string DistributionName() {
    73     return distribution_type.name();
     108    return typeid(distribution_type).name();
    74109  }
    75110
     111protected:
    76112  /** Constructor that instantiates a specific random number generator and
    77113   * distribution.
     
    79115   * @param _distribution_type instance of the desired distribution
    80116   */
    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        )
    91123  {
    92124    // note that we instantiate the variate_generator with the copied instances!
     
    96128   *
    97129   */
    98   ~RandomNumberGenerator_Encapsulation() {}
     130  virtual ~RandomNumberGenerator_Encapsulation() {}
    99131private:
    100   RandomNumberEngine_Encapsulation<engine> engine_type;
    101   RandomNumberDistribution_Encapsulation<distribution> distribution_type;
     132  engine engine_type;
     133  distribution distribution_type;
    102134  mutable boost::variate_generator<engine, distribution> randomgenerator;
    103135};
Note: See TracChangeset for help on using the changeset viewer.