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
|
Description: Unbundle cliquer library.
It was added in 2.7r1, but we use the Debian package instead.
Origin: https://src.fedoraproject.org/rpms/nauty/blob/d3634d0/f/nauty-unbundle-cliquer.patch
Last-Update: 2020-07-17
--- a/makefile.in
+++ b/makefile.in
@@ -5,7 +5,7 @@
SHELL=@SHELL@
CC=@CC@
CFLAGS=@CFLAGS@ @MORECFLAGS@
-LDFLAGS=@LDFLAGS@ @LIBS@
+LDFLAGS=@LDFLAGS@ @LIBS@ -lcliquer
TESTPROGS=@testprogs@
NAUTESTS=@nautests@
EXEEXT=@EXEEXT@
--- a/nautycliquer.c
+++ b/nautycliquer.c
@@ -18,2573 +18,6 @@
#include "nautycliquer.h"
-/*
- * This file contains the clique searching routines.
- *
- * Copyright (C) 2002 Sampo Niskanen, Patric stergrd.
- * Licensed under the GNU GPL, read the file LICENSE for details.
- * This version covered by nauty&Traces licence, see file COPYRIGHT.
- */
-
-/*
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/times.h>
-
-#include "cliquer.h"
-*/
-
-
-/* Default cliquer options; no TLS_ATTR on this one */
-static clique_options clique_default_options_struct = {
- reorder_by_default, NULL, clique_print_time, NULL, NULL, NULL, NULL, 0
-};
-clique_options *clique_default_options=&clique_default_options_struct;
-
-
-/* Calculate d/q, rounding result upwards/downwards. */
-#define DIV_UP(d,q) (((d)+(q)-1)/(q))
-#define DIV_DOWN(d,q) ((int)((d)/(q)))
-
-
-/* Global variables used: */
-/* These must be saved and restored in re-entrance. */
-static TLS_ATTR int *clique_size; /* c[i] == max. clique size in {0,1,...,i-1} */
-static TLS_ATTR set_t current_clique; /* Current clique being searched. */
-static TLS_ATTR set_t best_clique; /* Largest/heaviest clique found so far. */
-#if 0
-static struct tms cputimer; /* Timer for opts->time_function() */
-static struct timeval realtimer; /* Timer for opts->time_function() */
-#endif
-static TLS_ATTR int clique_list_count=0; /* No. of cliques in opts->clique_list[] */
-static TLS_ATTR int weight_multiplier=1; /* Weights multiplied by this when passing
- * to time_function(). */
-
-/* List cache (contains memory blocks of size g->n * sizeof(int)) */
-static TLS_ATTR int **temp_list=NULL;
-static TLS_ATTR int temp_count=0;
-
-
-/*
- * Macros for re-entrance. ENTRANCE_SAVE() must be called immediately
- * after variable definitions, ENTRANCE_RESTORE() restores global
- * variables to original values. entrance_level should be increased
- * and decreased accordingly.
- */
-static int entrance_level=0; /* How many levels for entrance have occurred? */
-
-#define ENTRANCE_SAVE() \
-int *old_clique_size = clique_size; \
-set_t old_current_clique = current_clique; \
-set_t old_best_clique = best_clique; \
-int old_clique_list_count = clique_list_count; \
-int old_weight_multiplier = weight_multiplier; \
-int **old_temp_list = temp_list;
-/*
-int old_temp_count = temp_count;
-struct tms old_cputimer; \
-struct timeval old_realtimer; \
-memcpy(&old_cputimer,&cputimer,sizeof(struct tms)); \
-memcpy(&old_realtimer,&realtimer,sizeof(struct timeval))
-*/
-
-#define ENTRANCE_RESTORE() \
-clique_size = old_clique_size; \
-current_clique = old_current_clique; \
-best_clique = old_best_clique; \
-clique_list_count = old_clique_list_count; \
-weight_multiplier = old_weight_multiplier; \
-temp_list = old_temp_list;
-/*
-temp_count = old_temp_count; \
-memcpy(&cputimer,&old_cputimer,sizeof(struct tms)); \
-memcpy(&realtimer,&old_realtimer,sizeof(struct timeval));
-temp_count = old_temp_count;
-*/
-
-
-/* Number of clock ticks per second (as returned by sysconf(_SC_CLK_TCK)) */
-#if 0
-static int clocks_per_sec=0;
-#endif
-
-/* Recursion and helper functions */
-static boolean sub_unweighted_single(int *table, int size, int min_size,
- graph_t *g);
-static int sub_unweighted_all(int *table, int size, int min_size, int max_size,
- boolean maximal, graph_t *g,
- clique_options *opts);
-static int sub_weighted_all(int *table, int size, int weight,
- int current_weight, int prune_low, int prune_high,
- int min_weight, int max_weight, boolean maximal,
- graph_t *g, clique_options *opts);
-
-
-static boolean store_clique(set_t clique, graph_t *g, clique_options *opts);
-static boolean is_maximal(set_t clique, graph_t *g);
-static boolean false_function(set_t clique,graph_t *g,clique_options *opts);
-
-/***** Unweighted searches *****/
-/*
- * Unweighted searches are done separately from weighted searches because
- * some effective pruning methods can be used when the vertex weights
- * are all 1. Single and all clique finding routines are separated,
- * because the single clique finding routine can store the found clique
- * while it is returning from the recursion, thus requiring no implicit
- * storing of the current clique. When searching for all cliques the
- * current clique must be stored.
- */
-
-
-/*
- * unweighted_clique_search_single()
- *
- * Searches for a single clique of size min_size. Stores maximum clique
- * sizes into clique_size[].
- *
- * table - the order of the vertices in g to use
- * min_size - minimum size of clique to search for. If min_size==0,
- * searches for a maximum clique.
- * g - the graph
- * opts - time printing options
- *
- * opts->time_function is called after each base-level recursion, if
- * non-NULL. (NOT IN THIS VERSION)
- *
- * Returns the size of the clique found, or 0 if min_size>0 and a clique
- * of that size was not found (or if time_function aborted the search).
- * The largest clique found is stored in current_clique.
- *
- * Note: Does NOT use opts->user_function of opts->clique_list.
- */
-static int unweighted_clique_search_single(int *table, int min_size,
- graph_t *g, clique_options *opts) {
-#if 0
- struct tms tms;
- struct timeval timeval;
-#endif
- int i,j;
- int v,w;
- int *newtable;
- int newsize;
-
- v=table[0];
- clique_size[v]=1;
- set_empty(current_clique);
- SET_ADD_ELEMENT(current_clique,v);
- if (min_size==1)
- return 1;
-
- if (temp_count) {
- temp_count--;
- newtable=temp_list[temp_count];
- } else {
- newtable=malloc(g->n * sizeof(int));
- }
- for (i=1; i < g->n; i++) {
- w=v;
- v=table[i];
-
- newsize=0;
- for (j=0; j<i; j++) {
- if (GRAPH_IS_EDGE(g, v, table[j])) {
- newtable[newsize]=table[j];
- newsize++;
- }
- }
-
- if (sub_unweighted_single(newtable,newsize,clique_size[w],g)) {
- SET_ADD_ELEMENT(current_clique,v);
- clique_size[v]=clique_size[w]+1;
- } else {
- clique_size[v]=clique_size[w];
- }
-
-#if 0
- if (opts && opts->time_function) {
- gettimeofday(&timeval,NULL);
- times(&tms);
- if (!opts->time_function(entrance_level,
- i+1,g->n,clique_size[v] *
- weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
- timeval.tv_sec-
- realtimer.tv_sec+
- (double)(timeval.tv_usec-
- realtimer.tv_usec)/
- 1000000,opts)) {
- temp_list[temp_count++]=newtable;
- return 0;
- }
- }
-#endif
-
- if (min_size) {
- if (clique_size[v]>=min_size) {
- temp_list[temp_count++]=newtable;
- return clique_size[v];
- }
- if (clique_size[v]+g->n-i-1 < min_size) {
- temp_list[temp_count++]=newtable;
- return 0;
- }
- }
- }
-
- temp_list[temp_count++]=newtable;
-
- if (min_size)
- return 0;
- return clique_size[v];
-}
-
-/*
- * sub_unweighted_single()
- *
- * Recursion function for searching for a single clique of size min_size.
- *
- * table - subset of the vertices in graph
- * size - size of table
- * min_size - size of clique to look for within the subgraph
- * (decreased with every recursion)
- * g - the graph
- *
- * Returns TRUE if a clique of size min_size is found, FALSE otherwise.
- * If a clique of size min_size is found, it is stored in current_clique.
- *
- * clique_size[] for all values in table must be defined and correct,
- * otherwise inaccurate results may occur.
- */
-static boolean sub_unweighted_single(int *table, int size, int min_size,
- graph_t *g) {
- int i;
- int v;
- int *newtable;
- int *p1, *p2;
-
- /* Zero or one vertices needed anymore. */
- if (min_size <= 1) {
- if (size>0 && min_size==1) {
- set_empty(current_clique);
- SET_ADD_ELEMENT(current_clique,table[0]);
- return TRUE;
- }
- if (min_size==0) {
- set_empty(current_clique);
- return TRUE;
- }
- return FALSE;
- }
- if (size < min_size)
- return FALSE;
-
- /* Dynamic memory allocation with cache */
- if (temp_count) {
- temp_count--;
- newtable=temp_list[temp_count];
- } else {
- newtable=malloc(g->n * sizeof(int));
- }
-
- for (i = size-1; i >= 0; i--) {
- v = table[i];
-
- if (clique_size[v] < min_size)
- break;
- /* This is faster when compiling with gcc than placing
- * this in the for-loop condition. */
- if (i+1 < min_size)
- break;
-
- /* Very ugly code, but works faster than "for (i=...)" */
- p1 = newtable;
- for (p2=table; p2 < table+i; p2++) {
- int w = *p2;
- if (GRAPH_IS_EDGE(g, v, w)) {
- *p1 = w;
- p1++;
- }
- }
-
- /* Avoid unneccessary loops (next size == p1-newtable) */
- if (p1-newtable < min_size-1)
- continue;
- /* Now p1-newtable >= min_size-1 >= 2-1 == 1, so we can use
- * p1-newtable-1 safely. */
- if (clique_size[newtable[p1-newtable-1]] < min_size-1)
- continue;
-
- if (sub_unweighted_single(newtable,p1-newtable,
- min_size-1,g)) {
- /* Clique found. */
- SET_ADD_ELEMENT(current_clique,v);
- temp_list[temp_count++]=newtable;
- return TRUE;
- }
- }
- temp_list[temp_count++]=newtable;
- return FALSE;
-}
-
-
-/*
- * unweighted_clique_search_all()
- *
- * Searches for all cliques with size at least min_size and at most
- * max_size. Stores the cliques as opts declares.
- *
- * table - the order of the vertices in g to search
- * start - first index where the subgraph table[0], ..., table[start]
- * might include a requested kind of clique
- * min_size - minimum size of clique to search for. min_size > 0 !
- * max_size - maximum size of clique to search for. If no upper limit
- * is desired, use eg. INT_MAX
- * maximal - requires cliques to be maximal
- * g - the graph
- * opts - time printing and clique storage options
- *
- * Cliques found are stored as defined by opts->user_function and
- * opts->clique_list. opts->time_function is called after each
- * base-level recursion, if non-NULL.
- *
- * clique_size[] must be defined and correct for all values of
- * table[0], ..., table[start-1].
- *
- * Returns the number of cliques stored (not neccessarily number of cliques
- * in graph, if user/time_function aborts).
- */
-static int unweighted_clique_search_all(int *table, int start,
- int min_size, int max_size,
- boolean maximal, graph_t *g,
- clique_options *opts) {
-#if 0
- struct timeval timeval;
- struct tms tms;
-#endif
- int i,j;
- int v;
- int *newtable;
- int newsize;
- int count=0;
-
- if (temp_count) {
- temp_count--;
- newtable=temp_list[temp_count];
- } else {
- newtable=malloc(g->n * sizeof(int));
- }
-
- clique_list_count=0;
- set_empty(current_clique);
- for (i=start; i < g->n; i++) {
- v=table[i];
- clique_size[v]=min_size; /* Do not prune here. */
-
- newsize=0;
- for (j=0; j<i; j++) {
- if (GRAPH_IS_EDGE(g,v,table[j])) {
- newtable[newsize]=table[j];
- newsize++;
- }
- }
-
- SET_ADD_ELEMENT(current_clique,v);
- j=sub_unweighted_all(newtable,newsize,min_size-1,max_size-1,
- maximal,g,opts);
- SET_DEL_ELEMENT(current_clique,v);
- if (j<0) {
- /* Abort. */
- count-=j;
- break;
- }
- count+=j;
-
-#if 0
- if (opts->time_function) {
- gettimeofday(&timeval,NULL);
- times(&tms);
- if (!opts->time_function(entrance_level,
- i+1,g->n,min_size *
- weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
- timeval.tv_sec-
- realtimer.tv_sec+
- (double)(timeval.tv_usec-
- realtimer.tv_usec)/
- 1000000,opts)) {
- /* Abort. */
- break;
- }
- }
-#endif
- }
- temp_list[temp_count++]=newtable;
- return count;
-}
-
-/*
- * sub_unweighted_all()
- *
- * Recursion function for searching for all cliques of given size.
- *
- * table - subset of vertices of graph g
- * size - size of table
- * min_size - minimum size of cliques to search for (decreased with
- * every recursion)
- * max_size - maximum size of cliques to search for (decreased with
- * every recursion). If no upper limit is desired, use
- * eg. INT_MAX
- * maximal - require cliques to be maximal (passed through)
- * g - the graph
- * opts - storage options
- *
- * All cliques of suitable size found are stored according to opts.
- *
- * Returns the number of cliques found. If user_function returns FALSE,
- * then the number of cliques is returned negative.
- *
- * Uses current_clique to store the currently-being-searched clique.
- * clique_size[] for all values in table must be defined and correct,
- * otherwise inaccurate results may occur.
- */
-static int sub_unweighted_all(int *table, int size, int min_size, int max_size,
- boolean maximal, graph_t *g,
- clique_options *opts) {
- int i;
- int v;
- int n;
- int *newtable;
- int *p1, *p2;
- int count=0; /* Amount of cliques found */
-
- if (min_size <= 0) {
- if ((!maximal) || is_maximal(current_clique,g)) {
- /* We've found one. Store it. */
- count++;
- if (!store_clique(current_clique,g,opts)) {
- return -count;
- }
- }
- if (max_size <= 0) {
- /* If we add another element, size will be too big. */
- return count;
- }
- }
-
- if (size < min_size) {
- return count;
- }
-
- /* Dynamic memory allocation with cache */
- if (temp_count) {
- temp_count--;
- newtable=temp_list[temp_count];
- } else {
- newtable=malloc(g->n * sizeof(int));
- }
-
- for (i=size-1; i>=0; i--) {
- v = table[i];
- if (clique_size[v] < min_size) {
- break;
- }
- if (i+1 < min_size) {
- break;
- }
-
- /* Very ugly code, but works faster than "for (i=...)" */
- p1 = newtable;
- for (p2=table; p2 < table+i; p2++) {
- int w = *p2;
- if (GRAPH_IS_EDGE(g, v, w)) {
- *p1 = w;
- p1++;
- }
- }
-
- /* Avoid unneccessary loops (next size == p1-newtable) */
- if (p1-newtable < min_size-1) {
- continue;
- }
-
- SET_ADD_ELEMENT(current_clique,v);
- n=sub_unweighted_all(newtable,p1-newtable,
- min_size-1,max_size-1,maximal,g,opts);
- SET_DEL_ELEMENT(current_clique,v);
- if (n < 0) {
- /* Abort. */
- count -= n;
- count = -count;
- break;
- }
- count+=n;
- }
- temp_list[temp_count++]=newtable;
- return count;
-}
-
-
-
-
-/***** Weighted clique searches *****/
-/*
- * Weighted clique searches can use the same recursive routine, because
- * in both cases (single/all) they have to search through all potential
- * permutations searching for heavier cliques.
- */
-
-
-/*
- * weighted_clique_search_single()
- *
- * Searches for a single clique of weight at least min_weight, and at
- * most max_weight. Stores maximum clique sizes into clique_size[]
- * (or min_weight-1, whichever is smaller).
- *
- * table - the order of the vertices in g to use
- * min_weight - minimum weight of clique to search for. If min_weight==0,
- * then searches for a maximum weight clique
- * max_weight - maximum weight of clique to search for. If no upper limit
- * is desired, use eg. INT_MAX
- * g - the graph
- * opts - time printing options
- *
- * opts->time_function is called after each base-level recursion, if
- * non-NULL.
- *
- * Returns 0 if a clique of requested weight was not found (also if
- * time_function requested an abort), otherwise returns >= 1.
- * If min_weight==0 (search for maximum-weight clique), then the return
- * value is the weight of the clique found. The found clique is stored
- * in best_clique.
- *
- * Note: Does NOT use opts->user_function of opts->clique_list.
- */
-static int weighted_clique_search_single(int *table, int min_weight,
- int max_weight, graph_t *g,
- clique_options *opts) {
-#if 0
- struct timeval timeval;
- struct tms tms;
-#endif
- int i,j;
- int v;
- int *newtable;
- int newsize;
- int newweight;
- int search_weight;
- int min_w;
- clique_options localopts;
-
- if (min_weight==0)
- min_w=INT_MAX;
- else
- min_w=min_weight;
-
-
- if (min_weight==1) {
- /* min_weight==1 may cause trouble in the routine, and
- * it's trivial to check as it's own case.
- * We write nothing to clique_size[]. */
- for (i=0; i < g->n; i++) {
- if (g->weights[table[i]] <= max_weight) {
- set_empty(best_clique);
- SET_ADD_ELEMENT(best_clique,table[i]);
- return g->weights[table[i]];
- }
- }
- return 0;
- }
-
- localopts.time_function=NULL;
- localopts.reorder_function=NULL;
- localopts.reorder_map=NULL;
- localopts.user_function=false_function;
- localopts.user_data=NULL;
- localopts.clique_list=&best_clique;
- localopts.clique_list_length=1;
- clique_list_count=0;
-
- v=table[0];
- set_empty(best_clique);
- SET_ADD_ELEMENT(best_clique,v);
- search_weight=g->weights[v];
- if (min_weight && (search_weight >= min_weight)) {
- if (search_weight <= max_weight) {
- /* Found suitable clique. */
- return search_weight;
- }
- search_weight=min_weight-1;
- }
- clique_size[v]=search_weight;
- set_empty(current_clique);
-
- if (temp_count) {
- temp_count--;
- newtable=temp_list[temp_count];
- } else {
- newtable=malloc(g->n * sizeof(int));
- }
-
- for (i = 1; i < g->n; i++) {
- v=table[i];
-
- newsize=0;
- newweight=0;
- for (j=0; j<i; j++) {
- if (GRAPH_IS_EDGE(g,v,table[j])) {
- newweight += g->weights[table[j]];
- newtable[newsize]=table[j];
- newsize++;
- }
- }
-
-
- SET_ADD_ELEMENT(current_clique,v);
- search_weight=sub_weighted_all(newtable,newsize,newweight,
- g->weights[v],search_weight,
- clique_size[table[i-1]] +
- g->weights[v],
- min_w,max_weight,FALSE,
- g,&localopts);
- SET_DEL_ELEMENT(current_clique,v);
- if (search_weight < 0) {
- break;
- }
-
- clique_size[v]=search_weight;
-
-#if 0
- if (opts->time_function) {
- gettimeofday(&timeval,NULL);
- times(&tms);
- if (!opts->time_function(entrance_level,
- i+1,g->n,clique_size[v] *
- weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
- timeval.tv_sec-
- realtimer.tv_sec+
- (double)(timeval.tv_usec-
- realtimer.tv_usec)/
- 1000000,opts)) {
- set_free(current_clique);
- current_clique=NULL;
- break;
- }
- }
-#endif
- }
- temp_list[temp_count++]=newtable;
- if (min_weight && (search_weight > 0)) {
- /* Requested clique has not been found. */
- return 0;
- }
- return clique_size[table[i-1]];
-}
-
-
-/*
- * weighted_clique_search_all()
- *
- * Searches for all cliques with weight at least min_weight and at most
- * max_weight. Stores the cliques as opts declares.
- *
- * table - the order of the vertices in g to search
- * start - first index where the subgraph table[0], ..., table[start]
- * might include a requested kind of clique
- * min_weight - minimum weight of clique to search for. min_weight > 0 !
- * max_weight - maximum weight of clique to search for. If no upper limit
- * is desired, use eg. INT_MAX
- * maximal - search only for maximal cliques
- * g - the graph
- * opts - time printing and clique storage options
- *
- * Cliques found are stored as defined by opts->user_function and
- * opts->clique_list. opts->time_function is called after each
- * base-level recursion, if non-NULL.
- *
- * clique_size[] must be defined and correct for all values of
- * table[0], ..., table[start-1].
- *
- * Returns the number of cliques stored (not neccessarily number of cliques
- * in graph, if user/time_function aborts).
- */
-static int weighted_clique_search_all(int *table, int start,
- int min_weight, int max_weight,
- boolean maximal, graph_t *g,
- clique_options *opts) {
-#if 0
- struct timeval timeval;
- struct tms tms;
-#endif
- int i,j;
- int v;
- int *newtable;
- int newsize;
- int newweight;
-
- if (temp_count) {
- temp_count--;
- newtable=temp_list[temp_count];
- } else {
- newtable=malloc(g->n * sizeof(int));
- }
-
- clique_list_count=0;
- set_empty(current_clique);
- for (i=start; i < g->n; i++) {
- v=table[i];
- clique_size[v]=min_weight; /* Do not prune here. */
-
- newsize=0;
- newweight=0;
- for (j=0; j<i; j++) {
- if (GRAPH_IS_EDGE(g,v,table[j])) {
- newtable[newsize]=table[j];
- newweight+=g->weights[table[j]];
- newsize++;
- }
- }
-
- SET_ADD_ELEMENT(current_clique,v);
- j=sub_weighted_all(newtable,newsize,newweight,
- g->weights[v],min_weight-1,INT_MAX,
- min_weight,max_weight,maximal,g,opts);
- SET_DEL_ELEMENT(current_clique,v);
-
- if (j<0) {
- /* Abort. */
- break;
- }
-
-#if 0
- if (opts->time_function) {
- gettimeofday(&timeval,NULL);
- times(&tms);
- if (!opts->time_function(entrance_level,
- i+1,g->n,clique_size[v] *
- weight_multiplier,
- (double)(tms.tms_utime-
- cputimer.tms_utime)/
- clocks_per_sec,
- timeval.tv_sec-
- realtimer.tv_sec+
- (double)(timeval.tv_usec-
- realtimer.tv_usec)/
- 1000000,opts)) {
- set_free(current_clique);
- current_clique=NULL;
- break;
- }
- }
-#endif
- }
- temp_list[temp_count++]=newtable;
-
- return clique_list_count;
-}
-
-/*
- * sub_weighted_all()
- *
- * Recursion function for searching for all cliques of given weight.
- *
- * table - subset of vertices of graph g
- * size - size of table
- * weight - total weight of vertices in table
- * current_weight - weight of clique found so far
- * prune_low - ignore all cliques with weight less or equal to this value
- * (often heaviest clique found so far) (passed through)
- * prune_high - maximum weight possible for clique in this subgraph
- * (passed through)
- * min_size - minimum weight of cliques to search for (passed through)
- * Must be greater than 0.
- * max_size - maximum weight of cliques to search for (passed through)
- * If no upper limit is desired, use eg. INT_MAX
- * maximal - search only for maximal cliques
- * g - the graph
- * opts - storage options
- *
- * All cliques of suitable weight found are stored according to opts.
- *
- * Returns weight of heaviest clique found (prune_low if a heavier clique
- * hasn't been found); if a clique with weight at least min_size is found
- * then min_size-1 is returned. If clique storage failed, -1 is returned.
- *
- * The largest clique found smaller than max_weight is stored in
- * best_clique, if non-NULL.
- *
- * Uses current_clique to store the currently-being-searched clique.
- * clique_size[] for all values in table must be defined and correct,
- * otherwise inaccurate results may occur.
- *
- * To search for a single maximum clique, use min_weight==max_weight==INT_MAX,
- * with best_clique non-NULL. To search for a single given-weight clique,
- * use opts->clique_list and opts->user_function=false_function. When
- * searching for all cliques, min_weight should be given the minimum weight
- * desired.
- */
-static int sub_weighted_all(int *table, int size, int weight,
- int current_weight, int prune_low, int prune_high,
- int min_weight, int max_weight, boolean maximal,
- graph_t *g, clique_options *opts) {
- int i;
- int v,w;
- int *newtable;
- int *p1, *p2;
- int newweight;
-
- if (current_weight >= min_weight) {
- if ((current_weight <= max_weight) &&
- ((!maximal) || is_maximal(current_clique,g))) {
- /* We've found one. Store it. */
- if (!store_clique(current_clique,g,opts)) {
- return -1;
- }
- }
- if (current_weight >= max_weight) {
- /* Clique too heavy. */
- return min_weight-1;
- }
- }
- if (size <= 0) {
- /* current_weight < min_weight, prune_low < min_weight,
- * so return value is always < min_weight. */
- if (current_weight>prune_low) {
- if (best_clique)
- set_copy(best_clique,current_clique);
- if (current_weight < min_weight)
- return current_weight;
- else
- return min_weight-1;
- } else {
- return prune_low;
- }
- }
-
- /* Dynamic memory allocation with cache */
- if (temp_count) {
- temp_count--;
- newtable=temp_list[temp_count];
- } else {
- newtable=malloc(g->n * sizeof(int));
- }
-
- for (i = size-1; i >= 0; i--) {
- v = table[i];
- if (current_weight+clique_size[v] <= prune_low) {
- /* Dealing with subset without heavy enough clique. */
- break;
- }
- if (current_weight+weight <= prune_low) {
- /* Even if all elements are added, won't do. */
- break;
- }
-
- /* Very ugly code, but works faster than "for (i=...)" */
- p1 = newtable;
- newweight = 0;
- for (p2=table; p2 < table+i; p2++) {
- w = *p2;
- if (GRAPH_IS_EDGE(g, v, w)) {
- *p1 = w;
- newweight += g->weights[w];
- p1++;
- }
- }
-
- w=g->weights[v];
- weight-=w;
- /* Avoid a few unneccessary loops */
- if (current_weight+w+newweight <= prune_low) {
- continue;
- }
-
- SET_ADD_ELEMENT(current_clique,v);
- prune_low=sub_weighted_all(newtable,p1-newtable,
- newweight,
- current_weight+w,
- prune_low,prune_high,
- min_weight,max_weight,maximal,
- g,opts);
- SET_DEL_ELEMENT(current_clique,v);
- if ((prune_low<0) || (prune_low>=prune_high)) {
- /* Impossible to find larger clique. */
- break;
- }
- }
- temp_list[temp_count++]=newtable;
- return prune_low;
-}
-
-
-
-
-/***** Helper functions *****/
-
-
-/*
- * store_clique()
- *
- * Stores a clique according to given user options.
- *
- * clique - the clique to store
- * opts - storage options
- *
- * Returns FALSE if opts->user_function() returned FALSE; otherwise
- * returns TRUE.
- */
-static boolean store_clique(set_t clique, graph_t *g, clique_options *opts) {
-
- clique_list_count++;
-
- /* clique_list[] */
- if (opts->clique_list) {
- /*
- * This has been a major source of bugs:
- * Has clique_list_count been set to 0 before calling
- * the recursions?
- */
- if (clique_list_count <= 0) {
- fprintf(stderr,"CLIQUER INTERNAL ERROR: "
- "clique_list_count has negative value!\n");
- fprintf(stderr,"Please report as a bug.\n");
- abort();
- }
- if (clique_list_count <= opts->clique_list_length)
- opts->clique_list[clique_list_count-1] =
- set_duplicate(clique);
- }
-
- /* user_function() */
- if (opts->user_function) {
- if (!opts->user_function(clique,g,opts)) {
- /* User function requested abort. */
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-/*
- * maximalize_clique()
- *
- * Adds greedily all possible vertices in g to set s to make it a maximal
- * clique.
- *
- * s - clique of vertices to make maximal
- * g - graph
- *
- * Note: Not very optimized (uses a simple O(n^2) routine), but is called
- * at maximum once per clique_xxx() call, so it shouldn't matter.
- */
-static void maximalize_clique(set_t s,graph_t *g) {
- int i,j;
- boolean add;
-
- for (i=0; i < g->n; i++) {
- add=TRUE;
- for (j=0; j < g->n; j++) {
- if (SET_CONTAINS_FAST(s,j) && !GRAPH_IS_EDGE(g,i,j)) {
- add=FALSE;
- break;
- }
- }
- if (add) {
- SET_ADD_ELEMENT(s,i);
- }
- }
- return;
-}
-
-
-/*
- * is_maximal()
- *
- * Check whether a clique is maximal or not.
- *
- * clique - set of vertices in clique
- * g - graph
- *
- * Returns TRUE is clique is a maximal clique of g, otherwise FALSE.
- */
-static boolean is_maximal(set_t clique, graph_t *g) {
- int i,j;
- int *table;
- int len;
- boolean addable;
-
- if (temp_count) {
- temp_count--;
- table=temp_list[temp_count];
- } else {
- table=malloc(g->n * sizeof(int));
- }
-
- len=0;
- for (i=0; i < g->n; i++)
- if (SET_CONTAINS_FAST(clique,i))
- table[len++]=i;
-
- for (i=0; i < g->n; i++) {
- addable=TRUE;
- for (j=0; j<len; j++) {
- if (!GRAPH_IS_EDGE(g,i,table[j])) {
- addable=FALSE;
- break;
- }
- }
- if (addable) {
- temp_list[temp_count++]=table;
- return FALSE;
- }
- }
- temp_list[temp_count++]=table;
- return TRUE;
-}
-
-
-/*
- * false_function()
- *
- * Returns FALSE. Can be used as user_function.
- */
-static boolean false_function(set_t clique,graph_t *g,clique_options *opts) {
- return FALSE;
-}
-
-
-
-
-/***** API-functions *****/
-
-/*
- * clique_unweighted_max_weight()
- *
- * Returns the size of the maximum (sized) clique in g (or 0 if search
- * was aborted).
- *
- * g - the graph
- * opts - time printing options
- *
- * Note: As we don't have an algorithm faster than actually finding
- * a maximum clique, we use clique_unweighted_find_single().
- * This incurs only very small overhead.
- */
-int clique_unweighted_max_weight(graph_t *g, clique_options *opts) {
- set_t s;
- int size;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(g!=NULL);
-
- s=clique_unweighted_find_single(g,0,0,FALSE,opts);
- if (s==NULL) {
- /* Search was aborted. */
- return 0;
- }
- size=set_size(s);
- set_free(s);
- return size;
-}
-
-
-/*
- * clique_unweighted_find_single()
- *
- * Returns a clique with size at least min_size and at most max_size.
- *
- * g - the graph
- * min_size - minimum size of clique to search for. If min_size==0,
- * searches for maximum clique.
- * max_size - maximum size of clique to search for. If max_size==0, no
- * upper limit is used. If min_size==0, this must also be 0.
- * maximal - require returned clique to be maximal
- * opts - time printing options
- *
- * Returns the set of vertices forming the clique, or NULL if a clique
- * of requested size/maximality does not exist in the graph (or if
- * opts->time_function() requests abort).
- *
- * The returned clique is newly allocated and can be freed by set_free().
- *
- * Note: Does NOT use opts->user_function() or opts->clique_list[].
- */
-set_t clique_unweighted_find_single(graph_t *g,int min_size,int max_size,
- boolean maximal, clique_options *opts) {
- int i;
- int *table;
- set_t s;
-
- ENTRANCE_SAVE();
- entrance_level++;
-
- if (opts==NULL)
- opts=clique_default_options;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(g!=NULL);
- ASSERT(min_size>=0);
- ASSERT(max_size>=0);
- ASSERT((max_size==0) || (min_size <= max_size));
- ASSERT(!((min_size==0) && (max_size>0)));
- ASSERT((opts->reorder_function==NULL) || (opts->reorder_map==NULL));
-
- if ((max_size>0) && (min_size>max_size)) {
- /* state was not changed */
- entrance_level--;
- return NULL;
- }
-
-#if 0
- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);
-#endif
-
- /* Dynamic allocation */
- current_clique=set_new(g->n);
- clique_size=malloc(g->n * sizeof(int));
- /* table allocated later */
- temp_list=malloc((g->n+2)*sizeof(int *));
- temp_count=0;
-
-#if 0
- /* "start clock" */
- gettimeofday(&realtimer,NULL);
- times(&cputimer);
-#endif
-
- /* reorder */
- if (opts->reorder_function) {
- table=opts->reorder_function(g,FALSE);
- } else if (opts->reorder_map) {
- table=reorder_duplicate(opts->reorder_map,g->n);
- } else {
- table=reorder_ident(g->n);
- }
- ASSERT(reorder_is_bijection(table,g->n));
-
-
- if (unweighted_clique_search_single(table,min_size,g,opts)==0) {
- set_free(current_clique);
- current_clique=NULL;
- goto cleanreturn;
- }
- if (maximal && (min_size>0)) {
- maximalize_clique(current_clique,g);
-
- if ((max_size > 0) && (set_size(current_clique) > max_size)) {
- clique_options localopts;
-
- s = set_new(g->n);
- localopts.time_function = opts->time_function;
- localopts.output = opts->output;
- localopts.user_function = false_function;
- localopts.clique_list = &s;
- localopts.clique_list_length = 1;
-
- for (i=0; i < g->n-1; i++)
- if (clique_size[table[i]]>=min_size)
- break;
- if (unweighted_clique_search_all(table,i,min_size,
- max_size,maximal,
- g,&localopts)) {
- set_free(current_clique);
- current_clique=s;
- } else {
- set_free(current_clique);
- current_clique=NULL;
- }
- }
- }
-
- cleanreturn:
- s=current_clique;
-
- /* Free resources */
- for (i=0; i < temp_count; i++)
- free(temp_list[i]);
- free(temp_list);
- free(table);
- free(clique_size);
-
- ENTRANCE_RESTORE();
- entrance_level--;
-
- return s;
-}
-
-
-/*
- * clique_unweighted_find_all()
- *
- * Find all cliques with size at least min_size and at most max_size.
- *
- * g - the graph
- * min_size - minimum size of cliques to search for. If min_size==0,
- * searches for maximum cliques.
- * max_size - maximum size of cliques to search for. If max_size==0, no
- * upper limit is used. If min_size==0, this must also be 0.
- * maximal - require cliques to be maximal cliques
- * opts - time printing and clique storage options
- *
- * Returns the number of cliques found. This can be less than the number
- * of cliques in the graph iff opts->time_function() or opts->user_function()
- * returns FALSE (request abort).
- *
- * The cliques found are stored in opts->clique_list[] and
- * opts->user_function() is called with them (if non-NULL). The cliques
- * stored in opts->clique_list[] are newly allocated, and can be freed
- * by set_free().
- */
-int clique_unweighted_find_all(graph_t *g, int min_size, int max_size,
- boolean maximal, clique_options *opts) {
- int i;
- int *table;
- int count;
-
- ENTRANCE_SAVE();
- entrance_level++;
-
- if (opts==NULL)
- opts=clique_default_options;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(g!=NULL);
- ASSERT(min_size>=0);
- ASSERT(max_size>=0);
- ASSERT((max_size==0) || (min_size <= max_size));
- ASSERT(!((min_size==0) && (max_size>0)));
- ASSERT((opts->reorder_function==NULL) || (opts->reorder_map==NULL));
-
- if ((max_size>0) && (min_size>max_size)) {
- /* state was not changed */
- entrance_level--;
- return 0;
- }
-
-#if 0
- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);
-#endif
-
- /* Dynamic allocation */
- current_clique=set_new(g->n);
- clique_size=malloc(g->n * sizeof(int));
- /* table allocated later */
- temp_list=malloc((g->n+2)*sizeof(int *));
- temp_count=0;
-
- clique_list_count=0;
- memset(clique_size,0,g->n * sizeof(int));
-
-#if 0
- /* "start clock" */
- gettimeofday(&realtimer,NULL);
- times(&cputimer);
-#endif
-
- /* reorder */
- if (opts->reorder_function) {
- table=opts->reorder_function(g,FALSE);
- } else if (opts->reorder_map) {
- table=reorder_duplicate(opts->reorder_map,g->n);
- } else {
- table=reorder_ident(g->n);
- }
- ASSERT(reorder_is_bijection(table,g->n));
-
-
- /* Search as normal until there is a chance to find a suitable
- * clique. */
- if (unweighted_clique_search_single(table,min_size,g,opts)==0) {
- count=0;
- goto cleanreturn;
- }
-
- if (min_size==0 && max_size==0) {
- min_size=max_size=clique_size[table[g->n-1]];
- maximal=FALSE; /* No need to test, since we're searching
- * for maximum cliques. */
- }
- if (max_size==0) {
- max_size=INT_MAX;
- }
-
- for (i=0; i < g->n-1; i++)
- if (clique_size[table[i]] >= min_size)
- break;
- count=unweighted_clique_search_all(table,i,min_size,max_size,
- maximal,g,opts);
-
- cleanreturn:
- /* Free resources */
- for (i=0; i<temp_count; i++)
- free(temp_list[i]);
- free(temp_list);
- free(table);
- free(clique_size);
- set_free(current_clique);
-
- ENTRANCE_RESTORE();
- entrance_level--;
-
- return count;
-}
-
-
-
-
-/*
- * clique_max_weight()
- *
- * Returns the weight of the maximum weight clique in the graph (or 0 if
- * the search was aborted).
- *
- * g - the graph
- * opts - time printing options
- *
- * Note: As we don't have an algorithm faster than actually finding
- * a maximum weight clique, we use clique_find_single().
- * This incurs only very small overhead.
- */
-int clique_max_weight(graph_t *g,clique_options *opts) {
- set_t s;
- int weight;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(g!=NULL);
-
- s=clique_find_single(g,0,0,FALSE,opts);
- if (s==NULL) {
- /* Search was aborted. */
- return 0;
- }
- weight=graph_subgraph_weight(g,s);
- set_free(s);
- return weight;
-}
-
-
-/*
- * clique_find_single()
- *
- * Returns a clique with weight at least min_weight and at most max_weight.
- *
- * g - the graph
- * min_weight - minimum weight of clique to search for. If min_weight==0,
- * searches for a maximum weight clique.
- * max_weight - maximum weight of clique to search for. If max_weight==0,
- * no upper limit is used. If min_weight==0, max_weight must
- * also be 0.
- * maximal - require returned clique to be maximal
- * opts - time printing options
- *
- * Returns the set of vertices forming the clique, or NULL if a clique
- * of requested weight/maximality does not exist in the graph (or if
- * opts->time_function() requests abort).
- *
- * The returned clique is newly allocated and can be freed by set_free().
- *
- * Note: Does NOT use opts->user_function() or opts->clique_list[].
- * Note: Automatically uses clique_unweighted_find_single if all vertex
- * weights are the same.
- */
-set_t clique_find_single(graph_t *g,int min_weight,int max_weight,
- boolean maximal, clique_options *opts) {
- int i;
- int *table;
- set_t s;
-
- ENTRANCE_SAVE();
- entrance_level++;
-
- if (opts==NULL)
- opts=clique_default_options;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(g!=NULL);
- ASSERT(min_weight>=0);
- ASSERT(max_weight>=0);
- ASSERT((max_weight==0) || (min_weight <= max_weight));
- ASSERT(!((min_weight==0) && (max_weight>0)));
- ASSERT((opts->reorder_function==NULL) || (opts->reorder_map==NULL));
-
- if ((max_weight>0) && (min_weight>max_weight)) {
- /* state was not changed */
- entrance_level--;
- return NULL;
- }
-
-#if 0
- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);
-#endif
-
- /* Check whether we can use unweighted routines. */
- if (!graph_weighted(g)) {
- min_weight=DIV_UP(min_weight,g->weights[0]);
- if (max_weight) {
- max_weight=DIV_DOWN(max_weight,g->weights[0]);
- if (max_weight < min_weight) {
- /* state was not changed */
- entrance_level--;
- return NULL;
- }
- }
-
- weight_multiplier = g->weights[0];
- entrance_level--;
- s=clique_unweighted_find_single(g,min_weight,max_weight,
- maximal,opts);
- ENTRANCE_RESTORE();
- return s;
- }
-
- /* Dynamic allocation */
- current_clique=set_new(g->n);
- best_clique=set_new(g->n);
- clique_size=malloc(g->n * sizeof(int));
- memset(clique_size, 0, g->n * sizeof(int));
- /* table allocated later */
- temp_list=malloc((g->n+2)*sizeof(int *));
- temp_count=0;
-
- clique_list_count=0;
-
-#if 0
- /* "start clock" */
- gettimeofday(&realtimer,NULL);
- times(&cputimer);
-#endif
-
- /* reorder */
- if (opts->reorder_function) {
- table=opts->reorder_function(g,TRUE);
- } else if (opts->reorder_map) {
- table=reorder_duplicate(opts->reorder_map,g->n);
- } else {
- table=reorder_ident(g->n);
- }
- ASSERT(reorder_is_bijection(table,g->n));
-
- if (max_weight==0)
- max_weight=INT_MAX;
-
- if (weighted_clique_search_single(table,min_weight,max_weight,
- g,opts)==0) {
- /* Requested clique has not been found. */
- set_free(best_clique);
- best_clique=NULL;
- goto cleanreturn;
- }
- if (maximal && (min_weight>0)) {
- maximalize_clique(best_clique,g);
- if (graph_subgraph_weight(g,best_clique) > max_weight) {
- clique_options localopts;
-
- localopts.time_function = opts->time_function;
- localopts.output = opts->output;
- localopts.user_function = false_function;
- localopts.clique_list = &best_clique;
- localopts.clique_list_length = 1;
-
- for (i=0; i < g->n-1; i++)
- if ((clique_size[table[i]] >= min_weight) ||
- (clique_size[table[i]] == 0))
- break;
- if (!weighted_clique_search_all(table,i,min_weight,
- max_weight,maximal,
- g,&localopts)) {
- set_free(best_clique);
- best_clique=NULL;
- }
- }
- }
-
- cleanreturn:
- s=best_clique;
-
- /* Free resources */
- for (i=0; i < temp_count; i++)
- free(temp_list[i]);
- free(temp_list);
- temp_list=NULL;
- temp_count=0;
- free(table);
- set_free(current_clique);
- current_clique=NULL;
- free(clique_size);
- clique_size=NULL;
-
- ENTRANCE_RESTORE();
- entrance_level--;
-
- return s;
-}
-
-
-
-
-
-/*
- * clique_find_all()
- *
- * Find all cliques with weight at least min_weight and at most max_weight.
- *
- * g - the graph
- * min_weight - minimum weight of cliques to search for. If min_weight==0,
- * searches for maximum weight cliques.
- * max_weight - maximum weight of cliques to search for. If max_weight==0,
- * no upper limit is used. If min_weight==0, max_weight must
- * also be 0.
- * maximal - require cliques to be maximal cliques
- * opts - time printing and clique storage options
- *
- * Returns the number of cliques found. This can be less than the number
- * of cliques in the graph iff opts->time_function() or opts->user_function()
- * returns FALSE (request abort).
- *
- * The cliques found are stored in opts->clique_list[] and
- * opts->user_function() is called with them (if non-NULL). The cliques
- * stored in opts->clique_list[] are newly allocated, and can be freed
- * by set_free().
- *
- * Note: Automatically uses clique_unweighted_find_all if all vertex
- * weights are the same.
- */
-int clique_find_all(graph_t *g, int min_weight, int max_weight,
- boolean maximal, clique_options *opts) {
- int i,n;
- int *table;
-
- ENTRANCE_SAVE();
- entrance_level++;
-
- if (opts==NULL)
- opts=clique_default_options;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(g!=NULL);
- ASSERT(min_weight>=0);
- ASSERT(max_weight>=0);
- ASSERT((max_weight==0) || (min_weight <= max_weight));
- ASSERT(!((min_weight==0) && (max_weight>0)));
- ASSERT((opts->reorder_function==NULL) || (opts->reorder_map==NULL));
-
- if ((max_weight>0) && (min_weight>max_weight)) {
- /* state was not changed */
- entrance_level--;
- return 0;
- }
-
-#if 0
- if (clocks_per_sec==0)
- clocks_per_sec=sysconf(_SC_CLK_TCK);
- ASSERT(clocks_per_sec>0);
-#endif
-
- if (!graph_weighted(g)) {
- min_weight=DIV_UP(min_weight,g->weights[0]);
- if (max_weight) {
- max_weight=DIV_DOWN(max_weight,g->weights[0]);
- if (max_weight < min_weight) {
- /* state was not changed */
- entrance_level--;
- return 0;
- }
- }
-
- weight_multiplier = g->weights[0];
- entrance_level--;
- i=clique_unweighted_find_all(g,min_weight,max_weight,maximal,
- opts);
- ENTRANCE_RESTORE();
- return i;
- }
-
- /* Dynamic allocation */
- current_clique=set_new(g->n);
- best_clique=set_new(g->n);
- clique_size=malloc(g->n * sizeof(int));
- memset(clique_size, 0, g->n * sizeof(int));
- /* table allocated later */
- temp_list=malloc((g->n+2)*sizeof(int *));
- temp_count=0;
-
-#if 0
- /* "start clock" */
- gettimeofday(&realtimer,NULL);
- times(&cputimer);
-#endif
-
- /* reorder */
- if (opts->reorder_function) {
- table=opts->reorder_function(g,TRUE);
- } else if (opts->reorder_map) {
- table=reorder_duplicate(opts->reorder_map,g->n);
- } else {
- table=reorder_ident(g->n);
- }
- ASSERT(reorder_is_bijection(table,g->n));
-
- /* First phase */
- n=weighted_clique_search_single(table,min_weight,INT_MAX,g,opts);
- if (n==0) {
- /* Requested clique has not been found. */
- goto cleanreturn;
- }
-
- if (min_weight==0) {
- min_weight=n;
- max_weight=n;
- maximal=FALSE; /* They're maximum cliques already. */
- }
- if (max_weight==0)
- max_weight=INT_MAX;
-
- for (i=0; i < g->n; i++)
- if ((clique_size[table[i]] >= min_weight) ||
- (clique_size[table[i]] == 0))
- break;
-
- /* Second phase */
- n=weighted_clique_search_all(table,i,min_weight,max_weight,maximal,
- g,opts);
-
- cleanreturn:
- /* Free resources */
- for (i=0; i < temp_count; i++)
- free(temp_list[i]);
- free(temp_list);
- free(table);
- set_free(current_clique);
- set_free(best_clique);
- free(clique_size);
-
- ENTRANCE_RESTORE();
- entrance_level--;
-
- return n;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-/*
- * clique_print_time()
- *
- * Reports current running information every 0.1 seconds or when values
- * change.
- *
- * level - re-entrance level
- * i - current recursion level
- * n - maximum recursion level
- * max - weight of heaviest clique found
- * cputime - CPU time used in algorithm so far
- * realtime - real time used in algorithm so far
- * opts - prints information to (FILE *)opts->output (or stdout if NULL)
- *
- * Returns always TRUE (ie. never requests abort).
- */
-boolean clique_print_time(int level, int i, int n, int max,
- double cputime, double realtime,
- clique_options *opts) {
- static float prev_time=100;
- static int prev_i=100;
- static int prev_max=100;
- static int prev_level=0;
- FILE *fp=opts->output;
- int j;
-
- if (fp==NULL)
- fp=stdout;
-
- if (ABS(prev_time-realtime)>0.1 || i==n || i<prev_i || max!=prev_max ||
- level!=prev_level) {
- for (j=1; j<level; j++)
- fprintf(fp," ");
- if (realtime-prev_time < 0.01 || i<=prev_i)
- fprintf(fp,"%3d/%d (max %2d) %2.2f s "
- "(0.00 s/round)\n",i,n,max,
- realtime);
- else
- fprintf(fp,"%3d/%d (max %2d) %2.2f s "
- "(%2.2f s/round)\n",
- i,n,max,realtime,
- (realtime-prev_time)/(i-prev_i));
- prev_time=realtime;
- prev_i=i;
- prev_max=max;
- prev_level=level;
- }
- return TRUE;
-}
-
-/*
- * clique_print_time_always()
- *
- * Reports current running information.
- *
- * level - re-entrance level
- * i - current recursion level
- * n - maximum recursion level
- * max - largest clique found
- * cputime - CPU time used in algorithm so far
- * realtime - real time used in algorithm so far
- * opts - prints information to (FILE *)opts->output (or stdout if NULL)
- *
- * Returns always TRUE (ie. never requests abort).
- */
-boolean clique_print_time_always(int level, int i, int n, int max,
- double cputime, double realtime,
- clique_options *opts) {
- static float prev_time=100;
- static int prev_i=100;
- FILE *fp=opts->output;
- int j;
-
- if (fp==NULL)
- fp=stdout;
-
- for (j=1; j<level; j++)
- fprintf(fp," ");
-
- if (realtime-prev_time < 0.01 || i<=prev_i)
- fprintf(fp,"%3d/%d (max %2d) %2.2f s (0.00 s/round)\n",
- i,n,max,realtime);
- else
- fprintf(fp,"%3d/%d (max %2d) %2.2f s (%2.2f s/round)\n",
- i,n,max,realtime,(realtime-prev_time)/(i-prev_i));
- prev_time=realtime;
- prev_i=i;
-
- return TRUE;
-}
-
-
-/*
- * This file contains the graph handling routines.
- *
- * Copyright (C) 2002 Sampo Niskanen, Patric stergrd.
- * Licensed under the GNU GPL, read the file LICENSE for details.
- */
-
-/*
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
-#include "graph.h"
-*/
-
-
-/*
- * graph_new()
- *
- * Returns a newly allocated graph with n vertices all with weight 1,
- * and no edges.
- */
-graph_t *graph_new(int n) {
- graph_t *g;
- int i;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(n>0);
-
- g=malloc(sizeof(graph_t));
- g->n=n;
- g->edges=malloc(g->n * sizeof(set_t));
- g->weights=malloc(g->n * sizeof(int));
- for (i=0; i < g->n; i++) {
- g->edges[i]=set_new(n);
- g->weights[i]=1;
- }
- return g;
-}
-
-/*
- * graph_free()
- *
- * Frees the memory associated with the graph g.
- */
-void graph_free(graph_t *g) {
- int i;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
- ASSERT(g!=NULL);
- ASSERT(g->n > 0);
-
- for (i=0; i < g->n; i++) {
- set_free(g->edges[i]);
- }
- free(g->weights);
- free(g->edges);
- free(g);
- return;
-}
-
-
-/*
- * graph_resize()
- *
- * Resizes graph g to given size. If size > g->n, the new vertices are
- * not connected to any others and their weights are set to 1.
- * If size < g->n, the last g->n - size vertices are removed.
- */
-void graph_resize(graph_t *g, int size) {
- int i;
-
- ASSERT(g!=NULL);
- ASSERT(g->n > 0);
- ASSERT(size > 0);
-
- if (g->n == size)
- return;
-
- /* Free/alloc extra edge-sets */
- for (i=size; i < g->n; i++)
- set_free(g->edges[i]);
- g->edges=realloc(g->edges, size * sizeof(set_t));
- for (i=g->n; i < size; i++)
- g->edges[i]=set_new(size);
-
- /* Resize original sets */
- for (i=0; i < MIN(g->n,size); i++) {
- g->edges[i]=set_resize(g->edges[i],size);
- }
-
- /* Weights */
- g->weights=realloc(g->weights,size * sizeof(int));
- for (i=g->n; i<size; i++)
- g->weights[i]=1;
-
- g->n=size;
- return;
-}
-
-/*
- * graph_crop()
- *
- * Resizes the graph so as to remove all highest-valued isolated vertices.
- */
-void graph_crop(graph_t *g) {
- int i;
-
- for (i=g->n-1; i>=1; i--)
- if (set_size(g->edges[i])>0)
- break;
- graph_resize(g,i+1);
- return;
-}
-
-
-/*
- * graph_weighted()
- *
- * Returns TRUE if all vertex weights of graph g are all the same.
- *
- * Note: Does NOT require weights to be 1.
- */
-boolean graph_weighted(graph_t *g) {
- int i,w;
-
- w=g->weights[0];
- for (i=1; i < g->n; i++)
- if (g->weights[i] != w)
- return TRUE;
- return FALSE;
-}
-
-/*
- * graph_edge_count()
- *
- * Returns the number of edges in graph g.
- */
-int graph_edge_count(graph_t *g) {
- int i;
- int count=0;
-
- for (i=0; i < g->n; i++) {
- count += set_size(g->edges[i]);
- }
- return count/2;
-}
-
-/*
- * graph_print()
- *
- * Prints a representation of the graph g to stdout (along with any errors
- * noticed). Mainly useful for debugging purposes and trivial output.
- *
- * The output consists of a first line describing the dimensions and then
- * one line per vertex containing the vertex number (numbered 0,...,n-1),
- * the vertex weight (if the graph is weighted), "->" and then a list
- * of all vertices it is adjacent to.
- */
-void graph_print(graph_t *g) {
- int i,j;
- int asymm=0;
- int refl=0;
- int nonpos=0;
- int extra=0;
- unsigned int weight=0;
- boolean weighted;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
-
- if (g==NULL) {
- printf(" WARNING: Graph pointer is NULL!\n");
- return;
- }
- if (g->n <= 0) {
- printf(" WARNING: Graph has %d vertices "
- "(should be positive)!\n",g->n);
- return;
- }
-
- weighted=graph_weighted(g);
-
- printf("%s graph has %d vertices, %d edges (density %.2f).\n",
- weighted?"Weighted":((g->weights[0]==1)?
- "Unweighted":"Semi-weighted"),
- g->n,graph_edge_count(g),
- (float)graph_edge_count(g)/((float)(g->n - 1)*(g->n)/2));
-
- for (i=0; i < g->n; i++) {
- printf("%2d",i);
- if (weighted) {
- printf(" w=%d",g->weights[i]);
- if (g->weights[i] <= 0) {
- printf("*NON-POSITIVE*");
- nonpos++;
- }
- }
- if (weight < INT_MAX)
- weight+=g->weights[i];
- printf(" ->");
- for (j=0; j < g->n; j++) {
- if (SET_CONTAINS_FAST(g->edges[i],j)) {
- printf(" %d",j);
- if (i==j) {
- printf("*REFLEXIVE*");
- refl++;
- }
- if (!SET_CONTAINS_FAST(g->edges[j],i)) {
- printf("*ASYMMERTIC*");
- asymm++;
- }
- }
- }
- for (j=g->n; j < SET_ARRAY_LENGTH(g->edges[i])*ELEMENTSIZE;
- j++) {
- if (SET_CONTAINS_FAST(g->edges[i],j)) {
- printf(" %d*NON-EXISTENT*",j);
- extra++;
- }
- }
- printf("\n");
- }
-
- if (asymm)
- printf(" WARNING: Graph contained %d asymmetric edges!\n",
- asymm);
- if (refl)
- printf(" WARNING: Graph contained %d reflexive edges!\n",
- refl);
- if (nonpos)
- printf(" WARNING: Graph contained %d non-positive vertex "
- "weights!\n",nonpos);
- if (extra)
- printf(" WARNING: Graph contained %d edges to "
- "non-existent vertices!\n",extra);
- if (weight>=INT_MAX)
- printf(" WARNING: Total graph weight >= INT_MAX!\n");
- return;
-}
-
-
-/*
- * graph_test()
- *
- * Tests graph g to be valid. Checks that g is non-NULL, the edges are
- * symmetric and anti-reflexive, and that all vertex weights are positive.
- * If output is non-NULL, prints a few lines telling the status of the graph
- * to file descriptor output.
- *
- * Returns TRUE if the graph is valid, FALSE otherwise.
- */
-boolean graph_test(graph_t *g,FILE *output) {
- int i,j;
- int edges=0;
- int asymm=0;
- int nonpos=0;
- int refl=0;
- int extra=0;
- unsigned int weight=0;
- boolean weighted;
-
- ASSERT((sizeof(setelement)*8)==ELEMENTSIZE);
-
- if (g==NULL) {
- if (output)
- fprintf(output," WARNING: Graph pointer is NULL!\n");
- return FALSE;
- }
-
- weighted=graph_weighted(g);
-
- for (i=0; i < g->n; i++) {
- if (g->edges[i]==NULL) {
- if (output)
- fprintf(output," WARNING: Graph edge set "
- "NULL!\n"
- " (further warning suppressed)\n");
- return FALSE;
- }
- if (SET_MAX_SIZE(g->edges[i]) < g->n) {
- if (output)
- fprintf(output," WARNING: Graph edge set "
- "too small!\n"
- " (further warnings suppressed)\n");
- return FALSE;
- }
- for (j=0; j < g->n; j++) {
- if (SET_CONTAINS_FAST(g->edges[i],j)) {
- edges++;
- if (i==j) {
- refl++;
- }
- if (!SET_CONTAINS_FAST(g->edges[j],i)) {
- asymm++;
- }
- }
- }
- for (j=g->n; j < SET_ARRAY_LENGTH(g->edges[i])*ELEMENTSIZE;
- j++) {
- if (SET_CONTAINS_FAST(g->edges[i],j))
- extra++;
- }
- if (g->weights[i] <= 0)
- nonpos++;
- if (weight<INT_MAX)
- weight += g->weights[i];
- }
-
- edges/=2; /* Each is counted twice. */
-
- if (output) {
- /* Semi-weighted means all weights are equal, but not 1. */
- fprintf(output,"%s graph has %d vertices, %d edges "
- "(density %.2f).\n",
- weighted?"Weighted":
- ((g->weights[0]==1)?"Unweighted":"Semi-weighted"),
- g->n,edges,(float)edges/((float)(g->n - 1)*(g->n)/2));
-
- if (asymm)
- fprintf(output," WARNING: Graph contained %d "
- "asymmetric edges!\n",asymm);
- if (refl)
- fprintf(output," WARNING: Graph contained %d "
- "reflexive edges!\n",refl);
- if (nonpos)
- fprintf(output," WARNING: Graph contained %d "
- "non-positive vertex weights!\n",nonpos);
- if (extra)
- fprintf(output," WARNING: Graph contained %d edges "
- "to non-existent vertices!\n",extra);
- if (weight>=INT_MAX)
- fprintf(output," WARNING: Total graph weight >= "
- "INT_MAX!\n");
- if (asymm==0 && refl==0 && nonpos==0 && extra==0 &&
- weight<INT_MAX)
- fprintf(output,"Graph OK.\n");
- }
-
- if (asymm || refl || nonpos || extra || weight>=INT_MAX)
- return FALSE;
-
- return TRUE;
-}
-
-
-/*
- * graph_test_regular()
- *
- * Returns the vertex degree for regular graphs, or -1 if the graph is
- * not regular.
- */
-int graph_test_regular(graph_t *g) {
- int i,n;
-
- n=set_size(g->edges[0]);
-
- for (i=1; i < g->n; i++) {
- if (set_size(g->edges[i]) != n)
- return -1;
- }
- return n;
-}
-
-
-
-/*
- * This file contains the vertex reordering routines.
- *
- * Copyright (C) 2002 Sampo Niskanen, Patric stergrd.
- * Licensed under the GNU GPL, read the file LICENSE for details.
- */
-
-/*
-#include "reorder.h"
-
-#include <time.h>
-#include <sys/times.h>
-#include <stdlib.h>
-
-#include <limits.h>
-*/
-
-
-/*
- * reorder_set()
- *
- * Reorders the set s with a function i -> order[i].
- *
- * Note: Assumes that order is the same size as SET_MAX_SIZE(s).
- */
-void reorder_set(set_t s,int *order) {
- set_t tmp;
- int i,j;
- setelement e;
-
- ASSERT(reorder_is_bijection(order,SET_MAX_SIZE(s)));
-
- tmp=set_new(SET_MAX_SIZE(s));
-
- for (i=0; i<(SET_MAX_SIZE(s)/ELEMENTSIZE); i++) {
- e=s[i];
- if (e==0)
- continue;
- for (j=0; j<ELEMENTSIZE; j++) {
- if (e&1) {
- SET_ADD_ELEMENT(tmp,order[i*ELEMENTSIZE+j]);
- }
- e = e>>1;
- }
- }
- if (SET_MAX_SIZE(s)%ELEMENTSIZE) {
- e=s[i];
- for (j=0; j<(SET_MAX_SIZE(s)%ELEMENTSIZE); j++) {
- if (e&1) {
- SET_ADD_ELEMENT(tmp,order[i*ELEMENTSIZE+j]);
- }
- e = e>>1;
- }
- }
- set_copy(s,tmp);
- set_free(tmp);
- return;
-}
-
-
-/*
- * reorder_graph()
- *
- * Reorders the vertices in the graph with function i -> order[i].
- *
- * Note: Assumes that order is of size g->n.
- */
-void reorder_graph(graph_t *g, int *order) {
- int i;
- set_t *tmp_e;
- int *tmp_w;
-
- ASSERT(reorder_is_bijection(order,g->n));
-
- tmp_e=malloc(g->n * sizeof(set_t));
- tmp_w=malloc(g->n * sizeof(int));
- for (i=0; i<g->n; i++) {
- reorder_set(g->edges[i],order);
- tmp_e[order[i]]=g->edges[i];
- tmp_w[order[i]]=g->weights[i];
- }
- for (i=0; i<g->n; i++) {
- g->edges[i]=tmp_e[i];
- g->weights[i]=tmp_w[i];
- }
- free(tmp_e);
- free(tmp_w);
- return;
-}
-
-
-
-/*
- * reorder_duplicate()
- *
- * Returns a newly allocated duplicate of the given ordering.
- */
-int *reorder_duplicate(int *order,int n) {
- int *new;
-
- new=malloc(n*sizeof(int));
- memcpy(new,order,n*sizeof(int));
- return new;
-}
-
-/*
- * reorder_invert()
- *
- * Inverts the given ordering so that new[old[i]]==i.
- *
- * Note: Asserts that order is a bijection.
- */
-void reorder_invert(int *order,int n) {
- int *new;
- int i;
-
- ASSERT(reorder_is_bijection(order,n));
-
- new=malloc(n*sizeof(int));
- for (i=0; i<n; i++)
- new[order[i]]=i;
- for (i=0; i<n; i++)
- order[i]=new[i];
- free(new);
- return;
-}
-
-/*
- * reorder_reverse()
- *
- * Reverses the given ordering so that new[i] == n-1 - old[i].
- */
-void reorder_reverse(int *order,int n) {
- int i;
-
- for (i=0; i<n; i++)
- order[i] = n-1 - order[i];
- return;
-}
-
-/*
- * reorder_is_bijection
- *
- * Checks that an ordering is a bijection {0,...,n-1} -> {0,...,n-1}.
- *
- * Returns TRUE if it is a bijection, FALSE otherwise.
- */
-boolean reorder_is_bijection(int *order,int n) {
- boolean *used;
- int i;
-
- used=calloc(n,sizeof(boolean));
- for (i=0; i<n; i++) {
- if (order[i]<0 || order[i]>=n) {
- free(used);
- return FALSE;
- }
- if (used[order[i]]) {
- free(used);
- return FALSE;
- }
- used[order[i]]=TRUE;
- }
- for (i=0; i<n; i++) {
- if (!used[i]) {
- free(used);
- return FALSE;
- }
- }
- free(used);
- return TRUE;
-}
-
-/*
- * reorder_ident()
- *
- * Returns a newly allocated identity ordering of size n, ie. order[i]==i.
- */
-int *reorder_ident(int n) {
- int i;
- int *order;
-
- order=malloc(n*sizeof(int));
- for (i=0; i<n; i++)
- order[i]=i;
- return order;
-}
-
-
-
-/*** Reordering functions for use in clique_options ***/
-
-/*
- * reorder_by_ident()
- *
- * Returns an identity ordering.
- */
-int *reorder_by_ident(graph_t *g,boolean weighted) {
- return reorder_ident(g->n);
-}
-
-/*
- * reorder_by_reverse()
- *
- * Returns a reverse identity ordering.
- */
-int *reorder_by_reverse(graph_t *g,boolean weighted) {
- int i;
- int *order;
-
- order=malloc(g->n * sizeof(int));
- for (i=0; i < g->n; i++)
- order[i]=g->n-i-1;
- return order;
-}
-
-/*
- * reorder_by_greedy_coloring()
- *
- * Equivalent to reorder_by_weighted_greedy_coloring or
- * reorder_by_unweighted_greedy_coloring according to the value of weighted.
- */
-int *reorder_by_greedy_coloring(graph_t *g,boolean weighted) {
- if (weighted)
- return reorder_by_weighted_greedy_coloring(g,weighted);
- else
- return reorder_by_unweighted_greedy_coloring(g,weighted);
-}
-
-
-/*
- * reorder_by_unweighted_greedy_coloring()
- *
- * Returns an ordering for the graph g by coloring the clique one
- * color at a time, always adding the vertex of largest degree within
- * the uncolored graph, and numbering these vertices 0, 1, ...
- *
- * Experimentally efficient for use with unweighted graphs.
- */
-int *reorder_by_unweighted_greedy_coloring(graph_t *g,boolean weighted) {
- int i,j,v;
- boolean *tmp_used;
- int *degree; /* -1 for used vertices */
- int *order;
- int maxdegree,maxvertex=0;
- boolean samecolor;
-
- tmp_used=calloc(g->n,sizeof(boolean));
- degree=calloc(g->n,sizeof(int));
- order=calloc(g->n,sizeof(int));
-
- for (i=0; i < g->n; i++) {
- for (j=0; j < g->n; j++) {
- ASSERT(!((i==j) && GRAPH_IS_EDGE(g,i,j)));
- if (GRAPH_IS_EDGE(g,i,j))
- degree[i]++;
- }
- }
-
- v=0;
- while (v < g->n) {
- /* Reset tmp_used. */
- memset(tmp_used,0,g->n * sizeof(boolean));
-
- do {
- /* Find vertex to be colored. */
- maxdegree=0;
- samecolor=FALSE;
- for (i=0; i < g->n; i++) {
- if (!tmp_used[i] && degree[i] >= maxdegree) {
- maxvertex=i;
- maxdegree=degree[i];
- samecolor=TRUE;
- }
- }
- if (samecolor) {
- order[v]=maxvertex;
- degree[maxvertex]=-1;
- v++;
-
- /* Mark neighbors not to color with same
- * color and update neighbor degrees. */
- for (i=0; i < g->n; i++) {
- if (GRAPH_IS_EDGE(g,maxvertex,i)) {
- tmp_used[i]=TRUE;
- degree[i]--;
- }
- }
- }
- } while (samecolor);
- }
-
- free(tmp_used);
- free(degree);
- return order;
-}
-
-/*
- * reorder_by_weighted_greedy_coloring()
- *
- * Returns an ordering for the graph g by coloring the clique one
- * color at a time, always adding the vertex that (in order of importance):
- * 1. has the minimum weight in the remaining graph
- * 2. has the largest sum of weights surrounding the vertex
- *
- * Experimentally efficient for use with weighted graphs.
- */
-int *reorder_by_weighted_greedy_coloring(graph_t *g, boolean weighted) {
- int i,j,p=0;
- int cnt;
- int *nwt; /* Sum of surrounding vertices' weights */
- int min_wt,max_nwt;
- boolean *used;
- int *order;
-
- nwt=malloc(g->n * sizeof(int));
- order=malloc(g->n * sizeof(int));
- used=calloc(g->n,sizeof(boolean));
-
- for (i=0; i < g->n; i++) {
- nwt[i]=0;
- for (j=0; j < g->n; j++)
- if (GRAPH_IS_EDGE(g, i, j))
- nwt[i] += g->weights[j];
- }
-
- for (cnt=0; cnt < g->n; cnt++) {
- min_wt=INT_MAX;
- max_nwt=-1;
- for (i=g->n-1; i>=0; i--)
- if ((!used[i]) && (g->weights[i] < min_wt))
- min_wt=g->weights[i];
- for (i=g->n-1; i>=0; i--) {
- if (used[i] || (g->weights[i] > min_wt))
- continue;
- if (nwt[i] > max_nwt) {
- max_nwt=nwt[i];
- p=i;
- }
- }
- order[cnt]=p;
- used[p]=TRUE;
- for (j=0; j < g->n; j++)
- if ((!used[j]) && (GRAPH_IS_EDGE(g, p, j)))
- nwt[j] -= g->weights[p];
- }
-
- free(nwt);
- free(used);
-
- ASSERT(reorder_is_bijection(order,g->n));
-
- return order;
-}
-
-/*
- * reorder_by_degree()
- *
- * Returns a reordering of the graph g so that the vertices with largest
- * degrees (most neighbors) are first.
- */
-int *reorder_by_degree(graph_t *g, boolean weighted) {
- int i,j,v;
- int *degree;
- int *order;
- int maxdegree,maxvertex=0;
-
- degree=calloc(g->n,sizeof(int));
- order=calloc(g->n,sizeof(int));
-
- for (i=0; i < g->n; i++) {
- for (j=0; j < g->n; j++) {
- ASSERT(!((i==j) && GRAPH_IS_EDGE(g,i,j)));
- if (GRAPH_IS_EDGE(g,i,j))
- degree[i]++;
- }
- }
-
- for (v=0; v < g->n; v++) {
- maxdegree=0;
- for (i=0; i < g->n; i++) {
- if (degree[i] >= maxdegree) {
- maxvertex=i;
- maxdegree=degree[i];
- }
- }
- order[v]=maxvertex;
- degree[maxvertex]=-1; /* used */
-/*** Max. degree withing unselected graph:
- for (i=0; i < g->n; i++) {
- if (GRAPH_IS_EDGE(g,maxvertex,i))
- degree[i]--;
- }
-***/
- }
-
- free(degree);
- return order;
-}
-
-/*
- * reorder_by_random()
- *
- * Returns a random reordering for graph g.
- * Note: Used the functions rand() and srand() to generate the random
- * numbers. srand() is re-initialized every time reorder_by_random()
- * is called using the system time.
- */
-int *reorder_by_random(graph_t *g, boolean weighted) {
- /* struct tms t; */
- int i,r;
- int *new;
- boolean *used;
-
-/*
- srand(times(&t)+time(NULL));
-*/
- INITRANBYTIME;
-
- new=calloc(g->n, sizeof(int));
- used=calloc(g->n, sizeof(boolean));
- for (i=0; i < g->n; i++) {
- do {
- r=NEXTRAN % g->n;
- } while (used[r]);
- new[i]=r;
- used[r]=TRUE;
- }
- free(used);
- return new;
-}
-
/************************************************************************/
/* This is an interface between nauty and cliquer for finding
--- a/nautycliquer.h
+++ b/nautycliquer.h
@@ -6,635 +6,7 @@
#include "nauty.h"
#include "gtools.h"
-#include <limits.h>
-
-/**********************************************************************
-#include "cliquerconf.h"
-*/
-
-/*
- * setelement is the basic memory type used in sets. It is often fastest
- * to be as large as can fit into the CPU registers.
- *
- * ELEMENTSIZE is the size of one setelement, measured in bits. It must
- * be either 16, 32 or 64 (otherwise additional changes must be made to
- * the source).
- *
- * The default is to use "unsigned long int" and attempt to guess the
- * size using <limits.h>, which should work pretty well. Check functioning
- * with "make test".
- */
-
-/* typedef unsigned long int setelement; */
-/* #define ELEMENTSIZE 64 */
-
-/*
- * INLINE is a command prepended to function declarations to instruct the
- * compiler to inline the function. If inlining is not desired, define blank.
- *
- * The default is to use "inline", which is recognized by most compilers.
- */
-
-/* #define INLINE */
-/* #define INLINE __inline__ */
-
-
-/*
- * Set handling functions are defined as static functions in set.h for
- * performance reasons. This may cause unnecessary warnings from the
- * compiler. Some compilers (such as GCC) have the possibility to turn
- * off the warnings on a per-function basis using a flag prepended to
- * the function declaration.
- *
- * The default is to use the correct attribute when compiling with GCC,
- * or no flag otherwise.
- */
-
-/* #define UNUSED_FUNCTION __attribute__((unused)) */
-/* #define UNUSED_FUNCTION */
-
-/*
- * Uncommenting the following will disable all assertions (checks that
- * function arguments and other variables are correct). This is highly
- * discouraged, as it allows bugs to go unnoticed easier. The assertions
- * are set so that they do not slow down programs notably.
- */
-
-/* #define ASSERT(x) */
-
-/**********************************************************************
-#include "misc.h"
-*/
-
-/*
- * We #define boolean instead of using a typedef because nauty.h uses it
- * also. AFAIK, there is no way to check for an existing typedef, and
- * re-typedefing is illegal (even when using exactly the same datatype!).
-#ifndef boolean
-#define boolean int
-#endif
-
-BDM: In nauty's version we will use nauty's boolean (which is int anyway).
- */
-
-/*
- * Default value for UNUSED_FUNCTION: use "__attribute__((unused))" for
- * GCC versions that support it, otherwise leave blank.
- */
-#ifndef UNUSED_FUNCTION
-# if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
-# define UNUSED_FUNCTION __attribute__((unused))
-# else
-# define UNUSED_FUNCTION
-# endif
-#endif /* !UNUSED_FUNCTION */
-
-/*
- * Default inlining directive: "inline"
- */
-#ifndef INLINE
-#define INLINE inline
-#endif
-
-#ifndef ASSERT
-#define ASSERT(expr) \
- if (!(expr)) { \
- fprintf(stderr,"cliquer file %s: line %d: assertion failed: " \
- "(%s)\n",__FILE__,__LINE__,#expr); \
- abort(); \
- }
-#endif /* !ASSERT */
-
-
-#ifndef FALSE
-#define FALSE (0)
-#endif
-#ifndef TRUE
-#define TRUE (!FALSE)
-#endif
-
-
-#ifndef MIN
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#endif
-#ifndef MAX
-#define MAX(a,b) (((a)>(b))?(a):(b))
-#endif
-#ifndef ABS
-#define ABS(v) (((v)<0)?(-(v)):(v))
-#endif
-
-/**********************************************************************
-#include "set.h"
-*/
-
-/*
- * This file contains the set handling routines.
- *
- * Copyright (C) 2002 Sampo Niskanen, Patric Östergård.
- * Licensed under the GNU GPL, read the file LICENSE for details.
- */
-
-/*
- * Sets are arrays of setelement's (typically unsigned long int's) with
- * representative bits for each value they can contain. The values
- * are numbered 0,...,n-1.
- */
-
-
-/*** Variable types and constants. ***/
-
-
-/*
- * If setelement hasn't been declared:
- * - use "unsigned long int" as setelement
- * - try to deduce size from ULONG_MAX
- */
-
-#ifndef ELEMENTSIZE
-typedef unsigned long int setelement;
-# if (ULONG_MAX == 65535)
-# define ELEMENTSIZE 16
-# elif (ULONG_MAX == 4294967295)
-# define ELEMENTSIZE 32
-# else
-# define ELEMENTSIZE 64
-# endif
-#endif /* !ELEMENTSIZE */
-
-typedef setelement * set_t;
-
-
-/*** Counting amount of 1 bits in a setelement ***/
-
-/* Array for amount of 1 bits in a byte. */
-static int set_bit_count[256] = {
- 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,
- 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
- 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
- 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
- 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
- 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
- 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
- 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
- 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
- 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
- 4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8 };
-
-/* The following macros assume that all higher bits are 0.
- * They may in some cases be useful also on with other ELEMENTSIZE's,
- * so we define them all. */
-#define SET_ELEMENT_BIT_COUNT_8(a) (set_bit_count[(a)])
-#define SET_ELEMENT_BIT_COUNT_16(a) (set_bit_count[(a)>>8] + \
- set_bit_count[(a)&0xFF])
-#define SET_ELEMENT_BIT_COUNT_32(a) (set_bit_count[(a)>>24] + \
- set_bit_count[((a)>>16)&0xFF] + \
- set_bit_count[((a)>>8)&0xFF] + \
- set_bit_count[(a)&0xFF])
-#define SET_ELEMENT_BIT_COUNT_64(a) (set_bit_count[(a)>>56] + \
- set_bit_count[((a)>>48)&0xFF] + \
- set_bit_count[((a)>>40)&0xFF] + \
- set_bit_count[((a)>>32)&0xFF] + \
- set_bit_count[((a)>>24)&0xFF] + \
- set_bit_count[((a)>>16)&0xFF] + \
- set_bit_count[((a)>>8)&0xFF] + \
- set_bit_count[(a)&0xFF])
-#if (ELEMENTSIZE==64)
-# define SET_ELEMENT_BIT_COUNT(a) SET_ELEMENT_BIT_COUNT_64(a)
-# define FULL_ELEMENT ((setelement)0xFFFFFFFFFFFFFFFF)
-#elif (ELEMENTSIZE==32)
-# define SET_ELEMENT_BIT_COUNT(a) SET_ELEMENT_BIT_COUNT_32(a)
-# define FULL_ELEMENT ((setelement)0xFFFFFFFF)
-#elif (ELEMENTSIZE==16)
-# define SET_ELEMENT_BIT_COUNT(a) SET_ELEMENT_BIT_COUNT_16(a)
-# define FULL_ELEMENT ((setelement)0xFFFF)
-#else
-# error "SET_ELEMENT_BIT_COUNT(a) not defined for current ELEMENTSIZE"
-#endif
-
-/*** Macros and functions ***/
-
-/*
- * Gives a value with bit x (counting from lsb up) set.
- *
- * Making this as a table might speed up things on some machines
- * (though on most modern machines it's faster to shift instead of
- * using memory). Making it a macro makes it easy to change.
- */
-#define SET_BIT_MASK(x) ((setelement)1<<(x))
-
-/* Set element handling macros */
-
-#define SET_ELEMENT_INTERSECT(a,b) ((a)&(b))
-#define SET_ELEMENT_UNION(a,b) ((a)|(b))
-#define SET_ELEMENT_DIFFERENCE(a,b) ((a)&(~(b)))
-#define SET_ELEMENT_CONTAINS(e,v) ((e)&SET_BIT_MASK(v))
-
-/* Set handling macros */
-
-#define SET_ADD_ELEMENT(s,a) \
- ((s)[(a)/ELEMENTSIZE] |= SET_BIT_MASK((a)%ELEMENTSIZE))
-#define SET_DEL_ELEMENT(s,a) \
- ((s)[(a)/ELEMENTSIZE] &= ~SET_BIT_MASK((a)%ELEMENTSIZE))
-#define SET_CONTAINS_FAST(s,a) (SET_ELEMENT_CONTAINS((s)[(a)/ELEMENTSIZE], \
- (a)%ELEMENTSIZE))
-#define SET_CONTAINS(s,a) (((a)<SET_MAX_SIZE(s))?SET_CONTAINS_FAST(s,a):FALSE)
-
-/* Sets can hold values between 0,...,SET_MAX_SIZE(s)-1 */
-#define SET_MAX_SIZE(s) ((s)[-1])
-/* Sets consist of an array of SET_ARRAY_LENGTH(s) setelements */
-#define SET_ARRAY_LENGTH(s) (((s)[-1]+ELEMENTSIZE-1)/ELEMENTSIZE)
-
-/*
- * set_new()
- *
- * Create a new set that can hold values in the range 0,...,size-1.
- */
-UNUSED_FUNCTION
-static set_t set_new(int size) {
- int n;
- set_t s;
-
- ASSERT(size>0);
-
- n=(size/ELEMENTSIZE+1)+1;
- s=calloc(n,sizeof(setelement));
- s[0]=size;
-
- return &(s[1]);
-}
-
-/*
- * set_free()
- *
- * Free the memory associated with set s.
- */
-UNUSED_FUNCTION
-static void set_free(set_t s) {
- ASSERT(s!=NULL);
- free(&(s[-1]));
-}
-
-/*
- * set_resize()
- *
- * Resizes set s to given size. If the size is less than SET_MAX_SIZE(s),
- * the last elements are dropped.
- *
- * Returns a pointer to the new set.
- */
-UNUSED_FUNCTION
-static set_t set_resize(set_t s, int size) {
- int n;
-
- ASSERT(size>0);
-
- n=(size/ELEMENTSIZE+1);
- s=((setelement *)realloc(s-1,(n+1)*sizeof(setelement)))+1;
-
- if (n>SET_ARRAY_LENGTH(s))
- memset(s+SET_ARRAY_LENGTH(s),0,
- (n-SET_ARRAY_LENGTH(s))*sizeof(setelement));
- if (size < SET_MAX_SIZE(s))
- s[(size-1)/ELEMENTSIZE] &= (FULL_ELEMENT >>
- (ELEMENTSIZE-size%ELEMENTSIZE));
- s[-1]=size;
-
- return s;
-}
-
-/*
- * set_size()
- *
- * Returns the number of elements in set s.
- */
-UNUSED_FUNCTION
-static int set_size(set_t s) {
- int count=0;
- setelement *c;
-
- for (c=s; c < s+SET_ARRAY_LENGTH(s); c++)
- count+=SET_ELEMENT_BIT_COUNT(*c);
- return count;
-}
-
-/*
- * set_duplicate()
- *
- * Returns a newly allocated duplicate of set s.
- */
-UNUSED_FUNCTION
-static set_t set_duplicate(set_t s) {
- set_t new;
-
- new=set_new(SET_MAX_SIZE(s));
- memcpy(new,s,SET_ARRAY_LENGTH(s)*sizeof(setelement));
- return new;
-}
-
-/*
- * set_copy()
- *
- * Copies set src to dest. If dest is NULL, is equal to set_duplicate.
- * If dest smaller than src, it is freed and a new set of the same size as
- * src is returned.
- */
-UNUSED_FUNCTION
-static set_t set_copy(set_t dest,set_t src) {
- if (dest==NULL)
- return set_duplicate(src);
- if (SET_MAX_SIZE(dest)<SET_MAX_SIZE(src)) {
- set_free(dest);
- return set_duplicate(src);
- }
- memcpy(dest,src,SET_ARRAY_LENGTH(src)*sizeof(setelement));
- memset(dest+SET_ARRAY_LENGTH(src),0,((SET_ARRAY_LENGTH(dest) -
- SET_ARRAY_LENGTH(src)) *
- sizeof(setelement)));
- return dest;
-}
-
-/*
- * set_empty()
- *
- * Removes all elements from the set s.
- */
-UNUSED_FUNCTION
-static void set_empty(set_t s) {
- memset(s,0,SET_ARRAY_LENGTH(s)*sizeof(setelement));
- return;
-}
-
-/*
- * set_intersection()
- *
- * Store the intersection of sets a and b into res. If res is NULL,
- * a new set is created and the result is written to it. If res is
- * smaller than the larger one of a and b, it is freed and a new set
- * is created and the result is returned.
- *
- * Returns either res or a new set that has been allocated in its stead.
- *
- * Note: res may not be a or b.
- */
-UNUSED_FUNCTION
-static set_t set_intersection(set_t res,set_t a,set_t b) {
- int i,max;
-
- if (res==NULL) {
- res = set_new(MAX(SET_MAX_SIZE(a),SET_MAX_SIZE(b)));
- } else if (SET_MAX_SIZE(res) < MAX(SET_MAX_SIZE(a),SET_MAX_SIZE(b))) {
- set_free(res);
- res = set_new(MAX(SET_MAX_SIZE(a),SET_MAX_SIZE(b)));
- } else {
- set_empty(res);
- }
-
- max=MIN(SET_ARRAY_LENGTH(a),SET_ARRAY_LENGTH(b));
- for (i=0; i<max; i++) {
- res[i]=SET_ELEMENT_INTERSECT(a[i],b[i]);
- }
-
- return res;
-}
-
-/*
- * set_union()
- *
- * Store the union of sets a and b into res. If res is NULL, a new set
- * is created and the result is written to it. If res is smaller than
- * the larger one of a and b, it is freed and a new set is created and
- * the result is returned.
- *
- * Returns either res or a new set that has been allocated in its stead.
- *
- * Note: res may not be a or b.
- */
-UNUSED_FUNCTION
-static set_t set_union(set_t res,set_t a,set_t b) {
- int i,max;
-
- if (res==NULL) {
- res = set_new(MAX(SET_MAX_SIZE(a),SET_MAX_SIZE(b)));
- } else if (SET_MAX_SIZE(res) < MAX(SET_MAX_SIZE(a),SET_MAX_SIZE(b))) {
- set_free(res);
- res = set_new(MAX(SET_MAX_SIZE(a),SET_MAX_SIZE(b)));
- } else {
- set_empty(res);
- }
-
- max=MAX(SET_ARRAY_LENGTH(a),SET_ARRAY_LENGTH(b));
- for (i=0; i<max; i++) {
- res[i]=SET_ELEMENT_UNION(a[i],b[i]);
- }
-
- return res;
-}
-
-
-/*
- * set_return_next()
- *
- * Returns the smallest value in set s which is greater than n, or -1 if
- * such a value does not exist.
- *
- * Can be used to iterate through all values of s:
- *
- * int i=-1;
- * while ((i=set_return_next(s,i))>=0) {
- * // i is in set s
- * }
- */
-UNUSED_FUNCTION
-static int set_return_next(set_t s, int n) {
- if (n<0)
- n=0;
- else
- n++;
- if (n >= SET_MAX_SIZE(s))
- return -1;
-
- while (n%ELEMENTSIZE) {
- if (SET_CONTAINS(s,n))
- return n;
- n++;
- if (n >= SET_MAX_SIZE(s))
- return -1;
- }
-
- while (s[n/ELEMENTSIZE]==0) {
- n+=ELEMENTSIZE;
- if (n >= SET_MAX_SIZE(s))
- return -1;
- }
- while (!SET_CONTAINS(s,n)) {
- n++;
- if (n >= SET_MAX_SIZE(s))
- return -1;
- }
- return n;
-}
-
-
-/*
- * set_print()
- *
- * Prints the size and contents of set s to stdout.
- * Mainly useful for debugging purposes and trivial output.
- */
-UNUSED_FUNCTION
-static void set_print(set_t s) {
- int i;
- printf("size=%d(max %d)",set_size(s),(int)SET_MAX_SIZE(s));
- for (i=0; i<SET_MAX_SIZE(s); i++)
- if (SET_CONTAINS(s,i))
- printf(" %d",i);
- printf("\n");
- return;
-}
-
-/********************************************************************
-#include "graph.h"
-*/
-
-typedef struct _graph_t graph_t;
-struct _graph_t {
- int n; /* Vertices numbered 0...n-1 */
- set_t *edges; /* A list of n sets (the edges). */
- int *weights; /* A list of n vertex weights. */
-};
-
-
-#define GRAPH_IS_EDGE_FAST(g,i,j) (SET_CONTAINS_FAST((g)->edges[(i)],(j)))
-#define GRAPH_IS_EDGE(g,i,j) (((i)<((g)->n))?SET_CONTAINS((g)->edges[(i)], \
- (j)):FALSE)
-#define GRAPH_ADD_EDGE(g,i,j) do { \
- SET_ADD_ELEMENT((g)->edges[(i)],(j)); \
- SET_ADD_ELEMENT((g)->edges[(j)],(i)); \
-} while (FALSE)
-#define GRAPH_DEL_EDGE(g,i,j) do { \
- SET_DEL_ELEMENT((g)->edges[(i)],(j)); \
- SET_DEL_ELEMENT((g)->edges[(j)],(i)); \
-} while (FALSE)
-
-
-graph_t *graph_new(int n);
-void graph_free(graph_t *g);
-void graph_resize(graph_t *g, int size);
-void graph_crop(graph_t *g);
-
-boolean graph_weighted(graph_t *g);
-int graph_edge_count(graph_t *g);
-
-graph_t *graph_read_dimacs(FILE *fp);
-graph_t *graph_read_dimacs_file(char *file);
-boolean graph_write_dimacs_ascii(graph_t *g, char *comment,FILE *fp);
-boolean graph_write_dimacs_ascii_file(graph_t *g,char *comment,char *file);
-boolean graph_write_dimacs_binary(graph_t *g, char *comment,FILE *fp);
-boolean graph_write_dimacs_binary_file(graph_t *g, char *comment,char *file);
-
-void graph_print(graph_t *g);
-boolean graph_test(graph_t *g, FILE *output);
-int graph_test_regular(graph_t *g);
-
-UNUSED_FUNCTION
-static int graph_subgraph_weight(graph_t *g,set_t s) {
- int i,j;
- int count=0;
- setelement e;
-
- for (i=0; i<SET_ARRAY_LENGTH(s); i++) {
- if (s[i]) {
- e=s[i];
- for (j=0; j<ELEMENTSIZE; j++) {
- if (e&1)
- count+=g->weights[i*ELEMENTSIZE+j];
- e = e>>1;
- }
- }
- }
- return count;
-}
-
-UNUSED_FUNCTION
-static int graph_vertex_degree(graph_t *g, int v) {
- return set_size(g->edges[v]);
-}
-
-/********************************************************************
-#include "reorder.h"
-*/
-
-void reorder_set(set_t s,int *order);
-void reorder_graph(graph_t *g, int *order);
-int *reorder_duplicate(int *order,int n);
-void reorder_invert(int *order,int n);
-void reorder_reverse(int *order,int n);
-int *reorder_ident(int n);
-boolean reorder_is_bijection(int *order,int n);
-
-
-#define reorder_by_default reorder_by_greedy_coloring
-int *reorder_by_greedy_coloring(graph_t *g, boolean weighted);
-int *reorder_by_weighted_greedy_coloring(graph_t *g, boolean weighted);
-int *reorder_by_unweighted_greedy_coloring(graph_t *g,boolean weighted);
-int *reorder_by_degree(graph_t *g, boolean weighted);
-int *reorder_by_random(graph_t *g, boolean weighted);
-int *reorder_by_ident(graph_t *g, boolean weighted);
-int *reorder_by_reverse(graph_t *g, boolean weighted);
-
-
-typedef struct _clique_options clique_options;
-struct _clique_options {
- int *(*reorder_function)(graph_t *, boolean);
- int *reorder_map;
-
- /* arguments: level, n, max, user_time, system_time, opts */
- boolean (*time_function)(int,int,int,int,double,double,
- clique_options *);
- FILE *output;
-
- boolean (*user_function)(set_t,graph_t *,clique_options *);
- void *user_data;
- set_t *clique_list;
- int clique_list_length;
-};
-
-extern clique_options *clique_default_options;
-
-/* Weighted clique functions */
-int clique_max_weight(graph_t *g,clique_options *opts);
-set_t clique_find_single(graph_t *g,int min_weight,int max_weight,
- boolean maximal, clique_options *opts);
-int clique_find_all(graph_t *g, int req_weight, boolean exact,
- boolean maximal, clique_options *opts);
-
-/* Unweighted clique functions */
-#define clique_unweighted_max_size clique_unweighted_max_weight
-int clique_unweighted_max_weight(graph_t *g, clique_options *opts);
-set_t clique_unweighted_find_single(graph_t *g,int min_size,
- int max_size,boolean maximal,
- clique_options *opts);
-int clique_unweighted_find_all(graph_t *g, int min_size, int max_size,
- boolean maximal, clique_options *opts);
-
-/* Time printing functions */
-boolean clique_print_time(int level, int i, int n, int max,
- double cputime, double realtime,
- clique_options *opts);
-boolean clique_print_time_always(int level, int i, int n, int max,
- double cputime, double realtime,
- clique_options *opts);
-
-
-/* Alternate spelling (let's be a little forgiving): */
-#define cliquer_options clique_options
-#define cliquer_default_options clique_default_options
+#include <cliquer/cliquer.h>
/* Procedures defined in nautycliquer.c */
int find_clique(graph *g, int m, int n,
--- a/nauty-pc.in
+++ b/nauty-pc.in
@@ -6,6 +6,6 @@
Name: nauty
Description: Programs and library for graph isomorphism
Version: @PACKAGE_VERSION@
-Libs: -L${libdir} LIBS
+Libs: -L${libdir} LIBS -lcliquer
Libs.private:
Cflags: -I${includedir} CFLGS
|