source: src/Fragmentation/Summation/SubsetMap.hpp@ 336da8

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator 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_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 336da8 was 19c50e, checked in by Frederik Heber <heber@…>, 12 years ago

IndexSetContainer now treats super set specially.

  • The super set must not gather its subsets via the gatherSubsets() as by construction all other sets are its subsets! As the super set is very large the power set way is no good idea.
  • added default cstor for SortedVector
  • removed SubsetMap::getMaximumSubsetLevel() as is replaced by ::getMaximumSetLevel() which is the level to sum up to.
  • changed all uses of getMaximumSubsetLevel() to getMaximumSetLevel().
  • TESTFIX: Changed unit test function on getMaximumSubsetLevel() to check on getMaximumSetLevel()
  • removed OrthogonalFullSummator as is fully replacable by OrthogonalSummator.
  • changed IndexSetContainer::createSuperSet a bit.
  • IndexSetContainer::AllIndices is now no more static convenience entity but truely contains the super set (non-statically). ::createSuperSet() is for convenience to be called in cstor for AllIndices.
  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * SubsetMap.hpp
3 *
4 * Created on: Jul 3, 2012
5 * Author: heber
6 */
7
8#ifndef SUBSETMAP_HPP_
9#define SUBSETMAP_HPP_
10
11
12// include config.h
13#ifdef HAVE_CONFIG_H
14#include <config.h>
15#endif
16
17#include <boost/shared_ptr.hpp>
18#include <map>
19
20#include "CodePatterns/Assert.hpp"
21
22#include "IndexSetContainer.hpp"
23
24class SubsetMapTest;
25
26/** A SubsetMap is a map containing shared_ptr of IndexSet instances that knows
27 * about which set is contained in which for fast lookup for SubsetValues.
28 */
29class SubsetMap
30{
31 //!> grant unit test access
32 friend class SubsetMapTest;
33public:
34 //!> typedef for wrapping an instance in a shared_ptr
35 typedef boost::shared_ptr<SubsetMap> ptr;
36
37 /** Constructor for SubsetMap that creates the internal map from IndexSet to a
38 * container with all contained sets.
39 *
40 * To this end, we first put each IndexSet in a multimap from size to IndexSet.
41 * Then we go "level-wise" from low to high through this map and use gatherSubsets()
42 * on each set as we are then sure that all contained subsets have already been
43 * initialized.
44 *
45 * @param _container container with IndexSet
46 */
47 SubsetMap(IndexSetContainer &_container);
48
49 /** Getter for all subsets of set \a ptr.
50 *
51 * @param ptr IndexSet
52 * @return IndexSetContainer with all contained sets
53 */
54 IndexSetContainer::ptr & getSubsets(const IndexSet_ptr &ptr) {
55 Lookup_t::iterator lookupiter = Lookup.find(ptr);
56 ASSERT(lookupiter != Lookup.end(),
57 "SubsetMap::getSubsets() - the set "+toString(*ptr)+" is not in the Lookup.");
58 return lookupiter->second;
59 }
60
61 /** Returns the size of the largest set.
62 *
63 * @return number of indices in largest set
64 */
65 size_t getMaximumSetLevel() const;
66
67private:
68 /** Private function to fill the internal Lookup for a given IndexSet \a ptr.
69 *
70 * @param ptr IndexSet
71 */
72 void gatherSubsets(const IndexSet_ptr &ptr);
73
74 /** Returns the index of \a subset in the power subsets of \a ptr.
75 *
76 * @param ptr set to check
77 * @param subset subset whose lexicographical position to find in \a ptr
78 * @return index of this subset
79 */
80 static const size_t getPowerSetIndex(const IndexSet_ptr &ptr, const IndexSet &subset);
81
82 /** Returns the number of power subsets for a given set size.
83 *
84 * @param SetSize size of the set
85 * @return possible number of true subsets
86 */
87 static size_t getNoPowerSets(const size_t SetSize) {
88 return (1 << SetSize);
89 }
90
91 /** Returns the subset for a given \a _set by its power set index \a PowerSetNo.
92 *
93 * The idea is that each bit in \a PowerSetNo encodes whether the Index at the
94 * position in the set is to appear in the subset or not. Hence, we use std::bitset
95 * to construct the bit representation from \a PowerSetNo and then go through each
96 * bit and either insert into the subset or not.
97 *
98 * @param _set index set
99 * @param PowerSetNo subset index
100 * @return specific power set subset given by the index
101 */
102 static IndexSet getSubset(const IndexSet &_set, size_t PowerSetNo);
103
104private:
105 //!> enumeration of states whether a subset is contained or not
106 enum ContainedState {
107 NotContained = 0,
108 Contained = 1,
109 };
110
111 //!> temporary IndexSet_ptr
112 IndexSet_ptr tempset;
113 //!> enumeration trick to define a maximum subset size
114 enum {MAX_SETSIZE = 32};
115 //!> typedef for the specific map from IndexSet to all contained IndexSets
116 typedef std::map< IndexSet_ptr, IndexSetContainer::ptr,
117 IndexSetContainer::Comparator_t> Lookup_t;
118 Lookup_t Lookup;
119};
120
121#endif /* SUBSETMAP_HPP_ */
Note: See TracBrowser for help on using the repository browser.