source: src/Bond/AdjacencyMatcher/Adjacency.hpp@ c66ae6

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 c66ae6 was c66ae6, checked in by Frederik Heber <heber@…>, 9 years ago

TESTFIX: Added AdjacencyMatcher to correctly compare .adj files in save-adjacency regression test.

  • GuiChecks sees a different (but still valid) ordering in the .adj file in the save-adjacency regression test.
  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Adjacency.hpp
3 *
4 * Created on: Jun 15, 2015
5 * Author: heber
6 */
7
8#ifndef ADJACENCY_HPP_
9#define ADJACENCY_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16#include <cassert>
17#include <iosfwd>
18#include <utility>
19#include <vector>
20
21namespace detail {
22
23struct Adjacency
24{
25 //!> typedef for the adjacency index type
26 typedef size_t index_t;
27
28 //!> typedef for the structure to store adjacency indices
29 typedef std::vector<index_t> indices_t;
30
31 //!> constant for invalid index
32 enum { INVALIDINDEX=-1 };
33
34 /** Constructor for struct adjacency.
35 *
36 */
37 Adjacency()
38 {}
39
40 /** Constructor for struct adjacency.
41 *
42 * \param _indices initial indices to set
43 */
44 Adjacency(const indices_t &_indices) :
45 indices(_indices)
46 {
47 if (!isSorted())
48 sortIndices();
49 }
50
51 /** Setter for the indices of the adjacency.
52 *
53 * \param _elements indices to be set (need not be sorted)
54 */
55 void set(const indices_t &_elements) {
56 indices = _elements;
57 if (!isSorted())
58 sortIndices();
59 }
60
61 /** Getter for the indices.
62 *
63 * \return set of sorted indices
64 */
65 const indices_t &get() const {
66 return indices;
67 }
68
69 /** Less comparator for adjacency, comparing indices.
70 *
71 * \return true - at least one index in this adjacency is smaller
72 */
73 bool operator<(const Adjacency &_other) const {
74 return indices < _other.indices;
75 }
76
77 /** Comparator for equivalence of adjacency.
78 *
79 * \return true - both index triples are the same
80 */
81 bool operator==(const Adjacency &_other) const {
82 return indices == _other.indices;
83 }
84
85 /** Comparator for non-equivalence of adjacency.
86 *
87 * \return true - both index triples are not the same
88 */
89 bool operator!=(const Adjacency &_other) const {
90 return !(*this == _other);
91 }
92
93private:
94 /** Sort the indices.
95 *
96 */
97 void sortIndices() {
98 std::sort(indices.begin(), indices.end());
99// if (indices[0] > indices[1]) {
100// if (indices[0] > indices[2])
101// std::swap(indices[0], indices[2]);
102// if (indices[0] > indices[1])
103// std::swap(indices[0], indices[1]);
104// } else {
105// // last element in between or up front?
106// if (indices[0] > indices[2]) {
107// std::swap(indices[1], indices[2]);
108// std::swap(indices[0], indices[1]);
109// } else
110// std::swap(indices[1], indices[2]);
111// }
112 assert( isSorted() );
113 }
114
115private:
116 /** Check whether indices are sorted.
117 *
118 * \return true - indices are sorted ascendingly
119 */
120 bool isSorted() const
121 {
122 bool status = true;
123 indices_t::const_iterator advancer = indices.begin();
124 indices_t::const_iterator iter = advancer++;
125 for (; advancer != indices.end(); iter = advancer++)
126 status &= *iter <= *advancer;
127 return status;
128 }
129
130private:
131 //!> fixed size array for containing indices
132 indices_t indices;
133};
134
135}; /* namespace detail */
136
137std::ostream& operator<<(std::ostream &_ost, const detail::Adjacency &_t) {
138 const detail::Adjacency::indices_t &indices = _t.get();
139 _ost << "[" << indices[0] << "," << indices[1] << "," << indices[2] << "]";
140 return _ost;
141}
142
143#endif /* ADJACENCY_HPP_ */
Note: See TracBrowser for help on using the repository browser.