votca 2024.2-dev
Loading...
Searching...
No Matches
graph_df_visitor.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
23// Local VOTCA includes
24#include "votca/tools/edge.h"
25#include "votca/tools/graph.h"
28
29using namespace std;
30
31namespace votca {
32namespace tools {
33
34bool Graph_DF_Visitor::queEmpty() const { return edge_list_.empty(); }
35
37 Edge ed = edge_list_.back();
38 edge_list_.pop_back();
39 return ed;
40}
41
42// Add edges to be explored
43void Graph_DF_Visitor::addEdges_(const Graph& g, Index vertex) {
44 auto eds = g.getNeighEdges(vertex);
45 if (edge_list_.empty()) {
46 // If first edges to be added
47 for (auto ed : eds) {
48 Index neigh_vert = ed.getOtherEndPoint(vertex);
49 if (explored_.count(neigh_vert) == 0) {
50 edge_list_.push_back(ed);
51 }
52 }
53 } else {
54 for (const auto& ed : eds) {
55 Index neigh_vert = ed.getOtherEndPoint(vertex);
56 if (explored_.count(neigh_vert) == 0) {
57 edge_list_.push_back(ed);
58 } else {
59 // Check if edge has already been added earlier in the queue
60 // if so we wil move it to the end
61 list<Edge>::iterator edge_found_iterator =
62 find(edge_list_.begin(), edge_list_.end(), ed);
63 if (edge_found_iterator != edge_list_.end()) {
64 // Move the edge to the back if it was stored earlier on.
65 edge_list_.splice(edge_list_.end(), edge_list_, edge_found_iterator);
66 }
67 }
68 }
69 }
70}
71} // namespace tools
72} // namespace votca
Connects to vertices.
Definition edge.h:42
std::set< Index > explored_
set containing all the vertix ids that have been explored
void addEdges_(const Graph &g, Index vertex) override
std::vector< Edge > getNeighEdges(Index vertex) const
Returns all the edges in the graph connected to vertex vertex
Definition graph.h:106
STL namespace.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26