-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.cpp
More file actions
269 lines (239 loc) · 8.59 KB
/
Client.cpp
File metadata and controls
269 lines (239 loc) · 8.59 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include "Graph.h"
#include <string>
//#include "Heap.h"
int main()
{
// Creation of graphs using .txt files
vector<Graph> G;
vector<Vertex> Q;
int taille;
int nb(0);
vector<Edge*> K;
vector<Vertex*> R;
vector<vector<Vertex* > > D;
Graph g1, g2, g3, g4,g;
g1.fileToGraph("Files/exampleUndirectedMatrix.txt");
g2.fileToGraph("Files/exampleDirectedMatrix.txt");
g3.fileToGraph("Files/exampleUndirectedList.txt");
g4.fileToGraph("Files/exampleDirectedList.txt");
cout << "Please chose the graph from the List Below" << endl;
cout << " 1 :Files/exampleUndirectedMatrix.txt" << endl;
cout << " 2 :Files/exampleDirectedMatrix.txt" << endl;
cout << " 3 :Files/exampleUndirectedList.txt" << endl;
cout << " 4 :Files/exampleDirectedList.txt" << endl;
int answer;
cin >> answer;
switch(answer)
{
case 1:g.fileToGraph("Files/exampleUndirectedMatrix.txt");
break;
case 2:g.fileToGraph("Files/exampleDirectedMatrix.txt");
break;
case 3:g.fileToGraph("Files/exampleUndirectedList.txt");
break;
case 4:g.fileToGraph("Files/exampleDirectedList.txt");
break;
default: cout << "error, this choice is not available" << endl;
break;
}
cin.ignore();
cout<< "AFFICHAGE GRAPH" << endl;
cout<<g<<endl<<endl<<endl;
cout << "Which algorithm do you want to use?" << endl;
cout << " 1 : Breadth-first search" << endl;
cout << " 2 : Depth-first-search" << endl;
cout << " 3 : Topological_Sort" << endl;
cout << " 4 : Strongly_Related" << endl;
cout << " 5 : Kruskal" << endl;
cout << " 6 : Prim" << endl;
cout << " 7 : Bellman-Ford" << endl;
cout << " 8 : Dijkstra" << endl;
cin >> answer;
int vertexid;
switch(answer)
{
case 1:cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin >>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
g.BFS(*g.getVertexList()[vertexid-1]);
}
else
{
cout<< "Error,no verticle found" << endl;
}
break;
case 2: cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin>>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
g.DFS(*g.getVertexList()[vertexid-1]);
for(int i=0; i<g.getNbVertex();i++)
{
cout << "Here are the entry and finishing times of the different Vertex reacheable from the one you've chosen" << endl;
if(g.getVertexList()[i]->getd() != -1)
{
nb++;
cout << "Vertex :" << *g.getVertexList()[i] << " entry time :" << g.getVertexList()[i]->getd() << "finishing time :" << g.getVertexList()[i]->getd() << endl;
}
if(nb==0)
{
cout << "No verticle reachabme" << endl;
}
}
}
else
{
cout<< "Error,no verticle found" << endl;
}
nb=0;
break;
case 3:cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin>>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
R=g.Topological_Sort(*g.getVertexList()[vertexid-1]);
cout << "Here is the result of the topological sort" << endl;
taille=R.size();
for(int k=0;k<taille;k++)
{
cout << *R[k] << " / ";
}
cout << endl;
}
else
{
cout<< "Error,no verticle found" << endl;
}
taille=0;
R.clear();
break;
case 4:if(g.getIsDirected()==false)
{
cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin>>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
D=g.SCC(*g.getVertexList()[vertexid-1]);
taille=D.size();
cout << "Here are the different component in the Graph" << endl;
for(int j=0;j<taille;j++)
{
cout << "component num :" << j+1 << endl;
for(int z=0;z<D[j].size();z++)
{
cout << *D[j][z] << " " ;
}
cout << endl;
}
}
else
{
cout<< "Error,no verticle found" << endl;
}
D.clear();
}
else
{
cout<<"Error, the Graph must Be directed" << endl;
}
break;
case 5:cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin>>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
K=g.Kruskal();
cout << "Here are the edges used to build the Kruskal Mst" << endl;
taille=K.size();
for(int i=0;i<taille;i++)
{
cout<< "Edge sources/destinations :" << *K[i]->getSrc() << "->" << *K[i]->getDst() << endl;
}
}
else
{
cout<< "Error,no verticle found" << endl;
}
K.clear();
break;
case 6:cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin>>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
g.Prim(*g.getVertexList()[vertexid-1]);
cout << "Here are the vertex with their parents computed(reachable) by the Prim's algorithm" << endl;
cout << "Vertex source :" <<*g.getVertexList()[vertexid-1] << endl;
for(int y=0;y<g.getNbVertex();y++)
{
if(g.getVertexList()[y]->getpred()!=0)
{
cout << "Vertex :" << *g.getVertexList()[y] << " Parent :" << *g.getVertexList()[y]->getpred() << endl;
nb++;
}
if(nb==0)
{
cout<< "Error, no Verticle reachable" << endl;
}
}
}
else
{
cout<< "Error,no verticle found" << endl;
}
nb=0;
break;
case 7:cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin>>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
g.BELLMAN_FORD(*g.getVertexList()[vertexid-1]);
cout << "Here are the Vertex and their Parent reachable from the Vertex you've chosen" << endl;
for(int y=0;y<g.getNbVertex();y++)
{
if(g.getVertexList()[y]->getpred()->getId()!=g.getVertexList()[y]->getId())
{
cout << "Vertex :" << *g.getVertexList()[y] << " Parent :" << *g.getVertexList()[y]->getpred() << endl;
nb++;
}
}
if(nb==0)
{
cout<< "Error, no Verticle reachable" << endl;
}
}
else
{
cout<< "Error,no verticle found" << endl;
}
nb=0;
break;
case 8:cout << "Please type in the id of the vertex you want to use the algorithm on." << endl;
cin>>vertexid;
if(vertexid>0 && vertexid<=g.getNbVertex())
{
g.DIJKSTRA(*g.getVertexList()[vertexid-1]);
cout << "Here are the Vertex and their Parent reachable from the Vertex you've chosen" << endl;
for(int y=0;y<g.getNbVertex();y++)
{
if(g.getVertexList()[y]->getpred()!=0)
{
cout << "Vertex :" << *g.getVertexList()[y] << " Parent :" << *g.getVertexList()[y]->getpred() << endl;
nb++;
}
}
if(nb==0)
{
cout<< "Error, no Verticle reachable" << endl;
}
}
else
{
cout<< "Error,no verticle found" << endl;
}
nb=0;
break;
default:
break;
}
return 0;
}