forked from SDTheSlayer/data-mining
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomparison_add.cpp
More file actions
360 lines (299 loc) · 14 KB
/
comparison_add.cpp
File metadata and controls
360 lines (299 loc) · 14 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#include<bits/stdc++.h>
#include"Iscan/iscan.h"
#include"readgml/readgml.h"
using namespace std;
int main(int argc, char* argv[])
{
// Input taken from GML
if (strcmp(argv[1], "--GML")==0)
{
NETWORK* N = new NETWORK();
FILE *F;
F = fopen (argv[2], "r");
if (F == NULL) perror ("Error opening file");
else
{
if(stof(argv[3])>1 || stof(argv[3])<=0){cout<<"Epsilon value should be between 0 and 1"<<endl;exit(0);}
if(stoi(argv[4])<=0){cout<<"Mu value should be greater than 0"<<endl;exit(0);}
int r = read_network(N, F);
graph* scanG = new graph();
graph* iscanG = new graph();
graph* iscanG2 = new graph();
// First add all vertices then add edges
for(int i=0;i<N->nvertices;i++)
{
// Add new vertex to graph with id and name
scanG->addVertex(N->vertex[i].id, N->vertex[i].label);
iscanG->addVertex(N->vertex[i].id, N->vertex[i].label);
iscanG2->addVertex(N->vertex[i].id, N->vertex[i].label);
}
int nEdges = 0;
scanG->numofEdges = nEdges;
iscanG->numofEdges = nEdges;
iscanG2->numofEdges = nEdges;
iscan *iscanObject = new iscan(stof(argv[3]), stoi(argv[4]), iscanG);
iscan *iscanObject2 = new iscan(stof(argv[3]), stoi(argv[4]), iscanG2);
double incrementalTime = 0;
double incrementalTime2 = 0;
double scanTime = 0;
for(int i=0;i<N->nvertices;i++)
{
for(int j=0;j<N->vertex[i].degree;j++)
{
if(scanG->findEdge(N->vertex[i].id, N->vertex[i].edge[j].target))
{
continue;
}
cout<<"Adding edge between "<<N->vertex[i].id<< " & "<<N->vertex[i].edge[j].target<<endl;
nEdges+=1;
scanG->numofEdges = nEdges;
iscanG->numofEdges = nEdges;
iscanG2->numofEdges = nEdges;
// Adding directed edges as Network contains a->b and b->a both
scanG->addEdge(N->vertex[i].id, N->vertex[i].edge[j].target);
graph* currentG = new graph();
for(auto it:scanG->graphObject)
{
currentG->addVertex((it.first)->ID,(it.first)->name);
}
for(auto iter = scanG->graphObject.begin(); iter != scanG->graphObject.end(); iter++)
{
for(auto it = iter->second.begin(); it!=iter->second.end();it++)
{
currentG->addDirectedEdge((iter->first)->ID,(*it)->ID);
}
}
currentG->numofEdges = nEdges;
cout<<"Graph structure after adding edge"<<endl;
currentG->printGraph();cout<<endl;
iscan *scanObject = new iscan(stof(argv[3]), stoi(argv[4]), currentG);
cout<<"Clustering by SCAN:"<<endl;
auto start = chrono::steady_clock::now();
scanObject->executeSCAN();
auto end = chrono::steady_clock::now();
auto diff = end - start;
scanTime += chrono::duration <double, milli> (diff).count();
currentG->printClusters();
cout<<"\n\nIncremental Clustering by ISCAN:"<<endl;
/*MultiThread*/
start = chrono::steady_clock::now();
iscanObject->updateEdge(N->vertex[i].id, N->vertex[i].edge[j].target, 1,true);
end = chrono::steady_clock::now();
diff = end - start;
incrementalTime += chrono::duration <double, milli> (diff).count();
/*Single Thread*/
start = chrono::steady_clock::now();
iscanObject2->updateEdge(N->vertex[i].id, N->vertex[i].edge[j].target, 1);
end = chrono::steady_clock::now();
diff = end - start;
incrementalTime2 += chrono::duration <double, milli> (diff).count();
iscanG2->printClusters();
cout<<"--------------------------------"<<endl;
}
}
cout<<"--------------------------------"<<endl;
cout<<"Running time:"<<endl;
cout<<"SCAN Time:"<<scanTime<<endl;
cout<<"Incremental SCAN Time with parallel threads:"<<incrementalTime<<endl;
cout<<"Incremental SCAN Time without parallel threads:"<<incrementalTime2<<endl;
}
}
// Input taken from txt file as adjacency matrix
if (strcmp(argv[1], "--MATRIX") == 0)
{
ifstream F(argv[2]);
if (!F) perror ("Error opening file");
else
{
string line;
int nvertices = 0;
if(stof(argv[3])>1 || stof(argv[3])<=0){cout<<"Epsilon value should be between 0 and 1"<<endl;exit(0);}
if(stoi(argv[4])<=0){cout<<"Mu value should be greater than 0"<<endl;exit(0);}
graph* scanG = new graph();
graph* iscanG = new graph();
graph* iscanG2 = new graph();
while(getline(F, line)){nvertices++;}
for(int i=0;i<nvertices;i++)
{
scanG->addVertex(i, "");
iscanG->addVertex(i, "");
iscanG2->addVertex(i, "");
}
F.clear();
F.seekg(0);
int nEdges = 0;
scanG->numofEdges = nEdges;
iscanG->numofEdges = nEdges;
iscanG2->numofEdges = nEdges;
iscan *iscanObject = new iscan(stof(argv[3]), stoi(argv[4]), iscanG);
iscan *iscanObject2 = new iscan(stof(argv[3]), stoi(argv[4]), iscanG2);
double incrementalTime = 0;
double incrementalTime2 = 0;
double scanTime = 0;
int temp;
for(int i=0;i<nvertices;i++)
{
for(int j=0;j<nvertices;j++)
{
F>>temp;
if(temp==1)
{
if(scanG->findEdge(i,j))
{
continue;
}
nEdges+=1;
scanG->numofEdges = nEdges;
iscanG->numofEdges = nEdges;
iscanG2->numofEdges = nEdges;
cout<<"Adding edge between "<<i<< " & "<<j<<endl;
// Adding directed edges as Network contains a->b and b->a both
scanG->addEdge(i, j);
graph* currentG = new graph();
for(auto it:scanG->graphObject)
{
currentG->addVertex((it.first)->ID,(it.first)->name);
}
for(auto iter = scanG->graphObject.begin(); iter != scanG->graphObject.end(); iter++)
{
for(auto it = iter->second.begin(); it!=iter->second.end();it++)
{
currentG->addDirectedEdge((iter->first)->ID,(*it)->ID);
}
}
currentG->numofEdges = nEdges;
iscan *scanObject = new iscan(stof(argv[3]), stoi(argv[4]), currentG);
auto start = chrono::steady_clock::now();
scanObject->executeSCAN();
auto end = chrono::steady_clock::now();
auto diff = end - start;
scanTime += chrono::duration <double, milli> (diff).count();
/*MultiThread*/
start = chrono::steady_clock::now();
iscanObject->updateEdge(i, j, 1,true);
end = chrono::steady_clock::now();
diff = end - start;
incrementalTime += chrono::duration <double, milli> (diff).count();
/*Single Thread*/
start = chrono::steady_clock::now();
iscanObject2->updateEdge(i, j, 1);
end = chrono::steady_clock::now();
diff = end - start;
incrementalTime2 += chrono::duration <double, milli> (diff).count();
}
}
}
cout<<"--------------------------------"<<endl;
cout<<"Running time:"<<endl;
cout<<"SCAN Time:"<<scanTime<<endl;
cout<<"Incremental SCAN Time with parallel threads:"<<incrementalTime<<endl;
cout<<"Incremental SCAN Time without parallel threads:"<<incrementalTime2<<endl;
}
}
if(strcmp(argv[1], "--LINK") == 0)
{
ifstream F(argv[2]);
if (!F) perror ("Error opening file");
else
{
if(stof(argv[3])>1 || stof(argv[3])<=0){cout<<"Epsilon value should be between 0 and 1"<<endl;exit(0);}
if(stoi(argv[4])<=0){cout<<"Mu value should be greater than 0"<<endl;exit(0);}
graph* scanG = new graph();
graph* iscanG = new graph();
graph* iscanG2 = new graph();
string line;
int nedges = 0;
while(getline(F, line)){nedges++;}
F.clear();
F.seekg(0);
int id1, id2;
for(int i=0;i<nedges;i++)
{
F>>id1>>id2;
if(scanG->vertexMap.find(id1)==scanG->vertexMap.end())
{
scanG->addVertex(id1, "");
iscanG->addVertex(id1, "");
iscanG2->addVertex(id1, "");
}
if(scanG->vertexMap.find(id2)==scanG->vertexMap.end())
{
scanG->addVertex(id2, "");
iscanG->addVertex(id2, "");
iscanG2->addVertex(id2, "");
}
}
int updateEdgeNumber = 10;
scanG->numofEdges = nedges;
iscanG->numofEdges = nedges-updateEdgeNumber;
iscanG2->numofEdges = nedges-updateEdgeNumber;
F.clear();
F.seekg(0);
int i, j;
for(int k=0;k<nedges-updateEdgeNumber;k++)
{
F>>i>>j;
// Adding directed edges as Network contains a->b and b->a both
scanG->addEdge(i, j);
iscanG->addEdge(i, j);
iscanG2->addEdge(i, j);
}
iscan *scanObject = new iscan(stof(argv[3]), stoi(argv[4]), iscanG);
iscan *iscanObject = new iscan(stof(argv[3]), stoi(argv[4]), iscanG);
iscan *iscanObject2 = new iscan(stof(argv[3]), stoi(argv[4]), iscanG2,4);
double incrementalTime = 0;
double incrementalTime2 = 0;
double scanTime = 0;
scanObject->executeSCAN();
// /*MultiThread*/
iscanObject->executeSCAN();
// /*Single Thread*/
iscanObject2->executeSCAN(true);
for(int k=0;k<updateEdgeNumber;k++)
{
F>>i>>j;
cout<<"Adding edge between "<<i<< " & "<<j<<endl;
// Adding directed edges as Network contains a->b and b->a both
scanG->addEdge(i, j);
graph* currentG = new graph();
for(auto it:scanG->graphObject)
{
currentG->addVertex((it.first)->ID,(it.first)->name);
}
for(auto iter = scanG->graphObject.begin(); iter != scanG->graphObject.end(); iter++)
{
for(auto it = iter->second.begin(); it!=iter->second.end();it++)
{
currentG->addDirectedEdge((iter->first)->ID,(*it)->ID);
}
}
currentG->numofEdges = nedges+k+1;
iscan *tempScanObject = new iscan(stof(argv[3]), stoi(argv[4]), currentG);
auto start = chrono::steady_clock::now();
tempScanObject->executeSCAN();
auto end = chrono::steady_clock::now();
auto diff = end - start;
scanTime += chrono::duration <double, milli> (diff).count();
/*MultiThread*/
start = chrono::steady_clock::now();
iscanObject->updateEdge(i, j, 1);
end = chrono::steady_clock::now();
diff = end - start;
incrementalTime += chrono::duration <double, milli> (diff).count();
/*Single Thread*/
start = chrono::steady_clock::now();
iscanObject2->updateEdge(i, j, 1, true);
end = chrono::steady_clock::now();
diff = end - start;
incrementalTime2 += chrono::duration <double, milli> (diff).count();
delete(tempScanObject);
delete(currentG);
}
cout<<"--------------------------------"<<endl;
cout<<"Running time:"<<endl;
cout<<"SCAN Time:"<<scanTime<<endl;
cout<<"Incremental SCAN Time without parallel threads:"<<incrementalTime<<endl;
cout<<"Incremental SCAN Time with parallel threads:"<<incrementalTime2<<endl;
}
}
}