GraphTool
 All Classes Files Functions Variables Typedefs
Graph.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 using namespace std;
6 
11 class Graph {
12 
13 private:
17  vector<vector<int>> adjacencyMatrix;
18 
22  vector<string> nodes;
23 
27  bool hasCycleCache = false;
28 
32  bool hasCycleFlag = false;
33 
37  enum Type {
38  UNCHECKED, DIRECTED, UNDIRECTED
39  };
40 
44  Type type = UNCHECKED;
45 
49  vector<int> inDeg;
50 
54  vector<int> outDeg;
55 
59  bool isFreeOfLoopsCache = false;
60 
64  bool isFreeOfLoopsFlag = false;
65 
69  bool isMultigraphCache = false;
70 
74  bool isMultigraphFlag = false;
75 
79  bool isForestCache = false;
80 
84  bool isForestFlag = false;
85 
89  bool isCompleteCache = false;
90 
94  bool isCompleteFlag = false;
95 
99  bool isRegularCache = false;
100 
104  bool isRegularFlag = false;
105 
113  bool hasCycleRec(const int i, bool *visited, bool *stack) const;
114 
123  vector<vector<int>> powerMatrix(vector<vector<int>> squareMatrix, int exponent);
124 
131  vector<vector<int>> getIdentityMatrix(int size);
132 
141  vector<vector<int>> multiplyMatrix(const vector<vector<int>> &A, const vector<vector<int>> &B);
142 
151  vector<vector<int>> addMatrix(const vector<vector<int>> &A, const vector<vector<int>> &B);
152 
161  vector<vector<int>> getZeroizedMatrix(int rows, int cols);
162 
171  bool isSameMatrix(const vector<vector<int>> &A, const vector<vector<int>> &B);
172 
179  bool isSquareMatrix(const vector<vector<int>> &adjacencyMatrix) const;
180 
181  const vector<vector<int>> &getAdjacencyMatrix() const;
182 
183 
184 
185 public:
186  Graph(vector<vector<int>> adjacencyMatrix);
187  Graph(vector<vector<int>> adjacencyMatrix, vector<string> node_names);
188 
195  Graph(string matlabMatrix);
196 
201  int getNumberOfNodes() const;
202 
207  int getNumberOfEdges();
208 
214  void exportFile(const string fileName, const string data) const;
215 
220  void exportAdjazenzmatrixFile(const string fileName) const;
221 
226  string graphToJson();
227 
232  bool hasCycle();
233 
240  bool hasEdge(const int from, const int to);
241 
247  bool hasPath(const vector<int> path) const;
248 
249  const string getAdjacencyMatrixString() const;
250 
257  bool isDirected();
258 
266  int getInDeg(int vertexIndex);
267 
275  int getOutDeg(int vertexIndex);
276 
283  bool isFreeOfLoops();
284 
292  bool isMultigraph();
293 
300  bool isSimple();
301 
310  bool isComplete();
311 
320  bool isRegular();
321 
330  bool isForest();
331 
339  bool hasConnectivity(int s, int t);
340 
345  string exportDot();
346 
355  bool areNeighbours(int from, int to);
356 
363  string exportDot(vector<int> path);
364 
365 };
Definition: Graph.h:11