votca 2024.2-dev
Loading...
Searching...
No Matches
reducededge.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20// Standard includes
21#include <algorithm>
22#include <cassert>
23
24// Local VOTCA includes
26
27namespace votca {
28namespace tools {
29
30using namespace std;
31
46void moveVertexWithSmallestValueToEnds_(vector<Index>& vertices) {
47 vertices.pop_back();
48 vector<Index>::iterator starting_iterator = next(vertices.begin());
49 Index min_vertex_index =
50 min_element(starting_iterator, vertices.end()) - vertices.begin();
51 if (vertices.front() > vertices.at(min_vertex_index)) {
52 rotate(vertices.begin(), vertices.begin() + min_vertex_index,
53 vertices.end());
54 }
55 vertices.push_back(vertices.front());
56}
57
86bool verticesShouldBeReversed_(vector<Index>& vertices) {
87 size_t length = vertices.size();
88 size_t max_index = length / 2;
89 for (size_t index = 0; index < max_index; ++index) {
90 if (vertices.at(index) < vertices.at(length - 1 - index)) {
91 return false;
92 } else if (vertices.at(index) > vertices.at(length - 1 - index)) {
93 return true;
94 }
95 }
96 return false;
97}
98
99ReducedEdge::ReducedEdge(vector<Index> vertices) {
100 assert(vertices.size() >= 2 &&
101 "Edge vertices must consist of at least two vertices.");
102 // Smallest value always placed at the front of the vector
103
104 // If we have a loop will arange the edge so that the smallest valued vertex
105 // sits at both ends
106 if (vertices.back() == vertices.front() && vertices.size() > 2) {
108 }
109
110 if (verticesShouldBeReversed_(vertices)) {
111 reverse(vertices.begin(), vertices.end());
112 }
113 vertices_ = vertices;
114}
115
116vector<Edge> ReducedEdge::expand() const {
117 vector<Edge> edges;
118 for (size_t index = 0; index < (vertices_.size() - 1); ++index) {
119 Edge ed(vertices_.at(index), vertices_.at(index + 1));
120 edges.push_back(ed);
121 }
122 return edges;
123}
124
125bool ReducedEdge::vertexExistInChain(const int& vertex) const {
126 vector<Index>::const_iterator vertex_iterator =
127 find(vertices_.begin(), vertices_.end(), vertex);
128 return vertex_iterator != vertices_.end();
129}
130
131bool ReducedEdge::operator==(const ReducedEdge& edge) const {
132 if (edge.vertices_.size() != vertices_.size()) {
133 return false;
134 }
135 for (size_t index = 0; index < vertices_.size(); ++index) {
136 if (vertices_.at(index) != edge.vertices_.at(index)) {
137 return false;
138 }
139 }
140 return true;
141}
142
143bool ReducedEdge::operator!=(const ReducedEdge& edge) const {
144 return !(*this == edge);
145}
146
147bool ReducedEdge::operator<(const ReducedEdge& edge) const {
148 if (this->vertices_.front() < edge.vertices_.front()) {
149 return true;
150 }
151 if (this->vertices_.front() > edge.vertices_.front()) {
152 return false;
153 }
154 if (this->vertices_.back() < edge.vertices_.back()) {
155 return true;
156 }
157 if (vertices_.size() < edge.vertices_.size()) {
158 return true;
159 }
160 for (size_t index = 0; index < vertices_.size(); ++index) {
161 if (vertices_.at(index) > edge.vertices_.at(index)) {
162 return false;
163 }
164 }
165 if (*this == edge) {
166 return false;
167 }
168 return true;
169}
170
171bool ReducedEdge::operator<=(const ReducedEdge& edge) const {
172 return (*this < edge || *this == edge);
173}
174
175bool ReducedEdge::operator>(const ReducedEdge& edge) const {
176 return !(*this <= edge);
177}
178
179bool ReducedEdge::operator>=(const ReducedEdge& edge) const {
180 return !(*this < edge);
181}
182
183ostream& operator<<(ostream& os, const ReducedEdge& edge) {
184 os << "Vertices" << endl;
185 for (auto vertex : edge.vertices_) {
186 os << vertex << " ";
187 }
188 os << endl;
189 return os;
190}
191} // namespace tools
192} // namespace votca
Connects to vertices.
Definition edge.h:42
std::vector< Index > vertices_
Definition edge.h:44
Connects two vertices, also stores the vertices between the endpoints.
Definition reducededge.h:49
bool operator!=(const ReducedEdge &edge) const
Checks if Edges are not equivalent.
std::vector< Edge > expand() const
Method expands the edge into its parts.
bool operator>=(const ReducedEdge &edge) const
bool vertexExistInChain(const int &vertex) const
Provided a vertex this method will determine if it exists within the reduced edge.
bool operator==(const ReducedEdge &edge) const
Checks if Edges are equivalent.
bool operator<=(const ReducedEdge &edge) const
bool operator>(const ReducedEdge &edge) const
bool operator<(const ReducedEdge &edge) const
STL namespace.
std::ostream & operator<<(std::ostream &out, const Correlate &c)
Definition correlate.h:53
bool verticesShouldBeReversed_(vector< Index > &vertices)
void moveVertexWithSmallestValueToEnds_(vector< Index > &vertices)
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26