Changeset 6ff0c8 for src


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:
1ee3b8d
Parents:
081e5d
git-author:
Frederik Heber <heber@…> (01/06/11 12:28:31)
git-committer:
Frederik Heber <heber@…> (02/03/11 09:51:19)
Message:

SetRandomNumbersEngineAction now only requires RandomNumberEngineFactory and uses seed.

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/RandomNumbersAction/SetRandomNumbersEngineAction.cpp

    r081e5d r6ff0c8  
    2525#include "World.hpp"
    2626
    27 #include "RandomNumbers/RandomNumberGeneratorFactory.hpp"
     27#include "RandomNumbers/RandomNumberEngine.hpp"
     28#include "RandomNumbers/RandomNumberEngineFactory.hpp"
    2829
    2930#include <iostream>
     
    4344  getParametersfromValueStorage();
    4445
     46  // create a new state for undo
    4547  CommandSetRandomNumbersEngineState *state =
    4648      new CommandSetRandomNumbersEngineState(
    47           RandomNumberGeneratorFactory::getInstance().getEngineName(),
     49          RandomNumberEngineFactory::getInstance().getCurrentTypeName(),
     50          RandomNumberEngineFactory::getInstance().getPrototype().getseed(),
    4851          params);
    49   RandomNumberGeneratorFactory::getInstance().setEngine(params.engine_type);
     52  // set new default
     53  RandomNumberEngineFactory::getInstance().setCurrentType(params.engine_type);
     54  // set new seed if given, have to use ugly const_cast as prototype is not manipulable
     55  if (params.seed != -1) {
     56    RandomNumberEngine &engine =
     57        const_cast<RandomNumberEngine &>(
     58            RandomNumberEngineFactory::getInstance().getPrototype(params.engine_type)
     59            );
     60    engine.seed(params.seed);
     61  }
    5062
    51   DoLog(0) && (Log() << Verbose(0) << "Engine of random number generator is now: "
    52       << RandomNumberGeneratorFactory::getInstance().getEngineName() << std::endl);
     63  DoLog(0) && (Log() << Verbose(0) << "Default random number engine is now: "
     64      << RandomNumberEngineFactory::getInstance().getCurrentTypeName() << std::endl);
    5365
    5466  return Action::state_ptr(state);
     
    5668
    5769Action::state_ptr CommandSetRandomNumbersEngineAction::performUndo(Action::state_ptr _state) {
    58   CommandSetRandomNumbersEngineState *state = assert_cast<CommandSetRandomNumbersEngineState*>(_state.get());
     70  CommandSetRandomNumbersEngineState *state =
     71      assert_cast<CommandSetRandomNumbersEngineState*>(_state.get());
    5972
     73  // create a new state for redo
    6074  CommandSetRandomNumbersEngineState *newstate =
    6175      new CommandSetRandomNumbersEngineState(
    62           RandomNumberGeneratorFactory::getInstance().getEngineName(),
     76          RandomNumberEngineFactory::getInstance().getCurrentTypeName(),
     77          RandomNumberEngineFactory::getInstance().getPrototype().getseed(),
    6378          state->params);
    64   RandomNumberGeneratorFactory::getInstance().setEngine(state->old_engine_type);
     79  // set new default
     80  RandomNumberEngineFactory::getInstance().setCurrentType(state->old_engine_type);
     81  RandomNumberEngine &engine = const_cast<RandomNumberEngine &>(
     82      RandomNumberEngineFactory::getInstance().getPrototype(state->params.engine_type)
     83    );
     84  // set new seed if given, have to use ugly const_cast as prototype is not manipulable
     85  if (state->params.seed != -1) {
     86    engine.seed(state->params.seed);
     87  }
    6588
    66   DoLog(0) && (Log() << Verbose(0) << "Engine of random number generator is undone to: "
    67       << RandomNumberGeneratorFactory::getInstance().getEngineName() << std::endl);
     89  DoLog(0) && (Log() << Verbose(0) << "Default random number engine is undone to: "
     90      << RandomNumberEngineFactory::getInstance().getCurrentTypeName() << std::endl);
    6891
    6992  return Action::state_ptr(newstate);
  • src/Actions/RandomNumbersAction/SetRandomNumbersEngineAction.def

    r081e5d r6ff0c8  
    1212// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1313// "undefine" if no parameters are required, use (NODEFAULT) for each (undefined) default value
    14 #define paramtypes (std::string)
    15 #define paramtokens ("set-random-number-engine")
    16 #define paramdescriptions ("name of the pseudo-random engine from boost::random")
    17 #undef paramdefaults
    18 #define paramreferences (engine_type)
     14#define paramtypes (std::string)(int)
     15#define paramtokens ("set-random-number-engine")("random-number-seed")
     16#define paramdescriptions ("name of the pseudo-random engine from boost::random")("seed of the pseudo-random number sequence")
     17#define paramdefaults (NODEFAULT)("-1")
     18#define paramreferences (engine_type)(seed)
    1919
    20 #define statetypes (std::string)
    21 #define statereferences (old_engine_type)
     20#define statetypes (std::string)(int)
     21#define statereferences (old_engine_type)(old_seed)
    2222
    2323// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/RandomNumbers/RandomNumberEngine.hpp

    r081e5d r6ff0c8  
    4343  virtual void seed(unsigned int _seed)=0;
    4444
     45  /** Getter for the generator's seed.
     46   *
     47   * @return _seed seed to set to
     48   */
     49  virtual unsigned int getseed() const = 0;
     50
    4551  /** Getter for smallest value the engine produces.
    4652   *
     
    7278   */
    7379  RandomNumberEngine() {};
    74 
    75   /** Getter for the generator's seed.
    76    *
    77    * @note is only used internally for unit test.
    78    *
    79    * @return _seed seed to set to
    80    */
    81   virtual unsigned int getseed() const = 0;
    8280};
    8381
  • src/RandomNumbers/RandomNumberEngineFactory.hpp

    r081e5d r6ff0c8  
    2727class RandomNumberEngine;
    2828class RandomNumberEngineFactoryUnitTest;
     29class CommandSetRandomNumbersEngineAction;
    2930
    3031/** This is the Prototype factory class for random number engines.
     
    4344  friend class Singleton<RandomNumberEngineFactory>;
    4445  friend class RandomNumberEngineFactoryTest;
     46  friend class CommandSetRandomNumbersEngineAction;
    4547
    4648protected:
  • src/RandomNumbers/RandomNumberEngineFactory.undef

    r081e5d r6ff0c8  
    11#ifdef RANDOMNUMBERENGINEFACTORY_DEF_
    22
     3#undef engine_seq
     4#undef engine_seq_a
    35#undef type_seq
    46#undef type_seq_size
Note: See TracChangeset for help on using the changeset viewer.