Changeset 9964ff for src


Ignore:
Timestamp:
Feb 3, 2011, 9:59:58 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:
ecb6c5
Parents:
0275ad
git-author:
Frederik Heber <heber@…> (01/07/11 15:35:13)
git-committer:
Frederik Heber <heber@…> (02/03/11 09:59:58)
Message:

RandomNumberGeneratorFactory now uses Engine and DistributionFactory defaults directly.

  • added unit test were these factory defaults are set and a composed Generator is made and its contained types tested.
Location:
src/RandomNumbers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/RandomNumbers/RandomNumberGeneratorFactory.cpp

    r0275ad r9964ff  
    103103{
    104104  // Instantiate and return (implicitly creates a copy of the stored prototype)
    105   return (GeneratorPrototypeTable[engine][distribution]->clone());
     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 ]->clone());
    106111}
    107112
     
    118123    eng_type = RandomNumberEngineFactory::getInstance().getEnum(engine_type);
    119124  } else
    120     eng_type = engine;
     125    eng_type = RandomNumberEngineFactory::getInstance().getCurrentTypeEnum();
    121126  if (!distribution_type.empty()) {
    122127    dis_type = RandomNumberDistributionFactory::getInstance().getEnum(distribution_type);
    123128  } else
    124     dis_type = distribution;
     129    dis_type = RandomNumberDistributionFactory::getInstance().getCurrentTypeEnum();
     130  return (GeneratorPrototypeTable[ eng_type ][ dis_type ]->clone());
     131
    125132  return (GeneratorPrototypeTable[ eng_type ][ dis_type ]->clone());
    126133}
     
    128135void RandomNumberGeneratorFactory::setEngine(std::string engine_type)
    129136{
    130   engine = RandomNumberEngineFactory::getInstance().getEnum(engine_type);
     137  RandomNumberEngineFactory::getInstance().setCurrentType(engine_type);
    131138}
    132139
    133140const std::string &RandomNumberGeneratorFactory::getEngineName() const
    134141{
    135   return RandomNumberEngineFactory::getInstance().getName(engine);
     142  return RandomNumberEngineFactory::getInstance().getCurrentTypeName();
    136143}
    137144
    138145void RandomNumberGeneratorFactory::setDistribution(std::string distribution_type)
    139146{
    140   distribution = RandomNumberDistributionFactory::getInstance().getEnum(distribution_type);
     147  RandomNumberDistributionFactory::getInstance().setCurrentType(distribution_type);
    141148}
    142149
    143150const std::string &RandomNumberGeneratorFactory::getDistributionName() const
    144151{
    145   return RandomNumberDistributionFactory::getInstance().getName(distribution);
     152  return RandomNumberDistributionFactory::getInstance().getCurrentTypeName();
    146153}
    147154
  • src/RandomNumbers/unittests/RandomNumberGeneratorFactoryUnitTest.cpp

    r0275ad r9964ff  
    103103      rng->DistributionName()
    104104  );
     105
     106  // set types in lower factories
     107  RandomNumberEngineFactory::getInstance().setCurrentType(RandomNumberEngineFactory::minstd_rand0);
     108  RandomNumberDistributionFactory::getInstance().setCurrentType(RandomNumberDistributionFactory::uniform_int);
     109  // ... and check whether generator delivers those set types
     110  RandomNumberGenerator *rng_A = RandomNumberGeneratorFactory::getInstance().
     111      makeRandomNumberGenerator();
     112  CPPUNIT_ASSERT_EQUAL(
     113      std::string(typeid(boost::minstd_rand0).name()),
     114      rng_A->EngineName()
     115  );
     116  CPPUNIT_ASSERT_EQUAL(
     117      std::string(typeid(boost::uniform_int<> ).name()),
     118      rng_A->DistributionName()
     119  );
     120  delete rng_A;
    105121}
Note: See TracChangeset for help on using the changeset viewer.