votca 2024.2-dev
Loading...
Searching...
No Matches
graph_bf_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// Local VOTCA includes
22#include "votca/tools/edge.h"
23#include "votca/tools/graph.h"
25
26using namespace std;
27
28namespace votca {
29namespace tools {
30
31bool Graph_BF_Visitor::queEmpty() const { return edge_que_.empty(); }
32
34 Edge oldest_edge = edge_que_.at(0).front();
35 edge_que_.at(0).pop();
36 if (edge_que_.at(0).size() == 0) {
37 edge_que_.pop_front();
38 }
39 return oldest_edge;
40}
41
42// Add edges to be explored
43void Graph_BF_Visitor::addEdges_(const Graph &graph, Index vertex) {
44
45 vector<Edge> newest_edges = graph.getNeighEdges(vertex);
46
47 // If first edges to be added
48 if (edge_que_.empty()) {
49 queue<Edge> first_edge_queue;
50 for (const Edge &edge : newest_edges) {
51 Index neigh_vert = edge.getOtherEndPoint(vertex);
52 if (explored_.count(neigh_vert) == 0) {
53 first_edge_queue.push(edge);
54 }
55 }
56 if (!first_edge_queue.empty()) {
57 edge_que_.push_back(first_edge_queue);
58 }
59 } else {
60
61 if (edge_que_.size() == 1) {
62 queue<Edge> new_edge_queue;
63 for (const Edge &edge : newest_edges) {
64 Index neigh_vert = edge.getOtherEndPoint(vertex);
65 if (explored_.count(neigh_vert) == 0) {
66 new_edge_queue.push(edge);
67 }
68 }
69 if (!new_edge_queue.empty()) {
70 edge_que_.push_back(new_edge_queue);
71 }
72 } else {
73 for (const Edge &edge : newest_edges) {
74 Index neigh_vert = edge.getOtherEndPoint(vertex);
75 if (explored_.count(neigh_vert) == 0) {
76 edge_que_.at(1).push(edge);
77 }
78 }
79 }
80 }
81}
82} // namespace tools
83} // namespace votca
Connects to vertices.
Definition edge.h:42
std::set< Index > explored_
set containing all the vertix ids that have been explored
std::deque< std::queue< Edge > > edge_que_
void addEdges_(const Graph &graph, 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