Algorithms and Computability Project 0.0.1
Algorithms and Computability Project, we implement graph size, a graph metric, maximum clique search and maximum common subgraph search
Loading...
Searching...
No Matches
graph.hpp
Go to the documentation of this file.
1
5#include <fstream>
6#include <functional>
7#include <vector>
8
12enum class AlgorithmAccuracy { APPROXIMATE, EXACT };
13
18class Graph {
19 private:
23 size_t vertexCount;
24
30 size_t vertexAndEdgeCount;
31
37 std::vector<std::vector<int>> adjacencyMatrix;
38
42 static constexpr size_t ESTIMATE_MULTIPLIER = 10;
43
58 auto maxCliqueHelper(size_t currentVertex,
59 std::vector<size_t>& currentClique,
60 std::vector<std::vector<size_t>>& maxCliques,
61 AlgorithmAccuracy accuracy, size_t& currentExecution,
62 size_t executionLimit, auto adjacencyFunction) const
63 -> void;
64
73 [[nodiscard]] auto totalConnections(const std::vector<size_t>& clique) const
74 -> size_t;
75
84 [[nodiscard]] auto edgeCount(const std::vector<size_t>& clique) const
85 -> size_t;
86
87 public:
94 Graph() : vertexCount{0}, vertexAndEdgeCount{0} {}
95
102 explicit Graph(const std::vector<std::vector<int>>&& adjacencyMatrix);
103
113 explicit Graph(std::istream& graphStream);
114
123 explicit Graph(std::istream&& graphStream) : Graph{graphStream} {}
124
139 [[nodiscard]] static auto fromFilename(const std::string& filename)
140 -> Graph;
141
146 [[nodiscard]] auto getVertexCount() const -> size_t { return vertexCount; }
147
159 [[nodiscard]] auto toDotLang() const -> std::string;
160
168 [[nodiscard]] auto operator[](size_t row) const -> std::vector<int>;
169
179 friend auto operator<<(std::ostream& outputStream, const Graph& graph)
180 -> std::ostream&;
181
190 friend auto operator==(const Graph& lhs, const Graph& rhs) -> bool;
191
199 [[nodiscard]] auto getSize() const -> size_t;
200
218 [[nodiscard]] auto metricDistanceTo(
219 const Graph& rhs,
220 AlgorithmAccuracy accuracy = AlgorithmAccuracy::EXACT) const -> size_t;
221
231 [[nodiscard]] auto modularProduct(const Graph& rhs) -> Graph;
232
241 [[nodiscard]] auto maxClique(
242 AlgorithmAccuracy accuracy = AlgorithmAccuracy::EXACT) const
243 -> std::vector<size_t>;
244
253 [[nodiscard]] auto modifiedMaxClique(
254 AlgorithmAccuracy accuracy = AlgorithmAccuracy::EXACT) const
255 -> std::vector<size_t>;
256
267 [[nodiscard]] auto maxSubgraph(
268 const Graph& rhs, AlgorithmAccuracy accuracy = AlgorithmAccuracy::EXACT)
269 -> Graph;
270
279 [[nodiscard]] auto maxCliqueGraph(AlgorithmAccuracy accuracy) const
280 -> Graph;
281
289 [[nodiscard]] auto subGraph(std::vector<size_t>& vertices) const -> Graph;
290};
Class that represents a graph as a matrix (vector of vectors) of adjacencies.
Definition: graph.hpp:18
Graph(std::istream &&graphStream)
constructs graph from data in a stream
Definition: graph.hpp:123
auto getSize() const -> size_t
Returns graph size.
Definition: graph.cpp:61
auto maxClique(AlgorithmAccuracy accuracy=AlgorithmAccuracy::EXACT) const -> std::vector< size_t >
Finds the maximum clique of the graph using Bron-Kerbosch algorithm.
Definition: graph.cpp:210
auto toDotLang() const -> std::string
returns string in DOT language
Definition: graph.cpp:65
auto subGraph(std::vector< size_t > &vertices) const -> Graph
Gives the induced subgraph given by the vertices.
Definition: graph.cpp:345
auto modifiedMaxClique(AlgorithmAccuracy accuracy=AlgorithmAccuracy::EXACT) const -> std::vector< size_t >
modidfied max clique algorithm for finding maximum induced subgraphs.
Definition: graph.cpp:228
static auto fromFilename(const std::string &filename) -> Graph
constructs graph from data in specified filename
Definition: graph.cpp:83
auto maxSubgraph(const Graph &rhs, AlgorithmAccuracy accuracy=AlgorithmAccuracy::EXACT) -> Graph
Returns maximum induced subgraph of two graphs.
Definition: graph.cpp:287
auto modularProduct(const Graph &rhs) -> Graph
Returns modular product of two graphs.
Definition: graph.cpp:165
auto maxCliqueGraph(AlgorithmAccuracy accuracy) const -> Graph
Graph of max clique.
Definition: graph.cpp:361
auto getVertexCount() const -> size_t
Return vertex count.
Definition: graph.hpp:146
auto metricDistanceTo(const Graph &rhs, AlgorithmAccuracy accuracy=AlgorithmAccuracy::EXACT) const -> size_t
Returns distance to another graph.
Definition: graph.cpp:153
Graph()
Default constructor.
Definition: graph.hpp:94
AlgorithmAccuracy
Little enum for choosing between approximate and exact algorithms.
Definition: graph.hpp:12