source: src/Fragmentation/Summation/IndexSet.cpp@ 8eafd6

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests 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_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 FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes 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 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 8eafd6 was 146c26d, checked in by Frederik Heber <heber@…>, 12 years ago

Added class IndexSet and unit test.

  • IndexSet contains the set of indices identifying the subspace.
  • has member typedef ptr to shared_ptr.
  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011-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 * IndexSet.cpp
25 *
26 * Created on: Apr 24, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "IndexSet.hpp"
38
39#include <boost/foreach.hpp>
40
41/** Constructor for class IndexSet.
42 *
43 */
44IndexSet::IndexSet()
45{}
46
47/** Destructor for class IndexSet.
48 *
49 */
50IndexSet::~IndexSet()
51{
52 clear();
53}
54
55/** Operator for output to std::ostream operator of an IndexSet.
56 * @param ost output stream
57 * @param indexset index set to output
58 * @return ost output stream
59 */
60std::ostream & operator<<(std::ostream &ost, const IndexSet &indexset)
61{
62 ost << "{ ";
63 for (IndexSet::const_iterator iter = indexset.begin();
64 iter != indexset.end();
65 ++iter)
66 ost << *iter << " ";
67 ost << "}";
68 return ost;
69}
70
71/** Checks whether each index of _IndexSet is contained in this subspace:Indices.
72 *
73 * @param _indexset index set to check
74 * @return true - _index is contained, false - at least index is not contained
75 */
76bool IndexSet::contains(const IndexSet &_indexset) const
77{
78 BOOST_FOREACH(size_t index, _indexset) {
79 if (!contains(index)) { // index not present, then not contained
80 return false;
81 }
82 }
83 return true;
84}
85
86/** Checks whether index is contained in this IndexSet.
87 *
88 * @param _index index to check
89 * @return true - _index is contained, false - at least index is not contained
90 */
91bool IndexSet::contains(const Index_t _index) const
92{
93 const_iterator iter = find(_index);
94 if (iter == end()) { // index not present, then not contained
95 return false;
96 } else {
97 return true;
98 }
99}
100
101bool IndexSet::operator<(const IndexSet &b) const
102{
103 if (size() < b.size()) {
104 return true;
105 } else if (size() > b.size()) {
106 return false;
107 } else {
108 const_iterator this_iter = begin();
109 const_iterator b_iter = b.begin();
110 for (;(this_iter != end()) && (b_iter != b.end());
111 ++this_iter, ++b_iter) {
112 if (*this_iter < *b_iter) {
113 return true;
114 } else if (*this_iter > *b_iter) {
115 return false;
116 }
117 }
118 return false;
119 }
120}
121
122bool IndexSet::operator>(const IndexSet &b) const
123{
124 if (size() > b.size()) {
125 return true;
126 } else if (size() < b.size()) {
127 return false;
128 } else {
129 const_iterator this_iter = begin();
130 const_iterator b_iter = b.begin();
131 for (;(this_iter != end()) && (b_iter != b.end());
132 ++this_iter, ++b_iter) {
133 if (*this_iter > *b_iter) {
134 return true;
135 } else if (*this_iter < *b_iter) {
136 return false;
137 }
138 }
139 return false;
140 }
141}
142
143bool IndexSet::operator==(const IndexSet &b) const
144{
145 if (size() != b.size()) {
146 return false;
147 } else {
148 const_iterator this_iter = begin();
149 const_iterator b_iter = b.begin();
150 for (;(this_iter != end()) && (b_iter != b.end());
151 ++this_iter, ++b_iter) {
152 if (*this_iter != *b_iter) {
153 return false;
154 }
155 }
156 return true;
157 }
158}
159
Note: See TracBrowser for help on using the repository browser.