source: src/Fragmentation/Summation/unittests/SubsetMapUnitTest.cpp@ e0ae58d

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 e0ae58d 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: 10.6 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * SubsetMapUnitTest.cpp
25 *
26 * Created on: Jul 3, 2012
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include "Fragmentation/Summation/SubsetMap.hpp"
42
43#include "SubsetMapUnitTest.hpp"
44
45#include <boost/assign.hpp>
46#include <boost/foreach.hpp>
47
48#include "CodePatterns/Assert.hpp"
49#include "CodePatterns/Log.hpp"
50#include "CodePatterns/Verbose.hpp"
51
52#ifdef HAVE_TESTRUNNER
53#include "UnitTestMain.hpp"
54#endif /*HAVE_TESTRUNNER*/
55
56using namespace boost::assign;
57
58/********************************************** Test classes **************************************/
59
60// Registers the fixture into the 'registry'
61CPPUNIT_TEST_SUITE_REGISTRATION( SubsetMapTest );
62
63
64void SubsetMapTest::setUp()
65{
66 // failing asserts should be thrown
67 ASSERT_DO(Assert::Throw);
68
69 setVerbosity(4);
70
71 allsets.reserve(5);
72 IndexSet tempset;
73 tempset += 1;
74 allsets += tempset;
75 tempset += 2;
76 allsets += tempset;
77 tempset.clear();
78 tempset += 3;
79 allsets += tempset;
80 tempset += 2;
81 allsets += tempset;
82 tempset += 4;
83 allsets += tempset;
84 tempset += 1;
85 allsets += tempset;
86 CPPUNIT_ASSERT_EQUAL( (size_t)6, allsets.size() );
87
88 SM = NULL;
89}
90
91
92void SubsetMapTest::tearDown()
93{
94 allsets.clear();
95 delete SM;
96}
97
98/** UnitTest for getNoPowerSets()
99 */
100void SubsetMapTest::getNoPowerSetsTest()
101{
102 CPPUNIT_ASSERT_EQUAL( (size_t)2, SubsetMap::getNoPowerSets(1) );
103 CPPUNIT_ASSERT_EQUAL( (size_t)4, SubsetMap::getNoPowerSets(2) );
104 CPPUNIT_ASSERT_EQUAL( (size_t)8, SubsetMap::getNoPowerSets(3) );
105 CPPUNIT_ASSERT_EQUAL( (size_t)16, SubsetMap::getNoPowerSets(4) );
106 CPPUNIT_ASSERT_EQUAL( (size_t)32, SubsetMap::getNoPowerSets(5) );
107 CPPUNIT_ASSERT_EQUAL( (size_t)64, SubsetMap::getNoPowerSets(6) );
108}
109
110
111/** UnitTest for getPowerSetIndex()
112 */
113void SubsetMapTest::getPowerSetIndexTest()
114{
115 // we just check here all subsets of order 4 "manually"
116 IndexSet_ptr ptr(new IndexSet(allsets.back()));
117 IndexSet tempset;
118 // subset order 4
119 CPPUNIT_ASSERT_EQUAL( (size_t)(0), SubsetMap::getPowerSetIndex(ptr, tempset));
120 tempset += 1;
121 CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
122 tempset += 2;
123 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2), SubsetMap::getPowerSetIndex(ptr, tempset));
124 tempset += 3;
125 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
126 tempset += 4;
127 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2 | 4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
128
129 // subset order 3
130 tempset.clear();
131 tempset += 2;
132 CPPUNIT_ASSERT_EQUAL( (size_t)(2), SubsetMap::getPowerSetIndex(ptr, tempset));
133 tempset += 3;
134 CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
135 tempset += 4;
136 CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
137
138 tempset.clear();
139 tempset += 1;
140// CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
141 tempset += 3;
142 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
143 tempset += 4;
144 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
145
146 tempset.clear();
147 tempset += 1;
148// CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
149 tempset += 2;
150 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2), SubsetMap::getPowerSetIndex(ptr, tempset));
151 tempset += 4;
152 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 2 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
153
154 // subset order 2
155 tempset.clear();
156 tempset += 1;
157// CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
158 tempset += 3;
159 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
160
161 tempset.clear();
162 tempset += 1;
163// CPPUNIT_ASSERT_EQUAL( (size_t)(1), SubsetMap::getPowerSetIndex(ptr, tempset));
164 tempset += 4;
165 CPPUNIT_ASSERT_EQUAL( (size_t)(1 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
166
167 tempset.clear();
168 tempset += 2;
169// CPPUNIT_ASSERT_EQUAL( (size_t)(2), SubsetMap::getPowerSetIndex(ptr, tempset));
170 tempset += 3;
171 CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 4), SubsetMap::getPowerSetIndex(ptr, tempset));
172
173 tempset.clear();
174 tempset += 2;
175// CPPUNIT_ASSERT_EQUAL( (size_t)(2), SubsetMap::getPowerSetIndex(ptr, tempset));
176 tempset += 4;
177 CPPUNIT_ASSERT_EQUAL( (size_t)(2 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
178
179 tempset.clear();
180 tempset += 3;
181 CPPUNIT_ASSERT_EQUAL( (size_t)(4), SubsetMap::getPowerSetIndex(ptr, tempset));
182 tempset += 4;
183 CPPUNIT_ASSERT_EQUAL( (size_t)(4 | 8), SubsetMap::getPowerSetIndex(ptr, tempset));
184
185 // subset order 1
186 tempset.clear();
187 tempset += 4;
188 CPPUNIT_ASSERT_EQUAL( (size_t)(8), SubsetMap::getPowerSetIndex(ptr, tempset));
189}
190
191/** UnitTest for getSubset()
192 */
193void SubsetMapTest::getSubsetTest()
194{
195 // we just check here all subsets of order 4 "manually"
196 IndexSet_ptr ptr(new IndexSet(allsets.back()));
197 IndexSet tempset;
198 // subset order 4
199 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(0) ));
200 tempset += 1;
201 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
202 tempset += 2;
203 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2) ));
204 tempset += 3;
205 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2 | 4) ));
206 tempset += 4;
207 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2 | 4 | 8) ));
208
209 // subset order 3
210 tempset.clear();
211 tempset += 2;
212 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2) ));
213 tempset += 3;
214 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 4) ));
215 tempset += 4;
216 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 4 | 8) ));
217
218 tempset.clear();
219 tempset += 1;
220// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
221 tempset += 3;
222 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 4) ));
223 tempset += 4;
224 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 4 | 8) ));
225
226 tempset.clear();
227 tempset += 1;
228// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
229 tempset += 2;
230// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2) ));
231 tempset += 4;
232 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 2 | 8) ));
233
234 // subset order 2
235 tempset.clear();
236 tempset += 1;
237// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
238 tempset += 3;
239// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 4) ));
240
241 tempset.clear();
242 tempset += 1;
243// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1) ));
244 tempset += 4;
245 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(1 | 8) ));
246
247 tempset.clear();
248 tempset += 2;
249// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2) ));
250 tempset += 3;
251// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 4) ));
252
253 tempset.clear();
254 tempset += 2;
255// CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2) ));
256 tempset += 4;
257 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(2 | 8) ));
258
259 tempset.clear();
260 tempset += 3;
261 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(4) ));
262 tempset += 4;
263 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(4 | 8) ));
264
265 // subset order 1
266 tempset.clear();
267 tempset += 4;
268 CPPUNIT_ASSERT_EQUAL( tempset, SubsetMap::getSubset(*ptr, (size_t)(8) ));
269}
270
271/** UnitTest for gatherSubset()
272 */
273void SubsetMapTest::gatherSubsetTest()
274{
275 /// we create a SubsetMap from an empty container
276 IndexSet tempset;
277 std::vector<IndexSet> sets;
278 sets.push_back(tempset);
279 tempset += 1;
280 sets.push_back(tempset);
281 tempset += 2;
282 sets.push_back(tempset);
283 tempset.clear();
284 tempset += 2;
285 sets.push_back(tempset);
286 IndexSetContainer container( sets );
287 // now we have {}, {1}, {2}, {1,2} in container
288
289 SM = new SubsetMap(container);
290 CPPUNIT_ASSERT( SM != NULL );
291 CPPUNIT_ASSERT_EQUAL( (size_t)4, SM->Lookup.size() );
292 const IndexSetContainer::Container_t &_container = container.getContainer();
293 for (IndexSetContainer::Container_t::const_iterator iter = _container.begin();
294 iter != _container.end(); ++iter) {
295 LOG(1, "INFO: Current set is " << **iter << ".");
296 SubsetMap::Lookup_t::const_iterator lookupiter = SM->Lookup.find(*iter);
297 CPPUNIT_ASSERT( lookupiter != SM->Lookup.end() );
298 CPPUNIT_ASSERT_EQUAL( lookupiter->second->getContainer().size(), SM->getSubsets(*iter)->getContainer().size() );
299 CPPUNIT_ASSERT_EQUAL( (size_t)(( 1 << (*iter)->size()) - 1), lookupiter->second->getContainer().size() );
300 }
301}
302
303/** UnitTest for getMaximumSetLevel()
304 */
305void SubsetMapTest::getMaximumSetLevelTest()
306{
307 // create small container
308 {
309 IndexSet tempset;
310 std::vector<IndexSet> sets;
311 sets.push_back(tempset);
312 tempset += 1;
313 sets.push_back(tempset);
314 tempset += 2;
315 sets.push_back(tempset);
316 tempset.clear();
317 tempset += 2;
318 sets.push_back(tempset);
319 IndexSetContainer container( sets );
320 // now we have {}, {1}, {2}, {1,2} in container
321
322 SM = new SubsetMap(container);
323 CPPUNIT_ASSERT( SM != NULL );
324
325 CPPUNIT_ASSERT_EQUAL( (size_t)2, SM->getMaximumSetLevel() );
326 // we are strictly the last set
327 CPPUNIT_ASSERT( SM->getMaximumSetLevel() == (--SM->Lookup.end())->first->size() );
328 }
329
330 // create larger container
331 {
332 IndexSetContainer container( allsets );
333 delete SM;
334 SM = new SubsetMap(container);
335 CPPUNIT_ASSERT( SM != NULL );
336
337 CPPUNIT_ASSERT_EQUAL( (size_t)4, SM->getMaximumSetLevel() );
338 CPPUNIT_ASSERT( SM->getMaximumSetLevel() == (--SM->Lookup.end())->first->size() );
339 }
340}
Note: See TracBrowser for help on using the repository browser.