votca 2024-dev
Loading...
Searching...
No Matches
graphdistvisitor.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"
27
28using namespace std;
29
30namespace votca {
31namespace tools {
32
33// Add the distance to the node that has not yet been explored
34void GraphDistVisitor::exploreNode(pair<Index, GraphNode>& p_gn, Graph& g,
35 Edge ed) {
36 // Determine if the node has already been explored
37 Index vertex = p_gn.first;
38 if (vertex == startingVertex_) {
39 p_gn.second.int_vals_["Dist"] = 0;
40 p_gn.second.initStringId_();
41 // Update the graph with new graph node
42 g.setNode(p_gn);
43 } else {
44 // Node has not been explored
45 if (explored_.count(vertex) == 0) {
46 Index prev_vertex = ed.getOtherEndPoint(vertex);
47 GraphNode gn_prev = g.getNode(prev_vertex);
48 p_gn.second.int_vals_["Dist"] = gn_prev.int_vals_["Dist"] + 1;
49 p_gn.second.initStringId_();
50 g.setNode(p_gn);
51 }
52 }
53 // Ensure the graph node is set to explored
55}
56} // namespace tools
57} // namespace votca
Connects to vertices.
Definition edge.h:42
Index getOtherEndPoint(Index ver) const
Given one of the integers in the edge the other will be output.
Definition edge.cc:37
void exploreNode(std::pair< Index, GraphNode > &p_gn, Graph &g, Edge ed=DUMMY_EDGE) override
A graph node that will take a variety of different values.
Definition graphnode.h:46
std::unordered_map< std::string, Index > int_vals_
Definition graphnode.h:49
Index startingVertex_
The vertex the visitor started on.
virtual void exploreNode(std::pair< Index, GraphNode > &vertex_and_node, Graph &graph, Edge edge=DUMMY_EDGE)
Edge(0,0) is a dummy value.
std::set< Index > explored_
set containing all the vertix ids that have been explored
GraphNode getNode(const Index vertex) const
Return a copy of the graph node at vertex 'vert'.
Definition graph.cc:97
void setNode(Index vertex, GraphNode &graph_node)
set the Node associated with vertex 'vert'
Definition graph.cc:87
STL namespace.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26