File: Graphs.m2

package info (click to toggle)
macaulay2 1.24.11%2Bds-5
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 171,648 kB
  • sloc: cpp: 107,850; ansic: 16,307; javascript: 4,188; makefile: 3,947; lisp: 682; yacc: 604; sh: 476; xml: 177; perl: 114; lex: 65; python: 33
file content (5532 lines) | stat: -rw-r--r-- 168,741 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
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
 -*
Copyright 2010 Amelia Taylor and Augustine O'Keefe.
You may redistribute this file under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 2 of
the License, or any later version.


Copyright 2014: Jack Burkart, David Cook II, Caroline Jansen
You may redistribute this file under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 2
of the License, or any later version.
*-
------------------------------------------
------------------------------------------
-- To Do List
------------------------------------------
------------------------------------------
-- Add more documentation
-- Add tests

------------------------------------------
------------------------------------------
-- Header
------------------------------------------
------------------------------------------

newPackage (
    "Graphs",
        Version => "0.3.4",
        Date => "May 15, 2021",
        Authors => {
            {Name => "Jack Burkart", Email => "jburkar1@nd.edu"},
            {Name => "David Cook II", Email => "dcook.math@gmail.com", HomePage => "http://ux1.eiu.edu/~dwcook/"},
            {Name => "Caroline Jansen", Email => "cjansen@alumni.nd.edu"},
            {Name => "Amelia Taylor", Email => "originalbrickhouse@gmail.com"},
            {Name => "Augustine O'Keefe", Email => "aokeefe@tulane.edu"}
        },
        Headline => "graphs and directed graphs (digraphs)",
	Keywords => {"Graph Theory"},
        Configuration => {
            "DotBinary" => "dot"
            },
	PackageImports => { "PrimaryDecomposition" },
        PackageExports => {
            "SimplicialComplexes"
            },
        DebuggingMode => false
        )

-- Load configurations
graphs'DotBinary = if instance((options Graphs).Configuration#"DotBinary", String) then (options Graphs).Configuration#"DotBinary" else "dot";

-- Exports
export {
    --
    -- Data type & constructor
    "Digraph",
    "Graph",
    "digraph",
    "graph",
        "EntryMode",
        "Singletons",
    --
    -- Basic data
    "adjacencyMatrix",
    "degreeMatrix",
    "degreeSequence",
    "edges",
    "incidenceMatrix",
    "laplacianMatrix",
    "simpleGraph",
    "vertexSet",
  --"vertices",
    --
    -- Display Methods
    "displayGraph",
    "showTikZ",
    "writeDotFile",
    --
    -- Derivative graphs
    "barycenter",
    "complementGraph",
    "digraphTranspose",
    "lineGraph",
    "underlyingGraph",
    --
    -- Enumerators
    "barbellGraph",
    "circularLadder",
    "cocktailParty",
    "completeGraph",
    "completeMultipartiteGraph",
    "crownGraph",
    "cycleGraph",
    "doubleStar",
    "friendshipGraph",
    "generalizedPetersenGraph",
    "graphLibrary",
    "kneserGraph",
    "ladderGraph",
    "lollipopGraph",
    "monomialGraph",
    "pathGraph",
    "prismGraph",
    "rattleGraph",
    "starGraph",
    "thresholdGraph",
    "wheelGraph",
    "windmillGraph",
    --
    -- Cut properties
    "edgeConnectivity",
    "edgeCuts",
    "minimalVertexCuts",
    "vertexConnectivity",
    "vertexCuts",
    --
    -- Properties
    "breadthFirstSearch",
        "discoveryTime",
        "finishingTime",
    "BFS",
    "center",
    "children",
    "chromaticNumber",
    "cliqueComplex",
    "cliqueNumber",
    "closedNeighborhood",
    "clusteringCoefficient",
    "coverIdeal",
    "criticalEdges",
    "degeneracy",
    "degreeCentrality",
    "degreeIn",
    "degreeOut",
    "density",
    "depthFirstSearch",
    "DFS",
    "descendants",
    "descendents",
    "distance",
    "distanceMatrix",
    "eccentricity",
    "edgeIdeal",
    "expansion",
    "findPaths",
    "floydWarshall",
    "forefathers",
    "foreFathers",
    "girth",
    "independenceComplex",
    "independenceNumber",
    "leaves",
    "lowestCommonAncestors",
    "minimalDegree",
    "neighbors",
    "nondescendants",
    "nondescendents",
    "nonneighbors",
    "numberOfComponents",
    "numberOfTriangles",
    "parents",
    "radius",
    "reachable",
    "reverseBreadthFirstSearch",
    "sinks",
    "sources",
    "spectrum",
    "vertexCoverNumber",
    "vertexCovers",
    --
    -- Boolean properties
    "hasEulerianTrail",
    "hasOddHole",
    "isBipartite",
    "isCM",
    "isChordal",
    "isConnected",
    "isCyclic",
    "isEulerian",
    "isForest",
    "isLeaf",
    "isPerfect",
    "isReachable",
    "isRegular",
    "isRigid",
    "isSimple",
    "isSink",
    "isSource",
    "isStronglyConnected",
    "isTree",
    "isWeaklyConnected",
    --
    -- Graph operations
    "cartesianProduct",
    "disjointUnion",
    "graphComposition",
    "graphPower",
    "lexicographicProduct",
    "strongProduct",
    "tensorProduct",
    --
    -- Graph manipulations
    "addEdge",
    "addEdges'",
    "addVertex",
    "addVertices",
    "bipartiteColoring",
    "deleteEdges",
    "deleteVertex",
    "deleteVertices",
    "indexLabelGraph",
    "inducedSubgraph",
    "reindexBy",
    "removeNodes",
    "spanningForest",
    "vertexMultiplication",
    
      -- "LabeledGraph",
    --"labeledGraph",
     "topologicalSort",
    "topSort",
    "SortedDigraph",
    "newDigraph"
    }

------------------------------------------
------------------------------------------
-- Methods
------------------------------------------
------------------------------------------

------------------------------------------
-- Non-exported functions
------------------------------------------

runcmd := cmd -> (
     stderr << "-- running: " << cmd << endl;
     r := run cmd;
     if r != 0 then error("-- command failed, error return code ", r);
     )

------------------------------------------
-- Data type & constructor
------------------------------------------
Digraph = new Type of HashTable
Graph = new Type of Digraph

Digraph.synonym = "digraph"
Graph.synonym = "graph"

digraph = method(Options => {symbol Singletons => null, symbol EntryMode => "auto"})
digraph List := Digraph => opts -> L -> (
    mode := if #L == 0 or opts.EntryMode == "edges" then "e" 
        else if opts.EntryMode == "neighbors" then "n"
        else if opts.EntryMode == "auto" then (if all(#L, i -> instance(L_i_1, List)) then "n" else "e")
        else error "EntryMode must be 'auto', 'edges', or 'neighbors'.";
    if mode == "e" then digraph(unique flatten (toList \ L), L, Singletons => opts.Singletons, EntryMode => "edges")
    else digraph(hashTable apply(L, x -> x_0 => toList(x_1)), Singletons => opts.Singletons, EntryMode => "neighbors")
    )
digraph HashTable := Digraph => opts -> g -> digraph(unique join(keys g, flatten (toList \ values g)), flatten apply(keys g, v -> apply(toList g#v, u -> {v, u})), Singletons => opts.Singletons, EntryMode => "edges")
digraph (List, List) := Digraph => opts -> (V, L) -> (
    mode := if #L == 0 or opts.EntryMode == "edges" then "e" 
        else if opts.EntryMode == "neighbors" then "n"
        else if opts.EntryMode == "auto" then (if all(#L, i -> instance(L_i_1, List)) then "n" else "e")
        else error "EntryMode must be 'auto', 'edges', or 'neighbors'.";
    E := if mode == "e" then toList \ L else flatten apply(L, N -> apply(N_1, v -> {N_0, v}));
    if not isSubset(flatten E, V) then error "There are edges with vertices outside the vertex set.";
    V = unique join(V, if instance(opts.Singletons, List) then opts.Singletons else {});
    A := if #V == 0 then map(ZZ^0, ZZ^0, 0) else matrix apply(#V, i -> apply(#V, j -> if member({V#i, V#j}, E) then 1 else 0));
    digraph(V, A)
    )
digraph (List, Matrix) := Digraph => opts -> (V, A) -> (
    if ( sort unique join( {0,1}, flatten entries A) != {0,1} ) then error "The given matrix is not an adjacency matrix.";
    if #V != numrows A or numrows A != numcols A then error "The given vertex set and matrix are incompatible.";
    V' := if instance(opts.Singletons, List) then opts.Singletons - set V else {};
    A' := matrix {{A, map(ZZ^(#V), ZZ^(#V'), 0)}, {map(ZZ^(#V'), ZZ^(#V), 0), 0}};
    new Digraph from {
        symbol vertexSet => join(V, V'),
        symbol adjacencyMatrix => A',
        symbol cache => new CacheTable from {}}
    )
digraph Matrix := Digraph => opts -> A -> digraph(toList(0..<numRows A), A, opts)

graph = method(Options => {symbol Singletons => null, symbol EntryMode => "auto"})
graph (List, List) := Graph => opts -> (V, L) -> (
    mode := if #L == 0 or opts.EntryMode == "edges" then "e" 
        else if opts.EntryMode == "neighbors" then "n"
        else if opts.EntryMode == "auto" then (if all(#L, i -> instance(L_i_1, List)) then "n" else "e")
        else error "EntryMode must be 'auto', 'edges', or 'neighbors'.";
    E := if mode == "e" then toList \ L else flatten apply(L, N -> apply(N_1, v -> {N_0, v}));
    if not isSubset(flatten E, V) then error "There are edges with vertices outside the vertex set.";
    V = unique join(V, if instance(opts.Singletons, List) then opts.Singletons else {});
    A := if #V == 0 then map(ZZ^0, ZZ^0, 0) else matrix apply(#V, i -> apply(#V, j -> if member({V#i, V#j}, E) or member({V#j, V#i}, E) then 1 else 0));
    graph(V, A)
    )
graph List := Graph => opts -> L -> (
    mode := if #L == 0 or opts.EntryMode == "edges" then "e" 
        else if opts.EntryMode == "neighbors" then "n"
        else if opts.EntryMode == "auto" then (if all(#L, i -> instance(L_i_1, List)) then "n" else "e")
        else error "EntryMode must be 'auto', 'edges', or 'neighbors'.";
    if mode == "e" then graph(unique flatten (toList \ L), L, Singletons => opts.Singletons, EntryMode => "edges")
    else graph(hashTable apply(L, x -> x_0 => toList(x_1)), Singletons => opts.Singletons, EntryMode => "neighbors")
    )
graph HashTable := Graph => opts -> g -> graph(unique join(keys g, flatten (toList \ values g)), flatten apply(keys g, v -> apply(toList g#v, u -> {v, u})), Singletons => opts.Singletons, EntryMode => "edges")
graph (List, Matrix) := Graph => opts -> (V,A) -> (
    if ( sort unique join( {0,1}, flatten entries A) != {0,1} ) then error "The given matrix is not an adjacency matrix.";
    if #V != numrows A or numrows A != numcols A then error "The given vertex set and matrix are incompatible.";
    V' := if instance(opts.Singletons, List) then opts.Singletons - set V else {};
    A' := matrix {{A, map(ZZ^(#V), ZZ^(#V'), 0)}, {map(ZZ^(#V'), ZZ^(#V), 0), 0}};
    new Graph from {
        symbol vertexSet => join(V, V'),
        symbol adjacencyMatrix => A',
        symbol cache => new CacheTable from {}}
        )
graph Matrix := Graph => opts -> A -> graph(toList(0..<numrows A), A)

graph Digraph := HashTable => opts -> D -> (
    V := vertexSet D;
    A := adjacencyMatrix D;
    hashTable apply(#V, i -> V_i => V_(positions(first entries A^{i}, j -> j != 0)))
    )

Digraph _ ZZ := Thing => (D, i) -> D.vertexSet#i
Digraph _ List := List => (D, L) -> D.vertexSet_L
installMethod(symbol _*, Digraph, D -> D.vertexSet)

net Digraph := Net => G -> (
    V := vertexSet G;
    A := adjacencyMatrix G;
    H := hashTable apply(#V, i -> V_i => V_(positions(first entries A^{i}, j -> j != 0)));
    horizontalJoin flatten (
        net class G,
        "{",
        stack (horizontalJoin \ sort apply(pairs H, (k,v) -> (net k, " => ", net v))),
        "}"
    ))

toString Digraph := String => D -> (
       concatenate( -- issue #1473 in github
 --   horizontalJoin(
        toLower toString class D, 
        " (",
        toString vertexSet D,
        ", ",
        toString (toList \ edges D),
        ")"
        )
    )

------------------------------------------
-- Basic data
------------------------------------------

adjacencyMatrix = method()
adjacencyMatrix Digraph := Matrix => D -> D.adjacencyMatrix

degree (Graph,Thing) := ZZ => (G,v) -> #neighbors(G,v)
degree (Digraph,Thing) := ZZ => (D,v) -> #(children(D,v) + parents(D,v))

degreeMatrix = method()
degreeMatrix Digraph := Matrix => G -> diagonalMatrix apply(entries transpose adjacencyMatrix G, a -> #positions(a, j -> j != 0))

degreeSequence = method()
degreeSequence Graph := List => G -> rsort \\ sum \ entries adjacencyMatrix G

edges = method()
edges Digraph := List => D -> (
    V := vertexSet D;
    A := adjacencyMatrix D;
    flatten for i from 0 to #V - 1 list for j from 0 to #V - 1 list if A_(i,j) == 1 then {V#i, V#j} else continue
    )
edges Graph := List => G -> (
    V := vertexSet G;
    A := adjacencyMatrix G;
    flatten for i from 0 to #V - 1 list for j from i+1 to #V - 1 list if A_(i,j) == 1 or A_(j,i) == 1 then set {V#i, V#j} else continue
    )

incidenceMatrix = method()
incidenceMatrix Graph := Matrix => G -> matrix apply(vertexSet G, v -> apply(edges G, e -> if member(v, e) then 1 else 0))

laplacianMatrix = method()
laplacianMatrix Graph := Matrix => G -> degreeMatrix G - adjacencyMatrix G

simpleGraph = underlyingGraph

vertexSet = method()
vertexSet Digraph := List => D -> D#(symbol vertexSet)
vertices Digraph := List => D -> D#(symbol vertexSet)

-------------------------------------------
-- Display Methods
-------------------------------------------

displayGraph = method()
displayGraph (String, String, Digraph) := (dotfilename, jpgfilename, G) -> (
     writeDotFile(dotfilename, G);
     runcmd(graphs'DotBinary  | " -Tjpg " | dotfilename | " -o " | jpgfilename);
     show URL("file://" | toAbsolutePath jpgfilename);
     )
displayGraph (String, Digraph) := (dotfilename, G) -> (
     jpgfilename := temporaryFileName() | ".jpg";
     displayGraph(dotfilename, jpgfilename, G);
     )
displayGraph Digraph := G -> (
     dotfilename := temporaryFileName() | ".dot";
     displayGraph(dotfilename, G);
     )

showTikZ = method(Options => {Options=>"-t math --prog=dot -f tikz --figonly"})
showTikZ Digraph := opt -> G -> (
     dotfilename := temporaryFileName() | ".dot";
     writeDotFile(dotfilename, G);
     output := temporaryFileName();
     runcmd("dot2tex "|opt#Options|" "|dotfilename|" >> "|output);
     get output
     )

html Digraph := G -> if G.cache#?"svg" then G.cache#"svg" else (
     dotfilename := temporaryFileName() | ".dot";
     writeDotFile(dotfilename, G);
     svgfilename := temporaryFileName() | ".svg";
     runcmd(graphs'DotBinary  | " -Tsvg " | dotfilename | " -o " | svgfilename);
     G.cache#"svg" = get svgfilename
     )

writeDotFile = method()
writeDotFile (String, Graph) := (filename, G) ->
    writeDotFileHelper(filename, G, "graph", "--")
writeDotFile (String, Digraph) := (filename, G) ->
    writeDotFileHelper(filename, G, "digraph", "->")

writeDotFileHelper = (filename, G, type, op) -> (
    fil := openOut filename;
    fil << type << " G {" << endl;
    V := vertexSet G;
    I := hashTable apply(#V, i -> V_i => i);
    scan(V, v -> fil << "\t" << I#v << " [label=\"" << toString v << "\"];" << endl);
    E := toList \ edges G;
    scan(E, e -> fil << "\t" << I#(e_0) << " " << op << " " << I#(e_1) << ";"
	<< endl);
    fil << "}" << endl << close;
    )

------------------------------------------
-- Derivative graphs
------------------------------------------
barycenter = method()
barycenter Graph := Graph => G -> inducedSubgraph(G, center G)

complementGraph = method()
complementGraph Graph := Graph => G -> graph(vertexSet G, subsets(vertexSet G, 2) - set(join(toList \ edges G, reverse@@toList \ edges G)), EntryMode => "edges")

digraphTranspose = method()
digraphTranspose Digraph := Digraph => D -> digraph(vertexSet D, reverse \ edges D, EntryMode => "edges")


lineGraph = method()
lineGraph Graph := Graph => (G) -> (
   E:=edges(G);
   if #E==0 then return graph({});
   EE:={};
   for e in E do (
      for f in E do (
         if not e===f then (
            if #(e*f)>0 then (
               EE=EE|{{e,f}};
               ); 
            );   
         ); 
      );
   --non-singletons
   nS:=unique flatten EE;
   --singletons
   S:=for e in E list if member(e,nS)===false then e else continue;
   return graph(EE,Singletons=>S);
)


underlyingGraph = method()
underlyingGraph Digraph := Graph => D -> graph(vertexSet D, edges D, EntryMode => "edges")

------------------------------------------
-- Enumerators
------------------------------------------

barbellGraph = method()
barbellGraph ZZ := Graph => n -> (
    V := toList(0..<2*n);
    E := select(flatten flatten apply(toList(0..<n), i -> apply(toList(0..<n), j -> {{i,j},{i+n,j+n}})), e -> e_0 != e_1) | {{n-1,n}};
    graph(V,E, EntryMode => "edges")
    )

circularLadder = method()
circularLadder ZZ := Graph => n -> generalizedPetersenGraph (n,1)

cocktailParty = method()
cocktailParty ZZ := Graph => n -> (
    V := toList(0..<2*n);
    E := subsets(2*n,2) - set apply(toList(0..<n), i -> {i, i+n});
    graph(V,E, EntryMode => "edges")
    )

completeGraph = method()
completeGraph ZZ := Graph => n -> graph(toList(0..<n), subsets(n, 2), EntryMode => "edges")

completeMultipartiteGraph = method()
completeMultipartiteGraph List := Graph => P -> (
    if #P == 1 then return graph(toList(0..<P_0), {});
    offset := 0;
    V := apply(sort P, p -> ( ret := toList(offset..(offset+p-1)); offset = offset + p; ret ));
    graph (flatten apply(#V-1, i -> flatten toList apply(i+1..#V-1, j -> toList \ toList((set V_i) ** (set V_j)))), EntryMode => "edges")
    )

crownGraph = method()
crownGraph ZZ := Graph => n -> (
    V := toList(0..<2*n);
    E := select(flatten apply(toList(0..<n), i -> apply(toList(0..<n), j -> {i, j+n})), e -> e_0 + n != e_1);
    graph (V,E, EntryMode => "edges")
    )

cycleGraph = method()
cycleGraph ZZ := Graph => n -> graph(toList(0..<n), prepend({0,n-1}, apply(n-1, i -> {i, i+1})), EntryMode => "edges")

doubleStar = method()
doubleStar (ZZ,ZZ) := Graph => (m,n) -> (
    V := toList(0..m+n+1);
    E := apply(toList(1..n), i -> {0,i}) | apply(toList(n+2..m+n+1), i -> {n+1, i}) | {{0, n+1}};
    graph (V,E, EntryMode => "edges")
)

friendshipGraph = method()
friendshipGraph ZZ := Graph => n -> windmillGraph(3, n)

generalizedPetersenGraph = method()
generalizedPetersenGraph (ZZ, ZZ) := Graph => (n, k) -> (
    V := toList (0..2*n-1);
    E := flatten apply(n, l -> {{l,(l+1) % n}, {l,l+n}, {l+n,n + ((l+k) % n)}});
    graph(V, E, EntryMode => "edges")
    )

graphLibrary = method()
graphLibrary String := Graph => s -> (
    s = toLower s;
    if s == "petersen" then return generalizedPetersenGraph(5,2);
    if s == "bidiakis cube" then return addEdges'(cycleGraph 12, {{0,6},{1,5},{7,11},{2,10},{3,9},{4,8}});
    if s == "desargues" then return generalizedPetersenGraph(10,3);
    if s == "dodecahedron" then return generalizedPetersenGraph(10,2);
    if s == "durer" then return generalizedPetersenGraph(6,2);
    if s == "claw" then return starGraph 4;
    if s == "cubical" then return circularLadder 4;
    if s == "f26a" then return addEdges'(cycleGraph 26, apply(select(toList(0..24),even), i -> {i,(i+7) % 26}));
    if s == "franklin" then return addEdges'(cycleGraph 12, apply(toList(0..5), i -> if even i then {i, i+7} else {i, i+5}));
    if s == "chvatal" then return addEdges'(cycleGraph 12, apply({0,1,2,5}, i -> {i,i+6}) | apply({0,1,2,6,7,8}, i -> {i,i+3}) | {{3,10},{4,9}});
    if s == "heawood" then return addEdges'(cycleGraph 14, apply(select(toList(0..12),even), i -> {i, i+5 % 14}));
    if s == "paw" then return addEdge(starGraph 4, set {2,3});
    if s == "mobius" then return generalizedPetersenGraph (8,3);
    if s == "nauru" then return generalizedPetersenGraph (12,5);
    if s == "kite" then return addEdge(cycleGraph 4, set {0,2});
    if s == "house" then return addEdge(cycleGraph 5; set {1,3});
    if s == "bull" then return addEdge(pathGraph 5, set {1,3});
    if s == "bowtie" then return friendshipGraph 2;
    if s == "dart" then return addEdges'(addVertex(cycleGraph 4, 4),{{0,2},{2,4}});
    )

kneserGraph = method()
kneserGraph (ZZ,ZZ) := Graph => (n,k) -> (
    S := subsets(n,k);
    L := for i from 0 to (#S-1) list
        for j from i+1 to (#S-1) list
            if #((set S_i)*(set S_j)) == 0 then {i,j} else continue;
    graph(toList(0..<#S), flatten L, EntryMode => "edges")
    )

ladderGraph = method()
ladderGraph ZZ := Graph => n -> (
    A := adjacencyMatrix pathGraph n;
    B := map(ZZ^n, ZZ^n, 1);
    C := matrix {{A, B}, {transpose B, A}};
    graph C
    )

lollipopGraph = method()
lollipopGraph (ZZ, ZZ) := Graph => (m,n) -> (
    V := toList (0..n+m-1);
    E := subsets(m,2) | apply(toList(m-1..m+n-2), i -> {i, i+1});
    graph(V,E, EntryMode => "edges")
    )

monomialGraph = method()
monomialGraph (MonomialIdeal, ZZ) := Graph => (I, d) -> (
    V := first entries lift(basis(d, quotient I),ring I);
    E := {};
    for v in V do(
        L := select(V, i -> first degree lcm (v,i) == d+1);
        E = E | apply(L, i -> {v,i});
        );
    E = unique E;
    graph(V,E, EntryMode => "edges")
    )

pathGraph = method()
pathGraph ZZ := Graph => n -> graph (apply(n-1, i -> {i, i+1}), EntryMode => "edges")

prismGraph = circularLadder

rattleGraph = method()
rattleGraph (ZZ, ZZ) := Graph => (m,n) -> (
    V := toList (0..n+m-1);
    E := apply(toList(0..m-2), i -> {i,i+1}) | {{0,m-1}} | apply(toList(m-1..m+n-2), i -> {i, i+1});
    graph(V,E, EntryMode => "edges")
    )

starGraph = method()
starGraph ZZ := Graph => n -> windmillGraph(2, n)

thresholdGraph = method()
thresholdGraph List := Graph => L ->(
    n := #L+1;
    P := positions(L, i -> i == 1); -- assumes other positions are 0
    E := if P === null then {} else flatten apply(P, i -> apply(i+1, j -> (j, i+1)));
    graph(toList(0..<n), E, EntryMode => "edges")
    )

wheelGraph = method()
wheelGraph ZZ := Graph => n -> (
    spokes := apply(toList(1..n-1), i -> {0,i});
    outside := apply(toList(1..n-2), i -> {i,i+1}) | {{1,n-1}};
    graph(toList(0..<n), join(spokes,outside), EntryMode => "edges")
    )

windmillGraph = method()
windmillGraph (ZZ,ZZ) := Graph => (k,d) -> (
    E := apply(subsets(k, 2), s -> (
        apply(d, i -> (
            apply(s, j -> if j != 0 then j + i*(k-1) else 0)
            ))
        ));
    graph(flatten E, EntryMode => "edges")
    )

------------------------------------------
-- Cut properties
------------------------------------------

edgeConnectivity = method()
edgeConnectivity Graph := ZZ => G -> #first edgeCuts G

edgeCuts = method()
edgeCuts Graph := List => G -> (
    if #edges G == 0 then return {{}};
    E := toList \ edges G;
    EC := {};
    for i from 0 to #E - 1 do (
        possibleSubsets := subsets(E, i);
        EC = for x in possibleSubsets list (
            G' := deleteEdges(G,x);
            if not isConnected G' then x else continue
            );
        if #EC != 0 then break;
        );
    EC
    )

minimalVertexCuts = method()
minimalVertexCuts Graph := List => G -> (
    V := vertexSet G;
    VC := {};
    for i from 0 to #V-1 do (
        possibleSubsets := subsets(V,i);
        VC = for x in possibleSubsets list (
            if not isConnected deleteVertices(G, x) then x else continue
            );
        if #VC != 0 then break;
        );
    VC
)

minimalDegree = method()
minimalDegree Graph := ZZ => G -> (
   return min for v in vertexSet(G) list degree(G,v);
)

vertexConnectivity = method()
--returns n-1 for K_n as suggested by West
vertexConnectivity Graph := ZZ => G -> (
if #(vertexSet G)==0 then return 0;
if cliqueNumber G == #(vertexSet G) then (
    return #(vertexSet G) - 1;
    ) else (
    return #(first minimalVertexCuts G);
    );
)

vertexCuts = method()
--West does not specify, but Wikipedia does, that K_n has no vertex cuts.  
--The method currently returns an empty list, which is technically correct.
vertexCuts Graph := List => G -> (
    V := vertexSet G;
    possibleSubsets := drop(subsets V, -1);
    for x in possibleSubsets list (
        G' := deleteVertices(G,x);
        if not isConnected G' then x else continue
        )
    )

------------------------------------------
-- Properties
------------------------------------------

breadthFirstSearch = method()
breadthFirstSearch (Digraph, Thing) := List => (G, v) -> (
    V := vertexSet G;
    if not member(v, V) then error "";
    Q := {{v, 0}};
    V = V - set {v};
    i := 0;
    while i < #Q do (
        C := select(toList children(G, first Q_i), u -> member(u, V));
        Q = Q | apply(C, c -> {c, last Q_i + 1});
        V = V - set C;
        i = i + 1;
        );
    P := partition(last, Q);
    apply(sort keys P, k -> first \ P#k)
    )

BFS = breadthFirstSearch

center = method()
center Graph := List => G -> select(vertexSet G, i -> eccentricity(G, i) == radius G)

children = method()
children (Digraph, Thing) := Set => (G, v) -> (
    i := position(vertexSet G, u -> u === v);
    if i === null then error "v is not a vertex of G.";
    set (vertexSet G)_(positions(first entries (adjacencyMatrix G)^{i}, j -> j != 0))
    )


chromaticNumber = method()
chromaticNumber Graph := ZZ => G -> (
    if #edges G == 0 and #vertexSet G == 0 then 0
    else if #edges G == 0 and #vertexSet G != 0 then 1
    else if isBipartite G then 2
    else (
        chi := 3;
        J := coverIdeal G;
        m := product gens ring J;
        while ((m^(chi - 1) % J^chi) != 0) do chi = chi+ 1;
        chi
        )
    )

cliqueComplex = method()
cliqueComplex Graph := SimplicialComplex => G -> simplicialComplex edgeIdeal complementGraph G

cliqueNumber = method()
cliqueNumber Graph := ZZ => G -> independenceNumber complementGraph G

closedNeighborhood = method()
closedNeighborhood (Graph, Thing) := Set => (G,a) -> neighbors(G,a) + set {a}

clusteringCoefficient = method()
clusteringCoefficient Graph := QQ => G -> (
    Cv := for v in vertexSet G list clusteringCoefficient(G,v);
    sum Cv / #Cv
    )
clusteringCoefficient (Graph, Thing) := QQ => (G,v) -> (
    N := toList neighbors(G,v);
    if #N == 0 or #N == 1 then return 0;
    G' := inducedSubgraph(G, N);
    2 * #edges G' / (#N * (#N - 1))
    )

-- the 'conneectedComponents' methods is defined in 'SimplicialComplexies'
connectedComponents Graph := List => G -> (
    V := vertexSet G;
    while #V != 0 list (
        C := {first V};
        i := 0;
        while i!= #C do (
            N := toList neighbors(G, C_i);
            C = unique(C | N);
            V = V - set C;
            i = i + 1;
            if #V == 0 then break;
            );
        C
        )
    )

coverIdeal = method()
coverIdeal Graph := Ideal => G -> dual edgeIdeal G

criticalEdges = method()
criticalEdges Graph := List => G -> (
    J := edgeIdeal G;
    isSquarefree := x -> all(first exponents x, i -> i <= 1);
    indSets := select(first entries basis(1,quotient J), isSquarefree);
    i := 2;
    while i >= 2 do (
        potential := select(first entries basis(i,quotient J), isSquarefree);
        if #potential != 0 then indSets = potential else break;
        i = i + 1;
        );
    indSets = indices \ indSets;
    A := adjacencyMatrix G;
    V := vertexSet G;
    E := flatten for i from 0 to #V - 1 list for j from i+1 to #V - 1 list if A_(i,j) == 1 or A_(j,i) == 1 then {i,j} else continue;
    nbrs := v -> positions(first entries (adjacencyMatrix G)^{v}, j -> j != 0);
    iE := select(E, e -> any (indSets, A -> (member(e_0, A) and #((set nbrs e_1)*set A) == 1) or (member(e_1, A) and #((set nbrs e_0)*set             A) == 1)));
    apply(iE, e -> set V_e)
    )

degeneracy = method()
degeneracy Graph := ZZ => G -> (
    nbrs := v -> positions(first entries (adjacencyMatrix G)^{v}, j -> j != 0);
    n := #vertexSet G;
    L := {};
    dV := new MutableHashTable from apply(n, i -> i => #nbrs i);
    D := apply(n, j -> select(n, i -> dV#i == j));
    k := 0;
    for l from 1 to n do (
        i := position(D, j -> #j != 0);
        k = max(k, i);
        v := first D_i;
        L = append(L, v);
        D = replace(i, drop(D_i, 1), D);
        scan(nbrs v, w -> dV#w = dV#w - 1);
        V' := toList(0..n-1) - set L;
        D = apply(n, j -> select(V', i -> dV#i == j));
        );
    k
    )

degreeCentrality = method()
degreeCentrality (Graph, Thing) := QQ => (G, v) -> degree(G, v)/(2*#edges G)

degreeIn = method()
degreeIn (Digraph,Thing) := ZZ => (D,v) -> #parents(D,v)

degreeOut = method()
degreeOut (Digraph,Thing) := ZZ => (D,v) -> #children(D,v)

density = method()
density Graph := QQ => G -> (
    E := #edges G;
    V := #vertexSet G;
    2*E / (V * (V - 1))
    )

depthFirstSearch = method()
depthFirstSearch Digraph := HashTable => G -> (
    V := vertexSet G;
    Q := {};
    discovery := new MutableHashTable from apply(V, v -> v => 0);
    finishing := new MutableHashTable from apply(V, v -> v => -1);
    parent := new MutableHashTable from apply(V, v -> v => null);
    t := 0;
    -- V maintains the vertexSet that have yet to be queued
    while #V != 0 do (
        Q = {V_0};
        V = drop(V, 1);
        -- While the queue is not empty...
        while #Q != 0 do (
            v := Q_0;
            Q = drop(Q, 1);
            t = t + 1;
            discovery#v = t;
            -- Find the unqueued children of v; mark v as their 'parent'
            C := select(toList children(G, v), u -> member(u, V));
            scan(C, u -> parent#u = v);
            -- If all children have been queued, then we are finished,
            -- as are all 'forefathers' of v that have no children in the queue.
            if #C == 0 then (
                while v =!= null and (#Q == 0 or parent#(first Q) =!= v) do (
                    t = t + 1;
                    finishing#v = t;
                    v = parent#v;
                    );
                )
            else (
                Q = C | Q;
                V = V - set C;
                );
            ); -- while #Q != 0
    ); -- while #V != 0
    hashTable{symbol discoveryTime => new HashTable from discovery, symbol finishingTime => new HashTable from finishing}
    )

DFS = depthFirstSearch

descendants = method()
descendants (Digraph, Thing) := Set => (D,v) -> set flatten breadthFirstSearch(D, v)
descendents = descendants

diameter Graph := ZZ => G -> (
    allEntries := flatten entries distanceMatrix G;
    if member(-1, allEntries) then infinity else max allEntries
    )

distance = method()
distance (Digraph, Thing, Thing) := ZZ => (G,v,u) -> (
    if not member(v, vertexSet G) or not member(u, vertexSet G) then error "The given vertexSet are not vertexSet of G.";
    n := #vertexSet G;
    v = position(vertexSet G, i -> i == v);
    u = position(vertexSet G, i -> i == u);
    C := new MutableList from toList(#vertexSet G:infinity);
    Q := {v};
    C#v = 0;
    while #Q != 0 do (
        y := first Q;
        Q = drop(Q, 1);
        N := select(positions(first entries (adjacencyMatrix G)^{y}, j -> j != 0), x -> C#x == infinity);
        if any(N, x -> x == u) then (
            C#u = C#y + 1;
            break;
            );
        Q = Q | N;
        for z in N do C#z = C#y + 1;
        );
    C#u
    )
distance (Digraph, Thing) := HashTable => (G, v) -> (
    if not member(v, vertexSet G) then error "The given vertex is not a vertex of G.";
    n := #vertexSet G;
    v = position(vertexSet G, i -> i === v);
    C := new MutableList from toList(#vertexSet G:infinity);
    Q := {v};
    C#v = 0;
    while #Q != 0 do (
        y := first Q;
        Q = drop(Q, 1);
        N := select(positions(first entries (adjacencyMatrix G)^{y}, j -> j != 0), x -> C#x == infinity);
        Q = Q | N;
        for z in N do C#z = C#y + 1;
        );
    hashTable apply(n, i -> (vertexSet G)_i => C#i)
    )

distanceMatrix = method()
distanceMatrix Digraph := Matrix => G -> (
    V := vertexSet G;
    matrix for i to #V - 1 list (
        H := distance(G, V_i);
        for j from 0 to #V -1 list (if H#(V_j) == infinity then -1 else H#(V_j))
        )
    )

eccentricity = method()
eccentricity (Graph, Thing) := ZZ => (G,v) ->(
    if isConnected G == false then error "Input graph must be connected";
    max apply(vertexSet G, i -> distance(G, v, i))
    )

edgeIdeal = method()
edgeIdeal Graph := Ideal => G -> (
    G = indexLabelGraph G;
    V := vertexSet G;
    x := local x;
    R := QQ(monoid[x_1..x_(#V)]);
    monomialIdeal (
        if #edges G == 0 then 0_R
        else apply(toList \ edges G, e -> R_(position(V, i -> i === e_0)) * R_(position(V, i -> i === e_1)))
        )
    )

expansion = method ()
expansion Graph := QQ => G -> (
   V:=set(vertexSet(G));
   E:=edges(G);
   --return 0 if graph is empty graph
   if #E===0 then return 0;
   n:=floor((#V)/2);
   --CS:={};
   RS:={};
   qq:=0;
   ee:=degree(G,(toList(V))_0);
   for i in 1..n do (
      for S in subsets(V,i) do (
           CS:=V-S;
           qq:=sum for e in edges(G) list if #(e*S)>0 and #(e*CS)>0 then 1 else 0;
           ee=min(ee,qq/#S);
           if(ee == qq) then RS=S;
           );
      );
   return ee;
)

findPaths = method()
findPaths (Digraph,Thing,ZZ) := List => (G,v,l) -> (
    if l < 0 then error "integer must be nonnegative";
    if l == 0 then {{v}}
    else(
        nbors := toList children (G,v);
        nPaths := apply(nbors, n -> findPaths(G,n,l-1));
        flatten apply(nPaths, P -> apply(P, p -> {v} | p))
    )
)

floydWarshall = method()
floydWarshall Digraph := HashTable => G -> (
    V := vertexSet G;
    D := new MutableHashTable from flatten apply(V, u -> apply(V, v-> (u,v) =>
        if u===v then 0 else if member(v, children(G,u)) then 1 else infinity));
    scan(V, w -> scan(V, u -> scan(V, v -> D#(u,v) = min(D#(u,v), D#(u,w) + D#(w,v)))));
    new HashTable from D
    )

forefathers = method()
forefathers (Digraph, Thing) := Set => (D,v) -> set flatten reverseBreadthFirstSearch(D,v)
foreFathers = forefathers

girth = method()
girth Graph := Thing => G -> (
    g := infinity;
    n := #vertexSet G;
    P := new MutableList from toList(n:0);
    D := new MutableList from toList(n:0);
    for v from 0 to n-1 do (
        S := {};
        R := {v};
        P#v = null;
        D#v = 0;
        while R != {} do(
            x := first R;
            S = append(S, x);
            R = drop(R, 1);
            L := positions(first entries (adjacencyMatrix G)^{x}, j -> j != 0) - set {P#x};
            for y in L do (
                if member(y, S) then
                    ( g = min {g, D#y + D#x + 1}; )
                else(
                    P#y = x;
                    D#y = 1 + D#x;
                    R = unique append(R, y);
                    );
                );
            );
        );
    g
    )

independenceComplex = method()
independenceComplex Graph := SimplicialComplex => G -> simplicialComplex edgeIdeal G

independenceNumber = method()
independenceNumber Graph := ZZ => G -> dim edgeIdeal G

leaves = method()
leaves Graph := List => G -> if not isTree G then error "input must be a tree" else select(vertexSet G, i -> degree(G, i) == 1)

lowestCommonAncestors = method()
lowestCommonAncestors (Digraph,Thing,Thing) := Thing => (D,u,v) -> (
    x := v;
    y := u;
    orderedVertices := flatten breadthFirstSearch(D, first vertexSet D);
    if position(orderedVertices, i -> i == u) >= position(orderedVertices, i -> i == v) then (
        x = u;
        y = v;
        );
    ancestX := reverseBreadthFirstSearch(D,x);
    ancestY := reverseBreadthFirstSearch(D,y);
    for i in ancestY do (
        for j in ancestX do (
            a := set i * set j;
            if #a != 0 then return toList a;
            );
        );
    {}
    )
highestCommonDescendant = method()
highestCommonDescendant(Digraph,Thing,Thing) := Thing => (D,u,v) -> (
    x := v;
    y := u;
    orderedVertices := flatten breadthFirstSearch(D, first vertexSet D);
    if position(orderedVertices, i -> i == u) >= position(orderedVertices, i -> i == v) then (
        x = u;
        y = v;
        );
    descendX := breadthFirstSearch(D,x);
    descendY := breadthFirstSearch(D,y);
    for i in descendY do (
        for j in descendX do (
            a := set i * set j;
            if #a != 0 then return toList a;
            );
        );
    {}
    )

neighbors = method()
neighbors (Graph, Thing) := Set => (G,v) -> (
    i := position(vertexSet G, u -> u === v);
    if i === null then error "v is not a vertex of G.";
    set (vertexSet G)_(positions(first entries (adjacencyMatrix G)^{i}, j -> j != 0))
    )

nondescendants = method()
nondescendants (Digraph, Thing) := Set => (D,v) -> set vertexSet D - (set {v} + descendants(D, v))
nondescendents = nondescendants

nonneighbors = method()
nonneighbors (Graph, Thing) := Set => (G,v) -> set vertexSet G - (set {v} + neighbors(G, v))

numberOfComponents = method()
numberOfComponents Graph := ZZ => G -> #connectedComponents G

numberOfTriangles = method()
numberOfTriangles Graph := ZZ => G -> number(ass (coverIdeal G)^2, i -> codim i == 3)

parents = method()
parents (Digraph, Thing) := Set => (G, v) -> (
    i := position(vertexSet G, u -> u === v);
    if i === null then error "v is not a vertex of G.";
    set (vertexSet G)_(positions(flatten entries (adjacencyMatrix G)_{i}, j -> j != 0))
    )

radius = method()
radius Graph := ZZ => G -> min apply(vertexSet G, i -> eccentricity(G,i))

reachable = method()
reachable (Digraph, List) := (D, A) -> unique flatten apply(A, v -> toList descendants(D, v))
reachable (Digraph, Set) := (D, A) -> set reachable(D, toList A)

reverseBreadthFirstSearch = method()
reverseBreadthFirstSearch (Digraph, Thing) := List => (G, v) -> (
    V := vertexSet G;
    if not member(v, V) then error "";
    Q := {{v, 0}};
    V = V - set {v};
    i := 0;
    while i < #Q do (
        C := select(toList parents(G, first Q_i), u -> member(u, V));
        Q = Q | apply(C, c -> {c, last Q_i + 1});
        V = V - set C;
        i = i + 1;
        );
    P := partition(last, Q);
    apply(sort keys P, k -> first \ P#k)
    )

sinks = method()
sinks Digraph := List => D -> select(vertexSet D, i -> isSink(D,i))

sources = method()
sources Digraph := List => D -> select(vertexSet D, i -> isSource(D, i))

spec = spectrum

spectrum = method()
spectrum Graph := List => G -> sort toList eigenvalues (adjacencyMatrix G, Hermitian => true)



topologicalSort = method(TypicalValue =>List)
topologicalSort Digraph := List => D -> topologicalSort(D, "")
topologicalSort (Digraph, String) := List => (D,s) -> (
    if instance(D, Graph) or isCyclic D then error "Topological sorting is only defined for acyclic directed graphs.";
    s = toLower s;
    processor := if s == "random" then random
        else if s == "min" then sort
        else if s == "max" then rsort
        else if s == "degree" then L -> last \ sort transpose {apply(L, v -> degree(D, v)), L}
        else identity;
    S := processor sources D;
    L := {};
    v := null;
    while S != {} do (
        v = S_0;
        L = L|{v};
        S = processor join(drop(S, 1), select(toList children (D, v), c -> isSubset(parents(D, c), L)));
        );
    L
    )




SortedDigraph = new Type of HashTable;

-- Keys:
--      digraph: the original digraph
--      NewDigraph: the digraph with vertices labeled as integers obtained from sorting
--      map: the map giving the sorted order

topSort = method(TypicalValue =>HashTable)
topSort Digraph := SortedDigraph => D ->  topSort(D,"") 
topSort (Digraph, String) := SortedDigraph => (D,s) -> ( 
L := topologicalSort (D,s);
g := graph D;
new SortedDigraph from {
digraph => D,
newDigraph => digraph hashTable apply(#L, i -> i + 1 => apply(toList g#(L_i), j -> position(L, k -> k == j) + 1)),
map => hashTable apply(#L, i -> L_i => i + 1)
}
)


vertexCoverNumber = method()
vertexCoverNumber Graph := ZZ => G -> min apply(vertexCovers G, i -> #i)

vertexCovers = method()
vertexCovers Graph := List => G -> (
    J := coverIdeal G;
    factoredIdealList := apply(J_*, indices);
    apply(factoredIdealList, i -> (vertexSet G)_i)
    )

weaklyConnectedComponents = method()
weaklyConnectedComponents Digraph := List => D -> connectedComponents underlyingGraph D

------------------------------------------
-- Boolean properties
------------------------------------------

hasEulerianTrail = method()
hasEulerianTrail Graph := Boolean => G -> (
    V := vertexSet G;
    V' := V - set select(V, v -> degree(G,v) == 0);
    oddDegrees := select(V, v -> odd (degree(G,v)));
    #oddDegrees <= 2 and isConnected inducedSubgraph(G,V')
    )
hasEulerianTrail Digraph := Boolean => G -> (
    V := vertexSet G;
    G' := underlyingGraph G;
    V' := V - set select(V, v -> degree(G',v) == 0);
    inMinusOut := {};
    outMinusIn := {};
    inDegrees := {};
    outDegrees := {};
    for v in V' do (
        outDeg := #children(G,v);
        inDeg := #parents(G,v);
        i := inDeg - outDeg;
        o := outDeg - inDeg;
        if i == 1 then inMinusOut = inMinusOut | {v};
        if o == 1 then outMinusIn = outMinusIn | {v};
        if i != 1 and o != 1 then (
            inDegrees = inDegrees | {inDeg};
            outDegrees = outDegrees | {outDeg};
            );
        );
    #inMinusOut <= 1 and #outMinusIn <= 1 and #(unique inDegrees) <= 1 and #(unique outDegrees) <= 1 and isConnected inducedSubgraph(G',V')
    )

hasOddHole = method()
hasOddHole Graph := Boolean => G -> any(ass (coverIdeal G)^2, i -> codim i > 3)

isBipartite = method()
isBipartite Graph := Boolean => G ->
    try bipartiteColoring G then true else false

isCM = method()
isCM Graph := Boolean => G -> (
    I := edgeIdeal G;
    codim I == pdim coker gens I
    )

isChordal = method()
isChordal Graph := Boolean => G -> (
    I := edgeIdeal complementGraph G;
    if I == ideal 0_(ring I) then true
    else (min flatten degrees I - 1) == regularity coker gens I
    )

isConnected = method()
isConnected Graph := Boolean => G -> numberOfComponents G <= 1

isCyclic = method()
isCyclic Graph := Boolean => G -> isConnected G and all(vertexSet G, v -> degree(G, v) == 2)
isCyclic Digraph := Boolean => G -> (
        D := depthFirstSearch G;
        any(vertexSet G, u ->
            any(toList children(G, u), v ->
                (D#symbol discoveryTime)#v < (D#symbol discoveryTime)#u and (D#symbol finishingTime)#u < (D#symbol finishingTime)#v
                )
            )
        )

isEulerian = method()
isEulerian Graph := Boolean => G -> all(apply(vertexSet G, v -> degree(G,v)), even) and isConnected G
isEulerian Digraph := Boolean => G -> (
    if #edges G == 0 then return false;
    V := vertexSet G;
    G' := underlyingGraph G;
    V' := V - set select(V, v -> degree(G',v) == 0);
    inDegree := #(parents(G, first V'));
    outDegree := #(children(G, first V'));
    all(V', v -> #parents(G, v) == inDegree) and all(V', v -> #children(G, v) == outDegree)    and isConnected inducedSubgraph(G', V')
    )

isForest = method()
isForest Graph := Boolean => G -> girth(G) == infinity

isLeaf = method()
isLeaf (Graph, Thing) := Boolean => (G,a) -> degree(G,a) == 1

isPerfect = method()
isPerfect Graph := Boolean => G -> not (hasOddHole G or hasOddHole complementGraph G)

isReachable = method()
isReachable (Digraph, Thing, Thing) := Boolean => (D,u,v) -> member(u, descendants(D,v))

isRegular = method()
isRegular Graph := Boolean => G -> (
    n := degree(G, first vertexSet G);
    all(drop(vertexSet G,1), v -> degree(G,v) == n)
    )


-- input: A graph G
-- output: Uses Laman's Theorem to determine if a graph is rigid or not
-- written by Tom Enkosky
--
isRigid = method();
isRigid Graph := G -> (
    local rigidity; local i; local j;
    
    rigidity=true;
    
    if #edges G < 2*#vertices G-3 then rigidity = false
    else (
	 for j from 2 to #vertices G-1 do(
	     for i in subsets(vertices G,j) do(
		 if #edges inducedSubgraph(G,i)>2*#i-3  then rigidity = false 
		 );
	     );
	 );
    return rigidity;
    )


isSimple = method()
isSimple Graph := Boolean => G -> (
    A := adjacencyMatrix G;
    all(toList(0..<numrows A), i -> A_(i,i) == 0)
)

isSink = method()
isSink (Digraph, Thing) := Boolean => (D,v) -> #children(D,v) == 0

isSource = method()
isSource (Digraph, Thing) := Boolean => (D,v) -> #parents(D,v) == 0

isStronglyConnected = method()
isStronglyConnected Digraph := Boolean => D -> all(unique flatten entries distanceMatrix D, i -> i>=0)

isTree = method()
isTree Graph := Boolean => G -> isConnected G and #edges G == #vertexSet G - 1

isWeaklyConnected = method()
isWeaklyConnected Digraph := Boolean => D -> isConnected underlyingGraph D

------------------------------------------
-- Graph operations
------------------------------------------

cartesianProduct = method()
cartesianProduct(Graph, Graph) := Graph => (G, H) -> (
    V := toList(set vertexSet G ** set vertexSet H);
    E := flatten for u in V list for v in V list
        if (u_0 == v_0 and member(set {u_1, v_1}, edges H))
        or (u_1 == v_1 and member(set {u_0, v_0}, edges G))
        then {u, v} else continue;
    graph(V, E, EntryMode => "edges")
    )

-- the 'directProduct' method is defined in 'Polyhedra'
directProduct(Graph,Graph) := Graph => (G, H) -> (
    V := toList(set vertexSet G ** set vertexSet H);
    E := flatten for u in V list for v in V list
        if member(set {u_0, v_0}, edges G) and member(set {u_1, v_1}, edges H)
        then {u, v} else continue;
    graph(V, E, EntryMode => "edges")
    )

disjointUnion = method()
disjointUnion List := Graph => L -> (
    if not all(L, G -> instance(G,Graph)) then error "must be a list of graphs";
    V := flatten for i to #L-1 list apply(vertexSet L_i, v -> {v, i});
    E := flatten for i to #L - 1 list apply(toList \ edges L_i, e -> {{e_0, i},{e_1, i}});
    graph(V, E, EntryMode => "edges")
    )

graphComposition = method()
graphComposition (Graph, Graph) := Graph => (G, H) -> (
    V := toList(set vertexSet G ** set vertexSet H);
    E := flatten for u in V list for v in V list
        if member(set {u_0, v_0}, edges G)
        or (u_0 == v_0 and member(set {u_1, v_1}, edges H))
        then {u, v} else continue;
    graph(V, E, EntryMode => "edges")
    )

graphPower = method()
graphPower (Graph, ZZ) := Graph => (G,k) -> (
    V := vertexSet G;
    E := flatten for i from 0 to #V-2 list (
        for j from i+1 to #V-1 list if distance(G,V_i, V_j) <= k then {V_i, V_j} else continue
        );
    graph(V, E, EntryMode => "edges")
    )

lexicographicProduct = graphComposition

strongProduct = method()
strongProduct (Graph, Graph) := Graph => (G, H) -> (
    V := toList \ toList(set vertexSet G ** set vertexSet H);
    E' := flatten for u in V list for v in V list
        if (u_0 == v_0 and member(set {u_1, v_1}, edges H))
        or (u_1 == v_1 and member(set {u_0, v_0}, edges G))
        then {u, v} else continue;
    E'' := flatten for u in V list for v in V list
        if member(set {u_0, v_0}, edges G) and member(set {u_1, v_1}, edges H)
        then {u, v} else continue;
    E := unique join(E', E'');
    graph(V, E, EntryMode => "edges")
    )

tensorProduct = directProduct

---------------------------
--Graph Manipulations
---------------------------
addEdge = method()
addEdge (Digraph, Set) := Graph => (G, s) -> addEdges'(G, {toList s})

addEdges' = method()
addEdges' (Graph, List) := Graph => (G, L) -> (
    A := mutableMatrix adjacencyMatrix G;
    while L != {} do(
        l := first L;
        e := apply(toList l, i -> position(vertexSet G, j -> j == i));
        f := sequence(first e, last e);
        A_f = 1;
        A_(reverse f) = 1;
        L = drop(L,1);
        );
    graph (vertexSet G, matrix A)
    )
addEdges' (Digraph, List) := Digraph => (G, L) -> (
    A := mutableMatrix adjacencyMatrix G;
    while L != {} do(
        l := first L;
        e := apply(toList l, i -> position(vertexSet G, j -> j == i));
        f := sequence(first e, last e);
        A_f = 1;
        L = drop(L,1);
        );
    digraph (vertexSet G, matrix A)
    )

addVertex = method()
addVertex (Digraph, Thing) := Digraph => (G, v) -> addVertices(G, {v})

addVertices = method()
addVertices (Graph, List) := Graph => (G, L) -> (
    L = L - set vertexSet G;
    n := #vertexSet G;
    m := #L;
    A := adjacencyMatrix G;
    B := map(ZZ^n, ZZ^m, 0);
    D := map(ZZ^m, ZZ^m, 0);
    A' := matrix {{A, B}, {transpose B, D}};
    graph(join(vertexSet G, L), A')
    )
addVertices(Digraph, List) := Graph => (G, L) -> (
    L = L - set vertexSet G;
    n := #vertexSet G;
    m := #L;
    A := adjacencyMatrix G;
    B := map(ZZ^n, ZZ^m, 0);
    D := map(ZZ^m, ZZ^m, 0);
    A' := matrix {{A, B}, {transpose B, D}};
    digraph (join(vertexSet G, L), A')
    )

bipartiteColoring = method()
bipartiteColoring Graph := List => G -> (
    n := # vertexSet G;
    v := 0;
    if n == 0 then return {{},{}};
    D := new MutableList from toList(n: infinity);
    while v != n do (
        uncolored := {position(toList D, i -> i == infinity)};
        D#(first uncolored) = 0;
        v = v + 1;
        while #uncolored != 0 do (
            x := first uncolored;
            uncolored = drop(uncolored, 1);
            N := positions(first entries (adjacencyMatrix G)^{x}, j -> j != 0);
            for y in N do (
                if D#y == infinity then (
                    D#y = 1 + D#x;
                    v = v + 1;
                    uncolored = append(uncolored, y);
                    ) else if (D#x - D#y) % 2 == 0 then
                        error "graph must be bipartite";
                );
            );
        );
    blue := positions(toList D, even);
    gold := toList(0..(n-1)) - set blue;
    {(vertexSet G)_blue, (vertexSet G)_gold}
    )

deleteEdges = method()
deleteEdges (Graph, List) := Graph => (G,L) -> (
    E := set edges G;
    E' := E - set(for l in L list set l);
    graph(vertexSet G, toList(E'), EntryMode => "edges")
    )
deleteEdges (Digraph, List) := Graph => (G,L) -> digraph(vertexSet G, edges G - set L)

deleteVertex = method()
deleteVertex (Graph, Thing) := Graph => (G, v) -> (
    if not member(v, vertexSet G) then error "v must be a vertex of G";
    V := vertexSet G - set {v};
    E := select(toList \ edges G, e -> not member(v, e));
    graph(V,E, EntryMode => "edges")
    )
deleteVertex (Digraph, Thing) := Digraph => (G, v) -> (
    if not member(v, vertexSet G) then error "v must be a vertex of G";
    V := vertexSet G - set {v};
    E := select(edges G, e -> not member(v,e));
    digraph(V,E, EntryMode => "edges")
    )

deleteVertices = method()
deleteVertices (Digraph, List) := Digraph => (D, L) -> inducedSubgraph(D, vertexSet D - set L)

indexLabelGraph = method()
indexLabelGraph Graph := Graph => G -> (
    V := vertexSet G;
    h := hashTable apply(#V, i -> V_i => i);
    E := apply(toList \ edges G, e -> {h#(e_0), h#(e_1)});
    graph(toList(0..<#V), E, EntryMode => "edges")
    )

indexLabelGraph Digraph := Digraph => G -> (
    V := vertexSet G;
    h := hashTable apply(#V, i -> V_i => i);
    E := apply(edges G, e -> {h#(e_0), h#(e_1)});
    digraph(toList(0..<#V), E, EntryMode => "edges")
    )

inducedSubgraph = method()
inducedSubgraph (Graph, List) := Graph => (G, S) -> (
    if S == {} then graph {}
    else E' := select(edges G, e -> isSubset(e,S));
    graph(S, E', EntryMode => "edges")
    )
inducedSubgraph (Digraph,List) := Digraph => (D,S) -> (
    E' := select(edges D, e -> isSubset(e,S));
    digraph(S, E', EntryMode => "edges")
    )

reindexBy = method()
reindexBy (Graph, String) := Graph => (G, s) -> (
    s = toLower s;
    if s == "maxdegree" then (
        V := vertexSet G;
        V' := {};
        while V != {} do (
            x := hashTable apply(V, i -> i => degree (G,i));
            S := select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = V' | S;
             );
        return graph (V', edges G)
        );
    if s == "mindegree" then (
        V = vertexSet G;
        V' = {};
        while V != {} do (
            x = hashTable apply(V, i -> i => degree (G,i));
            S = select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = S | V'
             );
        return graph (V', edges G)
        );
    if s == "random" then return graph (random vertexSet G, edges G, EntryMode => "edges");
    if s == "components" then return graph (flatten connectedComponents G, edges G, EntryMode => "edges");
    if s == "sort" then return graph (sort vertexSet G, edges G, EntryMode => "edges");
    )
reindexBy (Digraph, String) := Digraph => (D, s) -> (
    s = toLower s;
    if s == "maxdegreein" then (
        V := vertexSet D;
        V' := {};
        while V != {} do (
            x := hashTable apply(V, i -> i => #parents(D,i));
            S := select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = V' | S;
             );
        return digraph (V', edges D, EntryMode => "edges")
        );
    if s == "mindegreein" then (
        V = vertexSet D;
        V' = {};
        while V != {} do (
            x = hashTable apply(V, i -> i => #parents(D,i));
            S = select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = S | V';
             );
        return digraph (V', edges D, EntryMode => "edges")
        );
    if s == "maxdegreeout" then (
        V = vertexSet D;
        V' = {};
        while V != {} do (
            x = hashTable apply(V, i -> i => #children(D,i));
            S = select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = V' | S;
             );
        return digraph (V', edges D, EntryMode => "edges")
        );
    if s == "mindegreeout" then (
        V = vertexSet D;
        V' = {};
        while V != {} do (
            x = hashTable apply(V, i -> i => #children(D,i));
            S = select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = S | V';
             );
        return digraph (V', edges D, EntryMode => "edges")
        );
    if s == "maxdegree" then (
        V = vertexSet D;
        V' = {};
        while V != {} do (
            x = hashTable apply(V, i -> i => (#children(D,i) + #parents(D,i)));
            S = select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = V' | S;
             );
        return digraph (V', edges D, EntryMode => "edges")
        );
    if s == "mindegree" then (
        V = vertexSet D;
        V' = {};
        while V != {} do (
            x = hashTable apply(V, i -> i => (#children(D,i) + #parents(D,i)));
            S = select(keys x, i -> x#i == max values x);
            V = V - set S;
            V' = S | V';
             );
        return digraph (V', edges D, EntryMode => "edges")
        );
    if s == "random" then return digraph(random vertexSet D, edges D, EntryMode => "edges");
    if s == "sort" then return digraph(sort vertexSet D, edges D, EntryMode => "edges");
    )

removeNodes = deleteVertices

spanningForest = method()
spanningForest Graph := Graph => G -> (
    V := vertexSet G;
    E := {};
    for v in V do (
        N := toList (neighbors (G,v) - set select(V, x -> member(x, flatten E)));
        E = E | apply(N, n -> {v,n});
        );
    graph(V, E, EntryMode => "edges")
    )

vertexMultiplication = method()
vertexMultiplication (Graph, Thing, Thing) := Graph => (G,v,u) -> (
    if member(u, vertexSet G) == true then error "3rd argument is already a vertex of the input graph";
    if member(v, vertexSet G) == false then error "2nd argument must be in the input graph's vertex set";
    graph(append(vertexSet G, u), edges G | apply(toList neighbors (G,v), i -> {i,u}), EntryMode => "edges")
    )




-* 

--This code is written for an older version of Graphs and is not functional with current version of the packages.

graphData = "graphData"
labels = "labels"

LabeledGraph = new Type of HashTable

labeledGraph = method(TypicalValue =>LabeledGraph)
labeledGraph (Digraph,List) := (g,L) -> (
    C := new MutableHashTable;
    C#cache = new CacheTable from {};
    lg := new MutableHashTable;
    lg#graphData = g;
    label := new MutableHashTable;
    if instance(g,Graph) then (
        sg := simpleGraph g;
        scan(L, i -> 
            if (sg#graph#(i#0#0))#?(i#0#1) then label#(i#0) = i#1
            else if (sg#graph#(i#0#1))#?(i#0#0) then label#({i#0#1,i#0#0}) = i#1
            else error (toString(i#0)|" is not an edge of the graph");
            );
        )
    else (
        scan(L, i -> 
            if (g#graph#(i#0#0))#?(i#0#1) then label#(i#0) = i#1
            else error (toString(i#0)|" is not an edge of the graph");
            );
        );
    lg#labels = new HashTable from label;
    C#graph = lg;
    new LabeledGraph from C
    )

net LabeledGraph := g -> horizontalJoin flatten (
     net class g,
    "{",
    stack (horizontalJoin \ sort apply(pairs (g#graph),(k,v) -> (net k, " => ", net v))),
    "}"
    )

toString LabeledGraph := g -> concatenate(
    "new ", toString class g#graph,
    if parent g#graph =!= Nothing then (" of ", toString parent g),
    " from {",
    if #g#graph > 0 then demark(", ", apply(pairs g#graph, (k,v) -> toString k | " => " | toString v)) else "",
    "}"
    )

graph LabeledGraph := opts -> g -> g#graph  --used to transform the LabeledGraph into a hashtable

*- 




------------------------------------------
------------------------------------------
-- Documentation
------------------------------------------
------------------------------------------

beginDocumentation()

-- authors: add some text to this documentation node:
doc ///
  Key
    Graphs
  Headline
    graphs and digraphs
  Description
    Text
      This package defines classes for graphs and digraphs and related methods.
  Contributors
    Carlos Amendola, Alex Diaz, Luis David Garcia Puente, Roser Homs Pons,
    Olga Kuznetsova, Shaowei Lin, Sonja Mapes, Harshit J Motwani, Mike Stillman,
    and Doug Torrance contributed to this package.

///

-------------------------------
--Data Types
doc ///
    Key
    	Digraph
///

doc ///
    Key
    	Graph
///





-------------------------------
--Graph Constructors
-------------------------------

--digraph
doc///
    Key
        digraph
        (digraph, List)
        (digraph, List, List)
        (digraph, HashTable)
        (digraph, List, Matrix)
        (digraph, Matrix)
    Headline
        Constructs a digraph
    Usage
        G = digraph E
        G = digraph H
        G = digraph (V, E)
        G = digraph (V, A)
        G = digraph A
    Inputs
        E:List
            Denotes an edge list (a list of ordered pair lists)
        V:List
            Denotes a vertex list
        H:HashTable
        A:Matrix
            Denotes an adjacency matrix
    Outputs
        G:Digraph
    Description
        Text
            A digraph is a set of vertices connected by directed edges. Unlike the case with simple graphs, {u,v} being an edge does not imply that {v,u} is also an edge. Notably, this allows for non-symmetric adjacency matrices.
        Example
            G = digraph ({{1,2},{2,1},{3,1}}, EntryMode => "edges")
            G = digraph hashTable{1 => {2}, 3 => {4}, 5 => {6}}
            G = digraph ({{a,{b,c,d,e}}, {b,{d,e}}, {e,{a}}}, EntryMode => "neighbors")
            G = digraph ({x,y,z}, matrix {{0,1,1},{0,0,1},{0,1,0}})
            G = digraph matrix {{0,1,1},{0,0,1},{0,1,0}}
    SeeAlso
        graph
///

--graph
doc ///
    Key
        graph
        (graph, List)
        (graph, List, List)
        (graph, HashTable)
        (graph, List, Matrix)
        (graph, Matrix)
        [graph, Singletons]
        [graph, EntryMode]
	EntryMode
    Headline
        Constructs a simple graph
    Usage
        G = graph E
        G = graph (V,E)
        G = graph H
        G = graph (V, A)
        G = graph A
    Inputs
        E:List
        V:List
        H:HashTable
        A:Matrix
    Outputs
        G:Graph
            The graph with edges E and vertices V, or constructed from HashTable H, or from an adjacency matrix A, or from a new naming of vertices V and an adjacency matrix A.
    Description
        Text
            A graph consists of two sets, a vertex set and an edge set which is a subset of the collection of subsets of the vertex set. Edges in graphs are symmetric or two-way; if u and v are vertices then if {u,v} is an edge connecting them, {v,u} is also an edge (which is implicit in the definition, we will almost always just use one of the pairs). Graphs are defined uniquely from their Adjacency Matrices. These matrices use the entries as 0 or 1 to signal the existence of an edge connecting vertices.
            The options for EntryMode are "neighbors" and "edges" (the default).  This means that in including EntryMode => "edges" in the constructor allows the user to simply type in a list of edges to construct a graph.  See example 1 below.  Using the default takes an input of a list of pairs, where the first entry of each pair is a vertex and the second entry of each pair is that vertex's neighborhood.
            The options for Singletons allows the user to enter Singletons => {list of single points} in a graph if they desire to have isolated points in a graph.  See second example below.
        Example
            G = graph({{1,2},{2,3},{3,4}})
            G = graph({{1,2},{2,3},{3,4}}, Singletons => {5,6,7})
            G = graph ({{a,{b,c,d,e}}, {b,{d,e}}, {e,{a}}})
            G = graph hashTable {{1,{2}},{2,{1,3}},{3,{2,4}},{4,{3}}}
            G = graph(matrix {{0,1,1},{1,0,0},{1,0,0}})
            G = graph({a,b,c}, matrix {{0,1,1},{1,0,0},{1,0,0}})
    SeeAlso
        digraph

///

--graph
doc ///
    Key
        (graph, Digraph)
    Headline
        Returns the legacy G#graph hash table
    Usage
        G = graph D
    Inputs
        D:Digraph
    Outputs
        H:HashTable
            The hash table with a graph's vertices as keys and list of neighbors as values.
    Description
        Text
            A graph consists of two sets, a vertex set and an edge set which is a subset of the collection of subsets of the vertex set. Edges in graphs are symmetric or two-way; if u and v are vertices then if {u,v} is an edge connecting them, {v,u} is also an edge (which is implicit in the definition, we will almost always just use one of the pairs). The options for EntryMode are "neighbors" (the default) and "edges".  This method returns a hash table where the keys are vertices of a given graph or digraph and the values are their children (or neighbors, in the case of undirected graphs).
        Example
            G = graph digraph({{1,2},{2,1},{3,1}}, EntryMode => "edges")
            G = graph digraph(matrix {{0,1,1},{1,0,0},{1,0,0}})
    SeeAlso
        digraph
///

--------------------------------
--Graphs: Basic Data
--------------------------------

--adjacencyMatrix
doc ///
    Key
        adjacencyMatrix
        (adjacencyMatrix, Digraph)
    Headline
        Returns the adjacency matrix of a Graph or Digraph
    Usage
        A = adjacencyMatrix D
        A = adjacencyMatrix G
    Inputs
        D:Digraph
        G:Graph
    Outputs
        A:Matrix
    Description
        Text
            The adjacency matrix is the n by n matrix (where n is the number of vertices in graph/digraph G) with rows and columns indexed by the vertices of G. Entry A_(u,v) is 1 if and only if {u,v} is an edge of G and 0 otherwise. It is easy to observe that if we just use a simple graph G, then its adjacency matrix must be symmetric, but if we use a digraph, then it is not necessarily symmetric.
        Example
            D = digraph({{1,2},{2,3},{3,4},{4,3}},EntryMode=>"edges");
            adjacencyMatrix D
            G = graph({1,2,3,4}, {{1,2},{2,3},{3,4},{4,3}})
            adjacencyMatrix G
    SeeAlso
        degreeMatrix
        laplacianMatrix
///

--degree
doc ///
    Key
        (degree, Digraph, Thing)
    Headline
        returns the degree of a vertex in a digraph
    Usage
        x = degree(D,v)
    Inputs
        D:Digraph
        v:Thing
            a vertex in the graph/digraph
    Outputs
        x:ZZ
    Description
        Text
            In a simple graph, the degree of a vertex is the number of neighbors of the vertex. 
            In a digraph, we define the degree of a vertex to be the number of elements in the unique union of the parents and children of the vertex.
        Example
            D = digraph({1,2,3,4},{{1,2},{2,3},{3,4},{4,2},{2,4}});
            degree(D, 3)
            degree(D, 2)
    SeeAlso
        neighbors
        parents
        children
///

--degreeMatrix
doc ///
    Key
        degreeMatrix
        (degreeMatrix, Digraph)
    Headline
        Returns the degree matrix of a graph
    Usage
        D = degreeMatrix G
    Inputs
        G:Graph
    Outputs
        D:Matrix
            The degree matrix of graph G
    Description
        Text
            The degree matrix is the n by n diagonal matrix (where n is the number of vertices in the vertex set of the graph G) indexed by the vertices of G where A_(u,u) is the degree of vertex u. The degree of a vertex u is the number of edges such that {u,v} is an edge for any v also in the vertex set. This matrix is always diagonal.
        Example
            G = graph({1,2,3,4,5},{{1,2},{2,3},{3,4},{3,5},{4,5}});
            degreeMatrix G
    SeeAlso
        adjacencyMatrix
        laplacianMatrix
        degree
///

doc ///
    Key
        degreeSequence
        (degreeSequence, Graph)
    Headline
        the degree sequence of a graph
    Usage
        degreeSequence G
    Inputs
        G:Graph
    Outputs
        :List -- the degree sequence of G
    Description
        Text
            The degree sequence of a graph is the list of the degrees of its
            vertices sorted in nonincreasing order.
        Example
            degreeSequence pathGraph 5
///

--edges
doc ///
    Key
        edges
        (edges, Digraph)
        (edges, Graph)
    Headline
        Returns the edges of a digraph or graph
    Usage
        E = edges D
        E = edges G
    Inputs
        D:Digraph
        G:Graph
    Outputs
        E:List
            The edges of digraph D or graph G
    Description
        Text
            The edges of a graph are pairs (or ordered pairs if we are dealing with digraphs) of vertices that are connected in a graph. Any edge must be a member of the collection of subsets of the vertex set of a graph.
        Example
            D = digraph({{1,2},{2,1},{3,1}},EntryMode=>"edges");
            edges D
            G = cycleGraph 4;
            edges G
    SeeAlso
        vertexSet
///

--incidenceMatrix
doc ///
    Key
        incidenceMatrix
        (incidenceMatrix, Graph)
    Headline
        computes the incidence matrix of a graph
    Usage
        M = incidenceMatrix G
    Inputs
        G:Graph
    Outputs
        M:Matrix
            the incidence matrix of graph G
    Description
        Text
            An incidence matrix M is the #vertexSet of G by #edges of G matrix where entry (i,j) equals 1 if vertex i is incident to edge j, and equals 0 otherwise.
        Example
            M = incidenceMatrix cycleGraph 3
    SeeAlso
        adjacencyMatrix
///

--add laplacianMatrix to export list!
--laplacianMatrix
doc ///
    Key
        laplacianMatrix
        (laplacianMatrix, Graph)
    Headline
        Returns the laplacian matrix of a graph
    Usage
        L = laplacianMatrix G
    Inputs
        G:Graph
    Outputs
        L:Matrix
            the laplacian matrix of graph G
    Description
        Text
            The laplacian matrix of a graph is the adjacency matrix of the graph subtracted from the degree matrix of the graph.
        Example
            G = graph({1,2,3,4,5},{{1,2},{2,3},{3,4},{3,5},{4,5}});
            laplacianMatrix G
    SeeAlso
        adjacencyMatrix
        degreeMatrix
///

--vertexSet
doc ///
    Key
        vertexSet
        (vertexSet, Digraph)
        (vertices, Digraph)
    Headline
        Returns the vertices of a graph or digraph
    Usage
        V = vertexSet D
        V = vertexSet G
    Inputs
        D:Digraph
        G:Digraph
    Outputs
        V:List
            The vertices of digraph D
    Description
        Text
            The vertices of a graph are just singletons that can be indexed by numbers, letters, or even in some cases something as exotic as a monomial. These form the base of a graph; the edges are 2 member subsets of the vertex set of a graph.
        Example
            D = digraph({{1,2},{2,1},{3,1}},EntryMode=>"edges");
            vertexSet D;
            G = completeGraph 4;
            vertexSet G
            A = adjacencyMatrix G;
            graph({a,b,c,d}, A)
    SeeAlso
        edges
///

--------------------------------
--Graphs: Display Methods
--------------------------------

-- displayGraph
doc ///
    Key
        displayGraph
        (displayGraph, String, String, Digraph)
        (displayGraph, String, Digraph)
        (displayGraph, Digraph)
    Headline
        displays a digraph or graph using Graphviz
    Usage
        displayGraph(dotFileName,jpgFileName,G)
        displayGraph(dotFileName,G)
        displayGraph G
    Inputs
        G:Digraph
        dotFileName:String
        jpgFileName:String
    Description
        Text
            Displays a digraph or graph using Graphviz
        -- Example
        --     --G = graph({1,2,3,4,5},{{1,3},{3,4},{4,5}});
        --     --displayGraph("chuckDot","chuckJpg", G)
        --     --displayGraph("chuck", G)
        --     --displayGraph G
    SeeAlso
        showTikZ
        writeDotFile
///

-- showTikZ
doc ///
    Key
        showTikZ
        (showTikZ, Digraph)
    Headline
        Writes a string of TikZ syntax that can be pasted into a .tex file to display G
    Usage
        S = showTikZ(G)
    Inputs
        G:Digraph
        S:String
            TikZ syntax used to display G
    Description
        Text
            Writes a string of TikZ syntax that can be pasted into a .tex file to display G
        -- Example
        --     --G = graph({1,2,3,4,5},{{1,3},{3,4},{4,5}});
        --     --showTikZ G
    SeeAlso
        displayGraph
///

-- html
doc ///
    Key
        (html, Digraph)
    Headline
        Create an .svg representation of a graph or digraph
    Usage
        html G
    Inputs
        G:Digraph
    Description
        Text
            Uses graphviz to create an .svg representation of @TT "G"@,
            which is returned as a string.
        CannedExample
            i2 : html completeGraph 2
            -- running: dot -Tsvg /tmp/M2-2729721-0/0.dot -o /tmp/M2-2729721-0/1.svg

            o2 = <?xml version="1.0" encoding="UTF-8" standalone="no"?>
                 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
                  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
                 <!-- Generated by graphviz version 2.43.0 (0)
                  -->
                 <!-- Title: G Pages: 1 -->
                 <svg width="62pt" height="116pt"
                  viewBox="0.00 0.00 62.00 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                 <g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
                 <title>G</title>
                 <polygon fill="white" stroke="transparent" points="-4,4 -4,-112 58,-112 58,4 -4,4"/>
                 <!-- 0 -->
                 <g id="node1" class="node">
                 <title>0</title>
                 <ellipse fill="none" stroke="black" cx="27" cy="-90" rx="27" ry="18"/>
                 <text text-anchor="middle" x="27" y="-86.3" font-family="Times,serif" font-size="14.00">0</text>
                 </g>
                 <!-- 1 -->
                 <g id="node2" class="node">
                 <title>1</title>
                 <ellipse fill="none" stroke="black" cx="27" cy="-18" rx="27" ry="18"/>
                 <text text-anchor="middle" x="27" y="-14.3" font-family="Times,serif" font-size="14.00">1</text>
                 </g>
                 <!-- 0&#45;&#45;1 -->
                 <g id="edge1" class="edge">
                 <title>0&#45;&#45;1</title>
                 <path fill="none" stroke="black" d="M27,-71.7C27,-60.85 27,-46.92 27,-36.1"/>
                 </g>
                 </g>
                 </svg>
///

-- writeDotFile
doc ///
    Key
        writeDotFile
        (writeDotFile, String, Graph)
        (writeDotFile, String, Digraph)
    Headline
        Writes a graph to a dot file with a specified filename
    Usage
        writeDotFile(fileName,G)
    Inputs
        G:Graph
        fileName:String
    Description
        Text
            Writes the code for an inputted graph to be constructed in Graphviz with specified file name.
        -- Example
        --     --G = graph({1,2,3,4,5},{{1,3},{3,4},{4,5}});
        --     --writeDotFile("chuck", G)
    SeeAlso
///

--------------------------------
--Graphs: Derivative Graphs
--------------------------------

--barycenter
doc///
    Key
        barycenter
        (barycenter, Graph)
    Headline
        Returns the barycenter of a grah
    Usage
        H = barycenter G
    Inputs
        G:Graph
    Outputs
        H:Graph
            The barycenter of G
    Description
        Text
            The barycenter of a graph is the subgraph induced by all the vertices with eccentricity equal to the graph's radius, in other words, it is the subgraph induced by the center of a graph.
        Example
            barycenter pathGraph 6
            barycenter completeGraph 6
    SeeAlso
        center
///

--complementGraph
doc ///
    Key
        complementGraph
        (complementGraph,Graph)
    Headline
        Returns the complement of a graph
    Usage
        G' = complementGraph G
    Inputs
        G:Graph
    Outputs
        G':Graph
            The complement graph of G
    Description
        Text
            The complement graph of a graph G is the graph G^c where any two vertices are adjacent in G^c iff they are not adjacent in G. The original vertex set is preserved, only the edges are changed.
        Example
            G = cycleGraph 4
            complementGraph G
///


--digraphTranspose
doc ///
    Key
        digraphTranspose
        (digraphTranspose,Digraph)
    Headline
        returns the transpose of a Digraph
    Usage
        G = digraphTranspose D
    Inputs
        D:Digraph
    Outputs
        G:Digraph
            the transpose digraph of D
    Description
        Text
            The transpose of a digraph D is the graph formed by taking every edge (u,v) in D and changing it to (v,u). Intuitively, it reverses the direction of all the edges while keeping the same vertex set.  One can also view the transpose in terms of adjacency matrices, where the adjacency matrix of the transpose of D is the transpose of the adjacency matrix of D. In this way, we quickly see that the transpose of a transpose digraph is the original digraph, and that this operator is trivial for simple graphs since they have symmetric matrices.
        Example
            D = digraph ({{1,2},{2,3},{3,4},{4,1},{1,3},{4,2}},EntryMode=>"edges")
            D' = digraphTranspose D
            D'' = digraphTranspose D'
///

--lineGraph
doc ///
    Key
        lineGraph
        (lineGraph, Graph)
    Headline
        Returns the line graph of an undirected graph
    Usage
        L = lineGraph G
    Inputs
        G:Graph
    Outputs
        L:Graph
            The line graph of G
    Description
        Text
            The line graph L of an undirected graph G is the graph whose
            vertex set is the edge set of the original graph G and in
            which two vertices are adjacent if their corresponding
            edges share a common endpoint in G.
        Example
            G = graph({{1,2},{2,3},{3,4},{4,1},{1,3},{4,2}},EntryMode=>"edges")
            lineGraph G
    SeeAlso
///

--underlyingGraph
doc ///
    Key
        underlyingGraph
        (underlyingGraph, Digraph)
    Headline
        Returns the underlying graph of a digraph
    Usage
        G = underlyingGraph D
    Inputs
        D:Digraph
    Outputs
        G:Graph
            The underlying graph of digraph D
    Description
        Text
            The underlying graph of a digraph is the simple graph constructed by all edges {u,v} such that (u,v) or (v,u) is a directed edge in the digraph.
        Example
            D = digraph hashTable{1 => {2,3}, 2 => {1,3}, 3 => {}};
            underlyingGraph D
    SeeAlso
///

--------------------------------
--Graphs: Enumerators
--------------------------------
--barbellGraph
doc ///
    Key
        barbellGraph
        (barbellGraph, ZZ)
    Headline
        Returns the barbell graph
    Usage
        G = barbellGraph n
    Inputs
        n:ZZ
    Outputs
        G:Graph
            The barbell graph
    Description
        Text
            The barbell graph corresponding to an integer n is formed by the disjoint union of two complete graphs on n vertices joined together by exactly on edge connecting these complete graphs.
        Example
            G = barbellGraph 6
///

--circularLadder
doc ///
    Key
        circularLadder
        (circularLadder, ZZ)
    Headline
        Returns a circular ladder graph
    Usage
        G = circularLadder n
    Inputs
        n:ZZ
    Outputs
        G:Graph
            The circular ladder graph
    Description
        Text
            The circular ladder graph corresponding to an integer n is a ladder of size n with two extra edges that connect the each top vertex with its respective bottom vertex. This creates two cycles, one inside and the other outside, that are connected by edges.
        Example
            G = circularLadder 5
    SeeAlso
        ladderGraph
///

--cocktailParty
doc ///
    Key
        cocktailParty
        (cocktailParty, ZZ)
    Headline
        Returns a cocktail party graph
    Usage
        G = cocktailParty n
    Inputs
        n:ZZ
            The number of vertices on each side; there will be 2*n total vertices
    Outputs
        G:Graph
            The cocktail party graph
    Description
        Text
            The cocktail party graph with respect to an integer n is a graph with 2*n vertices. Its edge set is formed by taking a disjoint union of n path graphs on 2 vertices and taking its complement, yielding an edge set of every possible edge except for those that were initially adjacent on the ladder.
        Example
            cocktailParty 4
///

--completeGraph
doc ///
    Key
        completeGraph
        (completeGraph, ZZ)
    Headline
        Constructs a complete graph
    Usage
        K = completeGraph n
    Inputs
        n:ZZ
    Outputs
        K:Graph
            The complete graph with n vertices
    Description
        Text
            A complete graph on n vertices is a graph in which all the vertices are adjacent to each other.
        Example
            K = completeGraph 5
///

--completeMultipartiteGraph
doc ///
    Key
        completeMultipartiteGraph
        (completeMultipartiteGraph, List)
    Headline
        constructs a complete multipartite graph
    Usage
        G = completeMultipartiteGraph P
    Inputs
        P:List
            if P has k elements, the graph is k-partite. P_i determines how many vertices are in each partite group
    Outputs
        G:Graph
            a complete multipartite graph
    Description
        Text
            A complete multipartite graph is a graph that is first and foremost multi-partite. That is, the vertex set of a complete multipartite graph can be partitioned into k sets such that within each set, none of the vertices are connected by an edge.  The second condition is that each vertex is connected to ever vertex except for those in its partition so that it is "almost" a complete graph. For programming this graph, the input is a list P. The length of the list P will be the number of groups of vertices. For example, in a complete bipartite graph, the length of the list would be 2. The entry P_i will determine how many vertices are in each partition; necessarily, we see that the entries of the list must be positive integers.
        Example
            G = completeMultipartiteGraph {1,2,3}
///

--crownGraph
doc ///
    Key
        crownGraph
        (crownGraph, ZZ)
    Headline
        Returns a crown graph
    Usage
        G = crownGraph n
    Inputs
        n:ZZ
            The number of vertices on each side; there will be 2*n total vertices
    Outputs
        G:Graph
    Description
        Text
            The crown graph with respect to n is a type of bipartite graph. More specifically, it is the complement of the ladder graph with respect to n.
        Example
            crownGraph 4
    SeeAlso
        ladderGraph
///

--cycleGraph
doc ///
    Key
        cycleGraph
        (cycleGraph, ZZ)
    Headline
        Constructs a cycle graph
    Usage
        C = cycleGraph n
    Inputs
        n:ZZ
    Outputs
        C:Graph
            The cycle graph with n vertices
    Description
        Text
            A cycle graph is a graph on n vertices in which all the vertices are in a closed chain of edges.
        Example
            C = cycleGraph 5
///

--doubleStar
doc ///
    Key
        doubleStar
        (doubleStar,ZZ,ZZ)
    Headline
        returns a double star graph
    Usage
        G = doubleStar (m,n)
    Inputs
        n:ZZ
        m:ZZ
    Outputs
        G:Graph
    Description
        Text
            A double star graph is a graph formed by starting with 2 vertices and joining them together. Then each vertex is connected to a fixed amount of leaves (vertices of degree 1) specified by the user in the inputs.
        Example
            G = doubleStar(4,5)
    SeeAlso
        starGraph
        isLeaf
///

--friendshipGraph
doc ///
    Key
        friendshipGraph
        (friendshipGraph, ZZ)
    Headline
        Returns a friendship Graph
    Usage
        G = friendshipGraph n
    Inputs
        n:ZZ
    Outputs
        G:Graph
    Description
        Text
            Friendship graphs of size n are a special case of windmill graphs. A friendship graph of size n is n 3-cycles that all share one common vertex.
        Example
            G = friendshipGraph 4
            H = windmillGraph (3,4)
    SeeAlso
        windmillGraph
///

--generalizedPetersenGraph
doc ///
    Key
        generalizedPetersenGraph
        (generalizedPetersenGraph, ZZ, ZZ)
    Headline
        Returns a generalized petersen graph
    Usage
        G = generalizedPetersenGraph (n, k)
    Inputs
        n:ZZ
            The number of vertices will be 2*n, n in the outer ring and n in the inside ring
        k:ZZ
            The middle ring is a complete graph but looks like a star, k is the number of vertices that get jumped for each connection k must be less than n/2.
    Outputs
        G:Graph
            The generalized petersen graph
    Description
        Text
            The generalized Petersen Graph is a class of graphs with a particular edge set. There are two equal sets of vertices and each set is a cycle graph. This forms two disjoint cyclegraphs. Then each inside edge connects to an adjacent outside edge, similar to the circular ladder graph. The outer loop keeps a more "canonical" order for the cycle, in the sense that it does not "skip" vertices, while the inner cycle takes on a "star-like pattern" that jumps vertices but is still connected.
        Example
            generalizedPetersenGraph (5,2)
            --The standard petersen graph
    SeeAlso
        circularLadder
///

--graphLibrary
doc ///
    Key
        graphLibrary
        (graphLibrary, String)
    Headline
        constructs a graph of a type specified in the string input
    Usage
        G = graphLibrary(name)
    Inputs
        name:String
    Outputs
        G:Graph
            The graph of the type specified by the String name
    Description
        Text
            The graph library takes in a name of a special graph and constructs a graph of that type.  Possible inputs include:  "petersen", "bidiakis cube", "desargues", "dodecahedron", "durer", "claw", "cubical", "f26a", "franklin", "chvatal", "heawood", "paw", "mobius", "nauru", "kite", "house", "bull", "bowtie", "dart".  Each of these create the special graph described clearly by their name.
        Example
            G = graphLibrary("petersen")
            G = graphLibrary("f26a")
            G = graphLibrary("chvatal")
///

--kneserGraph
doc ///
    Key
        kneserGraph
        (kneserGraph, ZZ, ZZ)
    Headline
        constructs a kneser graph of specified size
    Usage
        G = kneserGraph(n,k)
    Inputs
        n:ZZ
        k:ZZ
    Outputs
        G:Graph
            The kneser graph constructed with vertices corresponding to the k-element subsets of a set of n elements.
    Description
        Text
            A kneser graph (n,k) has vertices corresponding to the k-element subsets of a set of n elements, where two vertices are adjacent if and only if their corresponding k-element subsets are disjoint.
        Example
            G = kneserGraph(5,2)
///

--ladderGraph
doc ///
    Key
        ladderGraph
        (ladderGraph, ZZ)
    Headline
        Returns a ladder graph
    Usage
        G = ladderGraph n
    Inputs
        n:ZZ
            The length length of the ladder
    Outputs
        G:Graph
            The ladder Graph
    Description
        Text
            A ladder graph of length n is two path graphs of size n each joined by a set of n edges. The first edge connects the top elements, the second the second elements and the last edge connects the bottom elements, making a 2 by n grid that looks like a ladder.
        Example
            ladderGraph 5
    SeeAlso
        circularLadder
///

--lollipopGraph
doc ///
    Key
        lollipopGraph
        (lollipopGraph, ZZ, ZZ)
    Headline
        constructs a lollipop graph
    Usage
        G = lollipopGraph (m, n)
    Inputs
        m:ZZ
            The number of vertices in the complete graph element
        n:ZZ
            The length of stem coming out of the complete graph element
    Outputs
        G:Graph
            The lollipop graph
    Description
        Text
            A lollipop graph is a graph that is the union of two major elements. The "candy" portion is a complete graph of size m. Coming out of this is the stick or stem, just a path graph of size n. The combination of these yields a lollipop graph.
        Example
            lollipopGraph (6,2)
    SeeAlso
        rattleGraph
///

--monomialGraph
doc///
    Key
        monomialGraph
        (monomialGraph, MonomialIdeal, ZZ)
    Headline
        Returns a monomial graph
    Usage
        G = monomialGraph(I,n)
    Inputs
        I:MonomialIdeal
            This monomial ideal be part of forming a quotient ring with respect to the ambient ring the ideal is in
        n:ZZ
            This integer determines the degree of monomials that will be considered
    Outputs
        G:Graph
            The monomial graph
    Description
        Text
            The monomial graph with respect to a monomial ideal and an integer n is a graph with a vertex set of the monomials of the expression of the sum of the generators of the ambient ring for I to the power n.  The edge set is formed by the rule that there is an edge between two of the vertices (which we are reminded are monomials) if and only if the degree of the least common multiple of the two vertices is n+1.
        Example
            R = QQ[x,y];
            I = monomialIdeal (x^3, y^2*x);
            monomialGraph (I, 3)
    SeeAlso
        lcm
///

--pathGraph
doc///
    Key
        pathGraph
        "pathGraph(ZZ)"
    Headline
        A method that makes a path graph
    Usage
        P = pathGraph n
    Inputs
        n:ZZ
    Outputs
        P:Graph
            the path grah of n vertices
    Description
        Text
            A path graph on n vertices is a cycle graph of n vertices minus one edge.
        Example
            pathGraph 5
    SeeAlso
        cycleGraph
///

--rattleGraph
doc///
    Key
        rattleGraph
        (rattleGraph, ZZ, ZZ)
    Headline
        Returns a rattle graph
    Usage
        G = rattleGraph (n, k)
    Inputs
        n:ZZ
            n determines the amount of vertices for the bulb or rattle part of the graph
        k:ZZ
            k determines the length of the stem coming out of the rattle part of the graph
    Outputs
        G:Graph
    Description
        Text
            The rattle graph is the union of two graphs. The rattle or bulb part of the graph is simply an n-cycle. This n cycle is joined to a stem or handle of a rattle of length k, so the second piece is just a path graph on k vertices.
        Example
            rattleGraph (6, 3)
    SeeAlso
        lollipopGraph
///

--starGraph
doc ///
    Key
        starGraph
        (starGraph, ZZ)
    Headline
        Returns a star graph
    Usage
        G = starGraph n
    Inputs
        n:ZZ
    Outputs
        G:Graph
    Description
        Text
            The star graph is a special class of the general windmill graph class, in particular, it is windmill(2,n). A star graph is best visualized having one vertex in the center of a circle of other vertices.  The edge set is formed by connecting this center vertex to each of the outside vertices. The outside vertices are only connected to the center vertex.
        Example
            starGraph 5
    SeeAlso
        windmillGraph
///

--thresholdGraph
doc ///
    Key
        thresholdGraph
        (thresholdGraph, List)
    Headline
        A method that generates a threshold graph from a binary list
    Usage
        G = thresholdGraph L
    Inputs
        L:List
            This list is of 0's and 1's only
    Outputs
        G:Graph
    Description
        Text
            A threshold graph is a graph that is constructed by starting with an isolated vertex and iteratively adding another isolated vertex or a vertex that shares an edge with each vertex generated before it (the dominating vertices). The isolated vertices are represented by 0's and the dominating vertices are represented by 1's. In this method, the initial vertex is implicit and by default is constructed, so the first entry need not always be 0 in the list.
        Example
            L = {1,0,0,1,0,1}
            thresholdGraph L
///

--wheelGraph
doc ///
    Key
        wheelGraph
        (wheelGraph, ZZ)
    Headline
        Constructs a wheel graph
    Usage
        G = wheelGraph n
    Inputs
        n:ZZ
    Outputs
        G:Graph
            The wheel graph with n vertices
    Description
        Text
            A wheel graph is a cycle graph on n-1 vertices with an extra single vertex adjacent to every vertex in the cycle.
        Example
            G = wheelGraph 6
    SeeAlso
        cycleGraph
        windmillGraph
///

--windmillGraph
doc ///
    Key
        windmillGraph
        (windmillGraph, ZZ, ZZ)
    Headline
        Constructs a windmill graph
    Usage
        G = windmillGraph(k,d)
    Inputs
        k:ZZ
        d:ZZ
    Outputs
        G:Graph
            The windmill graph constructed by joining d copies of the complete graph K_k at a shared vertex.
    Description
        Text
            A whidmill joins d amount of copies of a complete graph on k vertices at exactly one shared vertex.
        Example
            G = windmillGraph(4,5)
    SeeAlso
        completeGraph
        wheelGraph
        starGraph
        friendshipGraph
///

--------------------------------
--Graphs: Cut Properties
--------------------------------

--edgeConnectivity
doc ///
    Key
        edgeConnectivity
        (edgeConnectivity, Graph)
    Headline
        computes the edge connectivity of a graph
    Usage
        C = edgeConnectivity G
    Inputs
        G:Graph
    Outputs
        C:ZZ
            the edge connectivity of a graph
    Description
        Text
            The edge connectivity of a graph is the smallest amount of edges that need be removed from a graph to make it not connected.  This corresponds to the size of the edge cuts.  A not connected graph has edge connectivity equal to 0.
        Example
            G = graph({{1,2},{2,3},{3,1},{3,4},{4,5},{5,3}},EntryMode=>"edges");
            edgeConnectivity G
    SeeAlso
        edgeCuts
        vertexConnectivity
///

--edgeCuts
doc ///
    Key
        edgeCuts
        (edgeCuts, Graph)
    Headline
        returns the edge cuts of a graph
    Usage
        C = edgeCuts G
    Inputs
        G:Graph
    Outputs
        C:List
            the edge cuts of a graph
    Description
        Text
            An edge cut is a minimal set of edges that, when removed from a graph, make the graph not connected.  If the graph is already not connected, the method returns the empty set.
        Example
            G = graph({{1,2},{2,3},{3,1},{3,4},{4,5},{5,3}},EntryMode=>"edges");
            edgeCuts G
    SeeAlso
        vertexCuts
        minimalVertexCuts
        edgeConnectivity
///

--minimalVertexCuts
doc ///
    Key
        minimalVertexCuts
        (minimalVertexCuts, Graph)
    Headline
        finds the minimal vertex cuts of a graph
    Usage
        C = minimalVertexCuts G
    Inputs
        G:Graph
    Outputs
        C:List
            the minimal vertex cuts of a graph
    Description
        Text
            A vertex cut is a set of vertices that, when removed from a graph, make the graph have more than one component.  The minimal vertex cuts are the only the vertex cuts removing only the smallest amount of vertices.  If the graph is complete, it has no vertex cuts, so the method returns an empty list.
        Example
            G = graph({{1,2},{2,3},{3,1},{3,4},{4,5},{5,3}},EntryMode=>"edges");
            minimalVertexCuts G
    SeeAlso
        vertexCuts
        vertexConnectivity
///


--minimalDegree
doc ///
    Key
        minimalDegree
        (minimalDegree, Graph)
    Headline
       computes the minimal degree of a graph 
    Usage
        d = minimalDegree G
    Inputs
        G:Graph
    Outputs
        d:ZZ
            the minimal degree of a graph
    Description
        Text
           This computes the minimal vertex degree of an undirected
           graph.
        Example
            G = graph({{1,2}});
            minimalDegree G
    SeeAlso
        degree
///

--vertexConnectivity
doc ///
    Key
        vertexConnectivity
        (vertexConnectivity, Graph)
    Headline
        computes the vertex connectivity of a graph
    Usage
        C = vertexConnectivity G
    Inputs
        G:Graph
    Outputs
        C:ZZ
            the vertex connectivity of a graph
    Description
        Text
            The vertex connectivity of a graph is the smallest amount of vertices that need be removed from a graph to make it not connected or have one vertex.  This corresponds to the size of the smallest vertex cut.  A not connected graph has connectivity equal to 0.
        Example
            G = graph({{1,2},{2,3},{3,1},{3,4},{4,5},{5,3}},EntryMode=>"edges");
            vertexConnectivity G
    SeeAlso
        minimalVertexCuts
        vertexCuts
        edgeConnectivity
///

--vertexCuts
doc ///
    Key
        vertexCuts
        (vertexCuts, Graph)
    Headline
        lists all the vertex cuts of a graph
    Usage
        C = vertexCuts G
    Inputs
        G:Graph
    Outputs
        C:List
            the list of vertex cuts of a graph
    Description
        Text
            A vertex cut is a set of vertices that, when removed from a graph, make the graph have more than one component.  The complete graph has no vertex cuts, so the method returns an empty list.
        Example
            G = cycleGraph 5;
            vertexCuts G
    SeeAlso
        minimalVertexCuts
        vertexConnectivity
        edgeCuts
///

--------------------------------
--Graphs: Properties
--------------------------------

--breadthFirstSearch
doc ///
    Key
        breadthFirstSearch
        (breadthFirstSearch, Digraph, Thing)
    Headline
        runs a breadth first search on the digraph starting at a specified node
    Usage
        bfs = breadthFirstSearch(D,v)
    Inputs
        D:Digraph
        v:Thing
    Outputs
        bfs:List
            A list of the vertices of D in order discovered by the breadth first search
    Description
        Text
            A breadth first search begins the search at the specified vertex of a digraph, followed by that vertex's children (or in the case of an undirected graph, its neighbors), followed by     their children (or neighbors), etc, until all the descendants are exhausted, and returns a list, such that the list's index number indicates the     depth level of the vertex, of lists of the vertices in order searched.
        Example
            D = digraph ({{0,1},{0,2},{2,3},{3,4},{4,2}},EntryMode=>"edges");
            bfs = breadthFirstSearch(D,0)
            G = cycleGraph 6
            bfs = breadthFirstSearch(G,3)
    SeeAlso
        reverseBreadthFirstSearch
        depthFirstSearch
        topologicalSort
///

--center
doc ///
    Key
        center
        (center,Graph)
    Headline
        Returns the center of a graph
    Usage
        L = center G
    Inputs
        G:Graph
    Outputs
        L:List
            This is a list of the vertices of G that form the center of G
    Description
        Text
            The center of a graph G is defined to be the set of all vertices of G such that the eccentricity of the vertex is equal to the graph's radius. This list often will contain 1 member, for example, path graphs on with an odd amount of vertices.  It can also contain all the vertices (such as complete graphs).
        Example
            center graphLibrary "dart"
    SeeAlso
        barycenter
        eccentricity
        radius
///

--children
doc ///
    Key
        children
        (children, Digraph, Thing)
    Headline
        returns the children of a vertex of a digraph
    Usage
        C = children (D, v)
    Inputs
        D:Digraph
        v:Thing
            the vertex that we want to find the children of
    Outputs
        C:Set
            a set of the children of v
    Description
        Text
            The children of v are the all the vertices u such that {v,u} is in the edge set of the digraph D. So the children of a vertex v are exactly those vertices on a directed graph that v points to.
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            children(D, b)
    SeeAlso
        descendants
///

--chromaticNumber
doc ///
    Key
        chromaticNumber
        (chromaticNumber,Graph)
    Headline
        Computes the chromatic number of a graph
    Usage
        chi = chromaticNumber G
    Inputs
        G:Graph
    Outputs
        chi:ZZ
            The chromatic number of G
    Description
        Text
            The chromatic number of G is chi(G) = min{k | there exists a k-coloring of G}. A k-coloring of G is a partition into k sets of vertices such that in each of these sets, none of the members form edges with each other.
        Example
            G = cycleGraph 5;
            chromaticNumber G
    SeeAlso
        independenceNumber
///

--cliqueComplex
doc ///
    Key
        cliqueComplex
        (cliqueComplex,Graph)
    Headline
        Returns the clique complex of a graph
    Usage
        clG = cliqueComplex G
    Inputs
        G:Graph
    Outputs
        clG: SimplicialComplex
            The clique complex of G
    Description
        Text
            The clique complex of a graph G is the set of all cliques of G.
        Example
            G = graph(toList(1..4),{{1, 2}, {1, 3}, {2, 3}, {3, 4}});
            cliqueComplex G
    SeeAlso
        independenceComplex
        cliqueNumber
///

-- cliqueNumber
doc ///
    Key
        cliqueNumber
        (cliqueNumber,Graph)
    Headline
        Returns the clique number of a graph
    Usage
        omega = cliqueComplex G
    Inputs
        G:Graph
    Outputs
        omega:ZZ
            the clique number of G
    Description
        Text
            The clique number is the maximum number of vertices comprising a clique in G. A clique in a graph G is a set of vertices such that all the vertices are mutually adjacent (they are all connected to each other).
        Example
            G = graph({{1, 2}, {1, 3}, {2, 3}, {3, 4}},EntryMode=>"edges");
            cliqueNumber G
    SeeAlso
        independenceNumber
        cliqueComplex
///

--closedNeighborhood
doc ///
    Key
        closedNeighborhood
        (closedNeighborhood, Graph, Thing)
    Headline
        Returns the closed neighborhood of a vertex of a graph
    Usage
        N = closedNeighborhood(G,v)
    Inputs
        G:Graph
        v:Thing
    Outputs
        N:List
            The closed neighborhood of vertex v in graph G
    Description
        Text
            The closed neighborhood of a vertex v just the union of the open neighborhood (or neighbors) of v and the vertex v itself
        Example
            G = cycleGraph 4;
            closedNeighborhood(G,2)
    SeeAlso
        neighbors
///

--missing documentation for clusteringCoefficient

--connectedComponents
doc ///
    Key
        (connectedComponents, Graph)
    Headline
        Computes the connected components of a graph
    Usage
        C = connectedComponents G
    Inputs
        G:Graph
    Outputs
        C:List
            The list of connected components of G
    Description
        Text
            A connected component is a list of vertices of a graph that are connected, in other words there exists a path of edges between any two vertices in the component.
        Example
            G = graph(toList(1..8),{{1,2},{2,3},{3,4},{5,6}});
            connectedComponents G
    SeeAlso
        isConnected
        numberOfComponents
///

--coverIdeal
doc ///
    Key
        coverIdeal
        (coverIdeal, Graph)
    Headline
        Returns the vertex cover ideal of a graph
    Usage
        J = coverIdeal G
    Inputs
        G:Graph
    Outputs
        J:Ideal
            The vertex cover ideal of a graph G
    Description
        Text
            The vertex cover ideal of a graph G is the ideal generated by (m_s | s in [n] is a vertex cover of G), where m_s = product_(i in S)(x_i)
        Example
            G = graph({{1, 2}, {1, 3}, {2, 3}, {3, 4}},EntryMode=>"edges");
            coverIdeal G
    SeeAlso
        edgeIdeal
        vertexCovers
        vertexCoverNumber
///

--criticalEdges
doc ///
    Key
        criticalEdges
        (criticalEdges, Graph)
    Headline
        Finds the critical edges of a graph
    Usage
        C = criticalEdges G
    Inputs
        G:Graph
    Outputs
        C:List
            the critical edges of G
    Description
        Text
            A critical edge is an edge such that the removal of the edge from the graph increases the graph's independence number.
        Example
            G = graph({{1,2},{2,3},{3,1},{3,4},{4,1},{4,2},{4,5}},EntryMode=>"edges");
            criticalEdges G
    SeeAlso
            independenceNumber
///

--degeneracy
doc ///
    Key
        degeneracy
        (degeneracy, Graph)
    Headline
        Computes the degeneracy of a graph
    Usage
        d = degeneracy G
    Inputs
        G:Graph
    Outputs
        d:ZZ
    Description
        Text
            The degeneracy of a graph is the maximum degree of all vertices in any subgraph of G.  This is essentially equivalent to the coloring number of G, which is the least number k such that there exists an ordering of the vertices of G in which each vertex has less than k neighbors earlier in the ordering.  The coloring number is equal to the degeneracy plus one.
        Example
            G = completeGraph 10;
            degeneracy G
    SeeAlso
///

--degreeCentrality
doc ///
    Key
        degreeCentrality
        (degreeCentrality, Graph, Thing)
    Headline
        Returns the degreeCentrality of a vertex of a graph
    Usage
        x = degreeCentrality (G, v)
    Inputs
        G:Graph
        v:Thing
            v must be a vertex of G
    Outputs
        x:RR
            x is a real number between 0 and 1
    Description
        Text
            The degreeCentrality of a vertex of a graph is the degree of a vertex divided by 2 times the number of edges of the graph.  Intuitively, this number will give a measure of how "central" a vertex is in a graph. In other words, if a vertex has a relatively high degreeCentrality, it is connected to more vertexSet than other vertexSet of G, so it is more central or a bottleneck in the graph. Note that the sum of the degree centralities must be 1.
        Example
            L = apply(vertexSet pathGraph 5, i -> degreeCentrality (pathGraph 5, i))
            sum L
    SeeAlso
        center
        distance
        degree
///

--degreeIn
doc ///
    Key
        degreeIn
        (degreeIn, Digraph, Thing)
    Headline
        returns the "in-degree" of a vertex in a digraph
    Usage
        x = degreeIn (D, v)
    Inputs
        D:Digraph
        v:Thing
            a vertex of D
    Outputs
        x:ZZ
    Description
        Text
            In a directed graph, we define the degree into a vertex or the "in-degree" of a vertex to be the number of parents of that vertex. Intuitively, this give the number of edges that point into the vertex.
        Example
            D = digraph({1,2,3,4},{{1,2},{2,3},{3,4},{4,2}});
            degreeIn(D, 2)
    SeeAlso
        degree
        degreeOut
        parents
///

--degreeOut
doc ///
    Key
        degreeOut
        (degreeOut, Digraph, Thing)
    Headline
        returns the "out-degree" of a vertex in a digraph
    Usage
        x = degreeIn (D, v)
    Inputs
        D:Digraph
        v:Thing
            a vertex of D
    Outputs
        x:ZZ
    Description
        Text
            In a directed graph, we define the degree out of a vertex or the "out-degree" of a vertex to be the number of children of that vertex. Intuitively, this give the number of edges pointing out of a vertex to another vertex.
        Example
            D = digraph({1,2,3,4},{{1,2},{2,3},{3,4},{4,2}});
            degreeOut(D, 2)
    SeeAlso
        degree
        degreeIn
        children
///

--density
doc ///
    Key
        density
        (density, Graph)
    Headline
        computes the density of a graph
    Usage
        d = density G
    Inputs
        G:Graph
    Outputs
        d:QQ
            the density of G
    Description
        Text
            A dense graph has a high edge to vertex ratio, whereas a sparse graph has a low edge to vertex ratio.  Density is equal to 2*|E| divided by |V|*(|V|-1).  A complete graph has density 1; the minimal density of any graph is 0.
        Example
            G = graph({{1,2},{2,3},{3,4},{4,2},{1,4}},EntryMode=>"edges");
            density G
    SeeAlso
        degreeCentrality
///

--depthFirstSearch
doc ///
    Key
        depthFirstSearch
        (depthFirstSearch, Digraph)
    Headline
        runs a depth first search on the digraph
    Usage
        dfs = depthFirstSearch D
        dfs = depthFirstSearch G
    Inputs
        D:Digraph
        G:Graph
    Outputs
        dfs:HashTable
            A hash table with keys discoveryTime and finishingTime, whose values are hash tables containing for each vertex the discovery time and finishing time, respectively.
    Description
        Text
            A depth first search begins at the first vertex of a graph as a root and searches as far as possible along one branch from that root before backtracking to the next branch to the right. Discovery time denotes the order in which the vertex was searched first; finishing time denotes the time in which the vertex's descendents were all finished.
        Example
            D = digraph ({{0,1},{1,3},{1,4},{4,7},{4,8},{0,2},{2,5},{2,6}},EntryMode=>"edges")
            dfs = depthFirstSearch D
            G = cycleGraph 6
            dfs = depthFirstSearch G
    SeeAlso
        breadthFirstSearch
        topologicalSort
///

--descendants
doc ///
    Key
        descendants
        (descendants, Digraph, Thing)
    Headline
        returns the descendants of a digraph
    Usage
        L = descendants (D, v)
    Inputs
        D:Digraph
        v:Thing
            a vertex of the digraph
    Outputs
        L:Set
            a set of all the descendants of v
    Description
        Text
            The descendants of a directed graph are all the vertexSet u of D such that u is reachable from v.
            Another way to more intuitively see what the descendants are is to see the descendants of a vertex v
            can be found by first taking the children of v. Then if you take the children of each of the
            children, and continue the process until the list stops growing, this will form all the descendants of v.
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            descendants (D, a)
    SeeAlso
        children
        isReachable
        nondescendants
///

--diameter
doc ///
    Key
        (diameter, Graph)
    Headline
        Computes the diameter of a graph
    Usage
        d = diameter G
    Inputs
        G:Graph
    Outputs
        d:ZZ
            The diameter of G
    Description
        Text
            The diameter of a graph is the maximum of the distances between all the vertexSet of G.  If the graph is not connected, the diameter is infinity.
        Example
            G = graph({{1,2},{2,3},{3,4}},EntryMode=>"edges");
            d = diameter G
            G = graph({1,2,3,4},{{2,3},{3,4}});
            d = diameter G
    SeeAlso
        distance
        distanceMatrix
///

--distance
doc ///
    Key
        distance
        (distance, Digraph, Thing, Thing)
    Headline
        Computes the distance between two vertexSet in a graph
    Usage
        d = distance(G,v,u)
    Inputs
        G:Graph
        v:Thing
        u:Thing
    Outputs
        d:ZZ
            The distance between vertexSet v and u
    Description
        Text
            The distance between two vertexSet is calculated as the number of edges in the shortest path between the two vertexSet.  If the two vertexSet are not connected, the distance between them is infinity by convention.
        Example
            G = graph({{1,2},{2,3},{3,4}},EntryMode=>"edges");
            d = distance (G,1,4)
            G = graph({1,2,3,4},{{2,3},{3,4}});
            d = distance(G, 1, 4)
    SeeAlso
        (diameter, Graph)
        distanceMatrix
///

--distanceMatrix
doc ///
    Key
        distanceMatrix
        (distanceMatrix, Digraph)
    Headline
        Computes the distance matrix of a digraph
    Usage
        M = distanceMatrix(G)
    Inputs
        G:Digraph
    Outputs
        M:Matrix
            the distance matrix of G
    Description
        Text
            The distance matrix is the matrix where entry M_(i,j) corresponds to the distance between vertex indexed i and vertex indexed j in the specified graph.  If the distance between two vertexSet is infinite (i.e. the vertexSet are not connected) the matrix lists the distance as -1.
        Example
            G = graph({{1,2},{2,3},{3,4}},EntryMode=>"edges");
            d = distanceMatrix G
            G = digraph({1,2,3,4},{{2,3},{3,4}},EntryMode=>"edges");
            d = distanceMatrix G
    SeeAlso
        (diameter, Graph)
        distance
///

--eccentricity
doc ///
    Key
        eccentricity
        (eccentricity,Graph,Thing)
    Headline
        Returns the eccentricity of a vertex of a graph
    Usage
        k = eccentricity (G, v)
    Inputs
        G:Graph
            G must be a connected graph
        v:Thing
            v needs to be a vertex of the graph
    Outputs
        k:ZZ
    Description
        Text
            The eccentricity of a vertex is the maximal distance between the given vertex and any other vertex in the graph. It gives a measure of how far away a vertex is from the rest of the graph.
        Example
            eccentricity(pathGraph 5, 2)
            eccentricity(pathGraph 5, 1)
            eccentricity(pathGraph 5, 0)
    SeeAlso
        distance
        radius
        isConnected
///

--edgeIdeal
doc ///
    Key
        edgeIdeal
        (edgeIdeal, Graph)
    Headline
        returns the edge ideal of a graph
    Usage
        I = edgeIdeal G
    Inputs
        G:Graph
    Outputs
        I:Ideal
            the edge ideal of a graph G
    Description
        Text
            The edge ideal of a graph G is the ideal generated by the minimal nonfaces of the independence complex of G.
        Example
            G = graph({{1, 2}, {1, 3}, {2, 3}, {3, 4}},EntryMode=>"edges");
            edgeIdeal G
    SeeAlso
        coverIdeal
        independenceComplex
///

--expansion
doc ///
    Key
        expansion
        (expansion, Graph)
    Headline
        returns the expansion of a graph
    Usage
        h=expansion G
    Inputs
        G:Graph
    Outputs
        h:QQ
            the expansion of a graph G
    Description
        Text
            The expansion of a subset S of vertices is the ratio of
            the number of edges leaving S and the size of S. The
            (edge) expansion of a graph G is the minimal expansion of
            all not too large subsets of the vertex set. The expansion
            of a disconnected graph is 0 whereas the expansion of the
            complete graph on n vertices is ceiling(n/2)
        Example
            G = graph({{1, 2}, {1, 3}, {2, 3}, {3, 4}},EntryMode=>"edges");
            expansion G
            expansion pathGraph 7
            
///

--findPaths
doc ///
    Key
        findPaths
        (findPaths, Digraph, Thing, ZZ)
    Headline
        finds all the paths in a digraph of a given length starting at a given vertex
    Usage
        F = findPaths(D,v,l)
    Inputs
        D:Digraph
        v:Thing
            vertex at which paths start
        l:ZZ
            length of desired paths
    Outputs
        F:List
            list of paths starting at v of length l
    Description
        Text
            The method will return a list of all the paths of length l starting at a vertex v in the digraph D.  The method is compatible for graphs with loops or cycles, as variables can be repeatedly visited in paths.
        Example
            D = digraph(toList(1..5), {{1,2},{1,3},{2,5},{2,4}})
            F = findPaths(D,1,2)
            D = digraph(toList(a..d), {{a,c},{a,b},{b,b},{b,d}})
            F = findPaths(D,a,100)
    SeeAlso
        distance
        distanceMatrix
///

--floydWarshall
doc ///
    Key
        floydWarshall
        (floydWarshall, Digraph)
    Headline
        runs the Floyd-Warshall algorithm on a digraph to determine the minimum distance from one vertex
    Usage
        F = floydWarshall D
    Inputs
        D:Digraph
    Outputs
        F:HashTable
            A hash table with the keys representing pairs of vertexSet (u,v) and the value being the distance from u to v.
    Description
        Text
            The distance from one vertex u to another v in digraph D is the minimum number of edges forming a path from u to v.  If v is not reachable from u, the distance is infinity; if u = v, the distance is 0.
        Example
            D = digraph({{0,1},{0,2},{2,3},{3,4},{4,2}},EntryMode=>"edges")
            F = floydWarshall D
    SeeAlso
        distance
        distanceMatrix
///

--forefathers
doc ///
    Key
        forefathers
        (forefathers,Digraph,Thing)
	symbol foreFathers
    Headline
        returns the forefathers of a digraph
    Usage
        L = forefathers (D, v)
    Inputs
        D:Digraph
        v:Thing
            v must be a vertex of D
    Outputs
        L:Set
            a set of all the forefathers of v in D
    Description
        Text
            The forefathers of a vertex v in a digraph D are all the vertexSet u in D such that v is reachable from u. Another way to more intuitively see what the forefathers are is to see the forefathers of a vertex v can be found by first taking the parents of v. Then if you find the parents of each of the parents of v, and continue the process until the list stops growing, this will form all the descendants of v.
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            forefathers (D, d)
    Caveat
        The forefathers of a vertex in a digraph are more commonly known as the ancestors. But ancestors is an entirely different function in Macaulay 2, so forefathers is the convention we will use
    SeeAlso
        isReachable
        parents
///

--girth
doc ///
    Key
        girth
        (girth, Graph)
    Headline
        A method for computing the girth of a graph
    Usage
        g = girth G
    Inputs
        G:Graph
    Outputs
        g:ZZ
            the girth of G
    Description
        Text
            This method computes the girth (the smallest n such that G contains an n-cycle) of any graph. If the graph has no n-cycle as a subgraph, the output will be infinity.
        Example
            girth completeGraph 6
            girth pathGraph 6
///

--independenceComplex
doc ///
    Key
        independenceComplex
        (independenceComplex, Graph)
    Headline
        constructs the independence complex of a graph
    Usage
        indG = independenceComplex G
    Inputs
        G:Graph
    Outputs
        indG:SimplicialComplex
            the independence complex of G
    Description
        Text
            The independence complex of a graph G is the set of all the independent sets of G.
        Example
            G = graph({{1,2},{2,3},{3,4},{4,5}},EntryMode=>"edges");
            independenceComplex G
    SeeAlso
        independenceNumber
        cliqueComplex
///

--independenceNumber
doc ///
    Key
        independenceNumber
        (independenceNumber, Graph)
    Headline
        computes the independence number of a graph
    Usage
        alpha = independenceNumber G
    Inputs
        G:Graph
    Outputs
        alpha:ZZ
            the independence number of G
    Description
        Text
            The independence number of a graph G is the maximum number of vertexSet in any independent set of G.
        Example
            G = graph({{1,2},{2,3},{3,4},{4,5}},EntryMode=>"edges");
            independenceNumber G
    SeeAlso
        independenceComplex
        cliqueNumber
///

--leaves
doc ///
    Key
        leaves
        (leaves, Graph)
    Headline
        lists the leaves of a tree graph
    Usage
        L = leaves G
    Inputs
        G:Graph
    Outputs
        L:List
            list of leaves of a tree graph
    Description
        Text
            A vertex of a tree graph is a leaf if the degree of the vertex is 1
        Example
            G = graph({{1,2},{1,3},{3,4},{3,5}},EntryMode=>"edges");
            leaves G;
    SeeAlso
        isForest
        isLeaf
        isTree
///

--lowestCommonAncestors
doc ///
    Key
        lowestCommonAncestors
        (lowestCommonAncestors, Digraph, Thing, Thing)
    Headline
        determines the lowest common ancestors between two vertexSet
    Usage
        A = lowestCommonAncestors(D,u,v)
    Inputs
        D:Digraph
        u:Thing
        v:Thing
    Outputs
        A:List
            A list of the lowest common ancestors of u and v
    Description
        Text
            The lowest common ancestors between two vertexSet are the vertexSet that are ancestors of both u and v and are the shortest distance from the vertexSet in the digraph.
        Example
            D = digraph({{0,1},{0,2},{2,3},{3,4},{4,2}},EntryMode=>"edges");
            A = lowestCommonAncestors(D,1,3)
    SeeAlso
        reverseBreadthFirstSearch
        forefathers
///

-- neighbors
doc ///
    Key
        neighbors
        (neighbors, Graph, Thing)
    Headline
        returns the neighbors of a vertex in a graph
    Usage
        N = neighbors(G,v)
    Inputs
        G:Graph
        v:Thing
    Outputs
        N:Set
            the neighbors of vertex v in graph G
    Description
        Text
            The neighbors of a vertex v are all the vertexSet of G adjacent to v. That is, if u is a neighbor to v, {v,u} is an edge of G.
        Example
            G = graph({1,2,3,4},{{2,3},{3,4}});
            neighbors(G,3)
    SeeAlso
        nonneighbors

///

--nondescendants
doc ///
    Key
        nondescendants
        (nondescendants, Digraph, Thing)
    Headline
        returns the nondescendants of a vertex of a digraph
    Usage
        L = nondescendants (D, v)
    Inputs
        D:Digraph
        v:Thing
            a vertex of the digraph
    Outputs
        L:Set
            a set of all the nondescendants of v
    Description
        Text
            The nondescendants of a directed graph are all the vertexSet u of D such that u is not reachable from v.
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            nondescendants (D, d)
    SeeAlso
        children
        descendants
        isReachable
///

--nonneighbors
doc ///
    Key
        nonneighbors
        (nonneighbors, Graph, Thing)
    Headline
        returns the non-neighbors of a vertex in a graph
    Usage
        N = nonneighbors(G,v)
    Inputs
        G:Graph
        v:Thing
    Outputs
        N:Set
            the non-neighbors of vertex v in graph G
    Description
        Text
            The non-neighbors of a vertex v are all the vertexSet of G that are not adjacent to v. That is, if u is a non-neighbor to v, {u,v} is not an edge in G.
        Example
            G = graph({1,2,3,4},{{2,3},{3,4}});
            nonneighbors(G,2)
    SeeAlso
        neighbors
///

--numberOfComponents
doc ///
    Key
        numberOfComponents
        (numberOfComponents, Graph)
    Headline
        computes the number of connected components of a graph
    Usage
        n = numberOfComponents G
    Inputs
        G:Graph
    Outputs
        n:ZZ
            the number of connected components of G
    Description
        Text
            A connected component is a list of vertexSet of a graph that are connected, i.e. there exists a path of edges between any two vertexSet in the component.
        Example
            G = graph(toList(1..8),{{1,2},{2,3},{3,4},{5,6}});
            numberOfComponents G;
    SeeAlso
        isConnected
        connectedComponents
///

--numberOfTriangles
doc ///
    Key
        numberOfTriangles
        (numberOfTriangles, Graph)
    Headline
        counts how many subtriangles are present in a graph
    Usage
        t = numberOfTriangles G
    Inputs
        G:Graph
    Outputs
        t:ZZ
            number of subtriangles in a graph
    Description
        Text
            A triangle is formed by three vertexSet which are mutually adjacent.
        Example
            G = graph({{1,2},{2,3},{3,1},{3,4},{2,4}},EntryMode=>"edges");
            numberOfTriangles G
    SeeAlso
        hasOddHole
        isCyclic
        inducedSubgraph
///

--parents
doc ///
    Key
        parents
        (parents, Digraph, Thing)
    Headline
        returns the parents of a vertex on a digraph
    Usage
        P = parents (D, v)
    Inputs
        D:Digraph
        v:Thing
            the vertex whose parents we want to find
    Outputs
        P:Set
            the parents of v
    Description
        Text
            The parents of a vertex v in a digraph D are all the vertexSet u in D such that {u,v} is an edge of D. In other words, the parents of v are all the vertexSet that have edges coming out of them that point at v.
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            parents (D, b)
    SeeAlso
        forefathers
///

--radius
doc ///
    Key
        radius
        (radius,Graph)
    Headline
        Returns the radius of a graph
    Usage
        r = radius G
    Inputs
        G:Graph
    Outputs
        r:ZZ
    Description
        Text
            The radius of a graph is defined to be the minimum of the eccentricities of the vertexSet, i.e, the smallest number k such that for some vertex v, the distance between v and another vertex is less than or equal to k.
        Example
            radius completeGraph 5
            radius pathGraph 5
            radius graphLibrary "dart"
    SeeAlso
        eccentricity
        barycenter
        distance
///

--reachable
doc ///
    Key
        reachable
        (reachable,Digraph,List)
        (reachable,Digraph,Set)
    Headline
        Returns the vertices reachable in a digraph from a given collection of vertices
    Usage
        Rl = reachable(D, L)
        Rs = reachable(D, S)
    Inputs
        D:Digraph
        L:List
            a list of vertices
        S:Set
            a set of vertices
    Outputs
        Rl:List
            the list of reachable vertices
        Rs:Set
            the set of reachable vertices
    Description
        Text
            Given a collection of vertices of a digraph, the reachable vertices are those
            that are on a path away from a vertices in the collection.
    SeeAlso
        descendants
        isReachable
///

--reverseBreadthFirstSearch
doc ///
    Key
        reverseBreadthFirstSearch
        (reverseBreadthFirstSearch, Digraph, Thing)
    Headline
        runs a reverse breadth first search on the digraph starting at a specified node
    Usage
        bfs = reverseBreadthFirstSearch(D,v)
    Inputs
        D:Digraph
    Outputs
        bfs:List
            A list of the vertexSet of D in order discovered by the breadth first search
    Description
        Text
            A reverse breadth first search first searches the specified of a digraph, followed by that vertex's parents, followed by their parents, etc, until all the ancestors are exhausted, and returns a list, with the index of the item of the list signifying the     depth level of the result, of the vertexSet in order searched.
        Example
            D = digraph ({{0,1},{0,2},{2,3},{3,4},{4,2}},EntryMode=>"edges")
            bfs = reverseBreadthFirstSearch(D,2)
    SeeAlso
        breadthFirstSearch
        depthFirstSearch
        topologicalSort
///

--sinks
doc ///
    Key
        sinks
        (sinks, Digraph)
    Headline
        returns the sinks of a digraph
    Usage
        L = sinks D
    Inputs
        D:Digraph
            digraph whose sinks we are searching for
    Outputs
        L:List
            list of all the sinks (if there are any)
    Description
        Text
            A sink of a Digraph D is a vertex of D that has no children. That is, v is a sink of D if and only if there are only edges pointing into v; none can be pointing out (there is no edge of the form (v,u)).
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            sinks D
    SeeAlso
        sources
        isSink
///

--sources
doc ///
    Key
        sources
        (sources, Digraph)
    Headline
        returns the sources of a digraph
    Usage
        L = sources D
    Inputs
        D:Digraph
            digraph whose sources we are searching for
    Outputs
        L:List
            list of all the sources (if there are any)
    Description
        Text
            A source of a Digraph D is a vertex of D that has no parents. That is, v is a source of D if and only if there are only edges pointing from v; none can be pointing into v (there is no edge of the form (v,u)).
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            sources D
    SeeAlso
        sinks
        isSource
///

--spectrum
doc ///
    Key
        spectrum
        (spectrum, Graph)
    Headline
        Returns the spectrum of a graph
    Usage
        L = spectrum G
    Inputs
        G:Graph
    Outputs
        L:List
    Description
        Text
            The spectrum of a graph G is the set of the eigenvalues of the adjacency matrix A corresponding to G. For simple graphs, these eigenvalues are all real since A must be symmetric. The user should be aware that Macaulay 2 does not give exact values for these eigenvalues, they are numerical approximations, but it is still a good tool to use to check if two graphs are isomorphic; isomorphic graphs share the same spectrum although the converse is not necessarily true.
        Example
            spectrum completeGraph 6
            spectrum graphLibrary "petersen"
///

--vertexCoverNumber
doc ///
    Key
        vertexCoverNumber
        (vertexCoverNumber, Graph)
    Headline
        returns the vertex cover number of a graph
    Usage
        v = vertexCoverNumber G
    Inputs
        G:Graph
    Outputs
        v:ZZ
            the vertex cover number of graph G
    Description
        Text
            The vertex cover number is the minimum length of the set of vertex covers of a graph.
        Example
            G = graph({{1,2},{1,3},{1,4},{2,3}},EntryMode=>"edges");
            vertexCoverNumber G
    SeeAlso
        vertexCovers
        coverIdeal
///

--vertexCovers
doc ///
    Key
        vertexCovers
        (vertexCovers, Graph)
    Headline
        returns a list of the minimal vertex covers of a graph
    Usage
        V = vertexCovers G
    Inputs
        G:Graph
    Outputs
        V:List
            the list of minimal vertex covers of graph G
    Description
        Text
            A vertex cover of G is a set of vertexSet which intersects with every edge of G. In other words, L is a vertex cover of a graph if and only if their does not exist an edge {u,v} such that both u and v are not in L.
        Example
            G = graph({{1,2},{1,3},{1,4},{2,3}},EntryMode=>"edges");
            vertexCovers G
    SeeAlso
        vertexCoverNumber
        coverIdeal
///

------------------------------------------
--Boolean Methods
------------------------------------------

--hasEulerianTrail
doc ///
    Key
        hasEulerianTrail
        (hasEulerianTrail, Graph)
        (hasEulerianTrail, Digraph)
    Headline
        determines whether a graph or a digraph has an Eulerian trail
    Usage
        E = hasEulerianTrail G
        E = hasEulerianTrail D
    Inputs
        G:Graph
        D:Digraph
    Outputs
        E:Boolean
            whether G or D has an Eulerian trail
    Description
        Text
            A graph has an Eulerian trail if there is a path in the graph that visits each edge exactly once.  A digraph has a Eulerian trail if there is a directed path in the graph that visits each edge exactly once.  An Eulerian trail is also called an Eulerian path.  Unconnected graphs can have a Eulerian trail, but all vertices of degree greater than 0 of a graph (or all vertices of degree greater than 0 in the underlying graph of a digraph) must belong to a single connected component.
        Example
            G = cycleGraph 5;
            hasEulerianTrail G
            D = digraph(toList(1..4), {{1,2},{2,3},{3,4}});
            hasEulerianTrail D
    SeeAlso
        isEulerian
///


--hasOddHole
doc ///
    Key
        hasOddHole
        (hasOddHole, Graph)
    Headline
        checks whether a graph has a odd hole
    Usage
        oddHole = hasOddHole G
    Inputs
        G:Graph
    Outputs
        oddHole:Boolean
            whether the graph has an odd hole
    Description
        Text
            A graph has an odd hole if it has an induced cycle that is odd and has length of at least 5.
        Example
            G = graph({{1,2},{2,3},{3,4},{4,5}},EntryMode=>"edges");
            hasOddHole G
    SeeAlso
        cycleGraph
        isPerfect
        isChordal
///

--isBipartite
doc ///
    Key
        isBipartite
        (isBipartite, Graph)
    Headline
        determines whether a graph is bipartite
    Usage
        b = isBipartite G
    Inputs
        G:Graph
    Outputs
        b:Boolean
            whether graph G is bipartite
    Description
        Text
            A graph is bipartite if it has a chromatic number less than or equal to 2.
        Example
            G = graph({{0,1},{1,2},{2,4},{3,4},{4,5}},EntryMode=>"edges");
            isBipartite G
    SeeAlso
        bipartiteColoring
///

--isCM
doc ///
    Key
        isCM
        (isCM, Graph)
    Headline
        determines if a graph is Cohen-Macaulay
    Usage
        c = isCM G
    Inputs
        G:Graph
    Outputs
        c:Boolean
            whether the graph is Cohen-Macaulay
    Description
        Text
            This uses the edge ideal notion of Cohen-Macaulayness; a graph is called C-M if and only if its edge ideal is C-M.
        Example
            G = graph({{1,2},{1,3},{1,4},{2,5},{5,3},{3,2}},EntryMode=>"edges");
            isCM G
    SeeAlso
        edgeIdeal
///

--isChordal
doc ///
    Key
        isChordal
        (isChordal, Graph)
    Headline
        checks whether a graph is chordal
    Usage
        c = isChordal G
    Inputs
        G:Graph
    Outputs
        c:Boolean
            whether the graph is chordal
    Description
        Text
            A graph is chordal if its cycles with at least four vertices contain at least one edge between two vertices which are not adjacent in the cycle.
        Example
            G = graph({{1,2},{2,3},{3,4},{4,1},{2,4}}, EntryMode => "edges");
            isChordal G
    SeeAlso
        cycleGraph
        isPerfect
        hasOddHole
///

--isConnected
doc ///
    Key
        isConnected
        (isConnected, Graph)
    Headline
        determines whether a graph is connected
    Usage
        C = isConnected G
    Inputs
        G:Graph
    Outputs
        C:Boolean
            whether a graph is connected
    Description
        Text
            A graph is connected when there exists a path of edges between any two vertices in the graph.
        Example
            G = graph({{1,2},{2,3},{3,4},{5,6}},EntryMode=>"edges");
            isConnected G;
    SeeAlso
        connectedComponents
        numberOfComponents
///

--isCyclic
doc ///
    Key
        isCyclic
        (isCyclic, Graph)
    Headline
        determines whether a graph is cyclic
    Usage
        c = isCyclic G
    Inputs
        G:Graph
    Outputs
        c:Boolean
            whether a graph is cyclic
    Description
        Text
            A graph is cyclic if it is composed of vertices connected by a single chain of edges.
        Example
            G = graph({{1,2},{2,3},{3,1}},EntryMode=>"edges");
            isCyclic G
            G = graph({{1,2},{2,3},{3,4}},EntryMode=>"edges");
            isCyclic G
    SeeAlso
        cycleGraph
///

--isCyclic
doc ///
    Key
        (isCyclic, Digraph)
    Headline
        determines whether a digraph is cyclic
    Usage
        C = isCyclic D
    Inputs
        D:Digraph
    Outputs
        C:Boolean
            Whether the digraph D is cyclic
    Description
        Text
            A digraph is cyclic if it contains a cycle, i.e. for some vertex v of D, by following the edges of D, one can return to v.
        Example
            D = digraph ({{0,1},{0,2},{2,3},{3,4},{4,2}},EntryMode=>"edges")
            isCyclic D
    SeeAlso
        isCyclic
        --the isCyclic method for graphs!
///

--isEulerian
doc ///
    Key
        isEulerian
        (isEulerian, Graph)
        (isEulerian, Digraph)
    Headline
        determines if a graph or digraph is Eulerian
    Usage
        E = isEulerian G
        E = isEulerian D
    Inputs
        G:Graph
        D:Digraph
    Outputs
        E:Boolean
            whether G or D is Eulerian
    Description
        Text
            A graph is Eulerian if it has a path in the graph that visits each vertex exactly once.  A digraph is Eulerian if it has a directed path in the graph that visits each vertex exactly once.  Such a path is called an Eulerian circuit.  Unconnected graphs can be Eulerian, but all vertices of degree greater than 0 of a graph (or all vertices of degree greater than 0 in the underlying graph of a digraph) must belong to a single connected component.
        Example
            bridges = graph ({{0,1},{0,2},{0,3},{1,3},{2,3}}, EntryMode => "edges");
            E = isEulerian bridges
            D = digraph(toList(1..4), {{2,3},{3,4},{4,2}});
            E = isEulerian D
    SeeAlso
        hasEulerianTrail
///

--isForest
doc ///
    Key
        isForest
        (isForest, Graph)
    Headline
        determines whether a graph is a forest
    Usage
        f = isForest G
    Inputs
        G:Graph
    Outputs
        f:Boolean
            whether a graph is a forest
    Description
        Text
            A graph is a forest if it is a disjoint collection of trees.
        Example
            G = graph({{1,2},{1,3},{6,4},{4,5}},EntryMode=>"edges");
            isForest G
    SeeAlso
        isTree
        isLeaf
        leaves
///

--isLeaf
doc ///
    Key
        isLeaf
        (isLeaf, Graph, Thing)
    Headline
        determines whether a vertex is a leaf
    Usage
        l = isLeaf(G,v)
    Inputs
        G:Graph
        v:Thing
    Outputs
        l:Boolean
            whether vertex v of graph G is a leaf
    Description
        Text
            A vertex of a tree graph is a leaf if its degree is 1
        Example
            G = graph({{1,2},{1,3},{3,4},{3,5}},EntryMode=>"edges");
            isLeaf(G,2)
    SeeAlso
        isForest
        isTree
        leaves
///

--isPerfect
doc ///
    Key
        isPerfect
        (isPerfect, Graph)
    Headline
        checks whether a graph is perfect
    Usage
        p = isPerfect G
    Inputs
        G:Graph
    Outputs
        p:Boolean
            whether the graph is perfect
    Description
        Text
            A perfect graph is a graph where the chromatic number of every induced subgraph of G is equal to the clique number in that subgraph.
        Example
            G = graph {{1,2},{1,3},{1,4},{2,5},{5,3},{3,2}};
            isPerfect G
    SeeAlso
        chromaticNumber
        cliqueNumber
        hasOddHole
///

--isReachable
doc ///
    Key
        isReachable
        (isReachable, Digraph, Thing, Thing)
    Headline
        checks if a vertex u is reachable from a vertex v
    Usage
        r = isReachable(D, u, v)
    Inputs
        D:Digraph
        u:Thing
            this is the vertex that we are attempting to reach
        v:Thing
            this is the vertex that we are starting from
    Outputs
        r:Boolean
            whether or not us is reachable from v
    Description
        Text
            In a Digraph D, a vertex u of D is reachable from another vertex v of D if u is a descendant of v. Alternatively, u is reachable from v if there is some set of vertices u_0, ... , u_n such that u_n = u and u_0 = v and (u_i, u_i+1) is and edge of D for all i from 0 to n-1.
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            isReachable(D, e, a)
            isReachable(D, d, e)
    SeeAlso
        descendants
        forefathers
///

--isRegular
doc ///
    Key
        isRegular
        (isRegular, Graph)
    Headline
        determines whether a graph is regular
    Usage
        r = isRegular G
    Inputs
        G:Graph
    Outputs
        r:Boolean
            whether the graph G is regular or not.
    Description
        Text
            A graph is regular if all of its vertices have the same degree.
        Example
            G = cycleGraph 5;
            isRegular G
    SeeAlso
        completeGraph
        cycleGraph
///

--isRigid
doc ///
    Key
        isRigid
        (isRigid,Graph)
    Headline
        checks if a graph is rigid
    Usage
        r = isRigid G
    Inputs
        G:Graph
    Outputs
        r:Boolean
    Description
        Text
            A drawing of a graph is rigid in the plane if any continuous motion 
	    of the vertices that preserve edge lengths must preserve the distance 
	    between every pair of vertices.  A graph is generically rigid if any 
	    drawing of the graph with vertices in general position is rigid. This 
	    method uses Laman's Theorem to determine if a graph is rigid or not.
        Example
            G = cycleGraph 4;
            isRigid G
	    G' = addEdges' (G, {{1,1},{3,1}})
            isRigid G'
///


--isSimple
doc ///
    Key
        isSimple
        (isSimple,Graph)
    Headline
        checks if a graph is simple
    Usage
        r = isSimple G
    Inputs
        G:Graph
    Outputs
        r:Boolean
    Description
        Text
            A graph is said to be simple if it has a maximum of one edge between each vertex, contains no loops (vertices connected to themselves by edges), and is undirected. Since the Graph Type does not allow for multiple edges and directed edges, it is sufficient to check that the graph has no loops.
        Example
            G = cycleGraph 5;
            isSimple G
            G' = addEdge (G, set {1,1});
            isSimple G'
///

--isSink
doc ///
    Key
        isSink
        (isSink, Digraph, Thing)
    Headline
        determines if a vertex of a digraph is a sink or not
    Usage
        r = isSink (D, v)
    Inputs
        D:Digraph
        v:Thing
            the vertex being texted
    Outputs
        r:Boolean
            whether the vertex v is a sink or not
    Description
        Text
            A vertex v of a Digraph D is a sink if v has no children
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            isSink (D,b)
            isSink (D,d)
    SeeAlso
        sinks
///

--isSource
doc ///
    Key
        isSource
        (isSource, Digraph, Thing)
    Headline
        determines if a vertex of a digraph is a source or not
    Usage
        r = isSource (D, v)
    Inputs
        D:Digraph
        v:Thing
            the vertex being texted
    Outputs
        r:Boolean
            whether the vertex v is a source or not
    Description
        Text
            A vertex v of a Digraph D is a source if v has no parents
        Example
            D = digraph({a,b,c,d,e},{{a,b},{b,c},{b,d},{e,b}});
            isSource (D,c)
            isSource (D,e)
    SeeAlso
        sources
///

--isStronglyConnected
doc ///
    Key
        isStronglyConnected
        (isStronglyConnected,Digraph)
    Headline
        checks if a digraph is strongly connected
    Usage
        r = isStronglyConnected D
    Inputs
        D:Digraph
    Outputs
        r:Boolean
    Description
        Text
            A digraph is said to be strongly connected if for each vertex u of D, any other vertex of D is reachable from u. An equivalent definition is that D is strongly connected if the distance matrix of D has only positive terms in the non-diagonal entries.
        Example
            D = digraph({1,2,3,4},{{1,2},{2,3},{3,4},{4,2}});
            isStronglyConnected D
            D' = digraph({1,2,3,4},{{1,2},{2,1},{2,3},{3,4},{4,2}});
            isStronglyConnected D'
    SeeAlso
        isWeaklyConnected
        distanceMatrix
        isReachable
///

--isTree
doc ///
    Key
        isTree
        (isTree, Graph)
    Headline
        determines whether a graph is a tree
    Usage
        t = isTree G
    Inputs
        G:Graph
    Outputs
        t:Boolean
            whether a graph is a tree
    Description
        Text
            A graph is a tree if any two vertices are connected by a unique path of edges.
        Example
            G = graph({{1,2},{1,3},{3,4},{3,5}},EntryMode=>"edges");
            isTree G
    SeeAlso
        isForest
        isLeaf
        leaves
///

--isWeaklyConnected
doc ///
    Key
        isWeaklyConnected
        (isWeaklyConnected,Digraph)
    Headline
        checks if a digraph is weakly connected
    Usage
        r = isWeaklyConnected D
    Inputs
        D:Digraph
    Outputs
        r:Boolean
    Description
        Text
            A digraph is said to be weakly connected if the underlying graph of D, that is, the graph formed by taking away direction from the edges so each edge becomes "2-way" again, is connected.
        Example
            D = digraph({1,2,3,4},{{1,2},{2,3},{3,4},{4,2}});
            isWeaklyConnected D
    SeeAlso
        weaklyConnectedComponents
        isStronglyConnected
///

------------------------
--Graph operations
------------------------

--cartesianProduct
doc///
    Key
        cartesianProduct
        (cartesianProduct, Graph, Graph)
    Headline
        Computes the cartesian product of two graphs
    Usage
        F = cartesianProduct(G,H)
    Inputs
        G:Graph
        H:Graph
    Outputs
        F:Graph
            The Cartesian Product of G and H
    Description
        Text
            This method will take in any two graphs and output the cartesian product of the two graphs. The vertex set of this new graph is the cartesian product of the vertex sets of the two input graphs.  The keys for each vertex will be output as a sequence. Any two vertices (u,u') and (v,v') are adjacent in the cartesian product of G and H if and only if either u = v and u' is adjacent with v' in H, or u' = v' and u is adjacent with v in G.
        Example
            G = graph({1,2},{{1,2}});
            H = graph({3,4,5},{{3,4},{4,5}});
            G' = cartesianProduct(G,H)
    SeeAlso
        strongProduct
        directProduct
        graphComposition
///


--directProduct
doc ///
    Key
        directProduct
        (directProduct, Graph, Graph)
	symbol tensorProduct
    Headline
        Computes the direct product of two graphs
    Usage
        F = directProduct(G,H)
    Inputs
        G:Graph
        H:Graph
    Outputs
        F:Graph
            The Direct Product of G and H
    Description
        Text
            This method will take in any two graphs and output the direct product of these two graphs. The vertex set of the direct product of G and H is the cartesian product of G and H's vertex sets. The keys for each vertex will be output as a sequence to represent this.  Any two vertices (u,u') and (v,v') form an edge in the direct product of G and G if and only if u' is adjacent with v' and u is adjacent with v in the original graphs.
        Example
            G = graph({1,2},{{1,2}});
            H = graph({3,4,5},{{3,4},{4,5}});
            G'= directProduct(G,H)
    SeeAlso
        graphComposition
        strongProduct
        cartesianProduct
///

-- disjointUnion
doc ///
    Key
        disjointUnion
        (disjointUnion, List)
    Headline
        Returns the disjoint union of a list of graphs.
    Usage
        G = disjointUnion L
    Inputs
        L:List
    Outputs
        G:Graph
            The disjoint union of the graphs in list L
    Description
        Text
            The disjoint union of a list of graphs is the graph constructed from the unions of their respective vertex sets and edge sets. By default, the vertex set of the union will be listed as sequences.
        Example
            A = graph({{1,2},{2,3}},EntryMode=>"edges");
            B = graph({1,2,3,4,5},{{1,2},{4,5}});
            disjointUnion {A,B}
///

--graphComposition
doc///
    Key
        graphComposition
        (graphComposition, Graph, Graph)
    Headline
        A method for composing two graphs
    Usage
        F = graphComposition(G,H)
    Inputs
        G:Graph
        H:Graph
    Outputs
        F:Graph
            The Graph Composition of G and H
    Description
        Text
            This method will take in any two graphs and output the composition of the two graphs. The vertex set of the graph composition of G and H is the cartesian product of the vertex sets of G and H. The keys for each vertex will be output as a sequence to represent this. The edge set is formed by the rule that any two vertices (u,v) and (x,y) are adjacent the composition of G and H if and only if either u is adjacent with x in G or u = x and v is adjacent with y in H. Be careful, since this operation is not commutative, and the user needs to be mindful what order the graphs are entered into the method.
        Example
            G = graph({1,2},{{1,2}});
            H = graph({3,4,5},{{3,4},{4,5}})
            GH = graphComposition(G,H)
            HG = graphComposition(H,G)
    SeeAlso
        strongProduct
        directProduct
        cartesianProduct
///

--graphPower
doc ///
    Key
        graphPower
        (graphPower, Graph, ZZ)
    Headline
        constructs a graph raised to a power
    Usage
        G' = graphPower(G,k)
    Inputs
        G:Graph
        k:ZZ
    Outputs
        G':Graph
            graph G to the kth power
    Description
        Text
            G^k is the graph with the same vertices as G, where the vertices of G^k are adjacent if they are separated by distance less than or equal to k in graph G.  If the diameter of G is d, G^d is the complete graph with the same number of vertices as G.
        Example
            G = cycleGraph 6;
            graphPower(G,2)
    SeeAlso
        distance
        (diameter, Graph)
///

--strongProduct
doc ///
    Key
        strongProduct
        (strongProduct, Graph, Graph)
    Headline
        a method for taking the strong product of two graphs
    Usage
        F = strongProduct(G,H)
    Inputs
        G:Graph
        H:Graph
    Outputs
        F:Graph
            The Strong Product of G and H
    Description
        Text
            This method will take in any two graphs and output the strong product of the two graphs. The vertex set of 
            the strong product of G and H is the cartesian product of the vertex sets of G and H. The keys for each 
            vertex will be output as a sequence to represent this clearly. The edge set of the strong product of G and H 
            is formed by the rule any two distinct vertices (u,u') and (v,v') are adjacent in G and H if and only if u' 
            is adjacent with v' or u'=v' , and u is adjacent with v or u = v.
        Example
            G = graph({1,2},{{1,2}});
            H = graph({3,4,5},{{3,4},{4,5}});
            strongProduct(G,H)
    SeeAlso
        graphComposition
        directProduct
        cartesianProduct
///

---------------------------
--Graph Manipulations
---------------------------

--addEdges'
doc ///
    Key
        addEdge
        (addEdge, Digraph, Set)
        addEdges'
        (addEdges', Digraph, List)
    Headline
        A method for adding edges to a graph
    Usage
        H = addEdges' (G, L)
        H = addEdge (G, S)
    Inputs
        G:Graph
        L:List
            This List should be composed of other Lists, just as one would input an edge set
        S:Set
            This is used when only one edge needs to be used via addEdge
    Outputs
        H:Graph
            The Graph with the new edge
    Description
        Text
            This method will take in a Graph and a List of new edges, and output a graph with these new edges along with the previous edges.
        Example
            H = cycleGraph 4;
            G = addEdge(H, set {0,2})
            G = addEdges'(H, {{0,2},{3,1}})
    SeeAlso
        addVertices
///

--addVertices
doc ///
    Key
        addVertex
        (addVertex, Digraph, Thing)
        addVertices
        (addVertices, Digraph, List)
    Headline
        A method for adding a set of vertices to a graph
    Usage
        H = addVertex (G, v)
        H = addVertices (G, L)
    Inputs
        G:Graph
        L:List
            list of the names of the new vertices
        v:Thing
            name of the new vertex
    Outputs
        H:Graph
            This is the graph with the additional vertices specified in L
    Description
        Text
            This method will add vertices (as singletons) to any already present graph. Note that if you add a vertex that is already in the vertex set of the input graph, that vertex will be ignored.
        Example
            G = completeGraph 4
            H = addVertices(G, {3,4,5})
            --Notice that since 3 is already a vertex of G, it is ignored
    SeeAlso
        addEdges'
///

--bipartiteColoring
doc ///
    Key
        bipartiteColoring
        (bipartiteColoring, Graph)
    Headline
        Returns a coloring of a bipartite graph
    Usage
        coloring = bipartiteColoring G
    Inputs
        G:Graph
    Outputs
        coloring:List
            a coloring of bipartite graph G
    Description
        Text
            A graph is bipartite if it has a chromatic number less than or equal to 2.  This method colors the graph two colors. In other words, it partitions the graph into two sets such that there is no edge connecting any vertex within each set.
        Example
            G = graph({{0,1},{1,2},{2,4},{3,4},{4,5}},EntryMode=>"edges");
            bipartiteColoring G
    SeeAlso
        isBipartite
///

--deleteEdges
doc ///
    Key
        deleteEdges
        (deleteEdges, Graph, List)
    Headline
        Deletes a list of edges from a graph
    Usage
        G' = deleteEdges(G,E)
    Inputs
        G:Graph
        E:List
    Outputs
        G':Graph
            the graph resulting from deleting edges in list E from graph G
    Description
        Text
            This method deletes the specified edges from the graph, but preserves the original vertex set of the graph, and outputs the adjusted graph.
        Example
            G = cycleGraph 10;
            deleteEdges(G,{{1,2},{3,4},{7,8}})
    SeeAlso
        deleteVertices
        deleteVertex
///

--deleteVertex
doc ///
    Key
        deleteVertex
        (deleteVertex, Graph, Thing)
    Headline
        a method for deleting the vertex of a graph
    Usage
        H = deleteVertex(G, v)
    Inputs
        G:Graph
        v:Thing
            v should be a member of the vertex set of G
    Outputs
        H:Graph
            The graph with the vertex v and any edges touching it
    Description
        Text
            This is a method that takes in any graph and outputs this graph minus one specified vertex. This will also remove any edge that contained this vertex as one of its entries.
        Example
            G = cycleGraph 4;
            -- the graph
            G' = deleteVertex(G,1);
            -- the graph G minus vertex 1
    SeeAlso
        inducedSubgraph
        deleteVertices
        deleteEdges
///

--delete method for Graphs in package!
--deleteVertices
doc ///
    Key
        deleteVertices
        (deleteVertices, Digraph, List)
    Headline
        Deletes specified vertices from a digraph or graph
    Usage
        G' = deleteVertices(G,L)
    Inputs
        G:Digraph
        L:List
    Outputs
        G':Digraph
            Graph with vertices in list L and their incident edges deleted.
    Description
        Text
            Removes specified list of vertices and their incident edges from a graph or digraph.
        Example
            G = graph({1,2,3,4,5},{{1,3},{3,4},{4,5}});
            L = {1,2};
            deleteVertices(G,L)
    SeeAlso
        deleteVertex
        inducedSubgraph
        deleteEdges
///

--indexLabelGraph
doc ///
    Key
        indexLabelGraph
        (indexLabelGraph, Graph)
        (indexLabelGraph, Digraph)
    Headline
        Relabels the vertices of a graph or digraph according to their indices, indexed from 0.
    Usage
        G' = indexLabelGraph G
        D' = indexLabelGraph D
    Inputs
        G:Graph
        D:Digraph
    Outputs
        G':Graph
        D':Digraph
            the graph or digraph with vertices relabeled according to their indices starting from 0.
    Description
        Text
            This method relabels the vertices of a graph or digraph according to their indices.  The method indexes from 0 to the number of vertices minus one.
        Example
            G = graph({1,2,3,4,5},{{1,3},{3,4},{4,5}});
            indexLabelGraph G
            D = digraph({1,2,3,4,5},{{1,2},{2,3},{3,1},{4,5},{5,4}})
            indexLabelGraph D
    SeeAlso
        reindexBy
///

--inducedSubgraph
doc ///
    Key
        inducedSubgraph
        (inducedSubgraph, Graph, List)
        (inducedSubgraph, Digraph, List)
    Headline
        A method for finding the induced subgraph of any Graph or Digraph
    Usage
        H = inducedSubgraph(G, L)
        D' = inducedSubgraph(D, L)
    Inputs
        G:Graph
        D:Digraph
        L:List
            This list should contain vertices of G
    Outputs
        H:Graph
        D':Digraph
            The subgraph induced by removing the vertices in L
    Description
        Text
            This method takes a graph or digraph and a list as the inputs. The List should be the vertices of the subgraph the user wants to consider, and the output will contain just those vertices and any edges from G that connect them.  This method also is a way of iterating deleteVertex several times in a quick way.
        Example
            G = completeGraph 5
            S = {3,4}
            inducedSubgraph(G,S)
                --Observe that the output is a complete graph with 3 vertices, as desired
            D = digraph ({{1,2},{2,3},{3,4},{4,1},{2,4}},EntryMode=>"edges");
            D' = inducedSubgraph(D,{1,2,4})
    SeeAlso
        deleteVertex
///

--reindexBy
doc ///
    Key
        reindexBy
        (reindexBy, Graph, String)
        (reindexBy, Digraph, String)
    Headline
        reindexes the vertices according to the input ordering.
    Usage
        G' = reindexBy(G, ordering)
        D' = reindexBy(D, ordering)
    Inputs
        G:Graph
        D:Digraph
        ordering:String
    Outputs
        G':Graph
        D':Digraph
            the graph or digraph with vertices reindexed according to the String ordering
    Description
        Text
            This method reindexes the vertices of a specified graph or digraph according to the ordering method entered by the user.  The orderings available for graphs are:  "maxdegree" (orders the vertices in order of highest to lowest degree), "mindegree" (orders the vertices in order of lowest to highest degree), "random" (orders the vertices randomly), "components" (orders the vertices in the same connected components close together in indices), and "sort" (orders the vertices by sorting their names).  For digraphs, the orderings available are:  "maxdegreein" (orders the vertices in order of highest in-degree to lowest in-degree), "mindegreein" (orders the vertices in order of lowest in-degree to highest in-degree), "maxdegreeout" (orders the vertices in order of highest out-degree to lowest out-degree), "mindegreeout" (orders the vertices in order of lowest out-degree to highest out-degree), "maxdegree" (orders the vertices in order of highest to lowest degree in the underlying undirected graph), "mindegree" (orders the vertices in order of lowest to highest degree in the underlying undirected graph), "random" (orders the vertices randomly), "sort" (orders the vertices by sorting their names).
        Example
            G = graph({1,2,3,4,5},{{1,3},{3,4},{4,5}});
            reindexBy(G,"maxdegree")
            D = digraph({1,2,3,4,5},{{1,2},{2,3},{3,1},{4,5},{5,4}})
            reindexBy(D, "mindegreeout")
    SeeAlso
        reindexBy
///

--spanningForest
doc ///
    Key
        spanningForest
        (spanningForest, Graph)
    Headline
        constructs a spanning forest of a graph
    Usage
        F = spanningForest G
    Inputs
        G:Graph
    Outputs
        F:Graph
            a forest spanning G
    Description
        Text
            A graph is a forest if it is a disjoint collection of trees.  A graph is a tree if any two vertices are connected by a unique path of edges.  A spanning forest is a forest that spans all the vectors of G using edges of G.
        Example
            G = cycleGraph 5;
            spanningForest G
    SeeAlso
        isForest
        isTree
///

--vertexMultiplication
doc ///
    Key
        vertexMultiplication
        (vertexMultiplication, Graph, Thing, Thing)
    Usage
        H = vertexMultiplication (G, v, u)
    Inputs
        G:Graph
        u:Thing
            u is the new vertex to be added
        v:Thing
            v is the vertex whose neighbors become the vertices that u connects to.
    Outputs
        H:Graph
    Description
        Text
            Multiplying the vertex of a graph adds one vertex to the original graph. It also adds several edges, namely, if we are multiplying a vertex v and calling the new vertex u, {u,W} is an edge if and only if {v,w} is an edge.
        Example
            G = completeGraph 5
            H = vertexMultiplication(G, 0, 6)
///


doc /// 
    Key
        topologicalSort
        (topologicalSort, Digraph) 
	(topologicalSort, Digraph, String) 
    Headline
        outputs a list of vertices in a topologically sorted order of a DAG.
    Usage
        topologicalSort(D,S)
	topologicalSort(D)
    Inputs
        D:Digraph
	S:String
    Outputs
         :List 
    Description 
        Text
	    This function outputs a list of vertices in a topologically sorted order of a directed acyclic graph (DAG). 
	    S provides the preference given to the vertices in order to break ties and provide unique topological sorting to the DAG.
	    
	    Permissible values of S are: "random", "max", "min", "degree".
	    
	    S = "random" randomly sort the vertices of graph which have same precedence at any instance of the algorithm to break the ties.
	    
	    S = "min" sort the vertices according to their indices (from low to high) to break the ties.
	    
	    S = "max" sort the vertices according to their indices (from high to low) to break the ties.
	    
	    S = "degree" sort the vertices according to their degree (from low to high) to break the ties.
        Example
	   G = digraph{{5,2},{5,0},{4,0},{4,1},{2,3},{3,1}}
	   topologicalSort G
	   topologicalSort(G,"min")
	   topologicalSort(G,"max")
	   topologicalSort(G,"random")
	   topologicalSort(G,"degree")
	  
    SeeAlso
        topSort
   ///

--------------------------------------------
-- Documentation topSort
--------------------------------------------
doc /// 
    Key
        topSort
        (topSort, Digraph) 
	(topSort, Digraph, String)
    Headline
        topologically sort the vertices of a digraph
    Usage
        topSort(D)
	topSort(D,S)
    Inputs
        D:Digraph
	S: String 
    Outputs
         :HashTable 
    Description 
        Text
	    This method outputs a HashTable with keys digraph, map and newDigraph, where digraph is the original digraph,
	    map is the relation between old ordering and the new ordering of vertices and newDigraph is the Digraph with 
	    topologically sorted vertices. This method needs the input to be directed acyclic graph (DAG).
	    S provides the preference given to the vertices in order to break ties and provide unique topological sorting to the DAG.
	    
	    Permissible values of S are: "random", "max", "min", "degree".
	    
	    S = "random" randomly sort the vertices of graph which have same precedence at any instance of the algorithm to break the ties.
	    
	    S = "min" sort the vertices according to their indices (from low to high) to break the ties.
	    
	    S = "max" sort the vertices according to their indices (from high to low) to break the ties.
	    
	    S = "degree" sort the vertices according to their degree (from low to high) to break the ties.

        Example
	   G = digraph{{5,2},{5,0},{4,0},{4,1},{2,3},{3,1}}
	   H = topSort G
	   H#digraph
	   H#map
	   topSort(G,"min")
	   topSort(G,"max")
	   topSort(G,"random")
	   topSort(G,"degree")
    
    SeeAlso
          topologicalSort
	  SortedDigraph
	  newDigraph
   ///


doc /// 
    Key
        SortedDigraph
    Headline
        hashtable used in topSort
    Description 
        Text
	    This is a type of hashtable.The output of @TO topSort@ has class {\tt SortedDigraph}. In the current version of 
	    Graphs (version 0.3.3) the only use of SortedDigraph is in @TO topSort@.
        Example
	   G = digraph{{5,2},{5,0},{4,0},{4,1},{2,3},{3,1}}
	   H = topSort G
	   class H
    SeeAlso
          topSort
	  newDigraph
	  topologicalSort
   ///


doc /// 
    Key
        newDigraph
    Headline
        key used in the output of topSort
    Description 
        Text
	    This is a key of the hashtable output @TO SortedDigraph@  of @TO topSort@. 
        Example
	   G = digraph{{5,2},{5,0},{4,0},{4,1},{2,3},{3,1}}
	   H = topSort G
	   keys H
    SeeAlso
          topSort
	  SortedDigraph
	  topologicalSort
   ///


doc ///
    Key
        clusteringCoefficient
        (clusteringCoefficient, Graph)  
        (clusteringCoefficient, Graph, Thing)
    Headline
        a method for computing the clustering coefficient of a Graph
    Usage
        c = clusteringCoefficient(G, v)
        g = clusteringCoefficient(G)
    Inputs
        G:Graph
        v:Thing
            v should be a member of the vertex set of G
    Outputs
        c:ZZ
            The local clustering coefficient for G relative to v.
        g:ZZ
            The global clustering coefficient for G.
    Description
        Text
            The clustering coefficient is a measure of the degree to which nodes in a graph tend to cluster together. The global clustering coefficient gives an overall
            indication of the interconnectedness of the graph. The local clustering coefficient gives an indication of how embedded a single vertex is in the graph.
        Example
            clusteringCoefficient cycleGraph 4
            clusteringCoefficient completeGraph 4
///


TEST ///
--test expansion of graphs
G=pathGraph(7);
assert(expansion(G)===1/3);
///

TEST ///
--test connectivity
G=completeGraph(5);
assert(vertexConnectivity(G)===4);
assert(edgeConnectivity(G)===4);
H=graph({{1,2},{1,3},{2,4},{3,4},{4,5},{4,6},{5,7},{6,7}});
assert(vertexConnectivity(H)===1);
assert(edgeConnectivity(H)===2);
///

TEST ///
--test cuts
G=completeGraph(4);
--complete graphs have no vertex cuts
assert(vertexCuts(G)==={});
assert(edgeCuts(G)==={{{0,1},{0,2},{0,3}},{{0,1},{1,2},
{1,3}},{{0,2},{1,2},{2,3}},{{0,3},{1,3},{2,3}}});
H=graph({{1,2},{2,3},{3,4},{4,1}});
assert(vertexCuts(H)==={{1,3},{2,4}});
assert(edgeCuts(H)==={{{1,2},{4,1}},{{1,2},{2,3}},
{{4,1},{2,3}},{{1,2},{4,3}},{{4,1},{4,3}},{{2,3},{4,3}}});
///

TEST ///
--vertices of complete graphs start at zero
assert(vertexSet(completeGraph(4))==={0,1,2,3});
--vertices of path graphs start at zero
assert(vertexSet(pathGraph(4))==={0,1,2,3});
///

TEST ///
--check diameter
assert(diameter(pathGraph(7))===6);
///

TEST ///
--check chromatic number
G=starGraph(4);
H=completeGraph(3);
assert(chromaticNumber(G)===2);
assert(chromaticNumber(H)===3);
assert(chromaticNumber(cartesianProduct(G,H))===max(2,3));
///

TEST ///
--check graphs with vertices from different classes
G=graph({{1,2},{a,b},{3,c}});
assert(numberOfComponents(G)===3);
assert(chromaticNumber(G)===2);
assert(isConnected(G)===false);
assert(neighbors(G,a)===set({b}));
assert(deleteEdges(G,{{a,b}})===graph({1,2,a,b,3,c},{{1,2},{c,3}}));

H=digraph({{1,2},{a,b},{3,c}});
assert(children(H,3)===set({c}));
assert(parents(H,c)===set({3}));
assert(degree(H,c)===1);
///

TEST ///
--check properties of empty graph
G=graph({});
assert(vertexSet(G)==={});
assert(expansion(G)===0);
assert(edgeConnectivity(G)===0);
assert(vertexConnectivity(G)===0);
assert(edgeCuts(G)==={{}});
assert(vertexCuts(G)==={});
assert(connectedComponents(G)==={});
assert(cliqueNumber(G)===0);
assert(chromaticNumber(G)===0);
assert(independenceNumber(G)===0);
assert(numberOfComponents(G)===0);
assert(isConnected(G)===true);
assert(isBipartite(G)===true);
assert(isCyclic(G)===true);
assert(isForest(G)===true);
assert(isChordal(G)===true);
assert(isSimple(G)===true);
///

TEST ///
--check rigidity
assert( isRigid ( graph({{0,1},{0,3},{0,4},{1,3},{2,3}},Singletons => {5}) ) === false )
assert( isRigid ( graph({{0,4},{0,5},{0,6},{1,4},{1,5},{1,6},{2,4},{2,5},{2,6}}) ) === true )
assert( isRigid(graph{{0,1}}) === true )
assert( isRigid(graph{{0,1},{1,2}}) === false )
///

TEST ///

   D = digraph{{2,1},{3,1}}
   assert(topologicalSort D==={2,3,1})
///


TEST ///

   D = digraph{{2,1},{3,1}}
   assert(topSort D ===  new SortedDigraph from {map => new HashTable from {1 => 3, 2 => 1, 3
  => 2}, newDigraph => digraph ({1, 2, 3}, {{1, 3}, {2, 3}}), digraph =>
  digraph ({2, 1, 3}, {{2, 1}, {3, 1}})})
///

TEST ///
assert Equation(degreeSequence pathGraph 5, {2, 2, 2, 1, 1})
///

end;

loadPackage(Graphs, Reload => true)

restart
uninstallPackage "Graphs"
restart
installPackage "Graphs"
viewHelp Graphs

check Graphs