-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.h
More file actions
224 lines (175 loc) · 6.15 KB
/
Graph.h
File metadata and controls
224 lines (175 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#ifndef GRAPH_H_INCLUDED
#define GRAPH_H_INCLUDED
#include "Edge.h"
class Graph
{
private:
int nbVertex;
int time; // Used in DFS
bool isDirected; // A boolean to know if the graph is directed (1) or not (0)
bool isMatrix; // A boolean to know if the structure of the graph is describe by a list (0) or by a matrix (1)
vector<Vertex*> vertexList; // The Graph's Vertex list
vector<Edge*> edgeList; // The Graph's Edge list
vector<vector<vector<int> > > adjencyList;
vector<vector<int> > adjencyMatrix;
public:
// Constructor
Graph(): nbVertex(0), time(0), isDirected(0), isMatrix(0){};
//Function that reads a file in order to create a graph
void fileToGraph(string myFile);
// Fill the vertex/edge list using the adjency matrix/list. Are needed in fileToGraph()
void fillVertexList();
void fillEdgeList();
//Destructor
~Graph()
{
unsigned int i, j;
// Clear Edge and vertex List
edgeList.clear();
vertexList.clear();
// Clear adjency Matrix
for (i = 0; i < adjencyMatrix.size(); i++)
{
adjencyMatrix[i].clear();
}
adjencyMatrix.clear();
// Clear adjency List
for (i = 0; i < adjencyList.size(); i++)
{
for (j = 0; j < adjencyList[i].size(); j++)
{
adjencyList[i][j].clear();
}
adjencyList[i].clear();
}
adjencyList.clear();
};
// Create a file and save the information of a graph
void graphToFile(string myFile);
// Getters
int getNbVertex(){return nbVertex;};
bool getIsDirected(){return isDirected;};
bool getIsMatrix(){return isMatrix;};
vector<vector<vector<int> > > getadjencylist(){return adjencyList;};
vector<Vertex*> getVertexList(){return vertexList;};
// Setters
void setadjencyList(vector<vector<vector<int> > > &l){adjencyList=l;};
void setadjencyMatrix(vector<vector<int> > &m){adjencyMatrix=m;};
// Switch the description type of a graph from matrix to list or list to matrix
// Return 1 if succesful, 0 if not
int matrixToList();
int listToMatrix();
// Ostream function
friend ostream& operator<<(ostream &os, const Graph &g);
// search algrithms
void BFS(Vertex &src);
void DFS(Vertex &src);
void DFS_proc(Vertex &src);//same as DFS but without initialization
void DFS_Visit(Vertex&);
void DFSutil(Vertex&);
vector<Vertex*> Topological_Sort(Vertex& s);
void invert(void);
vector<vector<Vertex*> > SCC(Vertex& s);
void computeGT(void);
//shortest paths
void init_Single_Src(Vertex &s);
void relax(Vertex &u,Vertex &v,int w);
bool BELLMAN_FORD(Vertex &s);
vector<Vertex *> DIJKSTRA(Vertex &s);
vector<Vertex*>::iterator find_it(vector<Vertex*> Q,Vertex& v);
void Prim(Vertex& s);
vector<Edge*> Kruskal();
Vertex* find_set(Vertex& v);
void union_set(Vertex& u,Vertex& v);
};
vector<Edge*> sort(vector<Edge*> &G);
Vertex* extract_Mini(vector<Vertex *> &Q);
#endif // GRAPH_H_INCLUDED
#ifndef GRAPH_H_INCLUDED
#define GRAPH_H_INCLUDED
#include "Edge.h"
class Graph
{
private:
int nbVertex;
int time; // Used in DFS
bool isDirected; // A boolean to know if the graph is directed (1) or not (0)
bool isMatrix; // A boolean to know if the structure of the graph is describe by a list (0) or by a matrix (1)
vector<Vertex*> vertexList; // The Graph's Vertex list
vector<Edge*> edgeList; // The Graph's Edge list
vector<vector<vector<int> > > adjencyList;
vector<vector<int> > adjencyMatrix;
public:
// Constructor
Graph(): nbVertex(0), time(0), isDirected(0), isMatrix(0){};
//Function that reads a file in order to create a graph
void fileToGraph(string myFile);
// Fill the vertex/edge list using the adjency matrix/list. Are needed in fileToGraph()
void fillVertexList();
void fillEdgeList();
//Destructor
~Graph()
{
unsigned int i, j;
// Clear Edge and vertex List
edgeList.clear();
vertexList.clear();
// Clear adjency Matrix
for (i = 0; i < adjencyMatrix.size(); i++)
{
adjencyMatrix[i].clear();
}
adjencyMatrix.clear();
// Clear adjency List
for (i = 0; i < adjencyList.size(); i++)
{
for (j = 0; j < adjencyList[i].size(); j++)
{
adjencyList[i][j].clear();
}
adjencyList[i].clear();
}
adjencyList.clear();
};
// Create a file and save the information of a graph
void graphToFile(string myFile);
// Getters
int getNbVertex(){return nbVertex;};
bool getIsDirected(){return isDirected;};
bool getIsMatrix(){return isMatrix;};
vector<vector<vector<int> > > getadjencylist(){return adjencyList;};
vector<Vertex*> getVertexList(){return vertexList;};
// Setters
void setadjencyList(vector<vector<vector<int> > > &l){adjencyList=l;};
void setadjencyMatrix(vector<vector<int> > &m){adjencyMatrix=m;};
// Switch the description type of a graph from matrix to list or list to matrix
// Return 1 if succesful, 0 if not
int matrixToList();
int listToMatrix();
// Ostream function
friend ostream& operator<<(ostream &os, const Graph &g);
// search algrithms
void BFS(Vertex &src);
void DFS(Vertex &src);
void DFS_proc(Vertex &src);//same as DFS but without initialization
void DFS_Visit(Vertex&);
void DFSutil(Vertex&);
vector<Vertex*> Topological_Sort(Vertex& s);
void invert(void);
vector<vector<Vertex*> > SCC(Vertex& s);
//Graph computeGT(Graph& g);
void computeGT(void);
//shortest paths
void init_Single_Src(Vertex &s);
void relax(Vertex &u,Vertex &v,int w);
bool BELLMAN_FORD(Vertex &s);
vector<Vertex *> DIJKSTRA(Vertex &s);
vector<Vertex*>::iterator find_it(vector<Vertex*> Q,Vertex& v);
void Prim(Vertex& s);
vector<Edge*> Kruskal();
Vertex* find_set(Vertex& v);
void union_set(Vertex& u,Vertex& v);
};
void sort(vector<Edge*> &G);
Vertex* extract_Mini(vector<Vertex *> &Q);
#endif // GRAPH_H_INCLUDED