File: graph.cpp

package info (click to toggle)
socnetv 0.90-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,028 kB
  • sloc: cpp: 12,953; makefile: 75
file content (4500 lines) | stat: -rwxr-xr-x 163,672 bytes parent folder | download
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
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
/******************************************************************************
 SocNetV: Social Networks Visualizer 
 version: 0.90
 Written in Qt 4.4
 
                         graph.cpp  -  description
                             -------------------
    copyright            : (C) 2005-2010 by Dimitris B. Kalamaras
    email                : dimitris.kalamaras@gmail.com
*******************************************************************************/

/*******************************************************************************
*     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 3 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, see <http://www.gnu.org/licenses/>.    *
********************************************************************************/


#include <fstream>		//for writing the adjacency matrix to a file
#include <cmath>		//allows the use of pow(float/double, float/double) function
#include <cstdlib>		//allows the use of RAND_MAX macro 

#include <QPointF>
#include <QDebug>		//used for qDebug messages
#include <QDateTime> 	// used in exporting centrality files
#include <QHash> 
#include <list>			//for list iterators
#include <queue>		//for BFS queue Q

#include "graph.h"




Graph::Graph() {
	m_totalVertices=0;
	outEdgesVert=0;
	inEdgesVert=0;
	reciprocalEdgesVert=0;
	order=true;		//returns true if the indexes of the list is ordered.
	graphModified=false;
	m_undirected=false;
	symmetricAdjacencyMatrix=true;
	adjacencyMatrixCreated=false;
	distanceMatrixCreated=false;
	calculatedIDC=false;
	calculatedODC=false;
	calculatedCentralities=false;

	dynamicMovement=false;
	timerId=0;
	layoutType=0;

	parser.setParent(this);
	
	connect (	
			&parser, SIGNAL( createNode (int,int,QString, QString, int, QString, QString, int, QPointF, QString, bool) ), 
			this, SLOT(createVertex(int,int,QString, QString, int, QString, QString, int, QPointF, QString, bool) ) 
			) ;

	connect (
		&parser, SIGNAL(createEdge (int, int, float, QString, int, bool, bool)),
		this, SLOT(createEdge (int, int, float, QString, int, bool, bool) )
		);

	connect (
		&parser, SIGNAL(fileType(int, QString, int, int, bool)),
		this, SLOT(setFileType(int, QString, int, int, bool)) 
		);
		
	connect (
		&parser, SIGNAL(removeDummyNode(int)),
		this, SLOT (removeDummyNode(int)) 
		);
		


	connect (
		&crawler, SIGNAL( createNode (QString, int) ),
		this, SLOT(createVertex(QString, int ) )
		) ;

	connect (
		&crawler, SIGNAL(createEdge (int, int)), 
		this, SLOT(createEdge (int, int) ) 
		);
				

}




/**
	main node creation slot, associated with homonymous signal from Parser. 
	Adds a Vertex to the Graph and calls addNode of GraphicsWidget 
	p holds the desired position of the new node.
	The new Vertex is named i and stores its color, label, label color, shape and position p.
*/
void Graph::createVertex(int i, int size, QString nodeColor, QString numColor, int numSize, QString label, QString lColor, int lSize, QPointF p, QString nodeShape, bool signalMW){
	int value = 1;
	addVertex(i, value, size,  nodeColor, numColor, numSize, label, lColor, lSize, p, nodeShape);
	emit drawNode( i, size,  nodeColor, numColor, numSize, label, lColor, lSize, p, nodeShape, initShowLabels, initNumbersInsideNodes, true);
	if (signalMW)
		emit graphChanged(); 
	initVertexColor=nodeColor; //draw new user-clicked nodes with the same color with that of the file loaded
	initVertexShape=nodeShape;
	initVertexSize=size;

} 



/**
	auxilliary node creation slot. 
	Called from GW, with i and p as parameters.
	p holds the desired position of the new node.
	Calls the main creation slot with init node values.
*/
void Graph::createVertex(int i, QPointF p){
	if ( i < 0 )  i = lastVertexNumber() +1;
	qDebug("Graph::createVertex(). Using vertex number %i with FIXED coords...", i);
	createVertex(	i, initVertexSize,  initVertexColor,
					initVertexNumberColor, initVertexNumberSize,   
					QString::number(i), initVertexLabelColor, initVertexLabelSize,
					p, initVertexShape, true
					);
}




/**
	second auxilliary node creation slot. 
	Called from MW only with parameter i.
	Calculates a random position p from canvasWidth and Height.
	Then calls the main creation slot with init node values.
*/
void Graph::createVertex(int i, int cWidth, int cHeight){
	if ( i < 0 )  i = lastVertexNumber() +1;
	qDebug("Graph::createVertex(). Using vertex number %i with RANDOM node coords...", i);
	QPointF p;
	p.setX(rand()%cWidth);
	p.setY(rand()%cHeight);
	createVertex(	i, initVertexSize, initVertexColor,
					initVertexNumberColor, initVertexNumberSize,   
					QString::number(i), initVertexLabelColor, initVertexLabelSize,
					p, initVertexShape, true
					);
}



/**
	third auxilliary node creation slot. 
	Called from WebCrawler with parameter i.
	Calculates a random position p from canvasWidth and Height.
	Then calls the main creation slot with init node values.
*/

void Graph::createVertex(QString label, int i) {
	if ( i < 0 )  i = lastVertexNumber() +1;
	qDebug("Graph::createVertex(). Using vertex number %i with RANDOM node coords but with LABEL...", i);
	QPointF p;
	p.setX(rand()%canvasWidth);
	p.setY(rand()%canvasHeight);
	createVertex(	i, initVertexSize,  initVertexColor,
					initVertexNumberColor, initVertexNumberSize,   
					label, initVertexLabelColor,  initVertexLabelSize,
					p, initVertexShape, true
					);
	
}


void Graph::setCanvasDimensions(int w, int h){
	qDebug() << "Graph:: setCanvasDimensions() to " << w << " " << h ; 
	canvasWidth = w;
	canvasHeight= h;
}

/**
	Called from homonymous signal of Parser class. 
	Adds an Edge to the Graph, then emits drawEdge() which calls GraphicsWidget::addEdge() to draw the new edge. 
	Also called from MW when user clicks on the "add link" button 
	Alse called from GW (via createEdge() below) when user middle-clicks.
*/
void Graph::createEdge(int v1, int v2, float weight, QString color, int reciprocal=0, bool drawArrows=true, bool bezier=false){
	if ( reciprocal == 2) {
		qDebug()<<"*** Graph: createEdge() from "<<v1<<" to "<<v2<<" of weight "<<weight << " as RECIPROCAL and emitting drawEdge signal to GW";
		addEdge ( v1, v2, weight, color, reciprocal);
		emit drawEdge(v1, v2, weight, reciprocal, drawArrows, color, bezier);
	}
	else if (this->hasEdge( v2, v1) )  {  
		qDebug()<<"*** Graph: createEdge() from "<<v1<<" to "<<v2<<" of weight "<<weight << ". Opposite link exists. Emitting drawEdgeReciprocal to GW to make the original reciprocal";
		reciprocal = 1;
		addEdge ( v1, v2, weight, color, reciprocal);
		emit drawEdgeReciprocal(v2, v1);
	}
	else {
		qDebug()<<"*** Graph: createEdge() from "<<v1<<" to "<<v2<<" of weight "<<weight << ". Opposite link does not exist. Emitting drawEdge to GW...";
		reciprocal = 0;
		addEdge ( v1, v2, weight, color, reciprocal);
		emit drawEdge(v1, v2, weight, reciprocal, drawArrows, color, bezier);
	}
	initEdgeColor=color; //draw new edges the same color with those of the file loaded, on user clicks on the canvas
	emit graphChanged(); 
}


/**
	Called (via MW::addLink()) from GW when user middle-clicks on two nodes.
	Calls the above createEdge() method with initEdgeColor to set the default edge color.
*/
void Graph::createEdge(int v1, int v2, float weight, int reciprocal=0, bool drawArrows=true, bool bezier=false){
	createEdge(v1, v2, (float) weight, initEdgeColor, reciprocal, drawArrows, bezier);
}


/**
	Called from WebCrawler when it finds an new link 
	Calls the above createEdge() method with initEdgeColor 
*/
void Graph::createEdge (int source, int target){
	if (this->hasEdge(source, target) ) {
		qDebug()<< " Graph::createEdge - Edge from " << source << " to " << target << " already exists - returning...";
		return; 
	}		
	qDebug()<< " Graph::createEdge - New edge from " << source << " to " << target ;
	float weight = 1.0;
	bool reciprocal=false;
	bool drawArrows=true; 
	bool bezier=false;
	
	createEdge(source, target, weight, initEdgeColor, reciprocal, drawArrows, bezier);	
}

/**
*	This is called from loadPajek method of Parser in order to delete any redundant (dummy) nodes.
*/
void Graph::removeDummyNode(int i){
	qDebug("**Graph: RemoveDummyNode %i", i);
	removeVertex(i);
//	emit selectedVertex(i);

}



/**	Adds a Vertex 
	named v1, valued val, sized nszm colored nc, labeled nl, labelColored lc, shaped nsp, at point p
	This method is called by createVertex() method
*/
void Graph::addVertex (
		int v1, int val, int size, QString color,
		QString numColor, int numSize,
		QString label, QString labelColor, int labelSize,
		QPointF p, QString shape
		){

	if (order)
		index[v1]=m_totalVertices; 
	else 
		index[v1]=m_graph.size();

	m_graph.append( new Vertex(this, v1, val, size, color, numColor, numSize, label, labelColor, labelSize, p, shape) );
	m_totalVertices++;		

	qDebug() << "Graph: addVertex(): Vertex named " << m_graph.back()->name() << " appended with index= "<<index[v1]
			<< " Now, m_graph size " << m_graph.size() << ". New vertex position: " << p.x() << "," << p.y(); 
	graphModified=true;
}




/**
	updates MW  with the file type (0=nofile, 1=Pajek, 2=Adjacency etc)
*/
void Graph::setFileType (
		int type, QString networkName, int aNodes, int totalLinks, bool undirected)
{
	qDebug("Graph: setFileType %i", type);
	m_undirected = undirected;
	emit signalFileType (type, networkName, aNodes, totalLinks, m_undirected);
}



/**	Returns the name of the last vertex.
	Used by slotRemoveNode of MW 
*/
int Graph::lastVertexNumber() {
	if (m_totalVertices>0)
		return m_graph.back()->name();
	else return 0;
}


/**	Returns the name of the first vertex. 
	Used by slotRemoveNode of MW 
*/
int Graph::firstVertexNumber() {
	if (m_totalVertices>0)
		return m_graph.front()->name();
	else return 0;
}



/**	Removes the vertex named Doomed from the graph 
	First, it removes all edges to Doomed from other vertices
	Then it changes the index of all subsequent vertices inside m_graph
	Finally, it removes the vertex.
*/
void Graph::removeVertex(long int Doomed){
	qDebug() << "Graph: removeVertex " << m_graph[ index[Doomed] ]->name() << "  with index= " << index[Doomed] ;
	long int indexOfDoomed=index[Doomed];

	//Remove links to Doomed from each other vertex	
	for (QList<Vertex*>::iterator it=m_graph.begin(); it!=m_graph.end(); it++){
		if  ( (*it)->isLinkedTo(Doomed) != 0) {
			qDebug()<< "Graph: Vertex " << (*it)->name() << " is linked to selected and has outDegree " << (*it)->outDegree() ;
			if ( (*it)->outDegree() == 1 && (*it)->isLinkedFrom(Doomed) != 0 )	{
				qDebug() << "Graph: decreasing reciprocalEdgesVert";
				(*it)->setReciprocalLinked(FALSE);
			}
			(*it)->removeLinkTo(Doomed) ;
		}
		if (  (*it)->isLinkedFrom(Doomed) != 0 ) { 
		    (*it)->removeLinkFrom(Doomed);
		}
	}
	
	qDebug()<< "Graph: Finished with vertices. Update the index which maps vertices inside m_graph " ;
	long int prevIndex=indexOfDoomed;
	long int tempIndex=0;
	//Find the position of the Vertex inside m_graph
	map<long int,long int>::iterator pos=index.find(Doomed);
	qDebug() << "Graph: vertex " << (pos)->first << " index "<< (pos)->second << " to be erased. ";

	//find next active vertex inside index
	(pos)->second = -1;
	while ( (pos)->second == -1 )
	    ++pos;
	qDebug() << "Graph: posNext " << (pos)->first << " index "<< (pos)->second ;


	//Update the index of all subsequent vertices
	map<long int,long int>::iterator it1;
	for (it1=pos; it1!=index.end(); it1++)	{
		qDebug() << "Graph: vertex " << (it1)->first << " with index "<< (it1)->second << " will take index" << prevIndex;
		tempIndex=(it1)->second;
		(it1)->second=prevIndex;
		prevIndex=tempIndex;
		qDebug() << "Graph: now vertex " << (it1)->first << " has index "<< (it1)->second ;
	}
	
	//Now remove vertex Doomed from m_graph
	qDebug() << "Graph: graph vertices=size="<< vertices() << "=" << m_graph.size() <<  " removing vertex at index " << indexOfDoomed ;
	m_graph.removeAt( indexOfDoomed ) ;
	m_totalVertices--;
	qDebug() << "Graph: Now graph vertices=size="<< vertices() << "=" << m_graph.size() <<  " total edges now  " << totalEdges();

	order=false;
	graphModified=true;

	emit graphChanged();
	emit eraseNode(Doomed); 
}



/**	Creates an edge between v1 and v2
*/
void Graph::addEdge (int v1, int v2, float weight, QString color, int reciprocal) {

	int source=index[v1];
	int target=index[v2];

	qDebug()<< "Graph: addEdge() from vertex "<< v1 << "["<< source<< "] to vertex "<< v2 << "["<< target << "] of weight "<<weight;

	m_graph [ source ]->setOutLinked(TRUE) ;
	m_graph [ source ]->addLinkTo(v2, weight );
	m_graph [ target ]->setInLinked(TRUE) ;
	m_graph [ target ]->addLinkFrom(v1, weight);
	m_totalEdges++;

	if (reciprocal == 1){
	    m_graph [ source ]->setReciprocalLinked(TRUE);
	    m_graph [ target ]->setReciprocalLinked(TRUE);
	}
	else if (reciprocal == 2){
	    m_graph [ source ]->setReciprocalLinked(TRUE);
	    m_graph [ target ]->setReciprocalLinked(TRUE);
	    m_graph [ target ]->addLinkTo(v1, weight );
	    m_graph [ source ]->addLinkFrom(target, weight);
	    m_totalEdges++;
	}


	qDebug()<<"Graph: addEdge() now a("<< v1 << ","<< v2<< ") = " << m_graph [ source ]->isLinkedTo(v2) << " with color "<<  color<<" . Storing edge color..." << ". Total Links " <<m_totalEdges;
	m_graph[ source]->setOutLinkColor(v2, color);

	graphModified=true;
}




/**	
	Change edge (arc) weight between v1 and v2
*/
void Graph::setEdgeWeight (int v1, int v2, float weight) {
	qDebug() << "Graph: setEdgeWeight between " << v1 << "[" << index[v1] << "] and " << v2 << "[" << index[v2] << "]" << " = " << weight;
	m_graph [ index[v1] ]->changeLinkWeightTo(v2, weight);
	graphModified=true;
	emit graphChanged(); 
}

	
/** 	Removes the edge (arc) between v1 and v2
*/
void Graph::removeEdge (int v1, int v2) {	
	qDebug ()<< "Graph: removeEdge edge " << v1 << " to " << v2 << " to be removed from graph";
	qDebug() << "Graph: Vertex named " << m_graph[ index[v1] ]->name() << " has index = " << index[v1];
	m_graph [ index[v1] ]->removeLinkTo(v2);
	m_graph [ index[v2] ]->removeLinkFrom(v1);
	qDebug()<< "Graph: removeEdge between " << v1 << " i " << index[v1] << " and " << v2 << " i "<< index[v2] 
			<< "  NOW vertex v1 reports edge weight " << m_graph [ index[v1] ]->isLinkedTo(v2) ;
	if ( this->hasEdge(v2,v1) !=0) symmetricAdjacencyMatrix=false;
	m_totalEdges--;
	if (m_totalEdges<0) m_totalEdges=0;
	graphModified=true;
	qDebug("Graph: removeEdge(): emitting eraseEdge to GW"); 
	emit eraseEdge(v1,v2);
	emit graphChanged(); 
}





//Called by MW to start a web crawler...
void Graph::webCrawl( QString seed, int maxNodes, int maxRecursion,  bool goOut){
	qDebug() << "Graph:: webCrawl - Calling thread for " << seed ;
	crawler.load(seed, maxNodes, maxRecursion, goOut);
	qDebug("Graph:: See the thread? :)");
}






/**
	Called from filterOrphanNodes via MainWindow  to filter nodes with no links
	For each orphan Vertex in the Graph, emits the filterVertex()
*/
void Graph::filterOrphanVertices(bool filterFlag){
	if (filterFlag)
		qDebug() << "Graph: filterOrphanVertices() enabling all orphan nodes";
	else
		qDebug() << "Graph: filterOrphanVertices() disabling all orphan nodes";

	QList<Vertex*>::iterator it;
	for (QList<Vertex*>::iterator it=m_graph.begin(); it!=m_graph.end(); it++){
		if ( (*it)->isOutLinked() ||  (*it)->isInLinked() ){
			continue;
		}
		else {
			qDebug() << "Graph:filterOrphanNodes() Vertex " << (*it)->name()
				<< " not linked. Toggling it and emitting setVertexVisibility signal to GW...";
			(*it)->setEnabled (filterFlag) ;
			emit setVertexVisibility( (*it)-> name(), filterFlag );
		}
	}
}




/**
	Called from filterEdgesDialog via MainWindow 
	to filter edges over or under a specified weight (m_threshold)
	For each Vertex in the Graph, calls the homonymous method of Vertex class.
*/
void Graph::filterEdgesByWeight(float m_threshold, bool overThreshold){
	if (overThreshold)
		qDebug() << "Graph: filterEdgesByWeight() over " << m_threshold ;
	else 
		qDebug() << "Graph: filterEdgesByWeight()  below "<< m_threshold ;

	QList<Vertex*>::iterator it;
	for (QList<Vertex*>::iterator it=m_graph.begin(); it!=m_graph.end(); it++){ 
		if ( (*it)->isOutLinked() ){
			(*it)->filterEdgesByWeight ( m_threshold, overThreshold );
		}	
		else 
			qDebug() << "Graph:filterEdgesByWeight() Vertex " << (*it)->name() 
				<< " not linked. Proceeding...";
	}
}


void Graph::slotSetEdgeVisibility ( int source, int target, bool visible) {
	qDebug() << "Graph: slotSetEdgeVisibility  - emitting signal to GW";  
	emit setEdgeVisibility ( source, target, visible); 
}


/**	Checks if there is a specific vertex in the graph
	Returns the index or -1
	Complexity:  O(logN) for index retrieval 
*/
int Graph::hasVertex(long int num){
	qDebug () << "Graph: hasVertex() v: " << num <<  " with index " << index[num]  << " named " << m_graph[ index[num]] ->name();
	if (  m_graph[ index[num]] ->name() == num)  
		return index[num];
	else 
		return -1;
}



/**	Checks if there is a vertex with a specific label in the graph
	Returns the index or -1
	Complexity:  O(N) 

*/
int Graph::hasVertex(QString label){			
	qDebug ()<<"Graph: hasVertex( "<< label.toAscii() <<" ) ?" ;
	QList<Vertex*>::iterator it;
	int i=0;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		if ( (*it) ->label() == label)  {
			qDebug()<< "Graph: hasVertex() at pos %i" << i;
			return i;
		}
		i++;
	}	
	qDebug("Graph: hasVertex() NO - returning -1");
	return -1;
}




void Graph::setInitVertexSize (long int size) {
	initVertexSize=size;
}


//Changes the size.of vertex v 
void Graph::setVertexSize(long int v, int size) {
	m_graph[ index[v] ]->setSize(size);
	graphModified=true;
	emit graphChanged(); 
}


void Graph::setInitVertexShape(QString shape) {
	initVertexShape=shape;
}

//Changes the shape.of vertex v 
void Graph::setVertexShape(int v1, QString shape){
	m_graph[ index[v1] ]->setShape(shape);
	graphModified=true;
	emit graphChanged(); 
}


//returns the shape of this vertex
QString Graph::shape(int v1){
	return m_graph[ index[v1] ]->shape();

}

//Changes the initial color of vertices numbers 
void Graph::setInitVertexNumberColor (QString color) {
	initVertexNumberColor = color;
}

//Changes the initial size of vertices numbers 
void Graph::setInitVertexNumberSize (int size) {
	initVertexNumberSize = size;
}



/**Changes the label.of vertex v  */
void Graph::setVertexLabel(int v1, QString label){
	qDebug()<< "Graph: setVertexLabel for "<< v1 << ", index " << index[v1]<< " with label"<< label;
	m_graph[ index[v1] ]->setLabel ( label);
	graphModified=true;
	emit graphChanged(); 
}



//Changes the init size of new vertices labels
void Graph::setInitVertexLabelSize(int newSize) {
	initVertexLabelSize = newSize;
}


//Changes the size of a vertex label
void Graph::setVertexLabelSize(int v1, int newSize) {
	qDebug()<< "Graph: setVertexLabelSize for "<< v1 << ", index " << index[v1]<< " with size "<< newSize;
	m_graph[ index[v1] ] -> setLabelSize ( newSize );
	graphModified=true;
	emit graphChanged(); 

}



//Changes the shape.of vertex v 
void Graph::setVertexLabelColor(int v1, QString color){
	m_graph[ index[v1] ]->setLabelColor(color);
	graphModified=true;
	emit graphChanged(); 
}


void Graph::setInitVertexLabelColor(QString color){
	initVertexLabelColor=color;
}


QString Graph::label(int v1){
	return m_graph[ index[v1] ]->label ();
}


/**
	Changes the color of vertice v1
*/
void Graph::setVertexColor(long int v1, QString color){
	qDebug()<< "Graph: setVertexColor for "<< v1 << ", index " << index[v1]<< " with color "<< color;
	m_graph[ index[v1] ]->setColor ( color );
	graphModified=true;
	emit graphChanged(); 
}


void Graph::setInitVertexColor(QString color){
	initVertexColor=color;
}




void Graph::setInitEdgeColor(QString color){
	initEdgeColor=color;
}


/**
 	Changes the color of edge (s,t).
*/
void Graph::setEdgeColor(long int s, long int t, QString color){
	qDebug()<< "Graph: setEdgeColor for edge ("<< s << ","<< t<<")"<<" with index ("<< index[s]<< ","<<index[t]<<")"<<" with color "<< color;
	m_graph[ index[s] ]->setOutLinkColor(t, color);
	if (isSymmetric()) {
		m_graph[ index[t] ]->setOutLinkColor(s, color);
	}
	emit graphChanged(); 
}	



//Returns the edgeColor
QString Graph::edgeColor (long int s, long int t){
	return m_graph[ index[s] ]->outLinkColor(t);
}


	
/**	Checks if there is an edge from v1 to v2
	Complexity:  O(logN) for index retrieval + O(1) for QList index rerieval + O(logN) for checking edge(v2) 
*/
float Graph::hasEdge (int v1, int v2) {		
	float weight=0;
	if ( ! m_graph[ index[v1] ] -> isEnabled() || ! m_graph[ index[v2] ] -> isEnabled())
		return 0;
	if ( (weight=  m_graph[ index[v1] ] -> isLinkedTo(v2) ) != 0 ) {
	    //qDebug() << "Graph: hasEdge() between " <<  v1 << " " << index[v1] <<  " and " <<  v2 << " " << index[v2] << " = " << weight;
		return weight;
	}
	else {	
		return 0;
	}
}


/**
	Called from MainWindow
*/
void Graph::updateVertCoords(int v1, int  x, int y){
	//qDebug("Graph: updateVertCoords() for %i with index %i with %i, %i", v1, index[v1], x,y);
	m_graph[ index[v1] ]->setX( x );
	m_graph[ index[v1] ]->setY( y );
	graphModified=true;
}



/**	Returns the number of edges (arcs) from vertex v1
*/
int Graph::edgesFrom (int v1) {  
	qDebug("Graph: edgesFrom()");
	return m_graph[ index[v1] ]->outDegree();
}


/**	
	Returns the number of edges (arcs) to vertex v1
*/
int Graph::edgesTo (int v1) {  
	qDebug("Graph: edgesTo()");
	QList<Vertex*>::iterator it;
	int m_outEdgesTo=0;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		if  ( (*it)->isLinkedTo(v1) != 0) m_outEdgesTo++;
	}
	return m_outEdgesTo;
}


/** 
	Returns |E| of graph 
*/
int Graph::totalEdges () {
	qDebug("Graph: totalEdges()");
	int tEdges=0;
	QList<Vertex*>::iterator it;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		tEdges+=(*it)->outDegree();
	}
	qDebug() << "Graph: m_totalEdges = " << m_totalEdges << ", tEdges=" <<  tEdges;
 	return tEdges;
}


/**	
	Returns |V| of graph
*/
int Graph::vertices () { 
	qDebug("Graph: vertices()");
	return m_totalVertices;
}


float Graph::density() {
	qDebug("Graph: density()");
	int vert=vertices();
	if (vert!=0 && vert!=1)
		return  (float) totalEdges() / (float)(vert*(vert-1.0));
	else return 0;
}


/**
	Returns the sum of vertices having outEdges
*/
int Graph::verticesWithOutEdges(){
	return outEdgesVert;
}

/**
	Returns the sum of vertices having inEdges
*/
int Graph::verticesWithInEdges(){
	return inEdgesVert;
}


/**
	Returns the sum of vertices having reciprocal edges
*/
int Graph:: verticesWithReciprocalEdges(){
	return reciprocalEdgesVert;
}

/** 
	Clears all vertices 
*/
void Graph::clear() {
	//qDebug("Graph: m_graph reports size %i", m_graph.size());
	m_graph.clear();
	index.clear();
	discreteIDCs.clear();
	discreteODCs.clear();
	m_totalVertices=0;
	m_totalEdges=0;
	outEdgesVert=0;
	inEdgesVert=0;
	reciprocalEdgesVert=0;
	
	order=true;		//returns true if the indexes of the list is ordered.
	m_undirected=false;
	calculatedIDC=false;
	calculatedODC=false;
	calculatedCentralities=false;
	adjacencyMatrixCreated=false;
	graphModified=false;
	symmetricAdjacencyMatrix=true;
	
	if (parser.isRunning() )		//tell the other thread that we must quit! 
		parser.quit();
	
	if (crawler.isRunning() ){
		//tell the other thread that we must quit!
		crawler.terminateReaderQuit();
		crawler.quit();	
	}	 
	//qDebug("Graph: m_graph cleared. Now reports size %i", m_graph.size());
}



/**
	Returns TRUE if the adjacency matrix is symmetric 
*/
bool Graph::isSymmetric(){
	qDebug("Graph: isSymmetric ");
	if (graphModified){
		symmetricAdjacencyMatrix=TRUE;
		imap_f::iterator it1;
		int y=0;
		QList<Vertex*>::iterator it;
		for (it=m_graph.begin(); it!=m_graph.end(); it++){ 	//for all edges of u, (u,y)
			//qDebug("Graph: isSymmetric(): GRAPH CHANGED! Iterate over all edges of u...");
			for( it1 = (*it)->m_outEdges.begin(); it1 != (*it)->m_outEdges.end(); it1++ ) {
				y=index[it1->first];	
				if ( ! m_graph[y]->isLinkedTo( (*it)->name() )) {
					//qDebug("Graph: isSymmetric():  u = %i IS NOT inLinked from y = %i", (*it)->name(), it1->first  );
					symmetricAdjacencyMatrix=FALSE;
					qDebug("Graph: isSymmetric()  NO");
					return symmetricAdjacencyMatrix;
				}
				else {
				//	qDebug("Graph: isSymmetric():  u = %i IS inLinked from y = %i",it1->first, (*it)->name()  );					
				}
			}
		}
		graphModified=false;
	}
	qDebug("Graph: isSymmetric() YES");
	return symmetricAdjacencyMatrix;
}



/**
*	Transform the directed network to symmetric (all edges reciprocal) 
*/
void Graph::symmetrize(){
	qDebug("Graph: symmetrize");
	QList<Vertex*>::iterator it;
	imap_f::iterator it1;
	int y;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		//for all edges (u,y) of u, do
		qDebug("Graph: making all edges reciprocal. First iterate over all edges of u...");
		for( it1 = (*it)->m_outEdges.begin(); it1 != (*it)->m_outEdges.end(); it1++ ) {
			y=index[it1->first];	
			if ( ! m_graph[y]->isLinkedTo( (*it)->name() )) {
				qDebug() << "Graph: symmetrize: u = " << (*it)->name() << " IS NOT inLinked from y = " <<  it1->first  ;
				createEdge(it1->first, (*it)->name(), it1->second, initEdgeColor, false, true, false);
			}
			else
				qDebug() << "Graph: symmetrize: u = " << it1->first  << " IS inLinked from y = " <<   (*it)->name() ; 
		}
	}
	graphModified=TRUE;
	symmetricAdjacencyMatrix=TRUE;
	emit graphChanged(); 
}



bool Graph::symmetricEdge(int v1, int v2){
	qDebug("***Graph: symmetricEdge()");
	if ( (this->hasEdge ( v1, v2 ) ) > 0  &&  (this->hasEdge ( v2, v1 ) ) > 0   ) { 
		qDebug("Graph: symmetricEdge: YES");
		return true;
	}
	else {
		qDebug("Graph: symmetricEdge: NO");
		return false;
	}

}




/**
*  Returns the distance between nodes numbered (i-1) and (j-1)
*/
int Graph::distance(int i, int j){
	if (graphModified ||  !distanceMatrixCreated ){
		createDistanceMatrix(false);
		graphModified=false;
	}
  	return DM.item(index[i],index[j]);
}



/**
*  Returns the diameter of the graph, aka the largest geodesic distance between any two vertices
*/
int Graph::diameter(){
	if (graphModified){
		createDistanceMatrix(false);
		graphModified=false;
	}
  	return graphDiameter;
}



/**
*  Returns the average distance of the graph
*/
float Graph::averageGraphDistance(){
	if (graphModified){
		createDistanceMatrix(false);
		graphModified=false;
	}
  	return averGraphDistance;
}

/**
*  Writes the matrix of distances to a file
*/
void Graph::writeDistanceMatrix (const char* fn, const char* fn1, const char* netName) {
	qDebug ("Graph::writeDistanceMatrix()");
	createDistanceMatrix(false);
	qDebug ("Graph::writeDistanceMatrix() writing to file");
	ofstream file (fn);
	ofstream file1 (fn1);
	int dist=-1, sigma=-1;
	
	char one_space[]     = " ";	Q_UNUSED (one_space);
	char two_spaces[]    = "  ";
	char three_spaces[]  = "   ";	Q_UNUSED (three_spaces);
	char four_spaces[]   = "    ";
	char five_spaces[]   = "     ";	Q_UNUSED (five_spaces);
	char six_spaces[]    = "      ";
	char seven_spaces[]  = "       ";
	char eight_spaces[]  = "        ";
	char nine_spaces[]   = "         ";
	char ten_spaces[]    = "          ";

	file << "-Social Network Visualizer- \n";
	if (!netName) netName="Unnamed network";
	file << "Distance matrix of "<< netName<<": \n\n";
	//write out matrix of geodesic distances
	QList<Vertex*>::iterator it, it1;	
	int i=0, j=0;
	
	file << ten_spaces << two_spaces;   

	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		
		file << ++i ;
		if (i>9999)
			file << six_spaces;
		else if (i>999)
			file << seven_spaces;
		else if (i>99)
			file << eight_spaces;
		else if(i>9) 
			file << nine_spaces;
		else 
 			file << ten_spaces ; 

	}
	
	file<<endl;
	
	i=0;
	
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		file << ++i ;	

		if (i>9999)
			file << two_spaces;
		if (i>999)
			file << four_spaces;
		else if (i>99)
			file << six_spaces ;
		else if(i>9) 
			file << eight_spaces;
		else 
 			file << ten_spaces; 
 			
 		j=0;
 		
		for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){	
			++j;

			if ( (dist= DM.item( index[(*it)->name()],  index[(*it1)->name()] ) )!=-1 ) {
				file << dist;
				if (dist>999)
					file <<  seven_spaces;
				else if (dist>99)
					file <<  eight_spaces;  
				else if(dist>9) 
					file << nine_spaces;  
				else 
					file << ten_spaces; 
			}
			else
				file << "0"<< ten_spaces;
		}
 		file << endl;
	}
	file.close();
	//write out matrix of sigmas
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){	
			if ( (sigma= TM.item( index[(*it)->name()],  index[(*it1)->name()] ) )!=-1 ) {
				file1 << sigma<<" ";
			}
			else
				file1 << "0 ";
		}
 		file1 << endl;
	}
	file1.close();

}




/**
	Creates a matrix DM which stores geodesic distances between all vertices
	INPUT: 
		boolean doCalculcateCentralities
	OUTPUT:
		DM(i,j)=geodesic distance between vertex i and vertex j
		TM(i,j)=number of shortest paths from vertex i to vertex j, called sigma(i,j).
		graphDiameter is set to the length of the longest shortest path between every (i,j)
		Also, if doCalculcateCentralities==TRUE, it calculates the centralities for every u in V:
		- Betweeness: BC(u) = Sum ( sigma(i,j,u)/sigma(i,j) ) for every s,t in V
		- Stress: SC(u) = Sum ( sigma(i,j) ) for every s,t in V
		- Graph: CC(u) =  1/maxDistance(u,t)  for some t in V
		- Closeness: CC(u) =  1 / Sum( DM(u,t) )  for every  t in V
*/

void Graph::createDistanceMatrix(bool doCalculcateCentralities) {
	qDebug ("Graph::createDistanceMatrix()");
	if ( !graphModified && distanceMatrixCreated && !doCalculcateCentralities)  { 
		qDebug("Graph: distanceMatrix not mofified. Escaping.");
		return;
	}
	//Create a NxN DistanceMatrix. Initialise values to zero.
	qDebug() << "Graph::createDistanceMatrix() Resizing Matrices to hold " << m_totalVertices << " vertices";
	DM.resize(m_totalVertices);
	TM.resize(m_totalVertices);

	int aVertices=vertices();
	int aEdges = totalEdges();    //maybe we will use m_totalEdges here to save some time?...

	if ( aEdges == 0 )
		DM.fillMatrix(0);	
	else {
		qDebug() << "	for all vertices set their distances to -1 (infinum)";
		DM.fillMatrix(-1);
		qDebug () << "	for all vertices set their sigmas as 0";
		TM.fillMatrix(0);

		QList<Vertex*>::iterator it, it1;
		QList<int>::iterator it2;
		int w=0, u=0,s=0, i=0;
		float d_sw=0, d_su=0;
		float CC=0, BC=0, SC= 0, GC=0, EC=0, PC=0, stdGC=0, stdEC=0;
		int progressCounter=0;

		graphDiameter=0;

		distanceMatrixCreated = false;
		averGraphDistance=0;
		nonZeroDistancesCounter=0;

		qDebug() << "	graphDiameter "<< graphDiameter << " averGraphDistance " <<averGraphDistance;
		qDebug() << "	reciprocalEdgesVert "<< reciprocalEdgesVert << " inEdgesVert " << inEdgesVert 
				<< " outEdgesVert "<<  outEdgesVert;
		qDebug() << "	aEdges " << aEdges <<  " aVertices " << aVertices;
		

		maxIndexBC=0;
		maxIndexSC=0;
		maxIndexEC=0;
	
		qDebug("Graph: createDistanceMatrix() - initialising variables for maximum centrality indeces");
		if (symmetricAdjacencyMatrix) {
			maxIndexBC=( aVertices-1.0) *  (aVertices-2.0)  / 2.0;
			maxIndexSC=( aVertices-1.0) *  (aVertices-2.0) / 2.0;
			maxIndexCC=1.0/(aVertices-1.0);
			maxIndexEC=aVertices-1.0;
			maxIndexPC=aVertices-1.0;
			qDebug("############# symmetricAdjacencyMatrix - maxIndexBC %f, maxIndexCC %f, maxIndexSC %f", maxIndexBC, maxIndexCC, maxIndexSC);
		}
		else {	
			//maxIndexBC= ( ( outEdgesVert-1.0) *  (inEdgesVert-2.0) - (reciprocalEdgesVert-1.0))/ 2.0;
			maxIndexBC=( aVertices-1.0) *  (aVertices-2.0) ;
			maxIndexSC=1;
			maxIndexEC=(aVertices-1.0);
			maxIndexPC=aVertices-1.0;
			maxIndexCC=1.0/(aVertices-1.0);  //FIXME This applies only on undirected graphs
			qDebug("############# NOT SymmetricAdjacencyMatrix - maxIndexBC %f, maxIndexCC %f, maxIndexSC %f", maxIndexBC, maxIndexCC, maxIndexSC);
		}
		//float maxIndexBC-directed= (n1-1) * (n2-1)-(ns-1) , n1  vert outgoing n2 ingoing vert ns self  // all this divided by two.
		qDebug("Graph: createDistanceMatrix() - initialising variables for centrality index");
		maxCC=0; minCC=RAND_MAX; nomCC=0; denomCC=0; groupCC=0; maxNodeCC=0; minNodeCC=0; sumCC=0;
		discreteCCs.clear(); classesCC=0;
		maxBC=0; minBC=RAND_MAX; nomBC=0; denomBC=0; groupBC=0; maxNodeBC=0; minNodeBC=0; sumBC=0;
		discreteBCs.clear(); classesBC=0;
		maxSC=0; minSC=RAND_MAX; nomSC=0; denomSC=0; groupSC=0; maxNodeSC=0; minNodeSC=0; sumSC=0;
		discreteSCs.clear(); classesSC=0;
		maxGC=0; minGC=RAND_MAX; nomGC=0; denomGC=0; groupGC=0; maxNodeGC=0; minNodeGC=0; sumGC=0;
		discreteGCs.clear(); classesGC=0;
		maxPC=0; minPC=RAND_MAX; maxNodePC=0; minNodePC=0; sumPC=0;
		discretePCs.clear(); classesPC=0;
		maxEC=0; minEC=RAND_MAX; nomEC=0; denomEC=0; groupEC=0; maxNodeEC=0; minNodeEC=0; sumEC=0;
		discreteECs.clear(); classesEC=0;
		
		//Zero closeness indeces of each vertex
		if (doCalculcateCentralities) 
			for (it=m_graph.begin(); it!=m_graph.end(); it++) {
				(*it)->setBC( 0.0 );
				(*it)->setSC( 0.0 );
				(*it)->setGC( 0.0 );
				(*it)->setCC( 0.0 );
				(*it)->setPC( 0.0 );
		}
		qDebug("MAIN LOOP: for every s in V do (solve the single source shortest path problem...");
		for (it=m_graph.begin(); it!=m_graph.end(); it++){
			progressCounter++;
			emit updateProgressDialog( progressCounter );
			if ( ! (*it)->isEnabled() )
				continue;
			s=index[(*it)->name()];
			qDebug() << "Source vertex s = " << (*it)->name() << " of BFS algorithm has index " << s << ". Clearing Stack ...";
			if (doCalculcateCentralities){
				qDebug("Empty stack Stack which will return vertices in order of their (non increasing) distance from S ...");
				//- Complexity linear O(n) 
				while ( !Stack.empty() )  
					Stack.pop();
				i=0;
				qDebug("...and for each vertex: empty list Ps of predecessors");
				for (it1=m_graph.begin(); it1!=m_graph.end(); it1++) {
					(*it1)->clearPs();
					//initialize all sizeOfNthOrderNeighborhood to zero
					 sizeOfNthOrderNeighborhood[ i ]=0;
					 i++;
				}
			}

			qDebug() << "PHASE 1 (SSSP): Call BFS for source vertex " << (*it)->name() 
				<< " to determine distances and shortest path counts from s to every vertex t" ;
			BFS(s,doCalculcateCentralities );
			qDebug("***** FINISHED PHASE 1 (SSSP) BFS ALGORITHM. Continuing to calculate centralities");

			if (doCalculcateCentralities){
				qDebug() << "Set centrality for current source vertex " << (*it)->name() << "  with index s = " << s ;
				if ( (*it)->CC() != 0 ) //Closeness centrality must be inverted 	
					CC=1.0/(*it)->CC();
				else CC=0;
				(*it)->setSCC ( CC * ( aVertices-1.0)  );
				(*it)->setCC( CC );
				//Resolve classes Closeness centrality
				qDebug("=========Resolving CC classes...");
				resolveClasses(CC, discreteCCs, classesCC,(*it)->name() );
				sumCC+=CC;
				minmax( (*it)->SCC(), (*it), maxCC, minCC, maxNodeCC, minNodeCC) ;
				//And graph centrality must be inverted...
				if ( (*it)->GC() != 0 ) {
					EC=(*it)->GC();		//Eccentricity Centrality is max geodesic
					GC=1.0/EC;		//Graph Centrality is inverted Eccentricity
				}
				else { GC=0; EC=0;}
				(*it)->setGC( GC );		//Set Graph Centrality 
				(*it)->setEC( EC ); 		//Set Eccentricity Centrality 
				//Resolve classes Graph centrality
				resolveClasses(GC, discreteGCs, classesGC);
				stdGC =(aVertices-1.0)*GC ;
				(*it)->setSGC(stdGC);
				sumGC+=GC;
				minmax( GC, (*it), maxGC, minGC, maxNodeGC, minNodeGC) ;

				stdEC =EC/(aVertices-1.0);
				(*it)->setSEC(stdEC);
				sumEC+=EC;
				minmax( EC, (*it), maxEC, minEC, maxNodeEC, minNodeEC) ;
				
				i=1; //used in calculating power centrality
				sizeOfComponent = 1;
				PC=0;
				qDebug("PHASE 2 (ACCUMULATION): Start back propagation of dependencies. Set dependency delta[u]=0 on each vertex");
				for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){
					(*it1)->setDelta(0.0);
					//Calculate Power Centrality: In = [ 1/(N-1) ] * ( Nd1 + Nd2 * 1/2 + ... + Ndi * 1/i )
					// where Ndi (sizeOfNthOrderNeighborhood) is the number of nodes at distance i from this node.
					PC += ( 1.0 / (float) i ) * sizeOfNthOrderNeighborhood[i];
					// where N is the sum Nd0 + Nd1 + Nd2 + ... + Ndi, that is the amount of nodes in the same component as the current node
					sizeOfComponent += sizeOfNthOrderNeighborhood[i];
					i++;
				}
				(*it)->setPC( PC );		//Set Power Centrality
				sumPC += PC;
				minmax( PC, (*it), maxPC, minPC, maxNodePC, minNodePC) ; //Find min & max PC - not using stdSC
				if ( sizeOfComponent != 1 )
				    PC = ( 1.0/(sizeOfComponent-1.0) ) * PC;
				else
				    PC = 0;
				(*it)->setSPC( PC );		//Set Standardized Power Centrality

				qDebug() << "Visit all vertices in reverse order of their discovery (from s = " << s 
						<< " ) to sum dependencies. Initial Stack size has " << Stack.size();

				while ( !Stack.empty() ) {
					w=Stack.top(); 
					qDebug("Stack top is vertex w=%i. This is the furthest vertex from s. Popping it.", w);
					Stack.pop();
					QList<int> lst=m_graph[w]->Ps();
					qDebug("preLOOP: Checking size of predecessors list Ps[w]...  = %i ",lst.size());
					qDebug("LOOP: for every other vertex u in the list of predecessors Ps[w] of w....");
					if (lst.size() > 0) // just in case...do a sanity check
						for ( it2=lst.begin(); it2 != lst.end(); it2++ ){
							u=(*it2);
							qDebug("Selecting Ps[w] element u=%i with delta_u=%f. sigma(u)=TM(s,u)=%f, sigma(w)=TM(s,w)=%f, delta_w=%f ", u, m_graph[u]->delta(),TM.item(s,u), TM.item(s,w), m_graph[w]->delta());
							if ( TM.item(s,w) > 0) {
								//delta[u]=delta[u]+(1+delta[w])*(sigma[u]/sigma[w]) ;
								d_su=m_graph[u]->delta()+(1.0+m_graph[w]->delta() ) * ( (float)TM.item(s,u)/(float)TM.item(s,w) );
							}
							else {
								d_su=m_graph[u]->delta();
								qDebug("TM (s,w) zero, i.e. zero shortest path counts from s to w - using SAME DELTA for vertex u");
							}
							qDebug("Assigning new delta d_su = %f to u = %i", d_su, u);
							m_graph[u]->setDelta( d_su);
						}
					qDebug()<<" Adding delta_w to BC of w";
					if  (w!=s) { 
						qDebug("w!=s. For this furthest vertex we need to add its new delta %f to old BC index: %f",m_graph[w]->delta(), m_graph[w]->BC());
						d_sw = m_graph[w]->BC() + m_graph[w]->delta();
						qDebug("New BC = d_sw = %f", d_sw);
						m_graph[w]->setBC (d_sw);
					}
				}
			}
		}
		if (averGraphDistance!=0)
			averGraphDistance = averGraphDistance / (nonZeroDistancesCounter);
		
		if (doCalculcateCentralities) {
			for (it=m_graph.begin(); it!=m_graph.end(); it++) {
				if (symmetricAdjacencyMatrix) {
					qDebug("Betweeness centrality must be divided by two if the graph is undirected");
					(*it)->setBC ( (*it)->BC()/2.0);
				}
				BC=(*it)->BC();
				qDebug("Resolving BC classes...");
				resolveClasses(BC, discreteBCs, classesBC);
				qDebug("******************* BC %f maxIndex: %f", BC, maxIndexBC);
				(*it)->setSBC( BC/maxIndexBC );   
				//Find min & max BC - not using stdBC:  Wasserman & Faust, pp. 191-192
				sumBC+=BC;
				minmax( BC, (*it), maxBC, minBC, maxNodeBC, minNodeBC) ;
				
				qDebug("Resolving SC classes...");
				SC=(*it)->SC();
				resolveClasses(SC, discreteSCs, classesSC);
				(*it)->setSSC ( SC/maxIndexSC );
				//Find min & max SC - not using stdSC
				sumSC+=SC;
				minmax( SC, (*it), maxSC, minSC, maxNodeSC, minNodeSC) ;

			}
			for (it=m_graph.begin(); it!=m_graph.end(); it++) {
				//Find denominal of groupSC
				BC=(*it)->BC();
				SC=(*it)->SC();

				nomSC +=(maxSC - SC );

				//Calculate the numerator of groupBC according to Freeman's group Betweeness
				nomBC +=(maxBC - BC );
				//nomBC +=(maxBC - (*it)->SBC());	
				
				//Find denominal of groupGC
				nomGC += maxGC-(*it)->SGC();
				//Find denominal of groupCC
				nomCC += maxCC- (*it)->SCC();

			}
			maxCC = (aVertices-1.0)*maxCC;	//standardize minimum and maximum Closeness centrality
			minCC = (aVertices-1.0)*minCC; 
			denomCC =  (( aVertices-2.0) *  (aVertices-1.0))/ (2.0*aVertices-3.0);
			groupCC = nomCC/denomCC;	//Calculate group Closeness centrality
	
			nomBC*=2.0;
			denomBC =   (aVertices-1.0) *  (aVertices-1.0) * (aVertices-2.0);
			//denomBC =  (aVertices-1.0);
			groupBC=nomBC/denomBC;		//Calculate group Betweeness centrality
	
			denomGC =  ( ( aVertices-2.0) *  (aVertices-1.0) )/ (2.0*aVertices-3.0);
			groupGC= nomGC/denomGC;		//Calculate group Graph centrality
	
			nomSC*=2.0;
			denomSC =   (aVertices-1.0) *  (aVertices - 1.0) * (aVertices-2.0);
			groupSC = nomSC/denomSC;	//Calculate group Stress centrality
			calculatedCentralities=TRUE;
		}	
	}
			
	distanceMatrixCreated=TRUE;
	graphModified=FALSE;
	
}





/**
*	Breadth-First Search (BFS) method for unweighted graphs (directed or not)

	INPUT: 
		a 'source' vertex with index s and a boolean doCalculcateCentralities.
		(Implicitly, BFS uses the m_graph structure)
	
	OUTPUT: 
		For every vertex t: DM(s, t) is set to the distance of each t from s
		For every vertex t: TM(s, t) is set to the number of shortest paths between s and t

		Also, if doCalculcateCentralities is TRUE then BFS does extra operations:
			a) For source vertex s:
			    it calculates CC(s) as the sum of its distances from every other vertex.
			    it calculates GC(s) as the maximum distance from all other vertices.
			    it increases sizeOfNthOrderNeighborhood [ N ] by one, to store the number of nodes at distance n from source s
			b) For every vertex u:
			    it increases SC(u) by one, when it finds a new shor. path from s to t through u.
			    appends each neighbor y of u to the list Ps, thus Ps stores all predecessors of y on all all shortest paths from s
			c) Each vertex u popped from Q is pushed to a stack Stack
	
*/ 
void Graph::BFS(int s, bool doCalculcateCentralities){
	int u,w, dist_u=0, temp=0, dist_w=0;

	//set distance of s from s equal to 0	
	DM.setItem(s,s,0);
	//set sigma of s from s equal to 1
	TM.setItem(s,s,1);

	qDebug("BFS: Construct a queue Q of integers and push source vertex s=%i to Q as initial vertex", s);
	queue<int> Q;
//	qDebug("BFS: Q size %i", Q.size());

	Q.push(s);

	qDebug("BFS: LOOP: While Q not empty ");
	while ( !Q.empty() ) {
		qDebug("BFS: Dequeue: first element of Q is u=%i", Q.front());
		u=Q.front(); Q.pop();

		if ( ! m_graph [ u ]->isEnabled() ) continue ;

		if (doCalculcateCentralities){
			qDebug("BFS: If we are to calculate centralities, we must push u=%i to global stack Stack ", u);
			Stack.push(u);
		}
		imap_f::iterator it;
		qDebug("BFS: LOOP over every edge (u,w) e E, that is all neighbors w of vertex u");
		for( it = m_graph [ u ]->m_outEdges.begin(); it != m_graph [ u ]->m_outEdges.end(); it++ ) {
			
			w=index[it->first];	
			qDebug("BFS: u=%i is connected with w=%i of index %i. ", u, it->first, w);
			qDebug("BFS: Start path discovery");
			if (	DM.item(s, w) == -1 ) { //if distance (s,w) is infinite, w found for the first time.
				qDebug("BFS: first time visiting w=%i. Enqueuing w to the end of Q", w);
				Q.push(w);
				qDebug()<<"First check if distance(s,u) = -1 (aka infinite :)) and set it to zero";
				dist_u=DM.item(s,u);
				if (dist_u < 0 )
					dist_w = 0;
				else
					dist_w = dist_u + 1;
				qDebug("BFS: Setting distance of w=%i from s=%i equal to distance(s,u) plus 1. New distance = %i",w,s, dist_w );
				DM.setItem(s, w, dist_w);
				averGraphDistance += dist_w;
				nonZeroDistancesCounter++;
				if (doCalculcateCentralities){
					qDebug()<<"Calculate PC: store the number of nodes at distance " << dist_w << "from s";
					sizeOfNthOrderNeighborhood[dist_w]=sizeOfNthOrderNeighborhood[dist_w]+1;
					qDebug()<<"Calculate CC: the sum of distances (will invert it l8r)";
					m_graph [s]->setCC (m_graph [s]->CC() + dist_w);
					qDebug()<<"Calculate GC: the maximum distance (will invert it l8r) - also for Eccentricity";
					if (m_graph [s]->GC() < dist_w )
					    m_graph [s]->setGC(dist_w);

				}
				qDebug("BFS: Checking graphDiameter");
				if ( dist_w > graphDiameter){
					graphDiameter=dist_w;
					qDebug() << "BFS: new graphDiameter = " <<  graphDiameter ;
				}
			}		

			qDebug("BFS: Start path counting"); 	//Is edge (u,w) on a shortest path from s to w via u?
			if ( DM.item(s,w)==DM.item(s,u)+1) {
				temp= TM.item(s,w)+TM.item(s,u);
				qDebug("BFS: Found a NEW SHORTEST PATH from s=%i to w=%i via u=%i. Setting Sigma(%i, %i) = %i",s, w, u, s, w,temp);
				if (s!=w)
					TM.setItem(s,w, temp);
				if (doCalculcateCentralities){
					qDebug("If we are to calculate centralities, we must calculate SC as well");
					m_graph[u]->setSC(m_graph[u]->SC()+1);

					qDebug("BFS: appending u=%i to list Ps[w=%i] with the predecessors of w on all shortest paths from s ", u, w);
					m_graph[w]->appendToPs(u);
				}
			}
		}
	} 	
}










/**
	minmax() facilitates the calculations of minimum and maximum centralities during createDistanceMatrix()
*/
void Graph::minmax(float C, Vertex *v, float &max, float &min, int &maxNode, int &minNode) {
	qDebug() << "MINMAX C = " <<  C << "  max = " << max << "  min = " << min << " name = " <<  v->name(); 
	if (C > max ) {
		max=C;
		maxNode=v->name();
	}
	if (C < min ) {
		min=C;
		minNode=v->name();
	}
}




/** 	This method calculates the number of discrete centrality classes of all vertices
	It stores that number in a QHash<QString,int> type where the centrality value is the key.
	Called from createDistanceMatrix()
*/
void Graph::resolveClasses(float C, hash_si &discreteClasses, int &classes){
 	hash_si::iterator it2;
 	it2 = discreteClasses.find(QString::number(C));    //Amort. O(1) complexity
 	if (it2 == discreteClasses.end() )	{
 		classes++; 
 		qDebug("######This is a new centrality class. Amount of classes = %i", classes);
 		discreteClasses.insert(QString::number(C), classes);
 	}
}


/*
 * Overloaded method. It only adds displaying current vertex for debugging purposes. 
 */
void Graph::resolveClasses(float C, hash_si &discreteClasses, int &classes, int vertex){
 	hash_si::iterator it2;
 	it2 = discreteClasses.find(QString::number(C));    //Amort. O(1) complexity
 	if (it2 == discreteClasses.end() )	{
 		classes++; 
 		qDebug("######Vertex %i  belongs to a new centrality class. Amount of classes = %i", vertex, classes);
 		discreteClasses.insert(QString::number(C), classes);
 	}
}





//Calculates the Information centrality of each vertex - diagonal included
void Graph::centralityInformation(){
	qDebug()<< "Graph:: centralityInformation()";
	discreteICs.clear();
	sumIC=0;
	maxIC=0;
	minIC=RAND_MAX;
	classesIC=0;
	groupIC=0;

	TM.resize(m_totalVertices);
	isolatedVertices=0;
	int i=0, j=0, n=vertices();
        float m_weight=0, weightSum=1, diagonalEntriesSum=0, rowSum=0;
        float IC=0, SIC=0;
	/* Note: isolated nodes must be dropped from the AM
	    Otherwise, the TM might be singular, therefore non-invertible. */
	bool dropIsolates=true;
	createAdjacencyMatrix(dropIsolates);
	n-=isolatedVertices;
	qDebug() << "Graph:: centralityInformation() - computing node ICs for total n = " << n;

	for (i=0; i<n; i++){
	    weightSum = 1;
	    for (j=0; j<n; j++){
		if ( i == j )
		    continue;
		m_weight = AM.item(i,j);
		weightSum += m_weight; //sum of weights for all edges incident to i
		qDebug() << "Graph:: centralityInformation() -A("<< i <<  ","<< j <<") = 1-Xij = " << 1-m_weight;
		TM.setItem(i,j,1-m_weight);
	    }
	    TM.setItem(i,i,weightSum);
	    qDebug() << "Graph:: centralityInformation() - A("<< i << ","<< i <<") = 1+sum of all tie values = " << weightSum;
	}

	invM.inverseByGaussJordanElimination(TM);

	diagonalEntriesSum = 0;
	rowSum = 0;
	for (j=0; j<n; j++){
		rowSum += invM.item(0,j);
	}
	for (i=0; i<n; i++){
	    diagonalEntriesSum  += invM.item(i,i);  // calculate the matrix trace
	}
	qDebug() << "Graph:: centralityInformation() - R= " << rowSum << " D= "<<diagonalEntriesSum;


	QList<Vertex*>::iterator it;
	i=0;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		if ( (*it)->isIsolated() ) {
		    (*it) -> setIC ( 0 );
		    qDebug()<< "Graph:: centralityInformation() vertex: " <<  (*it)->name() << " isolated";
		    continue;
		}
		IC= 1.0 / ( invM.item(i,i) + (diagonalEntriesSum - 2.0 * rowSum) / n );
		if ( IC > maxIC ) {
		    maxIC = IC;
		    maxNodeIC=(*it)->name();
		}
		if ( IC < minIC ) {
		    minIC = IC;
		    minNodeIC=(*it)->name();
		}

		(*it) -> setIC ( IC );
		sumIC += IC;
		qDebug()<< "Graph:: centralityInformation() vertex: " <<  (*it)->name() << " IC  " << IC ;
		i++;
	}
        for (it=m_graph.begin(); it!=m_graph.end(); it++){
                IC = (*it)->IC();
                SIC = IC / sumIC ;
                (*it)->setSIC( SIC );
         }
	graphModified=false;
}



//Writes the information centralities to a file
void Graph::writeCentralityInformation(const QString fileName){
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating information centralities. Please wait...")) );
	centralityInformation();
	emit statusMessage ( QString(tr("Writing information centralities to file: ")).arg(fileName) );

	outText << tr("INFORMATION CENTRALITY (IC) OF EACH NODE")<<"\n";
	outText << tr("IC measures how much information is contained in the paths that originate or end at each node.")<<"\n";
	outText << tr("IC' is the standardized IC")<<"\n";

	outText << tr("IC  range:  0 < C < inf (this index has no max value)") << "\n";
	outText << tr("IC' range:  0 < C'< 1")<<"\n\n";
	outText << "Node"<<"\tIC\t\tIC'\t\t%IC\n";
	QList<Vertex*>::iterator it;
	float IC=0, SIC=0, sumSIC=0;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
                IC = (*it)->SIC();
                SIC = (*it)->SIC();
                sumSIC +=  SIC;
		outText << (*it)->name()<<"\t"<< IC << "\t\t"<< SIC  << "\t\t" <<  ( 100* SIC )<<endl;
		qDebug()<< "Graph::writeCentralityInformation() vertex: " <<  (*it)->name() << " SIC  " << SIC;
	}
	qDebug ("min %f, max %f", minIC, maxIC);
	if ( minIC == maxIC )
		outText << tr("\nAll nodes have the same IC value.\n");
	else  {
		outText << "\n";
		outText << tr("Max IC' = ") << maxIC <<" (node "<< maxNodeIC  <<  ")  \n";
		outText << tr("Min IC' = ") << minIC <<" (node "<< minNodeIC <<  ")  \n";
		outText << tr("IC classes = ") << classesIC<<" \n";
	}
	outText << "\n";
	outText << tr("The IC index measures the information that is contained in the paths passing through each actor.\n");
	outText << tr("The standardized values IC' can be seen as the proportion of total information flow that is controlled by each actor. Note that standard IC' values sum to unity, unlike any other centrality index.\n");
	outText << "(Wasserman & Faust, p. 196)\n";
	outText << "\n";

	float x=0;
	float n = ( this->vertices() - isolatedVertices );

	averageIC = sumSIC / n ;
	qDebug() << "sumSIC = " << sumSIC << "  n = " << n << "  averageIC = " << averageIC;
	groupIC=0;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
	       x = (  (*it)->SIC()  -  averageIC  ) ;
	       x *=x;
	       qDebug() << "SIC " <<  (*it)->SIC() << "  x " <<   (*it)->SIC() - averageIC  << " x*x" << x ;
	       groupIC  += x;
	}
	qDebug() << "groupIC   " << groupIC   << " n " << n ;
	groupIC  = groupIC  /  (n-1);
	qDebug() << "groupIC   " << groupIC   ;
	outText << tr("\nGROUP INFORMATION CENTRALISATION (GIC)\n\n");
	outText << tr("GIC = ") << groupIC<<"\n\n";
	outText << tr("GIC range: 0 < GIC < inf \n");
	outText << tr("GIC is computed using a simple variance formula. \n");
	outText << tr("In fact, following the results of Wasserman & Faust, we are using a bias-corrected sample variance.\n ");

	outText << tr("GIC = 0, when all nodes have the same IC value, i.e. a complete or a circle graph).\n");
	outText << tr("Larger values of GIC mean larger variability between the nodes' IC values.\n");
	outText <<"(Wasserman & Faust, formula 5.20, p. 197)\n\n";


	outText << tr("Information Centrality report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}


/**
*	Calculates In-Degree Centralities of each vertex - diagonal included
*	Also the mean value and the variance of the in-degrees.
*/
void Graph::centralityInDegree(bool weights){
	qDebug()<< "Graph:: centralityInDegree()";
	float IDC=0, nom=0, denom=0;
	float weight;
	classesIDC=0;
	sumIDC=0; 
	maxIDC=0;
	minIDC=vertices()-1;
	discreteIDCs.clear();
	varianceDegree=0;
	meanDegree=0;
	QList<Vertex*>::iterator it, it1;
	hash_si::iterator it2;
	int vert=vertices();
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		IDC=0;
		for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){
			if ( (weight=this->hasEdge ( (*it1)->name(), (*it)->name() ) ) !=0  )   {	
				if (weights)
					IDC+=weight;
				else
					IDC++;
			}		
		}
		(*it) -> setIDC ( IDC ) ;				//Set InDegree
		(*it) -> setSIDC( IDC / (vert-1.0) );		//Set Standard InDegree
		qDebug() << "Graph: vertex = " <<  (*it)->name() << " has IDC = " << IDC << " and SIDC " << (*it)->SIDC ();
		sumIDC += IDC;
		it2 = discreteIDCs.find(QString::number(IDC));
		if (it2 == discreteIDCs.end() )	{
			classesIDC++; 
			qDebug("This is a new IDC class");
			discreteIDCs.insert ( QString::number(IDC), classesIDC );
		}
		qDebug("IDC classes = %i ", classesIDC);
		if (maxIDC < IDC ) {
			maxIDC = IDC ;
			maxNodeIDC=(*it)->name();
		}
		if (minIDC > IDC ) {
			minIDC = IDC ;
			minNodeIDC=(*it)->name();
		}
	}

	if (minIDC == maxIDC)
		maxNodeIDC=-1;
	
	meanDegree = sumIDC / (float) vert;  /** BUG? WEIGHTS???? */
	qDebug("Graph: sumIDC = %f, meanDegree = %f", sumIDC, meanDegree);
	// Calculate Variance and the Degree Centralisation of the whole graph.
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		IDC= (*it)->IDC();
		//qDebug("Graph: IDC = %f, meanDegree = %f", IDC, meanDegree);
		varianceDegree += (IDC-meanDegree) * (IDC-meanDegree) ; 
		nom+= maxIDC-IDC;
	}
	if (symmetricAdjacencyMatrix)
		denom=(vert-1.0)*(vert-2.0);
	else
		denom=(vert-1.0)*(vert-1.0);
	varianceDegree=varianceDegree/(float) vert;
	groupIDC=nom/denom;
	qDebug("Graph: varianceDegree = %f, groupIDC = %f", varianceDegree, groupIDC);

	minIDC/=(float)(vert-1); // standardize
	maxIDC/=(float)(vert-1);
	calculatedIDC=TRUE;
	graphModified=false;
}




void Graph::writeCentralityInDegree
		(const QString fileName, const bool considerWeights)
{
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	centralityInDegree(considerWeights);
	float maximumIndexValue=vertices()-1.0;
	
	outText << tr("IN-DEGREE CENTRALITIES (IDC) OF EACH NODE\n\n");
	outText << tr("IDC  range: 0 < C < ")<<maximumIndexValue<<"\n";
	outText << "IDC' range: 0 < C'< 1"<<"\n\n";

	outText << "Node"<<"\tIDC\tIDC'\t%IDC\n";

	QList<Vertex*>::iterator it;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		outText <<(*it)->name()<<"\t"<<(*it)->IDC() << "\t"<< (*it)->SIDC() << "\t" <<  (100* ((*it)->IDC()) / sumIDC)<<endl;
	}
	if (symmetricAdjacencyMatrix) {
		outText << "\n";
		outText << tr("Mean Nodal Degree = ") << meanDegree<<"\n" ;
		outText << tr("Degree Variance = ") << varianceDegree<<"\n";
	}
	else{
		outText << "\n";
		outText << tr("Mean Nodal InDegree = ") << meanDegree<<"\n" ;
		outText << tr("InDegree Variance = ") << varianceDegree<<"\n";
	}

	if ( minIDC == maxIDC )
		outText << tr("All nodes have the same IDC value.") << "\n";
	else  {
		outText << tr("Max IDC' = ") << maxIDC <<" (node "<< maxNodeIDC <<  ")  \n";
		outText << tr("Min IDC' = ") << minIDC <<" (node "<< minNodeIDC <<  ")  \n";
		outText << tr("IDC classes = ") << classesIDC<<" \n"; 	
	}

	outText << "\nGROUP IN-DEGREE CENTRALISATION (GIDC)\n\n";
	outText << "GIDC = " << groupIDC<<"\n\n";

	outText << "GIDC range: 0 < GIDC < 1\n";
	outText << "GIDC = 0, when all in-degrees are equal (i.e. regular lattice).\n";
	outText << "GIDC = 1, when one node is linked from every other node.\n";
	outText << "The in-degree of the node is a measure of the \'activity\' of the node it represents\n";
	outText << "(Wasserman & Faust, p. 101)\n";
	
	outText << "\n\n";
	outText << tr("In-Degree Centrality Report, \n");
	outText << tr("created by SocNetV: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}



//Calculates the outDegree centrality of each vertex - diagonal included
void Graph::centralityOutDegree(bool weights){
	qDebug("Graph:: centralityOutDegree()");
	float ODC=0, nom=0, denom=0;
	float weight;
	classesODC=0;
	discreteODCs.clear();
	sumODC=0; 
	maxODC=0;
	minODC=vertices()-1;
	varianceDegree=0;
	meanDegree=0;
	int vert=vertices();
	QList<Vertex*>::iterator it, it1;
	hash_si::iterator it2;
	
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
		ODC=0;
		for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){	
			if ( (weight=this->hasEdge ( (*it)->name(), (*it1)->name() ) ) !=0  )   {	
				qDebug() << "Graph: vertex " <<  (*it)->name() << " isLinkedTo = " <<  (*it1)->name();
				if (weights)
					ODC+=weight;
				else 
					ODC++;
			}		
		}
		(*it) -> setODC ( ODC ) ;				//Set OutDegree
		(*it) -> setSODC( ODC / (vert-1.0) );		//Set Standard OutDegree
		qDebug() << "Graph: vertex " <<  (*it)->name() << " has ODC = " << ODC << " and SODC "<< (*it)->SODC ();
		sumODC += ODC;
		it2 = discreteODCs.find(QString::number(ODC));
		if (it2 == discreteODCs.end() )	{
			classesODC++; 
			qDebug("This is a new ODC class");
			discreteODCs.insert ( QString::number(ODC), classesODC );
		}
		qDebug("ODC classes = %i ", classesODC);
		if (maxODC < ODC ) {
			maxODC = ODC ;
			maxNodeODC=(*it)->name();
		}
		if (minODC > ODC ) {
			minODC = ODC ;
			minNodeODC=(*it)->name();
		}
	}

	if (minODC == maxODC)
		maxNodeODC=-1;
	
	meanDegree = sumODC / (float) vert;  /** BUG? WEIGHTS???? */
	qDebug("Graph: sumODC = %f, meanDegree = %f", sumODC, meanDegree);
	// Calculate Variance and the Degree Centralisation of the whole graph.
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		ODC= (*it)->ODC();
		qDebug() << "Graph: ODC = " << ODC << " meanDegree = " << meanDegree << " vertices " << vert;
		varianceDegree += (ODC-meanDegree) * (ODC-meanDegree) ; 
		nom+= maxODC-ODC;
	}
	if (symmetricAdjacencyMatrix)
		denom=(vert-1.0)*(vert-2.0);
	else
		denom=(vert-1.0)*(vert-1.0);
	varianceDegree=varianceDegree/(float) vert;
	groupODC=nom/denom;
	qDebug("Graph: varianceDegree = %f, groupODC = %f", varianceDegree, groupODC);

	minODC/=(float)(vert-1); // standardize
	maxODC/=(float)(vert-1);
	calculatedODC=TRUE;
	graphModified=false;
}




void Graph::writeCentralityOutDegree (
				const QString fileName, const bool considerWeights)
{
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	centralityOutDegree(considerWeights);

	float maximumIndexValue=vertices()-1.0;
	
	outText << tr("OUT-DEGREE CENTRALITIES (ODC) FOR EACH NODE\n\n");

	outText << tr("ODC  range: 0 < C < ")<<QString::number(maximumIndexValue)<<"\n";
	outText << "ODC' range: 0 < C'< 1"<<"\n\n";

	outText << "Node"<<"\tODC\tODC'\t%ODC\n";
	QList<Vertex*>::iterator it;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		outText << (*it)->name()<<"\t"<<(*it)->ODC() << "\t"<< (*it)->SODC() << "\t" <<  (100* ((*it)->ODC()) / sumODC)<< "\n";
	}
	if (symmetricAdjacencyMatrix) {
		outText << "\n";
		outText << tr("Mean Node Degree = ") << meanDegree<<"\n" ;
		outText << tr("Degree Variance = ") << varianceDegree<<"\n";
	}
	else{
		outText << "\n" ; 
		outText << tr("Mean Node OutDegree = ") << meanDegree<<"\n" ;
		outText << tr("OutDegree Variance = ") << varianceDegree<<"\n";
	}
	if ( minODC == maxODC )
		outText << tr("All nodes have the same ODC value.") << "\n";
	else  {
		outText << tr("Max ODC' = ") << maxODC <<" (node "<< maxNodeODC <<  ")  \n";
		outText << tr("Min ODC' = ") << minODC <<" (node "<< minNodeODC <<  ")  \n";
		outText << tr("ODC classes = ") << classesODC<<" \n"; 	
	}
	
	outText << "\nGROUP OUT-DEGREE CENTRALISATION (GODC)\n\n";
	outText << "GODC = " << groupODC<<"\n\n";

	outText << "GODC range: 0 < GODC < 1\n";
	outText << "GODC = 0, when all out-degrees are equal (i.e. regular lattice).\n";
	outText << "GODC = 1, when one node completely dominates or overshadows the other nodes.\n";
	outText << "(Wasserman & Faust, formula 5.5, p. 177)\n\n";
	outText << "The degree of the node is a measure of the \'activity\' of the node it represents\n";
	outText << "(Wasserman & Faust, p. 101)\n";
	
	outText << "\n\n";	
	outText << tr("Out-Degree Centrality Report, \n");
	outText << tr("created by SocNetV: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}


//Writes the closeness centralities to a file
void Graph::writeCentralityCloseness(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating shortest paths")) );
	createDistanceMatrix(true);
	emit statusMessage ( QString(tr("Writing closeness centralities to file:")).arg(fileName) );

	outText << tr("CLOSENESS CENTRALITY (CC) OF EACH NODE")<<"\n";
	outText << tr("CC is the invert sum of the distances of node u from all other nodes.")<<"\n";
	outText << tr("CC' is the standardized CC")<<"\n";
	
	outText << tr("CC  range:  0 < C < ")<<QString::number(maxIndexCC)<<"\n";
	outText << tr("CC' range:  0 < C'< 1")<<"\n\n";
	outText << "Node"<<"\tCC\t\tCC'\t\t%CC\n";
	QList<Vertex*>::iterator it;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		outText << (*it)->name()<<"\t"<<(*it)->CC() << "\t\t"<< (*it)->SCC() << "\t\t" <<  (100* ((*it)->CC()) / sumCC)<<endl;
	}
	qDebug ("min %f, max %f", minCC, maxCC);
	if ( minCC == maxCC )
		outText << tr("\nAll nodes have the same CC value.\n");
	else  {
		outText << "\n";
		outText << tr("Max CC' = ") << maxCC <<" (node "<< maxNodeCC  <<  ")  \n";
		outText << tr("Min CC' = ") << minCC <<" (node "<< minNodeCC <<  ")  \n";
		outText << tr("CC classes = ") << classesCC<<" \n"; 	
	}
		
	outText << tr("\nGROUP CLOSENESS CENTRALISATION (GCC)\n\n");
	outText << tr("GCC = ") << groupCC<<"\n\n";
	
	outText << tr("GCC range: 0 < GCC < 1\n");
	outText << tr("GCC = 0, when the lengths of the geodesics are all equal (i.e. a complete or a circle graph).\n");
	outText << tr("GCC = 1, when one node has geodesics of length 1 to all the other nodes, and the other nodes have geodesics of length 2 to the remaining (N-2) nodes. This is exactly the situation realised by a star graph.\n");
	outText <<"(Wasserman & Faust, formula 5.9, p. 187)\n\n";
	outText << tr("This measure focuses on how close a node is to all\n");
	outText << tr("the other nodes in the set of nodes. The idea is that a node\n");
	outText << tr("is central if it can quickly interact with all others\n");
	outText << "(Wasserman & Faust, p. 181)\n";

	outText << "\n\n";
	outText << tr("Closeness Centrality report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}


//Writes the betweeness centralities to a file
void Graph::writeCentralityBetweeness(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating shortest paths")) );
	createDistanceMatrix(true);
	emit statusMessage ( QString(tr("Writing betweeness centralities to file:")).arg(fileName) );
	
	outText << tr("BETWEENESS CENTRALITY (BC) OF EACH NODE")<<"\n";
	outText << tr("BC of a node u is the sum of delta (s,t,u) for all s,t in V")<<"\n"; 
	outText << tr("where delta (s,t,u) is the ratio of all geodesics between s and t which run through u.")<<"\n";
	outText << tr("Therefore, BC(u) reflects how often the node u lies on the geodesics between the other nodes of the network")<<"\n";
	outText << tr("BC' is the standardized BC")<<"\n";
	outText << tr("BC  range: 0 < BC < ")<<QString::number( maxIndexBC)<< tr(" (Number of pairs of nodes excluding i)")<<"\n";
	outText << tr("BC' range: 0 < BC'< 1  (C' is 1 when the node falls on all geodesics)\n\n");
	outText << "Node"<<"\tBC\t\tBC'\t\t%BC\n";
	QList<Vertex*>::iterator it;
	for (it= m_graph.begin(); it!= m_graph.end(); it++){ 
		outText <<(*it)->name()<<"\t"<<(*it)->BC() << "\t\t"<< (*it)->SBC() << "\t\t" <<  (100* ((*it)->BC()) /  sumBC)<<endl;
	}
	if ( minBC ==  maxBC)
		outText << "\n"<< tr("All nodes have the same BC value.\n");
	else {
		outText << "\n";
		outText << tr("Max BC' = ") << maxBC <<" (node "<< maxNodeBC  <<  ")  \n";
		outText << tr("Min BC' = ") << minBC <<" (node "<< minNodeBC <<  ")  \n";
		outText << tr("BC classes = ") << classesBC<<" \n"; 	
	}
		
	outText << tr("\nGROUP BETWEENESS CENTRALISATION (GBC)\n\n");
	outText << tr("GBC = ") <<  groupBC <<"\n\n";

	outText << tr("GBC range: 0 < GBC < 1\n");
	outText << tr("GBC = 0, when all the nodes have exactly the same betweeness index.\n");
	outText << tr("GBC = 1, when one node falls on all other geodesics between all the remaining (N-1) nodes. This is exactly the situation realised by a star graph.\n");
	outText << "(Wasserman & Faust, formula 5.13, p. 192)\n\n";
	
	outText << "\n\n";
	outText << tr("Betweeness Centrality report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}


//Writes the Graph centralities to a file
void Graph::writeCentralityGraph(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating shortest paths")) );
	createDistanceMatrix(true);
	emit statusMessage ( QString(tr("Writing graph centralities to file:")).arg(fileName) );

	outText << tr("GRAPH CENTRALITY (GC) OF EACH NODE")<<"\n";
	outText << tr("GC  range: 0 < GC < ")<<maxIndexGC<< " (GC=1 => distance from other nodes is max 1)\n";
	outText << tr("GC' range: 0 < GC'< 1  (GC'=1 => directly linked with all nodes)")<<"\n\n";

	outText << "Node"<<"\tGC\t\tGC'\t\t%GC\n";
	QList<Vertex*>::iterator it;
	for (it= m_graph.begin(); it!= m_graph.end(); it++){ 
		outText <<(*it)->name()<<"\t"<<(*it)->GC() << "\t\t"<< (*it)->SGC() << "\t\t" <<  (100* ((*it)->GC()) /  sumGC)<<endl;
	}
	
	if ( minGC ==  maxGC)
		outText << tr("\nAll nodes have the same GC value.\n");
	else {
		outText << "\n";
		outText << tr("Max GC' = ") << maxGC <<" (node "<< maxNodeGC  <<  ")  \n";
		outText << tr("Min GC' = ") << minGC <<" (node "<< minNodeGC <<  ")  \n";
		outText << tr("GC classes = ") << classesGC<<" \n";
	}
	
	outText << tr("\nGROUP GRAPH CENTRALISATION (GGC)\n\n");

	outText << tr("GGC = ") <<  groupGC<<"\n\n";

	outText << tr("GGC range: 0 < GGC < 1\n");
	outText << tr("GGC = 0, when all the nodes have exactly the same graph index.\n");
	outText << tr("GGC = 1, when one node falls on all other geodesics between all the remaining (N-1) nodes. This is exactly the situation realised by a star graph.\n");
	outText << "(Wasserman & Faust, formula 5.13, p. 192)\n\n";	

	outText << "\n\n";
	outText << tr("Graph Centrality report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}


//Writes the Stress centralities to a file
void Graph::writeCentralityStress(
		const QString fileName, const bool considerWeights)
{	
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating shortest paths")) );
	createDistanceMatrix(true);
	emit statusMessage ( QString(tr("Writing stress centralities to file:")).arg(fileName) );

	outText << tr("STRESS CENTRALITY (SC) OF EACH NODE")<<"\n";
	outText << tr("SC(u) is the sum of sigma(s,t,u): the number of geodesics from s to t through u.")<<"\n"; 
	outText << tr("SC(u) reflecoutText the total number of geodesics between all other nodes which run through u")<<"\n";

	outText << tr("SC  range: 0 < SC < ")<<QString::number(maxIndexSC)<<"\n";
	outText << tr("SC' range: 0 < SC'< 1  (SC'=1 when the node falls on all geodesics)\n\n");
	outText  << "Node"<<"\tSC\t\tSC'\t\t%SC\n";
	QList<Vertex*>::iterator it;
	for (it= m_graph.begin(); it!= m_graph.end(); it++){ 
		outText <<(*it)->name()<<"\t"<<(*it)->SC() << "\t\t"<< (*it)->SSC() << "\t\t" <<  (100* ((*it)->SC()) /  sumSC)<<endl;
	}
	
	if ( minSC ==  maxSC)
		outText  << tr("\nAll nodes have the same SC value.\n");
	else {
		outText << "\n";
		outText << tr("Max SC' = ") << maxSC <<" (node "<< maxNodeSC  <<  ")  \n";
		outText << tr("Min SC' = ") << minSC <<" (node "<< minNodeSC <<  ")  \n";
		outText << tr("SC classes = ") << classesSC<<" \n"; 	
	}

	outText << tr("GROUP STRESS CENTRALISATION (GSC)")<<"\n";
	outText << tr("GSC = ") <<  groupSC<<"\n\n";
	
	outText << tr("GSC range: 0 < GSC < 1\n");
	outText << tr("GSC = 0, when all the nodes have exactly the same stress index.\n");
	outText << tr("GSC = 1, when one node falls on all other geodesics between all the remaining (N-1) nodes. This is exactly the situation realised by a star graph.\n");
	
	outText << "\n\n";
	outText << tr("Stress Centrality report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}



void Graph::writeCentralityEccentricity(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating shortest paths")) );
	createDistanceMatrix(true);
	emit statusMessage ( QString(tr("Writing eccentricity centralities to file:")).arg(fileName) );
	
	outText << tr("ECCENTRICITY CENTRALITY (EC) OF EACH NODE") << "\n";
	outText << tr("EC of a node u is the largest geodesic distance (u,t) for t in V") << "\n"; 
	outText << tr("Therefore, EC(u) reflects how far, at most, is each node from every other node.") << "\n";
	outText << tr("EC' is the standardized EC") << "\n";
	outText << tr("EC  range: 0 < EC < ") << QString::number(maxIndexEC)<< tr(" (max geodesic distance)")<<"\n";
	outText << tr("EC' range: 0 < EC'< 1 \n\n");
	outText << "Node"<<"\tEC\t\tEC'\t\t%EC\n";
	QList<Vertex*>::iterator it;
	for (it= m_graph.begin(); it!= m_graph.end(); it++){ 
		outText << (*it)->name()<<"\t"<<(*it)->EC() << "\t\t"<< (*it)->SEC() << "\t\t" <<  (100* ((*it)->EC()) /  sumEC)<<endl;
	}
	if ( minEC ==  maxEC)
		outText << tr("\nAll nodes have the same EC value.\n");
	else {
		outText << "\n";
		outText << tr("Max EC' = ") << maxEC <<" (node "<< maxNodeEC  <<  ")  \n";
		outText << tr("Min EC' = ") << minEC <<" (node "<< minNodeEC <<  ")  \n";
		outText << tr("EC classes = ") << classesEC<<" \n"; 	
	}

	outText << "\n\n";
	outText << tr("Eccentricity Centrality report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}




void Graph::writeCentralityPower(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating shortest paths")) );
	createDistanceMatrix(true);
	emit statusMessage ( QString(tr("Writing Power centralities to file:")).arg(fileName) );

	outText << tr("POWER CENTRALITY (PC) OF EACH NODE") << "\n";
	outText << tr("PC of each node k, is the sum of the sizes of all Nth-order neighbourhoods with weight 1/n.") << "\n";
	outText << tr("Therefore, PC(u) is a generalised degree centrality index.") << "\n";
	outText << tr("PC' is the standardized index; divided by the total numbers of nodes in the same component minus 1") << "\n";
	outText << tr("PC  range: 0 < PC < ") << QString::number(maxIndexEC)<< tr(" (star node)")<<"\n";
	outText << tr("PC' range: 0 < PC'< 1 \n\n");
	outText << "Node"<<"\tPC\t\tPC'\t\t%PC\n";
	QList<Vertex*>::iterator it;
	for (it= m_graph.begin(); it!= m_graph.end(); it++){
		outText << (*it)->name()<<"\t"<<(*it)->PC() << "\t\t"<< (*it)->SPC() << "\t\t" <<  (100* ((*it)->PC()) /  sumPC)<<endl;
	}
	if ( minPC ==  maxPC)
		outText << tr("\nAll nodes have the same PC value.\n");
	else {
		outText << "\n";
		outText << tr("Max PC' = ") << maxPC <<" (node "<< maxNodePC  <<  ")  \n";
		outText << tr("Min PC' = ") << minPC <<" (node "<< minNodePC <<  ")  \n";
		outText << tr("PC classes = ") << classesPC<<" \n";
	}

	outText << "\n\n";
	outText << tr("Power Centrality report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}





/**
*	Writes the number of cliques (triangles) of each vertex into a given file.
*/
void Graph::writeNumberOfCliques(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	long int cliques=0, cliques_sum=0, N = vertices();
		
	QTextStream outText ( &file );

	emit statusMessage ( QString(tr("Writing number of triangles to file:")).arg(fileName) );
	
	outText << tr("NUMBER OF CLIQUES (CLQs) OF EACH NODE") << "\n";
	outText << tr("CLQs range: 0 < CLQs < ") <<"\n\n";
	outText << "Node"<<"\tCLQs\n";

	QList<Vertex*>::iterator it;
	
	for (it= m_graph.begin(); it!= m_graph.end(); it++){ 
		cliques=this->numberOfCliques((*it)->name()); 
		outText << (*it)->name()<<"\t"<< cliques <<endl;
		cliques_sum += cliques;
	}
	
	outText << endl << tr("NUMBER OF CLIQUES (CLQSUM) OF GRAPH")<< endl;
	outText << "CLQSUM = " <<  cliques_sum / 3.0 <<"\n\n";
	if ( N > 3) 
		outText << tr("CLQSUM Range: 0 < CLQSUM < ") << N * (N-1) * (N-2)/ 3 << endl;

	outText <<"\n\n" ;
	outText << tr("Number of Cliques Report,\n");
	outText << tr("created by SocNetV: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";

	file.close();
}



void Graph::writeClusteringCoefficient(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Calculating shortest paths")) );
	float clucof= clusteringCoefficient();
	Q_UNUSED(clucof);
	emit statusMessage ( QString(tr("Writing clustering coefficients to file:")).arg(fileName) );
	
	outText << tr("CLUSTERING COEFFICIENT (CLC) OF EACH NODE\n");
	outText << tr("CLC  range: 0 < C < 1") <<"\n";
	outText << "Node"<<"\tCLC\n";

	
	QList<Vertex*>::iterator it;
	for (it= m_graph.begin(); it!= m_graph.end(); it++){ 
		outText << (*it)->name()<<"\t"<<(*it)->CLC() <<endl;
	}
	if ( isSymmetric()) {
		outText << "\nAverage Clustering Coefficient = "<<  averageCLC<<"\n" ;
	//	outText << "DC Variance = "<<  varianceDegree<<"\n\n";
	}
	else{
		outText << "\nAverage Clustering Coefficient= "<<  averageCLC<<"\n" ;
//		outText << "ODC Variance = "<<  varianceDegree<<"\n\n";
	}
	if (  minCLC ==  maxCLC )
		outText << "\nAll nodes have the same clustering coefficient value.\n";
	else  {
		outText << "\nNode "<<  maxNodeCLC << " has the maximum Clustering Coefficient: " <<  maxCLC <<"  \n";
		outText << "\nNode "<<  minNodeCLC << " has the minimum Clustering Coefficient: " <<  minCLC <<"  \n";
	}
	
	outText << "\nGRAPH CLUSTERING COEFFICIENT (GCLC)\n\n";
	outText << "GCLC = " <<  averageCLC<<"\n\n";
	outText << tr("Range: 0 < GCLC < 1\n");
	outText << tr("GCLC = 0, when there are no cliques (i.e. acyclic tree).\n");
	outText << tr("GCLC = 1, when every node and its neighborhood are complete cliques.\n");

	outText <<"\n\n" ;
	outText << tr("Clustering Coefficient Report,\n");
	outText << tr("created by SocNetV: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";

	file.close();
}





void Graph::writeTriadCensus(
		const QString fileName, const bool considerWeights)
{
	Q_UNUSED(considerWeights);
	QFile file ( fileName );
	if ( !file.open( QIODevice::WriteOnly ) )  {
		qDebug()<< "Error opening file!";
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	
	QTextStream outText ( &file );

	emit statusMessage ( (tr("Conducting triad census. Please wait....")) );

	if (!triadCensus()){
		qDebug() << "Error in triadCensus(). Exiting...";
		file.close();
		return;
	}
		
	
	emit statusMessage ( QString(tr("Writing clustering coefficients to file:")).arg(fileName) );
	
	outText << "Type\t\tCensus\t\tExpected Value" << "\n";
	outText << "003" << "\t\t" << triadTypeFreqs[0] << "\n";
	outText << "012" << "\t\t" <<triadTypeFreqs[1] <<"\n";
	outText << "102" << "\t\t" <<triadTypeFreqs[2] <<"\n";	
	outText << "021D"<< "\t\t" <<triadTypeFreqs[3] <<"\n";	
	outText << "021U"<< "\t\t" <<triadTypeFreqs[4] <<"\n";	
	outText << "021C"<< "\t\t" <<triadTypeFreqs[5] <<"\n";
	outText << "111D"<< "\t\t" <<triadTypeFreqs[6] <<"\n";	
	outText << "111U"<< "\t\t" <<triadTypeFreqs[7] <<"\n";	
	outText << "030T"<< "\t\t" <<triadTypeFreqs[8] <<"\n";	
	outText << "030C"<< "\t\t" <<triadTypeFreqs[9] <<"\n";
	outText << "201" << "\t\t" <<triadTypeFreqs[10] <<"\n";	
	outText << "120D"<< "\t\t" <<triadTypeFreqs[11] <<"\n";	
	outText << "120U"<< "\t\t" <<triadTypeFreqs[12] <<"\n";	
	outText << "120C"<< "\t\t" <<triadTypeFreqs[13] <<"\n";
	outText << "210" << "\t\t" <<triadTypeFreqs[14] <<"\n";
	outText << "300" << "\t\t" <<triadTypeFreqs[15] <<"\n";

	outText << "\n\n";
	outText << tr("Triad Census report, \n");
	outText << tr("created by SocNetV on: ")<< actualDateTime.currentDateTime().toString ( QString ("ddd, dd.MMM.yyyy hh:mm:ss")) << "\n\n";
	file.close();

}



/** 
* Repositions all nodes on the periphery of different circles with radius analogous to their centrality
*/
void Graph::layoutRadialCentrality(double x0, double y0, double maxRadius, int CentralityType){
	qDebug("Graph: layoutRadialCentrality...");
	//first calculate centralities
        if ((graphModified || !calculatedCentralities) && CentralityType > 2 && CentralityType != 9 ) {
		qDebug("Graph: Calling createDistanceMatrix() to calc centralities");
		createDistanceMatrix(true);
	}
	else if ((graphModified || !calculatedIDC) && CentralityType == 1)
		centralityInDegree(true);
	else if ((graphModified || !calculatedODC) && CentralityType == 2)
		centralityOutDegree(true);
        else if ( CentralityType == 9 ){
                centralityInformation();
        }

	double rad=0;
	double i=0, std=0;
 	float C=0, maxC=0, offset=0.06;  //offset controls how far from the centre the central nodes be positioned
	double new_radius=0, new_x=0, new_y=0;
	double Pi = 3.14159265;
	int vert=vertices();

	for (QList<Vertex*>::iterator it=m_graph.begin(); it!=m_graph.end(); it++){
		switch (CentralityType) {
			case 1 : {	
					qDebug("Layout according to InDegree Centralities");
					C=(*it)->SIDC();
					std= (*it)->SIDC();
					maxC=maxIDC;
					break;
			}
			case 2 : {	
					qDebug("Layout according to OutDegree Centralities");
					C=(*it)->SODC();
					std= (*it)->SODC();
					maxC=maxODC;
					break;
			}
			case 3 : {	
					qDebug("Layout according to Closeness Centralities");
					C=(*it)->CC();
					std= (*it)->SCC();
					maxC=maxCC;
					break;
			}
			case 4 : {	
					qDebug("Layout according to Betweeness Centralities");
					C=(*it)->BC();
					std= (*it)->SBC();
					maxC=maxBC;
					break;
			}
			case 5 : {	
					qDebug("Layout according to Graph Centralities");
					C=(*it)->GC();
					std= (*it)->SGC();
					maxC=maxGC;
					break;
			}
			case 6 : {	
					qDebug("Layout according to Stress Centralities");
					C=(*it)->SC();
					std= (*it)->SSC();
					maxC=maxSC;
					break;
			}
			case 7 : {	
					qDebug("Layout according to Eccentricity Centralities");
					C=(*it)->EC();
					std= (*it)->SEC();
					maxC=maxEC;
					break;
			}
                        case 8 : {
                                qDebug("Layout according to Power Centralities");
                                C=(*it)->PC();
                                std= (*it)->SPC();
                                maxC=maxPC;
                                break;
                        }
                        case 9 : {
                                qDebug("Layout according to Information Centralities");
                                C=(*it)->IC();
                                std= (*it)->SIC();
                                maxC=maxIC;
                                break;
                        }

		};
		qDebug () << "Vertice " << (*it)->name() << " at x=" << (*it)->x() << ", y= "<< (*it)->y()
				<< ": C=" << C << ", stdC=" << std << ", maxradius " <<  maxRadius
				<< ", maxC " << maxC << ", C/maxC " << (C/maxC) << ", *maxRadius " << (C/maxC - 0.06)*maxRadius;
		switch (static_cast<int> (ceil(maxC)) ){
			case 0: {	
				qDebug("maxC=0.   Using maxHeight");
				new_radius=maxRadius; 	
				break;
			}
			default: { 
				new_radius=(maxRadius- (C/maxC - offset)*maxRadius); 	
				break;
			}
		};
		
		qDebug ("new radius %f", new_radius);
		
		//Calculate new position
		rad= (2.0* Pi/ vert );
		new_x=x0 + new_radius * cos(i * rad);
		new_y=y0 + new_radius * sin(i * rad);
		(*it)->setX( new_x );
		(*it)->setY( new_y );
		qDebug("Finished Calculation. Vertice will move to x=%f and y=%f ",new_x, new_y);
		//Move node to new position
		emit moveNode((*it)->name(),  new_x,  new_y);
		i++;
		emit addBackgrCircle (
							static_cast<int> (x0), 
							static_cast<int> (y0), 
							static_cast<int> (new_radius)
							);
	}
	graphModified=false;
}




/** 
*	 Repositions all nodes on different random positions
* 	Emits moveNode(i, x,y) to tell GW that the node item should be moved. 
*/
void Graph::layoutRandom(double maxWidth, double maxHeight){	
	qDebug("Graph: layoutRandom...");
	double new_x=0, new_y=0;
	for (Vertices::iterator it=m_graph.begin(); it!=m_graph.end(); it++){
		new_x= rand() % ( static_cast<int> (maxWidth) );
		new_y= rand() % ( static_cast<int> (maxHeight) );
		(*it)->setX( new_x );
		(*it)->setY( new_y );
		qDebug()<< "Graph: Emitting moveNode to move Vertice " << (*it)->name()
				//<< "indexed " << index((*it)->name())
				<< " to new position " << new_x << " , "<< new_y;
		emit moveNode((*it)->name(),  new_x,  new_y);
	}
}


/** 
*	 Repositions all nodes on different top-down levels according to their centrality
* 	Emits moveNode(i, x,y) to tell GW that the node item should be moved. 
*/
void Graph::layoutLayeredCentrality(double maxWidth, double maxHeight, int CentralityType){
	qDebug("Graph: layoutLevelCentrality...");
	//first calculate centralities
	if ((graphModified || !calculatedCentralities) && CentralityType > 2) {
		qDebug("Graph: Calling createDistanceMatrix() to calc centralities");
		createDistanceMatrix(true);
	}
	else if ((graphModified || !calculatedIDC) && CentralityType == 1)
		centralityInDegree(true);
	else if ((graphModified || !calculatedODC) && CentralityType == 2)
		centralityOutDegree(true);

	double i=0, std=0;
 	float C=0, maxC=0, offset=50;  //offset controls how far from the top the central nodes will be positioned
	double new_x=0, new_y=0;
//	int vert=vertices();
	maxHeight-=offset;
	maxWidth-=offset;
	for (QList<Vertex*>::iterator it=m_graph.begin(); it!=m_graph.end(); it++){
		switch (CentralityType) {
			case 1 : {	
					qDebug("Layout according to InDegree Centralities");
					C=(*it)->SIDC();
					std= (*it)->SIDC();
					maxC=maxIDC;
					break;
			}
			case 2 : {	
					qDebug("Layout according to OutDegree Centralities");
					C=(*it)->SODC();
					std= (*it)->SODC();
					maxC=maxODC;
					break;
			}
			case 3 : {	
					qDebug("Layout according to Closeness Centralities");
					C=(*it)->CC();
					std= (*it)->SCC();
					maxC=maxCC;
					break;
			}
			case 4 : {	
					qDebug("Layout according to Betweeness Centralities");
					C=(*it)->BC();
					std= (*it)->SBC();
					maxC=maxBC;
					break;
			}
			case 5 : {	
					qDebug("Layout according to Graph Centralities");
					C=(*it)->GC();
					std= (*it)->SGC();
					maxC=maxGC;
					break;
			}
			case 6 : {	
					qDebug("Layout according to Stress Centralities");
					C=(*it)->SC();
					std= (*it)->SSC();
					maxC=maxSC;
					break;
			}
		};
		qDebug()<< "Vertice " << (*it)->name() << " at x="<< (*it)->x() << ", y="<<  (*it)->y() << ": C=" << C << ", stdC=" << std 
				<< ", maxC "<<	maxC << ", maxWidth " << maxWidth <<" , maxHeight "<<maxHeight;
		//Calculate new position
		qDebug ("C/maxC %f, *maxHeight %f, +maxHeight %f ",C/maxC, (C/maxC)*maxHeight, maxHeight-(C/maxC)*maxHeight );
		switch ( static_cast<int> (ceil(maxC)) ){
			case 0: {	
				qDebug("maxC=0.   Using maxHeight");
				new_y=maxHeight; 	
				break;
			}
			default: { 
				new_y=offset/2.0+maxHeight-(C/maxC)*maxHeight; 	
				break;
			}
		};
		new_x=offset/2.0 + rand() % ( static_cast<int> (maxWidth) );
		qDebug ("new_x %f, new_y %f", new_x, new_y);
		(*it)->setX( new_x );
		(*it)->setY( new_y );
		qDebug("Finished Calculation. Vertice will move to x=%f and y=%f ",new_x, new_y);
		//Move node to new position
		emit moveNode((*it)->name(),  new_x,  new_y);
		i++;
		emit addBackgrHLine(static_cast<int> ( new_y ) );
	}
	graphModified=false;
}



/** layman's attempt to create a random network
*/
void Graph::createRandomNetErdos(int vert, double probability){
	qDebug("Graph: createRandomNetErdos");

	int progressCounter=0;
	
	for (register int i=0; i< vert ; i++) {
		int x=10+rand() %640;
		int y=10+rand() %480;
		qDebug("Graph: createRandomNetErdos, new node i=%i, at x=%i, y=%i", i+1, x,y);
		createVertex (
						i+1, initVertexSize, initVertexColor, 
						initVertexNumberColor, initVertexNumberSize,  
						QString::number (i+1), initVertexLabelColor, initVertexLabelSize,
						QPoint(x, y), initVertexShape, false
					);
		progressCounter++;
		emit updateProgressDialog( progressCounter );
	}
	for (register int i=0;i<vert; i++) {
		for (register int j=0; j<vert; j++) {
			qDebug("Random Experiment for link creation between %i and %i:", i+1, j+1);
			if (rand() % 100 < probability)    {
				qDebug("Creating link!");
				createEdge(i+1, j+1, 1, "black", true, true, false);
			}
			else 
				qDebug("Will not create link!");
		}
		progressCounter++;
		emit updateProgressDialog(progressCounter );
		qDebug("Emitting UPDATE PROGRESS %i", progressCounter);
	}
	emit graphChanged();
}




/** layman's attempt to create a random ring lattice network.
*/

void Graph::createRandomNetRingLattice( 
			int vert, int degree, 
			double x0, double y0, double radius)
{
	qDebug("Graph: createRingLatticeNetwork");
	int x=0;
	int y=0;
	int progressCounter=0;


	double Pi = 3.14159265;
	double rad= (2.0* Pi/ vert );
	for (register int i=0; i< vert ; i++) {
		x=x0 + radius * cos(i * rad);
		y=y0 + radius * sin(i * rad);
		createVertex(	i+1,initVertexSize,initVertexColor,
						initVertexNumberColor, initVertexNumberSize,  
						 QString::number (i+1), initVertexLabelColor,  initVertexLabelSize,
						 QPoint(x, y), initVertexShape, false);
		qDebug("Graph: createPhysicistLatticeNetwork, new node i=%i, at x=%i, y=%i", i+1, x,y);
		progressCounter++;
		emit updateProgressDialog( progressCounter );
	}
	int target = 0;
	for (register int i=0;i<vert; i++){
		qDebug("Creating links for node %i = ", i+1);	
		for (register int j=0; j< degree/2 ; j++) {
			target = i + j+1 ; 
			if ( target > (vert-1)) 
				target = target-vert; 
			qDebug("Creating Link between %i  and %i", i+1, target+1);
			createEdge(i+1, target+1, 1, "black", true, true, false);
		}
		progressCounter++;
		emit updateProgressDialog(progressCounter );
		qDebug("Emitting UPDATE PROGRESS %i", progressCounter);
	}
	graphChanged();
}





void Graph::createRandomNetSmallWorld (
				int vert, int degree, double beta, 
				double x0, double y0, double radius)
{
	qDebug("Graph: createRandomNetSmallWorld. First creating a ring lattice");

	createRandomNetRingLattice(vert, degree, x0, y0, radius);

	qDebug("******** Graph: REWIRING starts...");

	int candidate;
	
	for (register int i=1;i<vert; i++) {
		for (register int j=i+1;j<vert; j++) {
			qDebug()<<">>>>> REWIRING: Check if  "<< i << " is linked to " << j;
			if ( this-> hasEdge(i, j) ) {
				qDebug()<<">>>>> REWIRING: They're linked. Do a random REWIRING Experiment between "<< i<< " and " << j << " Beta parameter is " << beta;
				if (rand() % 100 < (beta * 100))  {
					qDebug(">>>>> REWIRING: We'l break this edge!");
					removeEdge(i, j);
					removeEdge(j, i);
					qDebug()<<">>>>> REWIRING: OK. Let's create a new edge!";
					for (;;) {	//do until we create a new edge
						candidate=rand() % (vert+1) ;		//pick another vertex.
						if (candidate == 0 || candidate == i) continue;
						qDebug()<<">>>>> REWIRING: Candidate: "<< candidate;
						if (! this->hasEdge(i, candidate) )	//Only if differs from i and hasnot edge with it
								qDebug("<----> Random New Edge Experiment between %i and %i:", i, candidate);
								if (rand() % 100 > 0.5) {
									qDebug("Creating new link!");
									createEdge(i, candidate, 1, "black", true, true, false);
									break;
								}
					}
				}
				else  qDebug("Will not break link!");
			}
		}
	}
}





/** layman's attempt to create a random network where nodes have the same degree.
*/

void Graph::createSameDegreeRandomNetwork(int vert, int degree){
	qDebug("Graph: createSameDegreeRandomNetwork");

	int progressCounter=0;

	for (register int i=0; i< vert ; i++) {
		int x=10+rand() %640;
		int y=10+rand() %480;
		qDebug("Graph: createUniformRandomNetwork, new node i=%i, at x=%i, y=%i", i+1, x,y);
		createVertex(
						i+1, initVertexSize,initVertexColor,
						initVertexNumberColor, initVertexNumberSize,  
						QString::number (i+1), initVertexLabelColor, initVertexLabelSize, 
						QPoint(x, y), initVertexShape,false
						);
		progressCounter++;
		emit updateProgressDialog( progressCounter );

	}
	int target = 0;
	for (register int i=0;i<vert; i++){
		qDebug("Creating links for node %i = ", i+1);	
		for (register int j=0; j< degree/2 ; j++) {
			target = i + j+1 ; 
			if ( target > (vert-1)) 
				target = target-vert; 
			qDebug("Creating Link between %i  and %i", i+1, target+1);
			createEdge(i+1, target+1, 1, "black", true, true, false);
		}
		progressCounter++;
		emit updateProgressDialog(progressCounter );
		qDebug("Emitting UPDATE PROGRESS %i", progressCounter);

	}
	graphChanged();
}

/**
	Calculates and returns the number of cliques which include vertex v1
	A clique (or triangle) is a complete subgraph of three nodes.
*/	
float Graph:: numberOfCliques(int v1){
	qDebug("*** Graph::numberOfCliques(%i) ", v1);
	float cliques=0;
	int  connectedVertex1=0, connectedVertex2=0;
	qDebug() << "Graph::numberOfCliques() Source vertex " << v1 << "[" << index[v1] << "] has inDegree " << edgesTo(v1) << " and outDegree "<< edgesFrom(v1);
	imap_f::iterator it1, it2;
	bool symmetric=FALSE;
	if ( ! (symmetric = isSymmetric()) ) {  //graph is not symmetric
		for( it1 =  m_graph[ index[v1] ] -> m_inEdges.begin(); it1 !=  m_graph[ index[v1] ] ->m_inEdges.end(); it1++ ) {
			connectedVertex1=it1->first;	
		    qDebug() << "Graph::numberOfCliques() In-connectedVertex1  " << connectedVertex1 << "[" << index[connectedVertex1] << "] ...Checking inLinks....";
			for( it2 =  m_graph[ index[v1] ] -> m_inEdges.begin(); it2 !=  m_graph[ index[v1] ] ->m_inEdges.end(); it2++ ) {
				connectedVertex2=it2->first;
				if (connectedVertex1 == connectedVertex2) continue;
				else {
					qDebug() << "Graph::numberOfCliques() Out-connectedVertex2  " << connectedVertex2 << "[" << index[connectedVertex2] << "]";
					if ( this->hasEdge( connectedVertex1, connectedVertex2 ) ) {
						qDebug("Graph::numberOfCliques()  %i  is connected to %i. Therefore we found a clique!", connectedVertex1, connectedVertex2);
						cliques++;
						qDebug("Graph::numberOfCliques() cliques = %f" ,  cliques);
					}
				}
			}
			qDebug("Graph::numberOfCliques()  .....Checking outLinks.... ");
			for( it2 =  m_graph[ index[v1] ] -> m_outEdges.begin(); it2 !=  m_graph[ index[v1] ] ->m_outEdges.end(); it2++ ) {
				connectedVertex2=it2->first;
				if (connectedVertex1 == connectedVertex2) continue;
				else {
				    qDebug() << "Graph::numberOfCliques() Out-connectedVertex2  " << connectedVertex2 << "[" << index[connectedVertex2] << "]";
					if ( this->hasEdge( connectedVertex1, connectedVertex2 ) || this-> hasEdge( connectedVertex2, connectedVertex1 ) ) {
						qDebug("Graph::numberOfCliques()  %i  is connected to %i. Therefore we found a clique!", connectedVertex1, connectedVertex2);
						cliques++;
						qDebug("Graph::numberOfCliques() cliques = %f" ,  cliques);
					}
				}
			}
		}
		
	}

	for( it1 =  m_graph[ index[v1] ] -> m_outEdges.begin(); it1 !=  m_graph[ index[v1] ] ->m_outEdges.end(); it1++ ) {
		connectedVertex1=it1->first;	
		qDebug() << "Graph::numberOfCliques() Out-connectedVertex1  " << connectedVertex1 << "[" << index[connectedVertex1] << "]";
		for( it2 =  m_graph[ index[v1] ] -> m_outEdges.begin(); it2 !=  m_graph[ index[v1] ] ->m_outEdges.end(); it2++ ) {
			connectedVertex2=it2->first;
			if (connectedVertex1 == connectedVertex2) continue;
			else if ( connectedVertex1 >= connectedVertex2 && symmetric) continue;
			else {
				qDebug() << "Graph::numberOfCliques() Out-connectedVertex2  " << connectedVertex2 << "[" << index[connectedVertex2] << "]";
				if ( this->hasEdge( connectedVertex1, connectedVertex2 ) ) {
					qDebug("Graph::numberOfCliques()  %i  is out-connected to %i. Therefore we found a clique!", connectedVertex1, connectedVertex2);
					cliques++;
					qDebug("Graph::numberOfCliques() cliques = %f" ,  cliques);
				}
				if (!symmetric)
					if ( this->hasEdge( connectedVertex2, connectedVertex1 ) ) {
						qDebug("Graph::numberOfCliques()  %i  is also in-connected to %i. Therefore we found a clique!", connectedVertex2, connectedVertex1);
						cliques++;
						qDebug("Graph::numberOfCliques() cliques = %f" ,  cliques);
					}
			}
		}
	}
	return cliques;
}


/**
	Calculates and returns the total number of cliques in the graph.
	Calls numberOfCliques(v1) to calculate the number of cliques of each vertex v1,
	sums the total number, then divides it by 3 because each vertex has been counted three times.
*/	
float Graph::numberOfCliques(){
	qDebug("Graph::	numberOfCliques()");
	float cliques=0;
	foreach (Vertex *v1, m_graph)  {
		cliques += numberOfCliques(v1->name());
		qDebug("Graph::	numberOfCliques now %f", cliques );
	}
	cliques = cliques / 3.0;
	qDebug("Graph::	numberOfCliques Dividing by three we get %f", cliques );
	return cliques ;
}



/**
	Returns the number of triples of vertex v1
	A triple Υ at a vertex v is a path of length two for which v is the center vertex.
*/
float Graph::numberOfTriples(int v1){
	float totalDegree=0;
	if (isSymmetric()){
		totalDegree=edgesFrom(v1);
		return totalDegree * (totalDegree -1.0) / 2.0;
	}
	totalDegree=edgesFrom(v1) + edgesTo(v1);  //FIXEM
	return	totalDegree * (totalDegree -1.0);
}



/**
	Returns the clustering coefficient (CLUCOF) of a vertex v1
	CLUCOF in a graph quantifies how close the vertex and its neighbors are to being a clique 
	This is used to determine whether a graph is a small-world network.
*/
float Graph:: clusteringCoefficient(int v1){
	float clucof=0;
	if ( !graphModified && (m_graph[ index [v1] ] -> hasCLC() ) )  {
		float clucof=m_graph[ index [v1] ] ->CLC(); 
		qDebug("Graph: clusteringCoefficient(%i) not modified. Returning previous clucof = %f", v1, clucof);
		return clucof;
	}

	qDebug("Graph::	clusteringCoefficient(v1) - Graph changed or clucof not calculated. Calling numberOfCliques() for vertex %i", v1);
	float totalCliques=numberOfCliques(v1);
	qDebug("Graph::	Number of Cliques for %i is %f.", v1, totalCliques);

	if (totalCliques==0) return 0;	//stop if we're at a leaf.
	
	float denom=0, totalDegree=0;
	
	if (isSymmetric()){
		totalCliques = totalCliques / 2.0;
		qDebug(" Graph::Calculating number of triples");
		totalDegree=edgesFrom(v1);
		denom =	totalDegree * (totalDegree -1.0) / 2.0;
		qDebug("Graph:: Symmetric. Number of triples is %f.  Dividing number of cliques with it", denom);
		
	}
	else {
		qDebug(" Graph::Calculating number of triples");
		totalDegree=edgesFrom(v1) + edgesTo(v1);  //FIXME
		denom = totalDegree * (totalDegree -1.0);
		qDebug("Graph:: Symmetric. Number of triples is %f.  Dividing number of cliques with it", denom);
	}

	clucof = totalCliques / denom;
	qDebug() << "=== Graph::clusteringCoefficient() - vertex " <<  v1 << " ["<< index[v1] << "]" << " has CLUCOF = "<< clucof;
	m_graph[ index [v1] ] ->setCLC(clucof);
	return clucof;
}


/**
	Calculates and returns the Clustering Coefficient for the whole graph
*/
float Graph::clusteringCoefficient (){
	qDebug("=== Graph::graphClusteringCoefficient()  ");
	averageCLC=0;
	maxCLC=0; minCLC=1;
	float temp=0;
	foreach (Vertex *v1, m_graph)  {
		temp = clusteringCoefficient(v1->name());
		if (temp > maxCLC)  {
			maxCLC = temp;
			maxNodeCLC = v1->name();			 
		}		
		if ( temp < minCLC ) {
			 minNodeCLC = v1->name();
			 minCLC= temp;		
		}
		averageCLC += temp;
	}
	
	averageCLC = averageCLC / vertices();
	qDebug("=== Graph::graphClusteringCoefficient()  is equal to %f", averageCLC);
	
	return averageCLC; 
}



/*tri
 *  Conducts a triad census and updates QList::triadTypeFreqs, 
 * 		which is the list carrying all triad type frequencies
 *  Complexity:O(n!)
 */
bool Graph::triadCensus(){
	int mut=0, asy=0, nul =0;
	int temp_mut=0, temp_asy=0, temp_nul =0, counter_021=0;
	int ver1, ver2, ver3;
	QString last_char;

	int progressCounter = 0;
	/*
	 * QList::triadTypeFreqs stores triad type frequencies with the following order:
	 * 0	1	2	3		4	5	6	7	8		9	10	11	12		13	14	15
	 * 003 012 102	021D 021U 021C 111D	111U 030T 030C 201 	120D 120U 120C 210 300
 	*/ 
	
	for (int i = 0; i < 15; ++i) {
		triadTypeFreqs.append(0);
	}
	QList<Vertex*>::iterator v1;
	QList<Vertex*>::iterator v2;
	QList<Vertex*>::iterator v3;

	for (v1=m_graph.begin(); v1!=m_graph.end(); v1++) {	 

		for (v2=(v1+1); v2!=m_graph.end(); v2++) {

			ver1=(*v1)->name();
			ver2=(*v2)->name();
		
			temp_mut=0, temp_asy=0, temp_nul =0;
			
			if ( (*v1)->isLinkedTo( ver2 ) ) {
				if ( (*v2)->isLinkedTo( ver1 ) )
					temp_mut++;
				else 
					temp_asy++;
			}
			else if ( (*v2)->isLinkedTo( ver1 )  )
				temp_asy++;
			else
				temp_nul++; 
			
			for (v3=(v2+1); v3!=m_graph.end(); v3++){

				mut = temp_mut ;
				asy = temp_asy ;
				nul = temp_nul ;

				ver3=(*v3)->name();
				
				if ( (*v1)->isLinkedTo( ver3 ) ) {
					if ( (*v3)->isLinkedTo( ver1 ) )
						mut++;
					else 
						asy++;
				}
				else if ( (*v3)->isLinkedTo( ver1 )  )
					asy++;
				else
					nul++; 
				
				if ( (*v2)->isLinkedTo( ver3 ) ) {
					if ( (*v3)->isLinkedTo( ver2 ) )
						mut++;
					else 
						asy++;
				}
				else if ( (*v3)->isLinkedTo( ver2 )  )
					asy++;
				else
					nul++; 
			
				//qDebug()<< "triad of ("<< ver1 << ","<< ver2 << ","<< ver3 << ") = ("	<<mut<<","<< asy<<","<<nul<<")";
				examine_MAN_label(mut, asy, nul, (*v1), (*v2),  (*v3) ) ;
				progressCounter++ ;
				emit updateProgressDialog( progressCounter );
				if ( mut==3 && asy==0 && nul==0 ){
					counter_021++;
				}
			} // end 3rd foreach
		}// end 2rd foreach
	}// end 1rd foreach
	qDebug() << " ****** 003 COUNTER: "<< counter_021;
	return true;
}




/** 
	Examines the triad type (in Mutual-Asymmetric-Null label format) 
	and increases by one the proper frequency element 
	inside QList::triadTypeFreqs
*/
void Graph:: examine_MAN_label(int mut, int asy, int nul, 
						Vertex* vert1, 
						Vertex* vert2,
						Vertex* vert3
						) 	{
	QString last_char;
	QList<Vertex*> m_triad;
	bool isDown=false, isUp=false, isCycle=false, isTrans=false;
	bool isOutLinked=false, isInLinked=false;
	m_triad<<vert1<<vert2<<vert3;
	 
	switch (mut){
		case 0:
				switch (asy){
					case 0:	//"003";
							triadTypeFreqs[0] ++;
							break;
					case 1:	 //"012";
							triadTypeFreqs[1] ++;
							break;
					case 2:
							// "021?" - find out!
						//	qDebug() << "triad vertices: ( "<< vert1->name() << ", "<< vert2->name()<< ", "<< vert3->name()<< " ) = ("	<<mut<<","<< asy<<","<<nul<<")";
							foreach (Vertex *source, m_triad)  {
									//qDebug() << "  Vertex " << source->name() ;
									isOutLinked=false; isInLinked=false;
									
									foreach (Vertex *target, m_triad)  	{
										if ( source->name() == target->name() )
												continue;
												
										if ( source->isLinkedTo(target->name()) ){
											if ( isOutLinked ){
												triadTypeFreqs[3] ++;//"021D"
												break;
											}
											else if (isInLinked){
												triadTypeFreqs[5] ++;//"021C"
												break;
											}
											else{
												isOutLinked=true;
											}
										}
										else if( target->isLinkedTo(source->name()) ){
										//	qDebug() << "    Vertex " << source->name()  << " is IN linked from " <<target->name(); 
											if ( isInLinked ){
												triadTypeFreqs[4] ++;//"021U"
												break;
											}
											else if (isOutLinked){
												triadTypeFreqs[5] ++;//"021C"
												break;
											}
											else{
												isInLinked=true;
											}
										}
									}
							}
							break;
					case 3:
							qDebug() << "triad vertices: ( "<< vert1->name() << ", "<< vert2->name()<< ", "<< vert3->name()<< " ) = ("	<<mut<<","<< asy<<","<<nul<<")";
							isTrans=false;
							foreach (Vertex *source, m_triad)  {
									qDebug() << "  Vertex " << source->name() ;
											
									isOutLinked=false; 
									
									foreach (Vertex *target, m_triad)  	{
										if ( source->name() == target->name() )
												continue;
												
										if ( source->isLinkedTo(target->name()) ){
											
											if ( isOutLinked ){
												triadTypeFreqs[8] ++;//"030T"
												isTrans=true;
												break;
											}
											else{
												isOutLinked=true;
											}
										}
									}
							}
							if ( ! isTrans ) {//"030C"
								triadTypeFreqs[9] ++;
							}
							break;
				}
				break;

		case 1:
				switch (asy){
					case 0:	//"102";
							triadTypeFreqs[2] ++;
							break;
					case 1:
							isDown=false; isUp=false;
							//qDebug() << "triad vertices: ( "<< vert1->name() << ", "<< vert2->name()<< ", "<< vert3->name()<< " ) = ("	<<mut<<","<< asy<<","<<nul<<")";
							foreach (Vertex *source, m_triad)  {
								//	qDebug() << "  Vertex " << source->name() ;
											
									isInLinked=false; 
									
									foreach (Vertex *target, m_triad)  	{
										if ( source->name() == target->name() )
												continue;
												
										if ( target->isLinkedTo(source->name()) ){
											
											if ( isInLinked ){
												triadTypeFreqs[6] ++;//"030T"
												isUp=true;
												break;
											}
											else{
												isInLinked=true;
											}
										}
									}
							}
							if ( ! isUp ) {//"111U"
								triadTypeFreqs[7] ++;
							}
							break;
					case 2:
							isDown=false; isUp=false; isCycle=true;
							qDebug() << "triad vertices: ( "<< vert1->name() << ", "<< vert2->name()<< ", "<< vert3->name()<< " ) = ("	<<mut<<","<< asy<<","<<nul<<")";

							foreach (Vertex *source, m_triad)  {
									//qDebug() << "  Vertex " << source->name() ;
									isOutLinked=false; isInLinked=false;
									
									foreach (Vertex *target, m_triad)  	{
										if ( source->name() == target->name() )
												continue;
												
										if ( source->isLinkedTo(target->name()) ){
											if (target->isLinkedTo(source->name() ) ){
												isInLinked=true;
												isOutLinked=true;
												continue;
											}
											else if ( isOutLinked && !isInLinked ){
												triadTypeFreqs[11] ++;//"120D"
												isDown=true;
												isCycle=false;
												break;
											}
											else{
												isOutLinked=true;
											}
										}
										else if( target->isLinkedTo(source->name()) ){
										//	qDebug() << "    Vertex " << source->name()  << " is IN linked from " <<target->name();
											if (source->isLinkedTo(target->name())){
												isOutLinked=true;
												isInLinked=true;
												continue;
											}
											else if ( isInLinked && !isOutLinked ){
												triadTypeFreqs[12] ++;//"120U"
												isUp=true;
												isCycle=false;
												break;
											}
											else{
												isInLinked=true;
											}
										}
									}
									if (isUp || isDown)
										break;
							}
							if ( isCycle ) {	//"120C"
								triadTypeFreqs[13] ++;
							}
							break;
					case 3:
							 // nothing here!
							break;
				}

				break;
		case 2:
				switch (asy){
					case 0:	// "201" 
						triadTypeFreqs[10] ++;
						break;
					case 1:	// "210" 
						triadTypeFreqs[14] ++;
						break;
				}
				break;
		case 3:	// "300" 
				if (asy==0 && nul==0)
					triadTypeFreqs[15] ++;
				break;
		}

	
}





/** 
	Calculates and returns x! factorial...
*/
int Graph:: factorial(int x) {
	int tmp;
	if(x <= 1) return 1;
	tmp = x * factorial(x - 1);
	return tmp;
}



/**
	Our almost universal network loader. :)
	Actually it calls the load() method of parser/qthread class.
*/
bool Graph::loadGraph (	QString fileName,  bool iSL, int maxWidth, int maxHeight, int fileFormat, int two_sm_mode){
	initShowLabels = iSL;
	bool loadGraphStatus = parser.load( 
				fileName, 
				initVertexSize, initVertexColor,
				initVertexShape,
				initVertexNumberColor, initVertexNumberSize,  
				initVertexLabelColor, initVertexLabelSize, 
				initEdgeColor, 
				maxWidth, maxHeight,
				fileFormat,
				two_sm_mode
				);
	return loadGraphStatus;
}



/**
	Our almost universal graph saver. :)
	Actually it just checks the requested file type and 
	calls the right saveGraphTo...() method  
*/
bool Graph::saveGraph ( 
				QString fileName, int fileType, 
				QString networkName, int maxWidth, int maxHeight ) 
{
	qDebug() << "Graph::saveGraph to ...";
	switch (fileType) {
		case 1 : {			//Pajek
				qDebug() << " 	... Pajek formatted file";
				return saveGraphToPajekFormat(fileName, networkName, maxWidth, maxHeight);
				break;			
		}
		case 2: {			// Adjacency
				qDebug() << " 	... Adjacency formatted file";
				return saveGraphToAdjacencyFormat(fileName, maxWidth,maxHeight);
				break;
		}
		case 3: {			// Dot
				qDebug() << " 	... Dot formatted file";
				return saveGraphToDotFormat(fileName, networkName, maxWidth, maxHeight);
				break;
		}
		case 4: {			// GraphML
				qDebug() << " 	... GraphML formatted file";
				return saveGraphToGraphMLFormat(fileName, networkName, maxWidth, maxHeight);
				break;
		}
		default: {
				qDebug() << " 	... Error! What format number is this anyway?";
				break;				
		}
	};
	return true;
}




/**
	Saves the active graph to a Pajek-formatted file
	Preserves node properties (positions, colours, etc)
*/
bool Graph::saveGraphToPajekFormat (
			QString fileName, QString networkName, int maxWidth, int maxHeight)
{
	qDebug () << " Graph::saveGraphToPajekFormat to file: " << fileName.toAscii();

	int weight=0;

	QFile f( fileName );
	if ( !f.open( QIODevice::WriteOnly ) )  {
		emit statusMessage (QString(tr("Could not write to %1")).arg(fileName));
		return false;
	}
	QTextStream t( &f );
	t<<"*Network "<<networkName<<"\n";
	
	t<<"*Vertices "<< vertices() <<"\n";
	QList<Vertex*>::iterator it;
	QList<Vertex*>::iterator jt;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		qDebug()<<" Name x "<<  (*it)->name()  ;
		t<<(*it)->name()  <<" "<<"\""<<(*it)->label()<<"\"" ;
		t << " ic ";
		t<<  (*it)->color() ;
		qDebug()<<" Coordinates x " << (*it)->x()<< " "<<maxWidth<<" y " << (*it)->y()<< " "<<maxHeight;
		t << "\t\t" <<(*it)->x()/(maxWidth)<<" \t"<<(*it)->y()/(maxHeight);
		t << "\t"<<(*it)->shape();
		t<<"\n";
	}

	t<<"*Arcs \n";
	qDebug()<< "Graph::saveGraphToPajekFormat: Arcs";
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		for (jt=m_graph.begin(); jt!=m_graph.end(); jt++){ 
			qDebug() << "Graph::saveGraphToPajekFormat:  it=" << (*it)->name() << ", jt=" << (*jt)->name() ;
			if  ( (weight=this->hasEdge( (*it)->name(), (*jt)->name())) !=0  
				 &&   ( this->hasEdge((*jt)->name(), (*it)->name())) == 0  
				 ) 
			{
				qDebug()<<"Graph::saveGraphToPajekFormat  weight "<< weight << " color "<<  (*it)->outLinkColor( (*jt)->name() ) ;
				t << (*it)->name() <<" "<<(*jt)->name()<< " "<<weight;
				//FIXME bug in outLinkColor() when we remove then add many nodes from the end
				t<< " c "<< (*it)->outLinkColor( (*jt)->name() );
				t <<"\n";
			}

		}
	}
	
	t<<"*Edges \n";
	qDebug() << "Graph::saveGraphToPajekFormat: Edges";
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		for (jt=m_graph.begin(); jt!=m_graph.end(); jt++){ 
			qDebug() << "Graph::saveGraphToPajekFormat:  it=" <<  (*it)->name() << ", jt=" <<(*jt)->name() ;
			if  ( (weight=this->hasEdge((*it)->name(), (*jt)->name()))!=0   &&   
					(this->hasEdge((*jt)->name(), (*it)->name()))!=0  
				)  {
				if ( (*it)->name() > (*jt)->name() ) 
					continue;
				t << (*it)->name() <<" "<<(*jt)->name()<< " "<<weight;
				t << " c "<< (*it)->outLinkColor( (*jt)->name() );
				t <<"\n";
			}
		}
	}
	f.close();
	QString fileNameNoPath=fileName.split("/").last();
	emit statusMessage (QString(tr( "File %1 saved" ) ).arg( fileNameNoPath ));
	return true;

	

}



bool Graph::saveGraphToAdjacencyFormat (
			QString fileName, int maxWidth, int maxHeight)
{
	Q_UNUSED(maxWidth);
	Q_UNUSED(maxHeight);
	QFile f( fileName );
	if ( !f.open( QIODevice::WriteOnly ) )  {
		emit statusMessage(QString(tr("Could not write to %1")).arg(fileName));
		return false;
	}
	QTextStream t( &f );
	qDebug("Graph: saveGraphToAdjacencyFormat() for %i vertices", vertices());

	writeAdjacencyMatrixTo(t);

	f.close();
	QString fileNameNoPath=fileName.split("/").last();
	emit statusMessage (QString( tr("Adjacency matrix-formatted network saved into file %1") ).arg( fileNameNoPath ));
	return true;
}


// Writes a known dataset to a file
void Graph::writeDataSetToFile (QString fileName) {
	QFile f( fileName );
	if ( !f.open( QIODevice::WriteOnly ) )  {
		emit statusMessage( QString(tr("Could not write to %1")).arg(fileName) );
		return;
	}
	QTextStream outText( &f );
	qDebug()<< "		... writing";
	if ( fileName == "Krackhardt_High-tech_managers_Advice_relation.sm" ) {
		outText <<
		"0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0 0 1" << endl <<
		"0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl <<
		"1 1 0 1 0 1 1 1 1 1 1 1 0 1 0 0 1 1 0 1 1" << endl <<
		"1 1 0 0 0 1 0 1 0 1 1 1 0 0 0 1 1 1 0 1 1" << endl <<
		"1 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1 1 1 1" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl <<
		"0 1 0 0 0 1 0 0 0 0 1 1 0 1 0 0 1 1 0 0 1" << endl <<
		"0 1 0 1 0 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 1" << endl <<
		"1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1" << endl <<
		"1 1 1 1 1 0 0 1 0 0 1 0 1 0 1 1 1 1 1 1 0" << endl <<
		"1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl <<
		"1 1 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0" << endl <<
		"0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 1" << endl <<
		"1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1" << endl <<
		"1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0" << endl <<
		"1 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl <<
		"1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 1 1 1" << endl <<
		"1 1 1 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0" << endl <<
		"1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1" << endl <<
		"0 1 1 1 0 1 1 1 0 0 0 1 0 1 0 0 1 1 0 1 0";
		
	}
	else if (fileName == "Krackhardt_High-tech_managers_Friendship_relation.sm"){
		outText<< "0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0" << endl <<
		"1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0" << endl <<
		"1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0" << endl <<
		"0 1 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 1" << endl <<
		"0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 1" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 1 0 0 0 1 0" << endl <<
		"1 1 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 1 1 0 0" << endl <<
		"1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1" << endl <<
		"0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0" << endl <<
		"0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0" << endl <<
		"1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0" << endl <<
		"1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 1 1" << endl <<
		"0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"1 1 1 0 1 0 0 0 0 0 1 1 0 1 1 0 0 0 0 1 0" << endl <<
		"0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0" << endl <<
		"0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0" ;
	}
	else if (fileName == "Krackhardt_High-tech_managers_ReportsTo_relation.sm"){
		outText<< "0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1" << endl << 
		"0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; 
	}
	else if (fileName == "Padgett_Florentine_Families_Marital_relation.sm"){
		outText<< "0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0" << endl <<
		"0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0" << endl << 
		"0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0" << endl << 
		"0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 1" << endl << 
		"0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0" << endl << 
		"1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0" << endl << 
		"0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1" << endl << 
		"0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0" << endl << 
		"0 0 0 1 1 0 0 0 0 0 1 0 1 0 0 0" << endl << 
		"0 0 0 0 0 0 1 0 1 0 0 0 1 0 0 0" ; 
 	}
	else if (fileName == "Padgett_Florentine_Families_Business_relation.sm"){
                outText<< "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 1 1 0 0 1 0 1 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0" << endl << 
		"0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0" << endl << 
		"0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0" << endl << 
		"0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1" << endl << 
		"0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 1 1 1 0 0 1 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl << 
		"0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0"; 
 	}
	else if (fileName == "Zachary_Karate_Club_Simple_Ties.sm"){
		outText<< "0 1 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 0" << endl <<
		"1 0 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0" << endl <<
		"1 1 0 1 0 0 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0" << endl <<
		"1 1 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" << endl <<
		"1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 1" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 0" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1" << endl <<
		"0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 1" << endl <<
		"0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 1" << endl <<
		"0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1" << endl <<
		"1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 1 1" << endl <<
		"0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1" << endl <<
		"0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0" ;
	}
	else if (fileName == "Zachary_Karate_Club_Weighted_Ties.sm"){
		outText<< "0 4 5 3 3 3 3 2 2 0 2 3 1 3 0 0 0 2 0 2 0 2 0 0 0 0 0 0 0 0 0 2 0 0" << endl <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<< endl <<
		"0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 2" << endl <<
		"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0 4 0 0 0 0 0 4 2" << endl <<
		"0 2 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3" << endl <<
		"2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 7 0 0 2 0 0 0 4 4" << endl <<
		"0 0 2 0 0 0 0 0 3 0 0 0 0 0 3 3 0 0 1 0 3 0 2 5 0 0 0 0 0 4 3 4 0 5" << endl <<
		"0 0 0 0 0 0 0 0 4 2 0 0 0 3 2 4 0 0 2 1 1 0 3 4 0 0 2 4 2 2 3 4 5 0";
	}
		else if (fileName == "Galaskiewicz_CEOs_and_clubs_affiliation_network_data.2sm"){
		outText<< "0 0 1 1 0 0 0 0 1 0 0 0 0 0 0" << endl <<
		"0 0 1 0 1 0 1 0 0 0 0 0 0 0 0" << endl <<
		"0 0 1 0 0 0 0 0 0 0 0 1 0 0 0" << endl <<
		"0 1 1 0 0 0 0 0 0 0 0 0 0 0 1" << endl <<
		"0 0 1 0 0 0 0 0 0 0 0 0 1 1 0" << endl <<
		"0 1 1 0 0 0 0 0 0 0 0 0 0 1 0" << endl <<
		"0 0 1 1 0 0 0 0 0 1 1 0 0 0 0" << endl <<
		"0 0 0 1 0 0 1 0 0 1 0 0 0 0 0" << endl <<
		"1 0 0 1 0 0 0 1 0 1 0 0 0 0 0" << endl <<
		"0 0 1 0 0 0 0 0 1 0 0 0 0 0 0" << endl <<
		"0 1 1 0 0 0 0 0 1 0 0 0 0 0 0" << endl <<
		"0 0 0 1 0 0 1 0 0 0 0 0 0 0 0" << endl <<
		"0 0 1 1 1 0 0 0 1 0 0 0 0 0 0" << endl <<
		"0 1 1 1 0 0 0 0 0 0 1 1 1 0 1" << endl <<
		"0 1 1 0 0 1 0 0 0 0 0 0 1 0 1" << endl <<
		"0 1 1 0 0 1 0 1 0 0 0 0 0 1 0" << endl <<
		"0 1 1 0 1 0 0 0 0 0 1 1 0 0 1" << endl <<
		"0 0 0 1 0 0 0 0 1 0 0 1 1 0 1" << endl <<
		"1 0 1 1 0 0 1 0 1 0 0 0 0 0 0" << endl <<
		"0 1 1 1 0 0 0 0 0 0 1 0 0 0 1" << endl <<
		"0 0 1 1 0 0 0 1 0 0 0 0 0 0 0" << endl <<
		"0 0 1 0 0 0 0 1 0 0 0 0 0 0 1" << endl <<
		"0 1 1 0 0 1 0 0 0 0 0 0 0 0 1" << endl <<
		"1 0 1 1 0 1 0 0 0 0 0 0 0 0 1" << endl <<
		"0 1 1 0 0 0 0 0 0 0 0 0 1 0 0" << endl <<
		"0 1 1 0 0 0 0 0 0 0 0 1 0 0 0";
	}
	else if (fileName == "Bernard_Killworth_Fraternity_Symmetric_Observer_Data.sm"){
                /*
		  Bernard & Killworth  recorded the interactions among students living in a fraternity at a West Virginia college.
                  Subjects had been residents in the fraternity from 3 months to 3 years.
		  This matrix counts the number of times a pair of subjects were seen in conversation
                  by an "unobtrusive" observer (observation time: 21 hours a day, for five days).
                  */
		outText<< "0 0 2 1 0 0 2 0 0 0 1 1 2 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 2 1 1 1 0 2 1 2 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 1 4 1 1 " << endl <<
		"0 0 10 0 0 2 1 0 2 0 0 0 6 2 0 1 0 0 0 1 0 10 2 0 4 0 3 0 1 1 0 0 0 0 5 1 0 4 0 0 0 0 0 1 1 0 0 5 3 0 0 0 0 1 0 1 4 0" << endl <<
		"2 10 0 6 11 14 15 4 12 0 5 4 3 8 10 8 11 0 2 19 2 15 1 2 6 1 5 0 12 5 4 0 1 4 15 3 1 3 6 0 2 3 0 9 8 2 1 3 6 2 0 2 2 16 4 5 19 1" << endl <<
		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0 1 2 1 7 8 7 0 1 12 0 0 1 0 2 0 1 1 0 3 1 0 8 2 1 1 2 1 0 1 4 2 0 0 0 0 3 0 4 0 0 0 0 5 1 2 4 3 " << endl <<
		"1 1 16 1 2 9 5 5 4 1 4 2 4 0 6 4 7 0 0 17 1 2 4 0 1 1 2 0 7 2 4 0 1 4 12 0 1 6 2 2 1 1 0 2 4 0 0 2 4 1 0 0 5 0 5 3 10 0 " << endl <<
		"1 0 4 2 0 3 14 0 3 0 6 0 1 2 4 2 4 2 0 11 2 1 1 0 1 1 2 0 1 1 1 0 0 3 2 2 0 1 2 0 1 1 1 1 0 1 0 1 2 1 0 0 1 5 0 12 7 1 " << endl <<
		"4 1 5 2 0 2 16 2 2 0 6 7 0 1 9 0 0 1 3 9 4 1 2 2 1 1 4 0 2 6 1 0 1 4 3 10 1 1 1 0 5 0 0 2 0 2 2 0 2 1 0 0 2 3 12 0 12 0 " << endl <<
		"1 4 19 3 4 18 20 4 7 0 12 3 0 5 4 11 11 0 1 23 2 3 3 1 5 2 6 0 10 10 3 0 3 3 6 1 3 4 2 2 1 3 0 3 1 4 6 2 3 0 0 0 4 10 7 12 0 1 " << endl <<
		"1 0 1 5 0 2 4 2 1 0 0 3 0 1 0 3 0 1 2 5 1 0 1 1 0 0 2 0 1 2 2 1 0 6 2 1 0 2 0 0 2 1 0 0 0 1 1 0 1 3 0 0 3 0 1 0 1 0 ";

        }
	else if (fileName == "Bernard_Killworth_Fraternity_Non_Symmetric_Cognitive_Data.sm"){
		/*
		  Bernard & Killworth  recorded the interactions among students living in a fraternity at a West Virginia college.
		  Subjects had been residents in the fraternity from 3 months to 3 years.
		  This matrix depicts rankings made by the subjects themselves of how frequently they interacted with other subjects in the observation week.
		*/
		outText<< "0 3 2 4 2 3 2 5 2 3 3 2 2 3 2 3 2 5 3 3 3 2 2 4 2 3 4 3 2 5 4 5 3 4 2 5 2 2 2 2 3 2 2 3 2 4 3 4 4 5 2 2 2 2 2 3 2 3" << endl <<
		"3 0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 5 2 5 2 3 1 2 2 2 1 5 1 3 2 0 2 1 2 1 1 1 1" << endl <<
		"2 2 3 3 2 2 4 2 4 2 3 4 2 3 3 2 2 3 3 2 4 4 3 3 3 4 3 2 2 2 2 2 3 3 3 2 3 2 2 4 2 2 3 3 3 3 3 3 3 3 2 0 1 2 1 4 2 3" << endl <<
		"2 2 3 5 2 5 5 1 2 1 3 2 2 4 3 4 4 1 4 5 1 1 4 1 3 1 1 5 3 5 2 2 5 4 3 1 1 3 2 1 4 4 3 1 1 1 1 1 4 2 1 1 0 4 2 3 3 3" << endl <<
		"2 3 5 3 3 5 3 2 4 3 2 4 4 2 2 3 3 1 2 5 2 5 2 1 5 2 4 3 5 3 2 1 4 2 5 3 2 4 3 4 2 4 4 3 3 2 2 2 3 4 2 2 4 0 5 5 3 3" << endl <<
		"2 2 3 2 2 3 4 2 2 3 4 2 3 3 3 2 2 4 1 5 4 3 2 2 5 1 3 1 4 2 4 1 3 3 3 2 1 2 1 1 1 2 2 2 2 3 4 2 2 4 1 1 2 5 0 4 1 3" << endl <<
		"3 1 3 4 2 5 5 3 5 3 4 5 2 4 5 5 5 1 5 3 3 3 3 3 4 2 4 1 4 4 3 3 4 4 5 5 3 1 2 4 4 3 4 4 2 5 3 5 3 5 1 4 3 5 4 0 5 3" << endl <<
		"2 1 5 5 5 3 4 1 4 1 5 2 2 3 3 4 3 1 2 5 3 2 2 1 1 1 4 1 5 5 1 1 3 2 5 5 1 2 3 2 1 3 2 3 4 2 5 1 3 2 1 2 3 3 1 5 0 3" << endl <<
		"3 2 2 5 2 4 2 3 3 3 3 4 1 3 3 3 2 3 3 2 2 2 4 4 2 2 3 1 2 3 3 2 2 5 3 2 2 2 2 2 4 2 2 2 2 2 2 2 5 4 1 3 3 3 3 3 3 0";

	}
	else if (fileName == "Mexican_Power_Network_1940s.lst"){
	outText<< "18 8 10 23 21" << endl <<
		"19 11 21" << endl <<
		"29 5 9 10" << endl <<
		"23 8 9 18 11" << endl <<
		"4 7 6 8 20 5 21" << endl <<
		"5 4 29 20 7 6 8 9 26 21" << endl <<
		"6 5 7 4 20 21 8" << endl <<
		"7 4 6 5 8 20 21" << endl <<
		"9 5 8 23 29 20 21 11 10" << endl <<
		"8 18 23 4 5 6 7 21 24 26 25 9 10 37 20" << endl <<
		"10 18 29 8 11 9 20 25 26" << endl <<
		"11 19 23 9 10 25 21 36" << endl <<
		"20 4 5 6 7 8 9 10" << endl <<
		"24 8 26" << endl <<
		"26 5 8 24 10" << endl <<
		"21 19 4 5 6 7 8 9 11 18" << endl <<
		"36 37 11" << endl <<
		"37 8 36" << endl <<
		"25 10 11 8";
	}

        f.close();
}
	
	
	

/** 
	Returns the adjacency matrix of G
	This is called from saveGraphToAdjacency() using << operator of Matrix class
	The resulting matrix HAS spaces between elements.
*/
void Graph::writeAdjacencyMatrixTo(QTextStream& os){
	qDebug("Graph: adjacencyMatrix(), writing matrix with %i vertices", vertices());
	QList<Vertex*>::iterator it, it1;	
	float weight=-1;
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
                if ( ! (*it)->isEnabled() ) continue;
		for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){	
                        if ( ! (*it1)->isEnabled() ) continue;
			if ( (weight = this->hasEdge ( (*it)->name(), (*it1)->name() )  ) !=0 ) {
				os << static_cast<int> (weight) << " ";
			}
			else
				os << "0 ";
		}
 		os << endl;
	}
	graphModified=false;
}


		
/**  	Outputs adjacency matrix to a text stream
*	Used in slotExportSM() of MainWindow class.
*/
QTextStream& operator <<  (QTextStream& os, Graph& m){
	QList<Vertex*>::iterator it, it1;	
	float weight=-1;
	for (it=m.m_graph.begin(); it!=m.m_graph.end(); it++){
		for (it1=m.m_graph.begin(); it1!=m.m_graph.end(); it1++){	
			if ( (weight = m.hasEdge ( (*it)->name(), (*it1)->name() )  ) !=0 ) {
				os << static_cast<int> (weight) << " ";
			}
			else
				os << "0 ";
		}
 		os << endl;
	}
	return os;
}



/** 
	Writes the adjacency matrix of G to a specified file  
	This is called by MainWindow::slotViewAdjacencyMatrix()
	The resulting matrix HAS NO spaces between elements.
*/
void Graph::writeAdjacencyMatrix (const char* fn, const char* netName) {
	qDebug()<<"Graph::writeAdjacencyMatrix() ";
	ofstream file (fn);
	int sum=0;
	float weight=0;
	file << "-Social Network Visualizer- \n";
	file << "Adjacency matrix of "<< netName<<": \n\n";
	QList<Vertex*>::iterator it, it1;	
	for (it=m_graph.begin(); it!=m_graph.end(); it++){
                if ( ! (*it)->isEnabled() ) continue;
		for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){	
                        if ( ! (*it1)->isEnabled() ) continue;
			if ( (weight =  this->hasEdge ( (*it)->name(), (*it1)->name() )  )!=0 ) {
				sum++;
				if (weight >= 1)
					file << static_cast<int> (weight);
				else 
					file << "1";
			}
			else
				file << "0";
		}
 		file << endl;
	}

	qDebug("Graph: Found a total of %i edge",sum);
	if ( sum != totalEdges() ) qDebug ("Error in edge count found!!!");
	else qDebug("Edge count OK!");
	file.close();
}



void Graph::createAdjacencyMatrix(bool dropIsolates){
    qDebug() << "Graph::createAdjacencyMatrix()";
    float m_weight=-1;
    int i=0, j=0;
    bool isolatedNode=true;
    isolatedVertices = 0;
    AM.resize(m_totalVertices);

    QList<Vertex*>::iterator it, it1;
    QList<int> isolatesList;
    for (it=m_graph.begin(); it!=m_graph.end(); it++){
	    if ( ! (*it)->isEnabled() )
		continue;
	    j=0;
	    for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){
		    if ( ! (*it1)->isEnabled() )
			continue;
		    if ( (m_weight = this->hasEdge ( (*it)->name(), (*it1)->name() )  ) !=0 ) {
			    AM.setItem(i,j, m_weight );
			    isolatedNode=false;
		    }
		    else{
			    AM.setItem(i,j, 0);

		    }
		    qDebug()<<" AM("<< i+1 << ","<< j+1 << ") = " <<  AM.item(i,j);
		    j++;
	    }
	    if (isolatedNode){
		qDebug()<< "Graph::createAdjacencyMatrix() - node " << i+1 << " is isolated. Marking it." ;
		(*it1)->setIsolated(true);
		isolatesList << i;
	    }
	    i++;
    }
    if (dropIsolates){
	qDebug()<< "Graph::createAdjacencyMatrix() - Dropping all isolated nodes.";
	for (int k = 0; k < isolatesList.size(); ++k) {
	    AM.deleteRowColumn( isolatesList.at(k) );
	}
	isolatedVertices=isolatesList.size();
	qDebug() << "Graph::createAdjacencyMatrix() - Total isolates found: " << isolatedVertices;
    }
    qDebug() << "Graph::createAdjacencyMatrix() - Done.";
}


void Graph::invertAdjacencyMatrix(){
    qDebug() << "Graph::invertAdjacencyMatrix()";

    invAM.resize(m_totalVertices);

    qDebug()<<"Graph::invertAdjacencyMatrix() - first create the Adjacency Matrix AM";
    bool dropIsolates=false;
    createAdjacencyMatrix(dropIsolates);

    qDebug()<<"Graph::invertAdjacencyMatrix() - invert the Adjacency Matrix AM and store it to invAM";
    invAM.inverseByGaussJordanElimination(AM);


}



void Graph::writeInvertAdjacencyMatrix(const char* fn, const char* netName){
    qDebug("Graph::writeInvertAdjacencyMatrix() ");
    int i=0, j=0;
    QList<Vertex*>::iterator it, it1;
    ofstream file (fn);
    file << "-Social Network Visualizer- \n";
    file << "Invert Matrix of "<< netName<<": \n\n";
    invertAdjacencyMatrix();
    for (it=m_graph.begin(); it!=m_graph.end(); it++){
	    if ( ! (*it)->isEnabled() )
		continue;
	    j=0;
	    for (it1=m_graph.begin(); it1!=m_graph.end(); it1++){
		    if ( ! (*it1)->isEnabled() )
			continue;
		    file << invAM.item(i,j)<< " ";
		    qDebug() << invAM.item(i,j)<< " ";
		    j++;
	    }
	    i++;
	    file << endl;
	    qDebug() << endl;
    }
    file.close();
}


bool Graph::saveGraphToDotFormat (
			QString fileName, QString networkName, int maxWidth, int maxHeight)
{
	Q_UNUSED(fileName);
	Q_UNUSED(networkName);
	Q_UNUSED(maxWidth);
	Q_UNUSED(maxHeight);
	return true;
}



bool Graph::saveGraphToGraphMLFormat (
			QString fileName, QString networkName, int maxWidth, int maxHeight)
{
		qDebug () << " Graph::saveGraphToGraphMLFormat to file: " << fileName.toAscii();

	int weight=0, source=0, target=0, edgeCount=0, m_size=1, m_labelSize;
	QString m_color, m_labelColor, m_label;
	bool openToken;
	QFile f( fileName );
	if ( !f.open( QIODevice::WriteOnly ) )  {

		emit statusMessage( QString(tr("Could not write to %1")).arg(fileName) );
		return false;
	}
	QTextStream outText( &f );
	qDebug()<< "		... writing xml version";
	outText << "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"; 
	outText << " <!-- Created by SocNetV v."<<  VERSION << " --> \n" ;
	outText << "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" " 
		"      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance \" "  
		"      xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns " 
		"      http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">"
		"\n";
	
	qDebug()<< "		... writing keys ";
	
	outText <<	"  <key id=\"d0\" for=\"node\" attr.name=\"label\" attr.type=\"string\"> \n" 
				"    <default>" "</default> \n" 
				"  </key> \n";

	outText <<	"  <key id=\"d1\" for=\"node\" attr.name=\"x_coordinate\" attr.type=\"double\"> \n" 
				"    <default>" << "0.0" << "</default> \n" 
				"  </key> \n";

	outText <<	"  <key id=\"d2\" for=\"node\" attr.name=\"y_coordinate\" attr.type=\"double\"> \n" 
				"    <default>" << "0.0" << "</default> \n" 
				"  </key> \n";
	outText <<	"  <key id=\"d3\" for=\"node\" attr.name=\"size\" attr.type=\"double\"> \n" 
				"    <default>"<< initVertexSize << "</default> \n" 
				"  </key> \n";

	outText <<	"  <key id=\"d4\" for=\"node\" attr.name=\"color\" attr.type=\"string\"> \n" 
				"    <default>" << initVertexColor << "</default> \n" 
				"  </key> \n";
				
	outText <<	"  <key id=\"d5\" for=\"node\" attr.name=\"shape\" attr.type=\"string\"> \n" 
				"    <default>" << initVertexShape << "</default> \n" 
				"  </key> \n";
	outText <<	"  <key id=\"d6\" for=\"node\" attr.name=\"label.color\" attr.type=\"string\"> \n" 
				"    <default>" << initVertexLabelColor << "</default> \n" 
				"  </key> \n";
	outText <<	"  <key id=\"d7\" for=\"node\" attr.name=\"label.size\" attr.type=\"string\"> \n" 
				"    <default>" << initVertexLabelSize << "</default> \n" 
				"  </key> \n";
	outText <<	"  <key id=\"d8\" for=\"edge\" attr.name=\"weight\" attr.type=\"double\"> \n"
				"    <default>1.0</default> \n"
				"  </key> \n";
				
	outText <<	"  <key id=\"d9\" for=\"edge\" attr.name=\"color\" attr.type=\"string\"> \n"
				"    <default>" << initEdgeColor << "</default> \n"
				"  </key> \n";
	
	qDebug()<< "		... writing graph tag";
	if (networkName == "") 
		networkName = "G";
	if (m_undirected)
		outText << "  <graph id=\""<< networkName << "\" edgedefault=\"undirected\"> \n";
	else 
		outText << "  <graph id=\""<< networkName << "\" edgedefault=\"directed\"> \n";

	QList<Vertex*>::iterator it;
	QList<Vertex*>::iterator jt;
	
	qDebug()<< "		    writing nodes data";
	for (it=m_graph.begin(); it!=m_graph.end(); it++){ 
		if ( ! (*it)->isEnabled () )
			continue;
		qDebug() << " 	Node id: "<<  (*it)->name()  ;
		outText << "    <node id=\"" << (*it)->name() << "\"> \n";
		m_color = (*it)->color();
		m_size = (*it)->size() ;
		m_labelSize=(*it)->labelSize() ;
		m_labelColor=(*it)->labelColor() ;
		m_label=(*it)->label(); 

		if (m_label.contains('&') ){
			m_label=m_label.replace('&',"&amp;");
		}
		if (m_label.contains('<') ){
			m_label=m_label.replace('<',"&lt;");
		}
		if (m_label.contains('>') ){
			m_label=m_label.replace('>',"&gt;");
		}
		if (m_label.contains('\"') ){
			m_label=m_label.replace('\"',"&quot;");
		}
		if (m_label.contains('\'') ){
			m_label=m_label.replace('\'',"&apos;");
		}


		outText << "      <data key=\"d0\">" << m_label <<"</data>\n";

		qDebug()<<" 		... Coordinates x " << (*it)->x()<< " "<<maxWidth
										<<" y " << (*it)->y()<< " "<<maxHeight;

		outText << "      <data key=\"d1\">" << (*it)->x()/(maxWidth) <<"</data>\n";
		outText << "      <data key=\"d2\">" << (*it)->y()/(maxHeight) <<"</data>\n";
		
		if (  initVertexSize != m_size ) {
			outText << "      <data key=\"d3\">" << m_size  <<"</data>\n";
		}

		if (  QString::compare ( initVertexColor, m_color,  Qt::CaseInsensitive) != 0) {
			outText << "      <data key=\"d4\">" << m_color <<"</data>\n";
		}
		
		outText << "      <data key=\"d5\">" << (*it)->shape() <<"</data>\n";

		
		if (  QString::compare ( initVertexLabelColor, m_labelColor,  Qt::CaseInsensitive) != 0) {
			outText << "      <data key=\"d6\">" << m_labelColor <<"</data>\n";
		}
		
		if (  initVertexLabelSize != m_labelSize ) {
			outText << "      <data key=\"d7\">" << m_labelSize <<"</data>\n";
		}

		outText << "    </node>\n";

	}

	qDebug() << "		... writing edges data";
	edgeCount=0;
	for (it=m_graph.begin(); it!=m_graph.end(); it++)
	{ 
		for (jt=m_graph.begin(); jt!=m_graph.end(); jt++)
		{ 
			source=(*it)->name();
			target=(*jt)->name();

			if  ( 	(weight= this->hasEdge( source,target ) ) !=0 ) 
			{
				++edgeCount;
				m_color = (*it)->outLinkColor( target );
				qDebug()<< "				edge no "<< edgeCount 
						<< " from n1=" << source << " to n2=" << target
						<< " with weight " << weight 
						<< " and color " << m_color.toAscii() ;
				outText << "    <edge id=\""<< "e"+QString::number(edgeCount) 
						<< "\" directed=\"" << "true" << "\" source=\"" << source 
						<< "\" target=\"" << target << "\"";
					
				openToken = true;
				if (weight > 1) {
					outText << "> \n";
					outText << "      <data key=\"d8\">" << weight<<"</data>" <<" \n";
					openToken=false;
				}
				if (  QString::compare ( initEdgeColor, m_color,  Qt::CaseInsensitive) != 0) {
					if (openToken) 
						outText << "> \n";
					outText << "      <data key=\"d9\">" << m_color <<"</data>" <<" \n";	
					openToken=false;
				}
				if (openToken) 
					outText << "/> \n";
				else 				
					outText << "    </edge>\n";

			}

		}
	}
	outText << "  </graph>\n";
	outText << "</graphml>\n";

	f.close();
	QString fileNameNoPath=fileName.split("/").last();
	emit statusMessage( QString(tr( "File %1 saved" ) ).arg( fileNameNoPath ) );
	return true;
}





void Graph::setShowLabels(bool toggle){
	initShowLabels=toggle;

}

void Graph::setShowNumbersInsideNodes(bool toggle){
	initNumbersInsideNodes=toggle;

}





/** 
	This slot is activated when the user clicks on the relevant MainWindow checkbox (SpringEmbedder, Fruchterman) 
	to start or stop the movement of nodes, according to the requested model.
	PARAMETERS: 
	state: movement on/off toggle 
	type:  controls the type of layout model requested. Available options 
			1: Spring Embedder
			2: FruchtermanReingold
	cW, cH: control the current canvasWidth and canvasHeight
*/
void Graph::nodeMovement(int state, int type, int cW, int cH){
	qDebug()<< "Graph: startNodeMovement() - state " << state;
	canvasWidth = cW;
	canvasHeight = cH;
	int factor=100;		//factor controls speed. Decrease it to increase speed...
	if (state == Qt::Checked){
		qDebug()<< "Graph: startNodeMovement() - STARTING dynamicMovement" ;
		dynamicMovement = TRUE;
		layoutType=type;
		if (!timerId) {
			qDebug("Graph: startTimer()");
			timerId = startTimer(factor);		
		}
	}
	else {
		qDebug()<< "Graph: startNodeMovement() - STOPPING dynamicMovement" ;
		dynamicMovement = FALSE;
		killTimer(timerId);
		timerId = 0;
	}
}




/**	
	This method is automatically invoked when a QTimerEvent occurs
	It checks layoutType to call the appropriate method with the Force Directed Placement algorithm. 
*/
void Graph::timerEvent(QTimerEvent *event) {	
	qDebug("Graph: timerEvent()");
	Q_UNUSED(event);
		switch (layoutType){
			case 1: {
				layoutForceDirectedSpringEmbedder(dynamicMovement);
				break;
			}
			case 2: {
				layoutForceDirectedFruchtermanReingold(dynamicMovement);
				break;
			}
		}
	if (!graphModified) {
		qDebug("Timer will be KILLED since no vertex is movin any more...");
		killTimer(timerId);
		timerId = 0;
	}
}




/** 
	The Spring Embedder model (Eades, 1984), part of the Force Directed Placement (FDP) family, 
	assigns forces to all vertices and edges, as if nodes were electrically charged particles (Coulomb's law) 
	and all edges were springs (i.e. Hooke's law).

	These forces are applied to the nodes iteratively, pulling them closer together or pushing them further apart,
	until the system comes to an equilibrium state (node positions do not change anymore).

	Note that, following Eades, we do not need to have a faithful simulation; 
	we can -and we do- apply unrealistic forces in an unrealistic manner.
	For instance, instead of the forces described by Hooke's law, 
	we will assume weaker logarithmic forces between far apart vertices...   
*/

void Graph::layoutForceDirectedSpringEmbedder(bool dynamicMovement){
	qreal xvel = 0, yvel = 0, dx=0, dy=0, ulv_x=0, ulv_y=0;
	qreal c_rep=3, c_spring=3, dux=0, duy=0, natural_length=70;
	double dist = 0;
	QPointF curPos, newPos, pos ;
		
	if (dynamicMovement){
		qDebug () << "max dx "<< canvasWidth << "max dy "<< canvasHeight;
		foreach (Vertex *v1, m_graph)  {
			xvel=0; yvel=0;
			qDebug() << "****************  Calculate forces for vertex " << v1->name()
			<< " with index " <<  index[v1->name()] << " and pos "<< v1->x() << ", "<< v1->y();
			foreach (Vertex *v2, m_graph)  {
				qDebug () << " v2 = "<< v2->name() << " with pos (" <<  v2->x() << "," << v2->y() << ")";
				if (v2 == v1) {
					qDebug() << " v1==v2, continuing";
					continue;
				}   
				dx = v2->x() - v1->x();
				dy = v2->y() - v1->y();
				dist = sqrt (dx * dx + dy * dy); //the euclideian distance of the two vertices
				qDebug()<< "v1= " << v1->name() <<  " v2= " <<  v2->name() << " - euclideian distance = " << dist;

				if ( this->hasEdge (v1->name(), v2->name())  ) {  //calculate spring forces (pulling) force
					ulv_x =  + dx / dist;
					ulv_y =  + dy / dist;
					dux = (ulv_x * c_spring) * log ( dist / natural_length ); 	
					duy = (ulv_y * c_spring) * log ( dist / natural_length );
					xvel +=  dux;
					yvel +=  duy;
					qDebug() << " v1= "<<v1->name() <<  " connected to and pulled by v2= "<< v2->name()
									<<"  c_spring=" << c_spring <<"  nat_length =" << natural_length
									<<" ulv_x="<<ulv_x 	<<" ulv_y="<<ulv_y 	<<" dist= "<<dist 
									<< " dux="<< dux << " duy="<< duy; 
					qDebug() << " ========== New Total Velocity for "<<  v1->name() << "xvel, yvel  "<< xvel << ", "<< yvel; 
					continue;
				}
				else {
					//calculate electric (repulsive) forces between non-adjacent vertices.
					ulv_x = - dx / dist;
					ulv_y = - dy / dist;
					dux = (ulv_x * c_rep) / (dist * dist); 	
					duy = (ulv_y * c_rep) / ( dist * dist) ;
					qDebug() << " v1 = "<<v1->name() <<  " NOT connected to and pushed away from  v2 = "<< v2->name() 
							<<"  c_rep=" << c_rep
							<<" ulv_x="<<ulv_x 	<<" ulv_y="<<ulv_y 	<<" dist^2="<<dist * dist
							<< " dux=" << dux 	<< " duy=" << duy;
					xvel +=  dux ;
					yvel +=  duy;
					qDebug() << " ========== New Total Velocity for "<<  v1->name() << "xvel, yvel  "<< xvel << ", "<< yvel; 
				}
			}
			//Move node to new position
			newPos = QPointF(v1->x()+ xvel, v1->y()+yvel);
			qDebug("current x and y: %f, %f. Possible new pos is to new x new y = %f, %f", v1->x(), v1->y(),  newPos.x(), newPos.y());
			if (newPos.x() < 5.0  ||newPos.y() < 5.0   || newPos.x() >= (canvasWidth -5)||   newPos.y() >= (canvasHeight-5)|| (v1->x() == newPos.x() && v1->y() == newPos.y() )) continue;  
			qDebug("current x and y: %f, %f. This node will move to new x new y = %f, %f", v1->x(), v1->y(),  newPos.x(), newPos.y());
			emit moveNode((*v1).name(),  newPos.x(),  newPos.y());
		}
	
	}

}





/**
	Fruchterman and Reingold (1991) refined the Spring Embedder model by replacing the forces. 
	In this model, "the vertices behave as atomic particles or celestial bodies, 
	exerting attractive and repulsive forces on one another." (ibid). 
	Again, only vertices that are neighbours attract each other but, unlike Spring Embedder, 
	all vertices repel each other. 
	These forces induce movement. The algorithm might resemble molecular or planetary simulations, 
	sometimes called n-body problems. 
*/
void Graph::layoutForceDirectedFruchtermanReingold(bool dynamicMovement){
	qreal xvel = 0, yvel = 0, dx=0, dy=0, ulv_x=0, ulv_y=0;
	qreal c_rep=10, dux=0, duy=0, natural_length=100, temperature=2;
	double dist = 0;
	QPointF curPos, newPos, pos ;
		
	if (dynamicMovement){
		qDebug() << "Graph: layoutForceDirectedFruchtermanReingold() "
				<< "max dx "<< canvasWidth << "max dy "<< canvasHeight;
		natural_length= sqrt ( (canvasWidth - 10)* (canvasHeight-10) / vertices() );
		qDebug () << "Graph: Setting natural_length = "<<  natural_length
				<< "...following Fruchterman-Reingold (1991) formula ";
		foreach (Vertex *v1, m_graph)  {
			qDebug() << "*****  Calculate forces for vertex " << v1->name()
				<< " with index " <<  index[v1->name()] << " and pos "<< v1->x() << ", "<< v1->y();
			if ( ! v1->isEnabled() ) {
				qDebug() << "  vertex " << v1->name() << " not enabled. Continuing...";
				continue;
			}
			xvel=0; yvel=0;
			dux=0; duy=0;
			foreach (Vertex *v2, m_graph)  {
				if ( ! v2->isEnabled() ) continue;
				qDebug () << "  v2 = "<< v2->name() << " with pos (" <<  v2->x() << "," << v2->y() << ")";
				if (v2 == v1) {
					qDebug() << "  v1==v2, continuing";
					continue;
				}   
				dx = v2->x() - v1->x();
				dy = v2->y() - v1->y();
				dist = (dx * dx + dy * dy);
				dist = sqrt ( dist );	//the euclideian distance of the two vertices
				qDebug()<< "  v1= " << v1->name() <<  " v2= " <<  v2->name() << " - euclideian distance = " << dist;

				if ( this->hasEdge (v1->name(), v2->name())  ) {  //calculate spring (pulling) force
					ulv_x =  dx / dist;
					ulv_y =  dy / dist;
					dux = ( ulv_x ) * ( dist * dist ) / natural_length;
					duy = ( ulv_y ) * ( dist * dist ) / natural_length;
					//limit the maximum displacement to a maximum temperature  
					xvel = ( dux / abs (dux) ) *  qMin( abs(dux), temperature) ;
					yvel = ( duy / abs (duy) ) *  qMin( abs(duy), temperature) ;

					qDebug() << "  v1= "<<v1->name() <<  " connected to and pulled by v2= "<< v2->name()
									<<"  nat_length =" << natural_length
									<<" ulv_x="<<ulv_x 	<<" ulv_y="<<ulv_y 	<<" dist= "<<dist 
									<< " dux="<< dux << " duy="<< duy  
									<< " xvel="<< xvel <<" yvel="<< yvel;
					continue;
				}
				//calculate electric (repulsive) force between all vertices
				ulv_x = - dx / dist;
				ulv_y = - dy / dist;
				
				dux = (ulv_x * natural_length * natural_length ) / ( dist ); 	
				duy = (ulv_y * natural_length * natural_length ) / ( dist ) ;

				//limit the maximum displacement to a maximum temperature  
				xvel += ( dux / abs (dux) ) *  qMin( abs(dux), temperature) ;
				yvel += ( duy / abs (duy) ) *  qMin( abs(duy), temperature) ;

				qDebug() << "  v1 = "<<v1->name() <<  " NOT connected to and pushed away from  v2 = "<< v2->name()
						<<"  c_rep=" << c_rep
						<<" ulv_x="<<ulv_x 	<<" ulv_y="<<ulv_y 	<<" dist^2="<<dist * dist
						<< " dux=" << dux 	<< " duy=" << duy
						<< " xvel="<< xvel <<" yvel="<< yvel;
				
			}
			//Move node to new position
			newPos = QPointF(v1->x()+ xvel, v1->y()+yvel);
			qDebug(">>>  current x and y: %f, %f. Possible new pos is to new x new y = %f, %f", v1->x(), v1->y(),  newPos.x(), newPos.y());
			if (newPos.x() < 5.0  ||newPos.y() < 5.0   || newPos.x() >= (canvasWidth -5)||   newPos.y() >= (canvasHeight-5)|| (v1->x() == newPos.x() && v1->y() == newPos.y() )) continue;  
			qDebug(">>> current x and y: %f, %f. This node will move to new x new y = %f, %f", v1->x(), v1->y(),  newPos.x(), newPos.y());
			emit moveNode((*v1).name(),  newPos.x(),  newPos.y());
		}
	
	}

}



Graph::~Graph() {
 	clear();
	index.clear();
}