Changeset 34af97 for src/Fragmentation
- Timestamp:
- Sep 9, 2016, 1:51:36 PM (8 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, 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_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fixes, 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, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, 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
- Children:
- 61fc12
- Parents:
- 9bdbc7
- git-author:
- Frederik Heber <heber@…> (09/01/16 20:31:45)
- git-committer:
- Frederik Heber <heber@…> (09/09/16 13:51:36)
- Location:
- src/Fragmentation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/KeySetsContainer.cpp
r9bdbc7 r34af97 42 42 #include <boost/tokenizer.hpp> 43 43 44 #include "CodePatterns/Assert.hpp" 44 45 #include "CodePatterns/Log.hpp" 45 46 … … 247 248 void KeySetsContainer::insert(const KeySetsContainer &other) 248 249 { 249 KeySets.reserve(KeySets.size()+other.KeySets.size()); 250 AtomCounter.reserve(AtomCounter.size()+other.AtomCounter.size()); 251 for (ArrayOfIntVectors::const_iterator iter = other.KeySets.begin(); 252 iter != other.KeySets.end(); ++iter) 253 insert(*iter, iter->size()); 250 // append sets and their atom count 251 KeySets.insert(KeySets.end(), other.KeySets.begin(), other.KeySets.end()); 252 AtomCounter.insert(AtomCounter.end(), other.AtomCounter.begin(), other.AtomCounter.end()); 253 254 // ASSUME: that the fragments inside other are number consecutively 255 256 // find the smallest number 257 int smallest_index = std::numeric_limits<int>::max(); 258 for(size_t i=0;i<other.OrderSet.size();++i) 259 for(IntVector::const_iterator iter = other.OrderSet[i].begin(); 260 iter != other.OrderSet[i].end(); ++iter) 261 smallest_index = std::min(smallest_index, (*iter)); 262 263 // renumber incoming fragments and insert into OrderSets 264 int nr_fragments = 0; 265 for(size_t i=0;i<other.OrderSet.size();++i) { 266 for(IntVector::const_iterator iter = other.OrderSet[i].begin(); 267 iter != other.OrderSet[i].end(); ++iter) { 268 if (i >= OrderSet.size() ) 269 OrderSet.resize(i+1); 270 OrderSet[i].push_back((*iter)+FragmentCounter-smallest_index); 271 if (i >= FragmentsPerOrder.size()) 272 FragmentsPerOrder.resize(i+1); 273 ++(FragmentsPerOrder[i]); 274 } 275 nr_fragments += other.OrderSet[i].size(); 276 } 277 Order = std::max(Order, other.Order); 278 // the following assert must not necessarily be true because of cycles: 279 // Order 4 with added cycles is still order 4. 280 //ASSERT( Order == (int)OrderSet.size(), 281 // "KeySetsContainer::insert() - order not max of either container?"); 282 FragmentCounter += nr_fragments; 254 283 } 255 284 -
src/Fragmentation/unittests/KeySetsContainerUnitTest.cpp
r9bdbc7 r34af97 43 43 #include <boost/archive/text_iarchive.hpp> 44 44 45 #include <boost/assign.hpp> 46 45 47 #include "Fragmentation/KeySetsContainer.hpp" 46 48 … … 50 52 #include "UnitTestMain.hpp" 51 53 #endif /*HAVE_TESTRUNNER*/ 54 55 using namespace boost::assign; 52 56 53 57 /********************************************** Test classes **************************************/ … … 105 109 delete Keys2; 106 110 }; 111 112 static void fillKeySetsContainer(KeySetsContainer *_Keys) 113 { 114 // insert keysets 115 KeySetsContainer::IntVector keyset; 116 keyset += 1; 117 _Keys->KeySets.push_back(keyset); 118 keyset += 2; 119 _Keys->KeySets.push_back(keyset); 120 keyset += 3; 121 _Keys->KeySets.push_back(keyset); 122 // insert number of keys per keyset 123 _Keys->AtomCounter += 1,2,3; 124 // insert total number of keysets/fragments 125 _Keys->FragmentCounter = 3; 126 // insert maximum number of keys over all contained keysets 127 _Keys->Order = 3; 128 // insert number of keysets with the same number of keys 129 _Keys->FragmentsPerOrder += 1,1,1; 130 // insert keyset index in keysets per same number of keys 131 _Keys->OrderSet.resize(3); 132 _Keys->OrderSet[0] = KeySetsContainer::IntVector(1, 0); 133 _Keys->OrderSet[1] = KeySetsContainer::IntVector(1, 1); 134 _Keys->OrderSet[2] = KeySetsContainer::IntVector(1, 2); 135 } 136 137 /** UnitTest for insert() into an empty container 138 */ 139 void KeySetsContainerTest::insertIntoEmptyTest() 140 { 141 // fill other container 142 KeySetsContainer *Keys2 = new KeySetsContainer(); 143 fillKeySetsContainer(Keys2); 144 145 // insert filled one (Keys2) into empty (Keys) 146 Keys->insert(*Keys2); 147 148 CPPUNIT_ASSERT (*Keys == *Keys2); 149 150 delete Keys2; 151 } 152 153 /** UnitTest for insert() empty into a filled container 154 */ 155 void KeySetsContainerTest::insertEmptyIntoTest() 156 { 157 // fill other container 158 KeySetsContainer *Keys2 = new KeySetsContainer(); 159 fillKeySetsContainer(Keys2); 160 161 // create result container (we know this works from insertIntoEmptyTest()) 162 KeySetsContainer *resultKeys = new KeySetsContainer(); 163 resultKeys->insert(*Keys2); 164 165 // fill empty (Keys) into filled oned (Keys2) 166 Keys2->insert(*Keys); 167 168 // create empty for comparison 169 KeySetsContainer *emptyKeys = new KeySetsContainer(); 170 171 CPPUNIT_ASSERT (*Keys2 == *resultKeys); 172 CPPUNIT_ASSERT (*Keys == *emptyKeys); 173 174 delete Keys2; 175 delete resultKeys; 176 delete emptyKeys; 177 } 178 179 /** UnitTest for insert() smaller filled into another filled container 180 */ 181 void KeySetsContainerTest::insertSmallerIntoTest() 182 { 183 // fill other container 184 KeySetsContainer *Keys2 = new KeySetsContainer(); 185 fillKeySetsContainer(Keys2); 186 187 // fill Keys, too 188 { 189 KeySetsContainer::IntVector keyset; 190 keyset += 2; 191 Keys->KeySets.push_back(keyset); 192 // insert number of keys per keyset 193 Keys->AtomCounter += 1; 194 // insert total number of keysets/fragments 195 Keys->FragmentCounter = 1; 196 // insert maximum number of keys over all contained keysets 197 Keys->Order = 1; 198 // insert number of keysets with the same number of keys 199 Keys->FragmentsPerOrder += 1; 200 // insert keyset index in keysets per same number of keys 201 Keys->OrderSet.resize(1); 202 Keys->OrderSet[0] = KeySetsContainer::IntVector(1, 0); 203 } 204 205 // create comparison container 206 KeySetsContainer *resultKeys = new KeySetsContainer(); 207 { 208 fillKeySetsContainer(resultKeys); 209 KeySetsContainer::IntVector keyset; 210 keyset += 2; 211 resultKeys->KeySets.push_back(keyset); 212 resultKeys->AtomCounter += 1; 213 resultKeys->FragmentCounter = 4; 214 resultKeys->Order = 3; 215 resultKeys->FragmentsPerOrder[0] = 2; 216 CPPUNIT_ASSERT( resultKeys->OrderSet.size() == (size_t)3 ); 217 resultKeys->OrderSet[0] += 3; 218 } 219 220 // insert smaller into larger one 221 Keys2->insert(*Keys); 222 223 CPPUNIT_ASSERT (*Keys != *Keys2); 224 CPPUNIT_ASSERT (*resultKeys == *Keys2); 225 226 delete Keys2; 227 delete resultKeys; 228 } 229 230 /** UnitTest for insert() larger filled into another filled container 231 */ 232 void KeySetsContainerTest::insertLargerIntoTest() 233 { 234 // fill other container 235 KeySetsContainer *Keys2 = new KeySetsContainer(); 236 fillKeySetsContainer(Keys2); 237 238 // fill Keys, too 239 { 240 KeySetsContainer::IntVector keyset; 241 keyset += 2; 242 Keys->KeySets.push_back(keyset); 243 // insert number of keys per keyset 244 Keys->AtomCounter += 1; 245 // insert total number of keysets/fragments 246 Keys->FragmentCounter = 1; 247 // insert maximum number of keys over all contained keysets 248 Keys->Order = 1; 249 // insert number of keysets with the same number of keys 250 Keys->FragmentsPerOrder += 1; 251 // insert keyset index in keysets per same number of keys 252 Keys->OrderSet.resize(1); 253 Keys->OrderSet[0] = KeySetsContainer::IntVector(1, 0); 254 } 255 256 // create comparison container 257 KeySetsContainer *resultKeys = new KeySetsContainer(); 258 { 259 // we know this works from insertIntoEmptyTest() 260 resultKeys->insert(*Keys); 261 // add larger keysets 262 fillKeySetsContainer(resultKeys); 263 264 resultKeys->AtomCounter.clear(); 265 resultKeys->AtomCounter += 1,1,2,3; 266 resultKeys->FragmentCounter = 4; 267 resultKeys->FragmentsPerOrder.clear(); 268 resultKeys->FragmentsPerOrder += 2,1,1; 269 resultKeys->OrderSet.clear(); 270 resultKeys->OrderSet.resize(3); 271 resultKeys->OrderSet[0] = KeySetsContainer::IntVector(1, 0); 272 resultKeys->OrderSet[0] += 1; 273 resultKeys->OrderSet[1] = KeySetsContainer::IntVector(1, 2); 274 resultKeys->OrderSet[2] = KeySetsContainer::IntVector(1, 3); 275 } 276 277 // insert larger into smaller one 278 Keys->insert(*Keys2); 279 280 CPPUNIT_ASSERT (*Keys != *Keys2); 281 CPPUNIT_ASSERT (*resultKeys == *Keys); 282 283 delete Keys2; 284 delete resultKeys; 285 } -
src/Fragmentation/unittests/KeySetsContainerUnitTest.hpp
r9bdbc7 r34af97 26 26 CPPUNIT_TEST ( EqualityTest ); 27 27 CPPUNIT_TEST ( SerializationTest ); 28 CPPUNIT_TEST ( insertIntoEmptyTest ); 29 CPPUNIT_TEST ( insertEmptyIntoTest ); 30 CPPUNIT_TEST ( insertSmallerIntoTest ); 31 CPPUNIT_TEST ( insertLargerIntoTest ); 28 32 CPPUNIT_TEST_SUITE_END(); 29 33 … … 33 37 void EqualityTest(); 34 38 void SerializationTest(); 39 void insertIntoEmptyTest(); 40 void insertEmptyIntoTest(); 41 void insertSmallerIntoTest(); 42 void insertLargerIntoTest(); 35 43 36 44 private:
Note:
See TracChangeset
for help on using the changeset viewer.