source: src/IdPool.hpp@ 5eaa23

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 5eaa23 was b97a60, checked in by Frederik Heber <heber@…>, 13 years ago

Modified IdPool implementation to give either unique or continuous ids.

  • added two class uniqueId and continuousId that get the id type via a template and contain a getNextId_impl(). Also, contains typedef is is_IdPool_trait:
    • uniqueId always return a greater id.
    • continuousId implements the old way.
  • IdPool is now based on two templates, the second is the template that is inherited and its contained function used in getNextId().
  • for atoms the id is the sole identifier for which we can guarantee uniqueness. For molecules uniqueness does not make sense.
  • updated World's documentation on its id pools.
  • TESTFIX: Filling/FillVoidWithMolecule - both changed because the order of the ids has changed. In one case the bonding id flipped, in the other one atom changed places in .xyz file. (Actually, it's surprising that this is the only glitch occuring due to the changing of the id policy).
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * IdPool.hpp
3 *
4 * This is completely based on the work of Till Crueger, factored out from
5 * World.cpp/hpp.
6 *
7 * Created on: Dec 23, 2011
8 * Author: heber
9 */
10
11#ifndef IDPOOL_HPP_
12#define IDPOOL_HPP_
13
14// include config.h
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19#include <set>
20
21#include "CodePatterns/Range.hpp"
22
23/** This class represents a pool of id that can be defragmented.
24 *
25 * This is templated to have whatever pool size (depending on the variable
26 * that stores the id).
27 *
28 * Note that the external class \a idpolicy decides upon how the next id is
29 * produced, \sa IdPool_policy.hpp.
30 */
31template <class T, class idpolicy>
32class IdPool : public idpolicy {
33 // when trait is not of correct type this will produce an error
34 typedef typename idpolicy::is_IdPool_policy check_for_IdPool_trait;
35public:
36 /** Constructor for class IdPool.
37 *
38 * @param _currId initial id
39 * @param _max_skips max skips before we really defragment
40 * @param _max_size max size of distinct id ranges before we really defragment
41 */
42 IdPool(const T _currId, const unsigned int _max_skips, const unsigned int _max_size);
43
44 /** Destructor for class IdPool.
45 *
46 */
47 ~IdPool();
48
49 /** Reserves a specific \a id.
50 *
51 * @param id which id to reserve
52 * @return true - \a id is reserved, false - \a id is already taken
53 */
54 bool reserveId(T id);
55
56 /** Release a reserved \a id.
57 *
58 * @param id id to release
59 */
60 void releaseId(T id);
61
62 /** Returns the next available id.
63 *
64 * @return free id that is reserved
65 */
66 T getNextId();
67
68private:
69 enum Actions {
70 release,
71 reserve,
72 NoAction
73 };
74
75 /** Sets the last action.
76 *
77 * This also increases IdPool::numAtomDefragSkips when we switch from one
78 * Action to another.
79 *
80 * @param _action new last action to set
81 */
82 void setLastAction(const enum Actions _action)
83 {
84 if (_action != lastAction)
85 ++numDefragSkips;
86 lastAction = _action;
87 }
88
89 //!> contains the last action such that skip counter is only increased when we switch
90 enum Actions lastAction;
91
92private:
93 /** Defragment the id pool.
94 *
95 * It is up to this function whether we really defrag or not.
96 *
97 */
98 void defragIdPool();
99
100private:
101 //!> internal typedef for the pool
102 typedef std::set<range<T> > IdPool_t;
103
104 //!> the id pool
105 IdPool_t pool;
106
107 //!> stores the next highest Id for atoms. This is the last resort of there is no pool.
108 T currId;
109
110 //!> size of the pool after last defrag, to skip some defrags
111 size_t lastPoolSize;
112
113 //!> current number of skips
114 unsigned int numDefragSkips;
115
116 //!> threshold after how many skips we reall defrag
117 const unsigned int MAX_FRAGMENTATION_SKIPS;
118
119 //!> threshold of how large the number of distinct ranges is before we defrag
120 const unsigned int MAX_POOL_FRAGMENTATION;
121
122};
123
124#endif /* IDPOOL_HPP_ */
Note: See TracBrowser for help on using the repository browser.