votca 2024.2-dev
Loading...
Searching...
No Matches
graph.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_GRAPH_H
21#define VOTCA_TOOLS_GRAPH_H
22
23// Standard includes
24#include <string>
25#include <unordered_map>
26#include <utility>
27#include <vector>
28
29// Local VOTCA includes
30#include "edgecontainer.h"
31#include "graphnode.h"
32
33namespace votca {
34namespace tools {
35
41class GraphNode;
42
43class Graph {
44 protected:
46
47 std::unordered_map<Index, GraphNode> nodes_;
48
51 std::string id_;
52
53 protected:
55 void calcId_();
56
57 public:
58 Graph() : id_("") {};
59 virtual ~Graph() = default;
65 Graph(std::vector<Edge> edges, std::unordered_map<Index, GraphNode> nodes);
66
69 bool operator!=(const Graph& graph) const;
70 bool operator==(const Graph& graph) const;
71
74 std::vector<std::pair<Index, GraphNode>> getIsolatedNodes(void) const;
75
78 std::vector<std::pair<Index, GraphNode>> getNeighNodes(Index vertex) const;
79
81 void setNode(Index vertex, GraphNode& graph_node);
82 void setNode(std::pair<Index, GraphNode>& id_and_node);
83
85 std::vector<Index> getJunctions() const;
86
88 GraphNode getNode(const Index vertex) const;
89
91 virtual std::vector<std::pair<Index, GraphNode>> getNodes() const;
92
95 std::vector<Index> getNeighVertices(Index vertex) const {
96 return edge_container_.getNeighVertices(vertex);
97 }
98
100 std::string getId() const { return id_; }
101
103 virtual std::vector<Edge> getEdges() { return edge_container_.getEdges(); }
104
106 std::vector<Edge> getNeighEdges(Index vertex) const {
107 return edge_container_.getNeighEdges(vertex);
108 }
109
111 std::vector<Index> getVertices() const;
112
121
123 Index getDegree(Index vertex) const;
124
126 virtual std::vector<Index> getVerticesDegree(Index degree) const;
127
129 bool vertexExist(Index vertex) const;
130
132 virtual bool edgeExist(const Edge& edge) const {
133 return edge_container_.edgeExist(edge);
134 }
135
137 void clearNodes();
140 void copyNodes(Graph& graph);
141
142 friend std::ostream& operator<<(std::ostream& os, const Graph graph);
143};
144
159bool cmpVertNodePair(const std::pair<Index, GraphNode>& id_and_node1,
160 const std::pair<Index, GraphNode>& id_and_node2);
161} // namespace tools
162} // namespace votca
163#endif // VOTCA_TOOLS_GRAPH_H
EdgeContainer is responsible for operations on groups of edges.
std::vector< Edge > getNeighEdges(Index vertex) const
Get the edges neighboring vert.
std::vector< Edge > getEdges() const
Get all the edges in vector form.
std::vector< Index > getNeighVertices(Index vertex) const
Get the vertices neighboring vert.
Index getMaxDegree() const
Get the value of the max degree.
bool edgeExist(const Edge &edge) const
Check if the edge exists returns true or false.
Connects to vertices.
Definition edge.h:42
A graph node that will take a variety of different values.
Definition graphnode.h:46
virtual std::vector< Edge > getEdges()
Returns all the edges in the graph.
Definition graph.h:103
Index getMaxDegree() const
Finds the max degree of a vertex in the graph.
Definition graph.h:120
std::vector< std::pair< Index, GraphNode > > getIsolatedNodes(void) const
Definition graph.cc:65
void copyNodes(Graph &graph)
Definition graph.cc:122
virtual ~Graph()=default
GraphNode getNode(const Index vertex) const
Return a copy of the graph node at vertex 'vert'.
Definition graph.cc:97
std::vector< Index > getJunctions() const
Gets all vertices with degree of 3 or greater.
Definition graph.cc:110
void setNode(Index vertex, GraphNode &graph_node)
set the Node associated with vertex 'vert'
Definition graph.cc:87
std::string id_
Definition graph.h:51
std::vector< Index > getNeighVertices(Index vertex) const
Definition graph.h:95
std::unordered_map< Index, GraphNode > nodes_
Definition graph.h:47
std::vector< Index > getVertices() const
Returns all the vertices in the graph.
Definition graph.cc:166
virtual std::vector< Index > getVerticesDegree(Index degree) const
Returns all the vertices with degree specified by degree
Definition graph.cc:162
EdgeContainer edge_container_
Definition graph.h:45
bool operator!=(const Graph &graph) const
Definition graph.cc:59
void calcId_()
Calculate the id of the graph.
Definition graph.cc:129
std::vector< std::pair< Index, GraphNode > > getNeighNodes(Index vertex) const
Definition graph.cc:76
bool operator==(const Graph &graph) const
Definition graph.cc:63
void clearNodes()
Remove contents of all nodes.
Definition graph.cc:120
std::vector< Edge > getNeighEdges(Index vertex) const
Returns all the edges in the graph connected to vertex vertex
Definition graph.h:106
virtual bool edgeExist(const Edge &edge) const
Determines if an edge is stored in the graph.
Definition graph.h:132
std::string getId() const
Returns the id of graph.
Definition graph.h:100
virtual std::vector< std::pair< Index, GraphNode > > getNodes() const
Return all the vertices and their graph nodes that are within the graph.
Definition graph.cc:102
friend std::ostream & operator<<(std::ostream &os, const Graph graph)
Definition graph.cc:170
Index getDegree(Index vertex) const
Calcualtes the degree, or number of edges connected to vertex vertex
Definition graph.cc:140
bool vertexExist(Index vertex) const
Determines if a vertex exists within the graph.
Definition graph.cc:152
bool cmpVertNodePair(const std::pair< Index, GraphNode > &id_and_node1, const std::pair< Index, GraphNode > &id_and_node2)
Compare function pair<Index ,GraphNode> object.
Definition graph.cc:179
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26