votca 2024-dev
Loading...
Searching...
No Matches
graphalgorithm.h
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#ifndef VOTCA_TOOLS_GRAPHALGORITHM_H
21#define VOTCA_TOOLS_GRAPHALGORITHM_H
22
23// Standard includes
24#include <memory>
25#include <string>
26
27// Local VOTCA includes
28#include "graphnode.h"
29#include "reducedgraph.h"
30
38namespace votca {
39namespace tools {
40
41class Graph;
42class GraphVisitor;
43
57bool singleNetwork(Graph& graph, GraphVisitor& graph_visitor);
58
96std::set<Edge> exploreBranch(Graph g, Index starting_vertex, const Edge& edge);
97
123ReducedGraph reduceGraph(Graph graph);
124
154std::vector<Graph> decoupleIsolatedSubGraphs(Graph graph);
155
167void exploreGraph(Graph& graph, GraphVisitor& graph_visitor);
168
180template <typename GV>
181std::string findStructureId(Graph& graph) {
182
183 // Determine the highest degree in the graph
184 Index maxD = graph.getMaxDegree();
185 // Get the vertices with this degree
186 std::vector<Index> vertices = graph.getVerticesDegree(maxD);
187
188 // Get the nodes and determine which node has the greatest stringID
189 // When compared using compare function
190 std::string str_id = "";
191 std::vector<Index> graph_node_ids;
192 for (const Index& vertex : vertices) {
193 GraphNode graph_node = graph.getNode(vertex);
194 Index comp_int = str_id.compare(graph_node.getStringId());
195 if (comp_int > 0) {
196 str_id = graph_node.getStringId();
197 graph_node_ids.clear();
198 graph_node_ids.push_back(vertex);
199 } else if (comp_int == 0) {
200 graph_node_ids.push_back(vertex);
201 }
202 }
203 // If the str_id is empty it means the nodes are empty and we will
204 // simply have to rely on the degree to choose the vertices to explore from
205 if (str_id.compare("") == 0) {
206 graph_node_ids = vertices;
207 }
208 // If two or more graph nodes are found to be equal then
209 // they must all be explored
210 std::string chosenId = "";
211 Graph graph_chosen = graph;
212
213 for (const Index& vertex : graph_node_ids) {
214 GV graph_visitor;
215 graph_visitor.setStartingVertex(vertex);
216 Graph graph_temp = graph;
217 exploreGraph(graph_temp, graph_visitor);
218 std::string temp_struct_id = graph_temp.getId();
219 if (chosenId.compare(temp_struct_id) < 0) {
220 chosenId = temp_struct_id;
221 graph_chosen = graph_temp;
222 }
223 }
224
225 graph = graph_chosen;
226 return chosenId;
227}
228} // namespace tools
229} // namespace votca
230
231#endif // VOTCA_TOOLS_GRAPHALGORITHM_H
A graph node that will take a variety of different values.
Definition graphnode.h:46
std::string getStringId() const
Get the string id unique to the contents of the graph node.
Definition graphnode.h:74
Index getMaxDegree() const
Finds the max degree of a vertex in the graph.
Definition graph.h:120
GraphNode getNode(const Index vertex) const
Return a copy of the graph node at vertex 'vert'.
Definition graph.cc:97
virtual std::vector< Index > getVerticesDegree(Index degree) const
Returns all the vertices with degree specified by degree
Definition graph.cc:162
std::string getId() const
Returns the id of graph.
Definition graph.h:100
ReducedGraph reduceGraph(Graph graph)
Will take a graph and reduce it, by removing all vertices with degree of 2.
bool singleNetwork(Graph &graph, GraphVisitor &graph_visitor)
Determine if every vertex is connected to every other one through some combination of edges.
std::set< Edge > exploreBranch(Graph g, Index starting_vertex, const Edge &edge)
Explore one of the branches if exploration is initiated at vertex starting_vertex.
std::string findStructureId(Graph &graph)
Find a unique identifier that describes graph structure.
std::vector< Graph > decoupleIsolatedSubGraphs(Graph graph)
Break graph into smaller graph instances if the network is made up of isolated sub networks.
void exploreGraph(Graph &graph, GraphVisitor &graph_visitor)
Explore a graph with a graph visitor.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26