forked from ulricha/studienarbeit-wot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
walktrap02.patch
783 lines (782 loc) · 21.7 KB
/
walktrap02.patch
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
Only in walktrap: .#communities.cpp
Only in walktrap: .#communities.h
diff -ru walktrap_clean/example.net walktrap/example.net
--- walktrap_clean/example.net 2005-06-08 11:32:42.000000000 +0200
+++ walktrap/example.net 2009-12-03 17:05:35.000000000 +0100
@@ -16,7 +16,7 @@
3 7
4 10
4 1
-5 7 3.2
+5 7
# the line above mean that there is an edges between 5 and 7 (with weight 3.2)
5 11
diff -ru walktrap_clean/graph.cpp walktrap/graph.cpp
--- walktrap_clean/graph.cpp 2005-06-07 15:20:58.000000000 +0200
+++ walktrap/graph.cpp 2009-12-03 17:02:55.000000000 +0100
@@ -1,308 +1,308 @@
-// File: graph.cpp
-//-----------------------------------------------------------------------------
-// Walktrap v0.2 -- Finds community structure of networks using random walks
-// Copyright (C) 2004-2005 Pascal Pons
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//-----------------------------------------------------------------------------
-// Author : Pascal Pons
-// Email : [email protected]
-// Web page : http://www.liafa.jussieu.fr/~pons/
-// Location : Paris, France
-// Time : June 2005
-//-----------------------------------------------------------------------------
-// see readme.txt for more details
-
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include "graph.h"
-
-using namespace std;
-
-
-bool operator<(const Edge& E1, const Edge& E2) {
- return(E1.neighbor < E2.neighbor);
-}
-
-
-Vertex::Vertex() {
- degree = 0;
- edges = 0;
- total_weight = 0.;
-}
-
-Vertex::~Vertex() {
- if(edges) delete[] edges;
-}
-
-Graph::Graph() {
- nb_vertices = 0;
- nb_edges = 0;
- vertices = 0;
- index = 0;
- total_weight = 0.;
-}
-
-Graph::~Graph () {
- if (vertices) delete[] vertices;
-}
-
-class Edge_list {
-public:
- int* V1;
- int* V2;
- float* W;
-
- int size;
- int size_max;
-
- void add(int v1, int v2, float w);
- Edge_list() {
- size = 0;
- size_max = 1024;
- V1 = new int[1024];
- V2 = new int[1024];
- W = new float[1024];
- }
- ~Edge_list() {
- if(V1) delete[] V1;
- if(V2) delete[] V2;
- if(W) delete[] W;
- }
-};
-
-void Edge_list::add(int v1, int v2, float w) {
- if(size == size_max) {
- int* tmp1 = new int[2*size_max];
- int* tmp2 = new int[2*size_max];
- float* tmp3 = new float[2*size_max];
- for(int i = 0; i < size_max; i++) {
- tmp1[i] = V1[i];
- tmp2[i] = V2[i];
- tmp3[i] = W[i];
- }
- delete[] V1;
- delete[] V2;
- delete[] W;
- V1 = tmp1;
- V2 = tmp2;
- W = tmp3;
- size_max *= 2;
- }
- V1[size] = v1;
- V2[size] = v2;
- W[size] = w;
- size++;
-}
-
-
-
-
-istream& operator>>(istream& stream, Graph& G) {
- if(G.vertices) delete[] G.vertices;
-
- int nb_line = 0;
- int max_vertex = 0;
-
- Edge_list EL;
-
- while (!stream.eof()) { // loop for each line of the file
- nb_line++;
- string str;
- getline(stream, str);
- if(str[0] == '#') continue; // a comment line
- istringstream line(str);
-
- int v1;
- line >> v1;
- if(line.fail()) {
- if(line.eof()) continue;
- cerr << "error : unable to read line " << nb_line << " : " << str << endl;
- exit(0);
- }
- int v2;
- line >> v2;
- if(line.fail()) {
- cerr << "error : unable to read line " << nb_line << " : " << str << endl;
- exit(0);
- }
- float w;
- line >> w;
- if(line.fail()) {
- if(line.eof()) w = 1.;
- else {
- cerr << "error : unable to read line " << nb_line << " : " << str << endl;
- exit(0);
- }
- }
- if(!line.eof()) {
- cerr << "error : line " << nb_line << " too long : " << str << endl;
- exit(0);
- }
-
- if(v1 > max_vertex) max_vertex = v1;
- if(v2 > max_vertex) max_vertex = v2;
- if((v1 < 0) || (v2 < 0)) {
- cerr << "error : line " << nb_line << " negative vertex number : " << str << endl;
- exit(0);
- }
- if(w < 0) {
- cerr << "error : line " << nb_line << " negative weight : " << str << endl;
- exit(0);
- }
- EL.add(v1, v2, w);
- }
-
- G.nb_vertices = max_vertex + 1;
- G.vertices = new Vertex[G.nb_vertices];
- G.nb_edges = 0;
- G.total_weight = 0.;
-
- for(int i = 0; i < EL.size; i++) {
- G.vertices[EL.V1[i]].degree++;
- G.vertices[EL.V2[i]].degree++;
- G.vertices[EL.V1[i]].total_weight += EL.W[i];
- G.vertices[EL.V2[i]].total_weight += EL.W[i];
- G.nb_edges++;
- G.total_weight += EL.W[i];
- }
-
- for(int i = 0; i < G.nb_vertices; i++) {
- if(G.vertices[i].degree == 0) {
- cerr << "error : degree of vertex " << i << " is 0" << endl;
- exit(0);
- }
- G.vertices[i].edges = new Edge[G.vertices[i].degree + 1];
- G.vertices[i].edges[0].neighbor = i;
- G.vertices[i].edges[0].weight = G.vertices[i].total_weight/double(G.vertices[i].degree);
- G.vertices[i].total_weight+= G.vertices[i].total_weight/double(G.vertices[i].degree);
- G.vertices[i].degree = 1;
- }
-
- for(int i = 0; i < EL.size; i++) {
- G.vertices[EL.V1[i]].edges[G.vertices[EL.V1[i]].degree].neighbor = EL.V2[i];
- G.vertices[EL.V1[i]].edges[G.vertices[EL.V1[i]].degree].weight = EL.W[i];
- G.vertices[EL.V1[i]].degree++;
- G.vertices[EL.V2[i]].edges[G.vertices[EL.V2[i]].degree].neighbor = EL.V1[i];
- G.vertices[EL.V2[i]].edges[G.vertices[EL.V2[i]].degree].weight = EL.W[i];
- G.vertices[EL.V2[i]].degree++;
- }
-
- for(int i = 0; i < G.nb_vertices; i++)
- sort(G.vertices[i].edges, G.vertices[i].edges+G.vertices[i].degree);
-
- for(int i = 0; i < G.nb_vertices; i++) { // merge multi edges
- int a = 0;
- for(int b = 1; b < G.vertices[i].degree; b++) {
- if(G.vertices[i].edges[b].neighbor == G.vertices[i].edges[a].neighbor)
- G.vertices[i].edges[a].weight += G.vertices[i].edges[b].weight;
- else
- G.vertices[i].edges[++a] = G.vertices[i].edges[b];
- }
- G.vertices[i].degree = a+1;
- }
-
- return stream;
-}
-
-
-long Graph::memory() {
- long m = 0;
- m += long(nb_vertices)*sizeof(Vertex);
- m += 2*long(nb_edges)*sizeof(Edge);
- m += sizeof(Graph);
- if(index != 0) {
- m += long(nb_vertices)*sizeof(char*);
- for(int i = 0; i < nb_vertices; i++)
- m += strlen(index[i]) + 1;
- }
- return m;
-}
-
-
-bool Graph::load_index(char* input_file) {
- ifstream f;
- f.open(input_file, ios::in);
- if(!f.is_open()) {
- cerr << "unable to open file " << index << " , index is ignored" << endl;
- return false;
- }
- index = new char*[nb_vertices];
- for(int i = 0; i < nb_vertices; ++i)
- index[i] = 0;
-
- int nb_line = 0;
- while (!f.eof()) { // loop for each line of the file
- nb_line++;
- int i;
- f >> i;
- if(f.fail()) {
- if(f.eof()) break;
- cerr << "error : unable to read line " << nb_line << " , index is ignored" << endl;
- for(int i = 0; i < nb_vertices; ++i)
- if(index[i]) delete[] index[i];
- delete[] index;
- index = 0;
- return false;
- }
- if(i < 0 || i >= nb_vertices || index[i] != 0) {
- cerr << "error : invalid vertex number at line : " << nb_line << " , index is ignored" << endl;
- for(int i = 0; i < nb_vertices; ++i)
- if(index[i]) delete[] index[i];
- delete[] index;
- index = 0;
- return false;
- }
- string str;
- getline(f, str);
- if(str.length() <= 1) {
- cerr << "error : unable to read line " << nb_line << " , index is ignored" << endl;
- for(int i = 0; i < nb_vertices; ++i)
- if(index[i]) delete[] index[i];
- delete[] index;
- index = 0;
- return false;
- }
- char* c = new char[str.size()];
- strcpy(c, str.c_str()+1);
- index[i] = c;
- }
-
- for(int i = 0; i < nb_vertices; ++i)
- if(index[i] == 0) {
- cerr << "error : vertex " << i << "not found, index is ignored" << endl;
- for(int i = 0; i < nb_vertices; ++i)
- if(index[i]) delete[] index[i];
- delete[] index;
- index = 0;
- return false;
- }
- return true;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+// File: graph.cpp
+//-----------------------------------------------------------------------------
+// Walktrap v0.2 -- Finds community structure of networks using random walks
+// Copyright (C) 2004-2005 Pascal Pons
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//-----------------------------------------------------------------------------
+// Author : Pascal Pons
+// Email : [email protected]
+// Web page : http://www.liafa.jussieu.fr/~pons/
+// Location : Paris, France
+// Time : June 2005
+//-----------------------------------------------------------------------------
+// see readme.txt for more details
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include "graph.h"
+
+using namespace std;
+
+
+bool operator<(const Edge& E1, const Edge& E2) {
+ return(E1.neighbor < E2.neighbor);
+}
+
+
+Vertex::Vertex() {
+ degree = 0;
+ edges = 0;
+ total_weight = 0.;
+}
+
+Vertex::~Vertex() {
+ if(edges) delete[] edges;
+}
+
+Graph::Graph() {
+ nb_vertices = 0;
+ nb_edges = 0;
+ vertices = 0;
+ index = 0;
+ total_weight = 0.;
+}
+
+Graph::~Graph () {
+ if (vertices) delete[] vertices;
+}
+
+class Edge_list {
+public:
+ int* V1;
+ int* V2;
+ float* W;
+
+ int size;
+ int size_max;
+
+ void add(int v1, int v2, float w);
+ Edge_list() {
+ size = 0;
+ size_max = 1024;
+ V1 = new int[1024];
+ V2 = new int[1024];
+ W = new float[1024];
+ }
+ ~Edge_list() {
+ if(V1) delete[] V1;
+ if(V2) delete[] V2;
+ if(W) delete[] W;
+ }
+};
+
+void Edge_list::add(int v1, int v2, float w) {
+ if(size == size_max) {
+ int* tmp1 = new int[2*size_max];
+ int* tmp2 = new int[2*size_max];
+ float* tmp3 = new float[2*size_max];
+ for(int i = 0; i < size_max; i++) {
+ tmp1[i] = V1[i];
+ tmp2[i] = V2[i];
+ tmp3[i] = W[i];
+ }
+ delete[] V1;
+ delete[] V2;
+ delete[] W;
+ V1 = tmp1;
+ V2 = tmp2;
+ W = tmp3;
+ size_max *= 2;
+ }
+ V1[size] = v1;
+ V2[size] = v2;
+ W[size] = w;
+ size++;
+}
+
+
+
+
+istream& operator>>(istream& stream, Graph& G) {
+ if(G.vertices) delete[] G.vertices;
+
+ int nb_line = 0;
+ int max_vertex = 0;
+
+ Edge_list EL;
+
+ while (!stream.eof()) { // loop for each line of the file
+ nb_line++;
+ string str;
+ getline(stream, str);
+ if(str[0] == '#') continue; // a comment line
+ istringstream line(str);
+
+ int v1;
+ line >> v1;
+ if(line.fail()) {
+ if(line.eof()) continue;
+ cerr << "error : unable to read line " << nb_line << " : " << str << endl;
+ exit(0);
+ }
+ int v2;
+ line >> v2;
+ if(line.fail()) {
+ cerr << "error : unable to read line " << nb_line << " : " << str << endl;
+ exit(0);
+ }
+ float w;
+ line >> w;
+ if(line.fail()) {
+ if(line.eof()) w = 1.;
+ else {
+ cerr << "error : unable to read line " << nb_line << " : " << str << endl;
+ exit(0);
+ }
+ }
+ if(!line.eof()) {
+ cerr << "error : line " << nb_line << " too long : " << str << endl;
+ exit(0);
+ }
+
+ if(v1 > max_vertex) max_vertex = v1;
+ if(v2 > max_vertex) max_vertex = v2;
+ if((v1 < 0) || (v2 < 0)) {
+ cerr << "error : line " << nb_line << " negative vertex number : " << str << endl;
+ exit(0);
+ }
+ if(w < 0) {
+ cerr << "error : line " << nb_line << " negative weight : " << str << endl;
+ exit(0);
+ }
+ EL.add(v1, v2, w);
+ }
+
+ G.nb_vertices = max_vertex + 1;
+ G.vertices = new Vertex[G.nb_vertices];
+ G.nb_edges = 0;
+ G.total_weight = 0.;
+
+ for(int i = 0; i < EL.size; i++) {
+ G.vertices[EL.V1[i]].degree++;
+ G.vertices[EL.V2[i]].degree++;
+ G.vertices[EL.V1[i]].total_weight += EL.W[i];
+ G.vertices[EL.V2[i]].total_weight += EL.W[i];
+ G.nb_edges++;
+ G.total_weight += EL.W[i];
+ }
+
+ for(int i = 0; i < G.nb_vertices; i++) {
+ if(G.vertices[i].degree == 0) {
+ cerr << "error : degree of vertex " << i << " is 0" << endl;
+ exit(0);
+ }
+ G.vertices[i].edges = new Edge[G.vertices[i].degree + 1];
+ G.vertices[i].edges[0].neighbor = i;
+ G.vertices[i].edges[0].weight = G.vertices[i].total_weight/double(G.vertices[i].degree);
+ G.vertices[i].total_weight+= G.vertices[i].total_weight/double(G.vertices[i].degree);
+ G.vertices[i].degree = 1;
+ }
+
+ for(int i = 0; i < EL.size; i++) {
+ G.vertices[EL.V1[i]].edges[G.vertices[EL.V1[i]].degree].neighbor = EL.V2[i];
+ G.vertices[EL.V1[i]].edges[G.vertices[EL.V1[i]].degree].weight = EL.W[i];
+ G.vertices[EL.V1[i]].degree++;
+ G.vertices[EL.V2[i]].edges[G.vertices[EL.V2[i]].degree].neighbor = EL.V1[i];
+ G.vertices[EL.V2[i]].edges[G.vertices[EL.V2[i]].degree].weight = EL.W[i];
+ G.vertices[EL.V2[i]].degree++;
+ }
+
+ for(int i = 0; i < G.nb_vertices; i++)
+ sort(G.vertices[i].edges, G.vertices[i].edges+G.vertices[i].degree);
+
+ for(int i = 0; i < G.nb_vertices; i++) { // merge multi edges
+ int a = 0;
+ for(int b = 1; b < G.vertices[i].degree; b++) {
+ if(G.vertices[i].edges[b].neighbor == G.vertices[i].edges[a].neighbor)
+ G.vertices[i].edges[a].weight += G.vertices[i].edges[b].weight;
+ else
+ G.vertices[i].edges[++a] = G.vertices[i].edges[b];
+ }
+ G.vertices[i].degree = a+1;
+ }
+
+ return stream;
+}
+
+
+long Graph::memory() {
+ long m = 0;
+ m += long(nb_vertices)*sizeof(Vertex);
+ m += 2*long(nb_edges)*sizeof(Edge);
+ m += sizeof(Graph);
+ if(index != 0) {
+ m += long(nb_vertices)*sizeof(char*);
+ for(int i = 0; i < nb_vertices; i++)
+ m += strlen(index[i]) + 1;
+ }
+ return m;
+}
+
+
+bool Graph::load_index(char* input_file) {
+ ifstream f;
+ f.open(input_file, ios::in);
+ if(!f.is_open()) {
+ cerr << "unable to open file " << index << " , index is ignored" << endl;
+ return false;
+ }
+ index = new char*[nb_vertices];
+ for(int i = 0; i < nb_vertices; ++i)
+ index[i] = 0;
+
+ int nb_line = 0;
+ while (!f.eof()) { // loop for each line of the file
+ nb_line++;
+ int i;
+ f >> i;
+ if(f.fail()) {
+ if(f.eof()) break;
+ cerr << "error : unable to read line " << nb_line << " , index is ignored" << endl;
+ for(int i = 0; i < nb_vertices; ++i)
+ if(index[i]) delete[] index[i];
+ delete[] index;
+ index = 0;
+ return false;
+ }
+ if(i < 0 || i >= nb_vertices || index[i] != 0) {
+ cerr << "error : invalid vertex number at line : " << nb_line << " , index is ignored" << endl;
+ for(int i = 0; i < nb_vertices; ++i)
+ if(index[i]) delete[] index[i];
+ delete[] index;
+ index = 0;
+ return false;
+ }
+ string str;
+ getline(f, str);
+ if(str.length() <= 1) {
+ cerr << "error : unable to read line " << nb_line << " , index is ignored" << endl;
+ for(int i = 0; i < nb_vertices; ++i)
+ if(index[i]) delete[] index[i];
+ delete[] index;
+ index = 0;
+ return false;
+ }
+ char* c = new char[str.size()];
+ strcpy(c, str.c_str()+1);
+ index[i] = c;
+ }
+
+ for(int i = 0; i < nb_vertices; ++i)
+ if(index[i] == 0) {
+ cerr << "error : vertex " << i << "not found, index is ignored" << endl;
+ for(int i = 0; i < nb_vertices; ++i)
+ if(index[i]) delete[] index[i];
+ delete[] index;
+ index = 0;
+ return false;
+ }
+ return true;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff -ru walktrap_clean/graph.h walktrap/graph.h
--- walktrap_clean/graph.h 2005-06-07 14:18:46.000000000 +0200
+++ walktrap/graph.h 2009-12-03 17:04:10.000000000 +0100
@@ -1,71 +1,74 @@
-// File: graph.h
-//-----------------------------------------------------------------------------
-// Walktrap v0.2 -- Finds community structure of networks using random walks
-// Copyright (C) 2004-2005 Pascal Pons
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//-----------------------------------------------------------------------------
-// Author : Pascal Pons
-// Email : [email protected]
-// Web page : http://www.liafa.jussieu.fr/~pons/
-// Location : Paris, France
-// Time : June 2005
-//-----------------------------------------------------------------------------
-// see readme.txt for more details
-
-
-#ifndef GRAPH_H
-#define GRAPH_H
-#include <iostream>
-
-using namespace std;
-
-class Edge { // code an edge of a given vertex
-public:
- int neighbor; // the number of the neighbor vertex
- float weight; // the weight of the edge
-};
-bool operator<(const Edge& E1, const Edge& E2);
-
-
-class Vertex {
-public:
- Edge* edges; // the edges of the vertex
- int degree; // number of neighbors
- float total_weight; // the total weight of the vertex
-
- Vertex(); // creates empty vertex
- ~Vertex(); // destructor
-};
-
-class Graph {
-public:
- int nb_vertices; // number of vertices
- int nb_edges; // number of edges
- float total_weight; // total weight of the edges
- Vertex* vertices; // array of the vertices
-
- long memory(); // the total memory used in Bytes
- Graph(); // create an empty graph
- ~Graph(); // destructor
- char** index; // to keep the real name of the vertices
- bool load_index(char* input_file);
-};
-
-istream& operator>>(istream& in, Graph& G); // get a graph from a stream
-
-
-#endif
-
+// File: graph.h
+//-----------------------------------------------------------------------------
+// Walktrap v0.2 -- Finds community structure of networks using random walks
+// Copyright (C) 2004-2005 Pascal Pons
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//-----------------------------------------------------------------------------
+// Author : Pascal Pons
+// Email : [email protected]
+// Web page : http://www.liafa.jussieu.fr/~pons/
+// Location : Paris, France
+// Time : June 2005
+//-----------------------------------------------------------------------------
+// see readme.txt for more details
+
+
+#ifndef GRAPH_H
+#define GRAPH_H
+#include <iostream>
+#include <cstdlib>
+#include <algorithm>
+#include <cstring>
+
+using namespace std;
+
+class Edge { // code an edge of a given vertex
+public:
+ int neighbor; // the number of the neighbor vertex
+ float weight; // the weight of the edge
+};
+bool operator<(const Edge& E1, const Edge& E2);
+
+
+class Vertex {
+public:
+ Edge* edges; // the edges of the vertex
+ int degree; // number of neighbors
+ float total_weight; // the total weight of the vertex
+
+ Vertex(); // creates empty vertex
+ ~Vertex(); // destructor
+};
+
+class Graph {
+public:
+ int nb_vertices; // number of vertices
+ int nb_edges; // number of edges
+ float total_weight; // total weight of the edges
+ Vertex* vertices; // array of the vertices
+
+ long memory(); // the total memory used in Bytes
+ Graph(); // create an empty graph
+ ~Graph(); // destructor
+ char** index; // to keep the real name of the vertices
+ bool load_index(char* input_file);
+};
+
+istream& operator>>(istream& in, Graph& G); // get a graph from a stream
+
+
+#endif
+