1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239
|
/*
* Normaliz
* Copyright (C) 2007-2019 Winfried Bruns, Bogdan Ichim, Christof Soeger
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* As an exception, when this program is distributed through (i) the App Store
* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
* by Google Inc., then that store may impose any digital rights management,
* device limits and/or redistribution restrictions that are required by its
* terms of service.
*/
//---------------------------------------------------------------------------
#include <cstdlib>
#include <set>
#include <map>
#include <iostream>
#include <string>
#include <algorithm>
#include <chrono>
#include <deque>
#include <cmath>
#include <iomanip>
#include <fstream>
#include "libnormaliz/cone.h"
#include "libnormaliz/full_cone.h"
#include "libnormaliz/project_and_lift.h"
#include "libnormaliz/vector_operations.h"
#include "libnormaliz/list_and_map_operations.h"
// #include "libnormaliz/map_operations.h"
#include "libnormaliz/integer.h"
#include "libnormaliz/sublattice_representation.h"
#include "libnormaliz/offload_handler.h"
#ifdef _MSC_VER
typedef long long ssize_t;
#endif
//---------------------------------------------------------------------------
namespace libnormaliz {
using namespace std;
// clock_t pyrtime;
const size_t EvalBoundTriang = 5000000; // if more than EvalBoundTriang simplices have been stored
// evaluation is started (whenever possible)
const size_t EvalBoundPyr = 500000; // the same for stored pyramids of level > 0
const size_t EvalBoundLevel0Pyr = 500000; // 1000000; // the same for stored level 0 pyramids
const int largePyramidFactor = 20; // used in the decision whether a pyramid is large
const int SuppHypRecursionFactor = 320000; // pyramids for supphyps formed if Pos*Neg > ...
const size_t RAM_Size = 1000000000; // we assume that there is at least 1 GB of RAM
const long GMP_time_factor = 10; // factor by which GMP arithmetic differs from long long
const long renf_time_factor = 20; // N the same for renf
const long renf_time_factor_pyr = 5; // used for control of pyramid building without triangulation
// const long ticks_norm_quot = 155; // approximately the quotient of the ticks row/cont in A553 with GMP
/*
size_t count_rank_test_small = 0;
size_t count_rank_test_large = 0;
size_t count_comp_test_small = 0;
size_t count_comp_test_large = 0;
size_t count_large_pyrs = 0;
*/
//-------------------------------------------------------------------------
// Hedre to avoid a problem with certain compikers
void integrate(SignedDec<mpz_class>& SD, const bool do_virt_mult);
template <typename Integer>
bool SignedDec<Integer>::ComputeIntegral(const bool do_virt) {
assert(false);
return true;
}
template <>
bool SignedDec<mpz_class>::ComputeIntegral(const bool do_virt) {
if (decimal_digits > 0)
approximate = true;
approx_denominator = 1;
if (approximate) {
for (long i = 0; i < decimal_digits; ++i)
approx_denominator *= 10;
}
if (verbose)
verboseOutput() << "Generic " << Generic;
#ifdef NMZ_COCOA
integrate(*this, do_virt);
#endif
return true;
}
//-------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_automorphisms(size_t nr_special_gens) {
if (!do_automorphisms || isComputed(ConeProperty::Automorphisms)) {
return;
}
// bool only_from_god_father = false; // not used at present
// if (do_integrally_closed && descent_level > 0) // we can only work with automprphisms induced by God_Father
// only_from_god_father = true;
get_supphyps_from_copy(true); // of course only if they haven't been computed
extreme_rays_and_deg1_check(); // ditto
if (!isComputed(ConeProperty::SupportHyperplanes) || !isComputed(ConeProperty::ExtremeRays)) {
throw FatalException("Trying to compute austomorphism group without sufficient data! THIS SHOULD NOT HAPPEN!");
}
if (!inhomogeneous && quality_of_automorphisms == AutomParam::rational && !isComputed(ConeProperty::Grading))
throw NotComputableException("Rational austomorphism group only computable for polytopes");
if (verbose)
verboseOutput() << "Computing automorphism group" << endl;
Matrix<Integer> SpecialLinForms(0, dim);
if (inhomogeneous) {
SpecialLinForms.append(Truncation);
}
if (isComputed(ConeProperty::Grading) && Grading.size() > 0) {
SpecialLinForms.append(Grading);
}
Automs = AutomorphismGroup<Integer>(Generators.submatrix(Extreme_Rays_Ind), Support_Hyperplanes, SpecialLinForms);
bool success = Automs.compute(quality_of_automorphisms);
if (!success) {
/* if (only_from_god_father) {
if (verbose)
verboseOutput() << "Coputation of automorphism group from extreme rays failed" << endl;
return;
} */
if (verbose)
verboseOutput() << "Coputation of integral automorphism group from extreme rays failed, using Hilbert basis" << endl;
if (!isComputed(ConeProperty::HilbertBasis)) {
if (verbose)
verboseOutput() << "Must compute Hilbert basis first, making copy" << endl;
Full_Cone<Integer> Copy(Generators);
Copy.do_Hilbert_basis = true;
Copy.keep_order = true;
Copy.verbose = verbose;
Copy.Support_Hyperplanes = Support_Hyperplanes;
Copy.nrSupport_Hyperplanes = nrSupport_Hyperplanes;
Copy.setComputed(ConeProperty::SupportHyperplanes);
Copy.Extreme_Rays_Ind = Extreme_Rays_Ind;
Copy.setComputed(ConeProperty::ExtremeRays);
Copy.compute();
if (Copy.isComputed(ConeProperty::HilbertBasis)) {
Hilbert_Basis.clear();
Hilbert_Basis.splice(Hilbert_Basis.begin(), Copy.Hilbert_Basis);
setComputed(ConeProperty::HilbertBasis);
do_Hilbert_basis = false;
}
// do_Hilbert_basis=true; <-- makes no sense
}
Automs = AutomorphismGroup<Integer>(Generators.submatrix(Extreme_Rays_Ind), Support_Hyperplanes, SpecialLinForms);
Automs.addComputationGens(Matrix<Integer>(Hilbert_Basis));
success = Automs.compute(AutomParam::integral);
}
assert(success == true);
/* if (only_from_god_father) {
if (!check_extension_to_god_father())
return;
}*/
setComputed(ConeProperty::Automorphisms);
if (verbose)
verboseOutput() << Automs.getQualitiesString() << "automorphism group of order " << Automs.getOrder() << " done" << endl;
}
template <>
void Full_Cone<renf_elem_class>::compute_automorphisms(size_t nr_special_gens) {
if (!do_automorphisms || isComputed(ConeProperty::Automorphisms)) {
return;
}
get_supphyps_from_copy(true); // of course only if they haven't been computed
extreme_rays_and_deg1_check(); // ditto
if (!isComputed(ConeProperty::SupportHyperplanes) || !isComputed(ConeProperty::ExtremeRays)) {
throw FatalException("Trying to compute austomorphism group without sufficient data! THIS SHOULD NOT HAPPEN!");
return;
}
if (verbose)
verboseOutput() << "Computing automorphism group" << endl;
Matrix<renf_elem_class> HelpGen = Generators.submatrix(Extreme_Rays_Ind);
vector<renf_elem_class> HelpGrading;
if (!inhomogeneous) {
if (!isComputed(ConeProperty::Grading))
throw NotComputableException("For automorphisms of algebraic polyhedra input must define a polytope");
HelpGrading = Grading;
}
else {
HelpGrading = Truncation;
}
/*for(size_t i=0;i<HelpGen.nr_of_rows();++i){ // norm the extreme rays to vertices of polytope
renf_elem_class test=v_scalar_product(HelpGen[i],HelpGrading);
if(test==0)
throw NotComputableException("For automorphisms of algebraic polyhedra input must defime a polytope!");
v_scalar_division(HelpGen[i],test);
}*/
Matrix<renf_elem_class> SpecialLinForms(0, dim);
if (HelpGrading.size() > 0)
SpecialLinForms.append(HelpGrading);
Automs = AutomorphismGroup<renf_elem_class>(HelpGen, Support_Hyperplanes, SpecialLinForms);
Automs.compute(AutomParam::algebraic);
setComputed(ConeProperty::Automorphisms);
if (verbose)
verboseOutput() << Automs.getQualitiesString() << "automorphism group of order " << Automs.getOrder() << " done" << endl;
}
//---------------------------------------------------------------------------
/* debugging routine
template <typename Integer>
void Full_Cone<Integer>::check_facet(const FACETDATA<Integer>& Fac, const size_t& new_generator) const {
for (size_t jj = 0; jj < nr_gen; ++jj)
if (in_triang[jj] && v_scalar_product(Fac.Hyp, Generators[jj]) < 0) {
cerr << "Hyp negative on generator " << jj << endl;
assert(false);
}
vector<key_t> FacetKey;
for (size_t jj = 0; jj < nr_gen; ++jj) {
if (in_triang[jj] || jj == new_generator) {
if (Fac.GenInHyp[jj])
FacetKey.push_back(jj);
}
else {
if (Fac.GenInHyp[jj]) {
cerr << "in_triang error generator " << jj << endl;
assert(false);
}
}
}
if (Generators.rank_submatrix(FacetKey) < dim - 1) {
cerr << "Redundant hyperplane" << endl;
assert(false);
}
bool correct = true;
for (size_t jj = 0; jj < nr_gen; ++jj) {
if (in_triang[jj] && Fac.GenInHyp[jj] && v_scalar_product(Fac.Hyp, Generators[jj]) != 0) {
cerr << "Damned "
<< " Index " << jj << endl;
correct = false;
}
if (in_triang[jj] && !Fac.GenInHyp[jj] && v_scalar_product(Fac.Hyp, Generators[jj]) == 0) {
cerr << "Damned 2"
<< " Index " << jj << endl;
correct = false;
}
}
if (!correct) {
cerr << "--------------- ";
if (is_pyramid)
cerr << "pyr";
cerr << endl;
assert(false);
}
}
*/
//---------------------------------------------------------------------------
template <typename Integer>
chrono::nanoseconds Full_Cone<Integer>::rank_time() {
size_t nr_tests = 50;
/*
if(using_GMP<Integer>())
nr_tests/=GMP_time_factor;
if(using_renf<Integer>())
nr_tests/=renf_time_factor;*/
size_t nr_selected = min(3 * dim, nr_gen);
auto cl0 = chrono::high_resolution_clock::now();
#pragma omp parallel for
for (int kk = 0; kk < omp_get_max_threads(); ++kk) {
Matrix<Integer>& Test = Top_Cone->RankTest[kk];
for (size_t i = 0; i < nr_tests; ++i) {
vector<key_t> test_key;
for (size_t j = 0; j < nr_selected; ++j)
test_key.push_back(rand() % nr_gen);
Test.rank_submatrix(Generators, test_key);
}
}
auto cl1 = chrono::high_resolution_clock::now();
ticks_rank_per_row = (cl1 - cl0) / (nr_tests * nr_selected);
if (verbose)
verboseOutput() << "Per row " << ticks_rank_per_row.count() << " nanoseconds" << endl;
return ticks_rank_per_row;
}
template <typename Integer>
chrono::nanoseconds Full_Cone<Integer>::cmp_time() {
vector<list<dynamic_bitset>> Facets_0_1(omp_get_max_threads());
auto Fac = Facets.begin();
for (size_t i = 0; i < old_nr_supp_hyps; ++i, ++Fac) {
if (Fac->simplicial)
continue;
Facets_0_1[0].push_back(Fac->GenInHyp);
}
for (int i = 1; i < omp_get_max_threads(); ++i)
Facets_0_1[i] = Facets_0_1[0];
auto cl0 = chrono::high_resolution_clock::now();
#pragma omp parallel
{
#pragma omp for
for (int i = 0; i < omp_get_max_threads(); ++i) {
for (auto p = Facets_0_1[i].begin(); p != Facets_0_1[i].end(); ++p) {
/*bool contained=*/Facets.begin()->GenInHyp.is_subset_of(*p) && (*p) != (*Facets_0_1[i].begin()) &&
(*p) != (*Facets_0_1[i].end());
}
}
}
auto cl1 = chrono::high_resolution_clock::now();
ticks_comp_per_supphyp = (cl1 - cl0) / old_nr_supp_hyps;
if (verbose)
verboseOutput() << "Per comparison " << ticks_comp_per_supphyp.count() << " ticks (nanoseconds)" << endl;
return ticks_comp_per_supphyp;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::set_zero_cone() {
assert(dim == 0);
if (verbose) {
errorOutput() << "WARNING: Zero cone detected!" << endl;
}
// The basis change already is transforming to zero.
setComputed(ConeProperty::Sublattice);
setComputed(ConeProperty::Generators);
setComputed(ConeProperty::ExtremeRays);
Support_Hyperplanes = Matrix<Integer>(0);
setComputed(ConeProperty::SupportHyperplanes);
totalNrSimplices = 1;
setComputed(ConeProperty::TriangulationSize);
detSum = 1;
setComputed(ConeProperty::TriangulationDetSum);
SHORTSIMPLEX<Integer> empty_simpl;
empty_simpl.key = vector<key_t>();
empty_simpl.vol = 1;
empty_simpl.height = 0;
empty_simpl.mult = 1;
Triangulation.push_back(empty_simpl);
setComputed(ConeProperty::Triangulation);
setComputed(ConeProperty::StanleyDec);
multiplicity = 1;
setComputed(ConeProperty::Multiplicity);
setComputed(ConeProperty::HilbertBasis);
if (!inhomogeneous)
setComputed(ConeProperty::Deg1Elements);
Hilbert_Series = HilbertSeries(vector<num_t>(1, 1), vector<denom_t>()); // 1/1
setComputed(ConeProperty::HilbertSeries);
if (!is_Computed.test(ConeProperty::Grading)) {
Grading = vector<Integer>(dim);
// GradingDenom = 1;
setComputed(ConeProperty::Grading);
}
pointed = true;
setComputed(ConeProperty::IsPointed);
deg1_extreme_rays = true;
setComputed(ConeProperty::IsDeg1ExtremeRays);
deg1_hilbert_basis = true;
setComputed(ConeProperty::IsDeg1HilbertBasis);
if (inhomogeneous) { // empty set of solutions
setComputed(ConeProperty::VerticesOfPolyhedron);
module_rank = 0;
setComputed(ConeProperty::ModuleRank);
setComputed(ConeProperty::ModuleGenerators);
level0_dim = 0;
setComputed(ConeProperty::RecessionRank);
}
if (!inhomogeneous) {
ClassGroup.resize(1, 0);
setComputed(ConeProperty::ClassGroup);
}
if (inhomogeneous || ExcludedFaces.nr_of_rows() != 0) {
multiplicity = 0;
setComputed(ConeProperty::Multiplicity);
Hilbert_Series.reset(); // 0/1
setComputed(ConeProperty::HilbertSeries);
}
if (do_automorphisms)
setComputed(ConeProperty::Automorphisms);
}
template <>
void Full_Cone<renf_elem_class>::set_zero_cone() {
assert(dim == 0);
if (verbose) {
verboseOutput() << "Zero cone detected!" << endl;
}
// The basis change already is transforming to zero.
setComputed(ConeProperty::Sublattice);
setComputed(ConeProperty::Generators);
setComputed(ConeProperty::ExtremeRays);
Support_Hyperplanes = Matrix<renf_elem_class>(0);
setComputed(ConeProperty::SupportHyperplanes);
totalNrSimplices = 1;
setComputed(ConeProperty::TriangulationSize);
detSum = 1;
SHORTSIMPLEX<renf_elem_class> empty_simpl;
empty_simpl.key = vector<key_t>();
empty_simpl.vol = 1;
Triangulation.push_back(empty_simpl);
setComputed(ConeProperty::Triangulation);
pointed = true;
setComputed(ConeProperty::IsPointed);
deg1_extreme_rays = true;
setComputed(ConeProperty::IsDeg1ExtremeRays);
if (inhomogeneous) { // empty set of solutions
setComputed(ConeProperty::VerticesOfPolyhedron);
module_rank = 0;
setComputed(ConeProperty::ModuleRank);
setComputed(ConeProperty::ModuleGenerators);
level0_dim = 0;
setComputed(ConeProperty::RecessionRank);
}
if (do_automorphisms)
setComputed(ConeProperty::Automorphisms);
}
//===========================================================
/* debuggin
template <typename Integer>
void Full_Cone<Integer>::check_simpliciality_hyperplane(const FACETDATA<Integer>& hyp) const {
size_t nr_gen_in_hyp = 0;
for (size_t i = 0; i < nr_gen; ++i)
if (in_triang[i] && hyp.GenInHyp.test(i))
nr_gen_in_hyp++;
if ((hyp.simplicial && nr_gen_in_hyp != dim - 2) || (!hyp.simplicial && nr_gen_in_hyp == dim - 2)) {
// NOTE: in_triang set at END of main loop in build_cone
errorOutput() << "Simplicial " << hyp.simplicial << " dim " << dim << " gen_in_hyp " << nr_gen_in_hyp << endl;
assert(false);
}
}
*/
template <typename Integer>
void Full_Cone<Integer>::set_simplicial(FACETDATA<Integer>& hyp) {
size_t nr_gen_in_hyp = 0;
for (size_t i = 0; i < nr_gen; ++i)
if (in_triang[i] && hyp.GenInHyp.test(i))
nr_gen_in_hyp++;
hyp.simplicial = (nr_gen_in_hyp == dim - 2);
}
template <typename Integer>
void Full_Cone<Integer>::number_hyperplane(FACETDATA<Integer>& hyp, const size_t born_at, const size_t mother) {
// add identifying number, the birth day and the number of mother
if (don_t_add_hyperplanes)
return;
hyp.Mother = mother;
hyp.BornAt = born_at;
if (!multithreaded_pyramid) {
hyp.Ident = HypCounter[0];
HypCounter[0]++;
return;
}
int tn;
if (omp_get_level() == omp_start_level)
tn = 0;
else
tn = omp_get_ancestor_thread_num(omp_start_level + 1);
hyp.Ident = HypCounter[tn];
HypCounter[tn] += omp_get_max_threads();
// we nneed 64 bit for HypCounter[tn] in sufficiently big examples
assert(HypCounter[tn] % omp_get_max_threads() == (size_t)(tn + 1) % omp_get_max_threads());
}
//---------------------------------------------------------------------------
// used to decide if a hyperplane has the order vector on the positive side
// plus lex criterion
template <typename Integer>
bool Full_Cone<Integer>::is_hyperplane_included(FACETDATA<Integer>& hyp) {
if (!is_pyramid) { // in the topcone we always have ov_sp > 0
return true;
}
// check if it would be an excluded hyperplane
Integer ov_sp = v_scalar_product(hyp.Hyp, Order_Vector);
if (ov_sp > 0) {
return true;
}
else if (ov_sp == 0) {
for (size_t i = 0; i < dim; i++) {
if (hyp.Hyp[i] > 0) {
return true;
}
else if (hyp.Hyp[i] < 0) {
return false;
}
}
}
return false;
}
//---------------------------------------------------------------------------
// produces the linear combination needed for a Fourier-Motzkin step
template <typename Integer>
vector<Integer> Full_Cone<Integer>::FM_comb(
const vector<Integer>& Pos, const Integer& PosVal, const vector<Integer>& Neg, const Integer& NegVal, bool extract_gcd) {
size_t k;
vector<Integer> NewFacet(dim);
for (k = 0; k < dim; k++) {
NewFacet[k] = PosVal * Neg[k] - NegVal * Pos[k];
if (!check_range(NewFacet[k]))
break;
}
if (k == dim) {
if (extract_gcd)
v_make_prime(NewFacet);
}
else {
#pragma omp atomic
GMP_hyp++;
vector<mpz_class> mpz_neg(dim), mpz_pos(dim), mpz_sum(dim);
convert(mpz_neg, Neg);
convert(mpz_pos, Pos);
mpz_class mpz_NV, mpz_PV;
mpz_NV = convertTo<mpz_class>(NegVal);
mpz_PV = convertTo<mpz_class>(PosVal);
for (k = 0; k < dim; k++)
mpz_sum[k] = mpz_PV * mpz_neg[k] - mpz_NV * mpz_pos[k];
if (extract_gcd)
v_make_prime(NewFacet);
v_make_prime(mpz_sum);
convert(NewFacet, mpz_sum);
}
return NewFacet;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::make_pyramid_for_last_generator(const FACETDATA<Integer>& Fac) {
if (v_scalar_product(Fac.Hyp, Top_Cone->Generators[Top_Cone->top_last_to_be_inserted]) >= 0)
return;
vector<key_t> Pyramid_key;
Pyramid_key.push_back(static_cast<key_t>(Top_Cone->top_last_to_be_inserted));
for (size_t i = 0; i < Top_Cone->nr_gen; i++) {
if (v_scalar_product(Fac.Hyp, Top_Cone->Generators[i]) == 0) {
Pyramid_key.push_back(static_cast<key_t>(i));
}
}
#pragma omp critical(STOREPYRAMIDS)
{
Top_Cone->Pyramids[0].push_back(Pyramid_key);
Top_Cone->nrPyramids[0]++;
}
}
template <typename Integer>
void Full_Cone<Integer>::add_hyperplane(const size_t& new_generator,
const FACETDATA<Integer>& positive,
const FACETDATA<Integer>& negative,
list<FACETDATA<Integer>>& NewHyps,
bool known_to_be_simplicial) {
// adds a new hyperplane found in find_new_facets to this cone (restricted to generators processed)
if (don_t_add_hyperplanes)
return;
size_t k;
FACETDATA<Integer> NewFacet;
NewFacet.Hyp.resize(dim);
NewFacet.GenInHyp.resize(nr_gen);
// NewFacet.is_positive_on_all_original_gens = false;
// NewFacet.is_negative_on_some_original_gen = false;
Integer help;
for (k = 0; k < dim; k++) {
NewFacet.Hyp[k] = negative.Hyp[k];
NewFacet.Hyp[k] *= positive.ValNewGen;
help = negative.ValNewGen;
if (help != 0) {
help *= positive.Hyp[k];
NewFacet.Hyp[k] -= help;
}
// NewFacet.Hyp[k] = positive.ValNewGen * negative.Hyp[k] - negative.ValNewGen * positive.Hyp[k];
if (!check_range(NewFacet.Hyp[k]))
break;
}
if (k == dim)
v_make_prime(NewFacet.Hyp);
else {
#pragma omp atomic
GMP_hyp++;
vector<mpz_class> mpz_neg(dim), mpz_pos(dim), mpz_sum(dim);
convert(mpz_neg, negative.Hyp);
convert(mpz_pos, positive.Hyp);
for (k = 0; k < dim; k++)
mpz_sum[k] =
convertTo<mpz_class>(positive.ValNewGen) * mpz_neg[k] - convertTo<mpz_class>(negative.ValNewGen) * mpz_pos[k];
v_make_prime(mpz_sum);
convert(NewFacet.Hyp, mpz_sum);
}
NewFacet.ValNewGen = 0;
NewFacet.GenInHyp = positive.GenInHyp & negative.GenInHyp; // new hyperplane contains old gen iff both pos and neg do
if (known_to_be_simplicial) {
NewFacet.simplicial = true;
}
else
set_simplicial(NewFacet);
NewFacet.GenInHyp.set(new_generator); // new hyperplane contains new generator
number_hyperplane(NewFacet, nrGensInCone, positive.Ident);
// check_facet(NewFacet, new_generator);
if (!pyramids_for_last_built_directly)
NewHyps.emplace_back(std::move(NewFacet));
else
make_pyramid_for_last_generator(NewFacet);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_new_facets(const size_t& new_generator) {
// our Fourier-Motzkin implementation
// the special treatment of simplicial facets was inserted because of line shellings.
// At present these are not computed.
// to see if possible to replace the function .end with constant iterator since push-back is performed.
// for dimension 0 and 1 F-M is never necessary and can lead to problems
// when using dim-2
if (dim <= 1)
return;
// NEW: new_generator is the index of the generator being inserted
size_t i;
size_t subfacet_dim = dim - 2; // NEW dimension of subfacet
size_t facet_dim = dim - 1; // NEW dimension of facet
const bool tv_verbose = // true;
false; // verbose && !is_pyramid; // && Support_Hyperplanes.nr_of_rows()>10000; //verbose in this method call
// preparing the computations, the various types of facets are sorted into the deques
deque<FACETDATA<Integer>*> Pos_Simp, Pos_Non_Simp;
deque<FACETDATA<Integer>*> Neg_Simp, Neg_Non_Simp;
deque<FACETDATA<Integer>*> Neutral_Simp, Neutral_Non_Simp;
dynamic_bitset GenInPosHyp(nr_gen), GenInNegHyp(nr_gen); // here we collect the generators that lie in a
// positive resp. negative hyperplane
bool simplex;
if (tv_verbose)
verboseOutput() << "find_new_facets:" << flush;
for (auto& facet : Facets) {
if (facet.positive) {
GenInPosHyp |= facet.GenInHyp;
}
if (facet.negative) {
GenInNegHyp |= facet.GenInHyp;
}
}
dynamic_bitset Gen_BothSides(nr_gen); // indicator for generators that are in a negative as well as a positive supphyp
Gen_BothSides = GenInPosHyp & GenInNegHyp;
vector<key_t> Gen_BothSides_key;
for (i = 0; i < nr_gen; ++i) {
if (Gen_BothSides[i])
Gen_BothSides_key.push_back(static_cast<key_t>(i));
}
for (auto& facet : Facets) {
simplex = facet.simplicial; // at present simplicial, will become nonsimplicial if neutral
if (facet.neutral) {
facet.GenInHyp.set(new_generator); // Must be set explicitly !!
facet.simplicial = false; // simpliciality definitely gone with the new generator
if (simplex) {
Neutral_Simp.push_back(&facet); // simplicial without the new generator
}
else {
Neutral_Non_Simp.push_back(&facet); // nonsimplicial already without the new generator
}
continue;
}
size_t nr_relevant_gens = 0;
for (size_t i = 0; i < Gen_BothSides_key.size(); ++i) {
if (facet.GenInHyp[Gen_BothSides_key[i]])
nr_relevant_gens++;
}
if (nr_relevant_gens < subfacet_dim)
continue;
if (facet.positive) {
if (simplex) {
Pos_Simp.push_back(&facet);
}
else {
Pos_Non_Simp.push_back(&facet);
}
}
else if (facet.negative) {
if (simplex) {
Neg_Simp.push_back(&facet);
}
else {
Neg_Non_Simp.push_back(&facet);
}
}
}
// TO DO: Negativliste mit GenInPosHyp verfeinern, also die aussondern, die nicht genug positive Erz enthalten
// Eventuell sogar Rang-Test einbauen.
// Letzteres knnte man auch bei den positiven machen, bevor sie verarbeitet werden
size_t nr_PosSimp = Pos_Simp.size();
size_t nr_PosNonSimp = Pos_Non_Simp.size();
size_t nr_NegSimp = Neg_Simp.size();
size_t nr_NegNonSimp = Neg_Non_Simp.size();
size_t nr_NeuSimp = Neutral_Simp.size();
size_t nr_NeuNonSimp = Neutral_Non_Simp.size();
if (tv_verbose)
verboseOutput() << " PS " << nr_PosSimp << ", P " << nr_PosNonSimp << ", NS " << nr_NegSimp << ", N " << nr_NegNonSimp
<< ", ZS " << nr_NeuSimp << ", Z " << nr_NeuNonSimp << endl;
if (tv_verbose)
verboseOutput() << "find_new_facets: subfacet of NS: " << flush;
vector<list<pair<dynamic_bitset, int>>> Neg_Subfacet_Multi(omp_get_max_threads());
// This parallel region cannot throw a NormalizException
// Next we produce the subfacets of the negative simplicial facets by threads
#pragma omp parallel
{
dynamic_bitset RelGen_NegHyp, subfacet;
size_t nr_RelGen_NegHyp;
#pragma omp for schedule(dynamic)
for (i = 0; i < nr_NegSimp; i++) {
RelGen_NegHyp = Gen_BothSides & Neg_Simp[i]->GenInHyp;
nr_RelGen_NegHyp = 0;
for (size_t j = 0; j < nr_gen; j++) {
if (RelGen_NegHyp.test(j))
nr_RelGen_NegHyp++;
if (nr_RelGen_NegHyp > subfacet_dim) {
break;
}
}
if (nr_RelGen_NegHyp == subfacet_dim) // only one subfacet to build
Neg_Subfacet_Multi[omp_get_thread_num()].push_back(pair<dynamic_bitset, int>(RelGen_NegHyp, i));
if (nr_RelGen_NegHyp == facet_dim) {
for (size_t k = 0; k < nr_gen; k++) {
if (RelGen_NegHyp.test(k)) {
subfacet = RelGen_NegHyp;
subfacet.reset(k); // remove k-th element from facet to obtain subfacet
Neg_Subfacet_Multi[omp_get_thread_num()].push_back(pair<dynamic_bitset, int>(subfacet, i));
}
}
}
}
} // parallel
// Now all threads get united
list<pair<dynamic_bitset, int>> Neg_Subfacet_Multi_United;
for (int i = 0; i < omp_get_max_threads(); ++i)
Neg_Subfacet_Multi_United.splice(Neg_Subfacet_Multi_United.begin(), Neg_Subfacet_Multi[i]);
Neg_Subfacet_Multi_United.sort();
if (tv_verbose)
verboseOutput() << Neg_Subfacet_Multi_United.size() << ", " << flush;
// remove negative subfacets shared by two neg simpl facets
for (auto jj = Neg_Subfacet_Multi_United.begin(); jj != Neg_Subfacet_Multi_United.end();) {
auto del = jj++;
if (jj != Neg_Subfacet_Multi_United.end() &&
(*jj).first == (*del).first) { // delete since is the intersection of two negative simplicies
Neg_Subfacet_Multi_United.erase(del);
del = jj++;
Neg_Subfacet_Multi_United.erase(del);
}
}
size_t nr_NegSubfMult = Neg_Subfacet_Multi_United.size();
if (tv_verbose)
verboseOutput() << " after removal " << nr_NegSubfMult << ", " << flush;
vector<list<FACETDATA<Integer>>> NewHypsSimp(nr_PosSimp);
vector<list<FACETDATA<Integer>>> NewHypsNonSimp(nr_PosNonSimp);
map<dynamic_bitset, int> Neg_Subfacet;
size_t nr_NegSubf = 0;
// size_t NrMatches=0, NrCSF=0, NrRank=0, NrComp=0, NrNewF=0;
/* deque<bool> Indi(nr_NegNonSimp);
for(size_t j=0;j<nr_NegNonSimp;++j)
Indi[j]=false; */
if (multithreaded_pyramid) {
nrTotalComparisons += nr_NegNonSimp * nr_PosNonSimp;
}
else {
nrTotalComparisons += nr_NegNonSimp * nr_PosNonSimp;
}
bool skip_remaining = false;
std::exception_ptr tmp_exception;
if ((using_GMP<Integer>() || using_renf<Integer>()) && Generators_float.nr_of_rows() == 0) {
bool potential_ranktest = false;
if (using_GMP<Integer>())
potential_ranktest =
(old_nr_supp_hyps > GMP_time_factor * dim * dim * dim / 3); // in this case the rank computation takes longer
if (using_renf<Integer>())
potential_ranktest = (old_nr_supp_hyps > renf_time_factor * dim * dim * dim / 3);
if (potential_ranktest)
convert(Generators_float, Generators);
}
//=====================================================================
// biohg parallel block from here
/* cout << "*****************************************" << endl;
cout << "nr_NegSubfMult " << nr_NegSubfMult << " nr_NeuSimp " << nr_NeuSimp << " nr_NeuNonSimp "
<< nr_NeuNonSimp << " nr_NegNonSimp " << nr_NegNonSimp << endl;
cout << "*****************************************" << endl;*/
#pragma omp parallel
{
size_t i, j, k, nr_RelGen_PosHyp;
dynamic_bitset subfacet(dim - 2);
auto jj = Neg_Subfacet_Multi_United.begin();
size_t jjpos = 0;
int tn = omp_get_ancestor_thread_num(omp_start_level + 1);
// We remove negative simplicial subfacets that appear in neuitral facets or negative nonsimplicial facets
if (nr_NegSubfMult * (nr_NeuSimp + nr_NeuNonSimp + nr_NegNonSimp) <=
100000000) { // to prevent a disaster in the double loops,
bool found;
// This for region cannot throw a NormalizException
#pragma omp for schedule(dynamic)
for (size_t j = 0; j < nr_NegSubfMult; ++j) { // remove negative subfacets shared
for (; j > jjpos; ++jjpos, ++jj)
; // by non-simpl neg or neutral facets
for (; j < jjpos; --jjpos, --jj)
;
subfacet = (*jj).first;
found = false;
if (nr_NeuSimp < 100000) { // to prevent disaster
for (i = 0; i < nr_NeuSimp; i++) {
found = subfacet.is_subset_of(Neutral_Simp[i]->GenInHyp);
if (found)
break;
}
}
if (!found && nr_NeuNonSimp < 100000) {
for (i = 0; i < nr_NeuNonSimp; i++) {
found = subfacet.is_subset_of(Neutral_Non_Simp[i]->GenInHyp);
if (found)
break;
}
}
if (!found && nr_NegNonSimp < 100000) {
for (i = 0; i < nr_NegNonSimp; i++) {
found = subfacet.is_subset_of(Neg_Non_Simp[i]->GenInHyp);
if (found)
break;
}
}
if (found) {
jj->second = -1;
}
}
}
#pragma omp single
{ // remove elements that were found in the previous loop
auto last_inserted = Neg_Subfacet.begin(); // used to speedup insertion into the new map
for (auto jj = Neg_Subfacet_Multi_United.begin(); jj != Neg_Subfacet_Multi_United.end(); ++jj) {
if ((*jj).second != -1) {
last_inserted = Neg_Subfacet.insert(last_inserted, *jj);
}
}
nr_NegSubf = Neg_Subfacet.size();
}
#pragma omp single nowait
{ Neg_Subfacet_Multi_United.clear(); }
//**********************************************************
// Now the matching of positive and negative facets starts *
// the outer loops run over the positive facets *
//**********************************************************
dynamic_bitset RelGen_PosHyp(nr_gen);
#pragma omp single nowait
if (tv_verbose) {
verboseOutput() << "PS vs NS and PS vs N , " << flush;
}
vector<key_t> key(nr_gen);
size_t nr_missing;
bool common_subfacet;
// we cannot use nowait here because of the way we handle exceptions in this loop
#pragma omp for schedule(dynamic) // nowait
for (size_t i = 0; i < nr_PosSimp; i++) {
if (skip_remaining)
continue;
try {
INTERRUPT_COMPUTATION_BY_EXCEPTION
RelGen_PosHyp = Gen_BothSides & Pos_Simp[i]->GenInHyp;
nr_RelGen_PosHyp = 0;
for (j = 0; j < nr_gen && nr_RelGen_PosHyp <= facet_dim; j++)
if (RelGen_PosHyp.test(j)) {
key[nr_RelGen_PosHyp] = static_cast<key_t>(j);
nr_RelGen_PosHyp++;
}
if (nr_RelGen_PosHyp < subfacet_dim)
continue;
// first PS vs NS
if (nr_RelGen_PosHyp == subfacet_dim) { // NEW slight change in logic. Positive simpl facet shared at most
auto jj_map = Neg_Subfacet.find(RelGen_PosHyp); // one subfacet with negative simpl facet
if (jj_map != Neg_Subfacet.end()) {
add_hyperplane(new_generator, *Pos_Simp[i], *Neg_Simp[(*jj_map).second], NewHypsSimp[i], true);
(*jj_map).second = -1; // block subfacet in further searches
}
}
if (nr_RelGen_PosHyp == facet_dim) { // now there could be more such subfacets. We make all and search them.
for (k = 0; k < nr_gen; k++) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (RelGen_PosHyp.test(k)) {
subfacet = RelGen_PosHyp;
subfacet.reset(k); // remove k-th element from facet to obtain subfacet
auto jj_map = Neg_Subfacet.find(subfacet);
if (jj_map != Neg_Subfacet.end()) {
add_hyperplane(new_generator, *Pos_Simp[i], *Neg_Simp[(*jj_map).second], NewHypsSimp[i], true);
(*jj_map).second = -1;
// Indi[j]=true;
}
}
}
}
// now PS vs N
for (j = 0; j < nr_NegNonSimp; j++) { // search negative facet with common subfacet
INTERRUPT_COMPUTATION_BY_EXCEPTION
nr_missing = 0;
common_subfacet = true;
for (k = 0; k < nr_RelGen_PosHyp; k++) {
if (!Neg_Non_Simp[j]->GenInHyp.test(key[k])) {
nr_missing++;
if (nr_missing == 2 || nr_RelGen_PosHyp == subfacet_dim) {
common_subfacet = false;
break;
}
}
}
if (common_subfacet) {
add_hyperplane(new_generator, *Pos_Simp[i], *Neg_Non_Simp[j], NewHypsSimp[i], true);
if (nr_RelGen_PosHyp == subfacet_dim) // only one subfacet can lie in negative hyperplane
break;
}
}
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
} // Done: PS vs NS and PS vs N
if (!skip_remaining) {
#pragma omp single nowait
if (tv_verbose) {
verboseOutput() << "P vs NS and P vs N" << endl;
}
// the lists below are made because we want to move successful reducers
// to the top indeoendently in each thread
list<dynamic_bitset> Facets_0_1_thread;
for (i = 0; i < nr_PosNonSimp; ++i)
Facets_0_1_thread.push_back(Pos_Non_Simp[i]->GenInHyp);
for (i = 0; i < nr_NegNonSimp; ++i)
Facets_0_1_thread.push_back(Neg_Non_Simp[i]->GenInHyp);
for (i = 0; i < nr_NeuNonSimp; ++i)
Facets_0_1_thread.push_back(Neutral_Non_Simp[i]->GenInHyp);
size_t nr_NonSimp = nr_PosNonSimp + nr_NegNonSimp + nr_NeuNonSimp;
bool ranktest;
FACETDATA<Integer>*PosHyp_Pointer, *NegHyp_Pointer; // pointers to current hyperplanes
size_t missing_bound, nr_CommonGens;
dynamic_bitset CommonGens(nr_gen);
vector<key_t> common_key;
common_key.reserve(nr_gen);
vector<int> key_start(nrGensInCone);
#pragma omp for schedule(dynamic)
for (size_t i = 0; i < nr_PosNonSimp; i++) { // Positive Non Simp vs.Negative Simp and Non Simp
if (skip_remaining)
continue;
try {
INTERRUPT_COMPUTATION_BY_EXCEPTION
auto jj_map = Neg_Subfacet.begin(); // First the Simp
for (j = 0; j < nr_NegSubf; ++j, ++jj_map) {
if ((*jj_map).second != -1) { // skip used subfacets
if (jj_map->first.is_subset_of(Pos_Non_Simp[i]->GenInHyp)) {
add_hyperplane(new_generator, *Pos_Non_Simp[i], *Neg_Simp[(*jj_map).second], NewHypsNonSimp[i],
true);
(*jj_map).second = -1; // has now been used
}
}
}
// Now the NonSimp --- the critical task
PosHyp_Pointer = Pos_Non_Simp[i];
RelGen_PosHyp =
Gen_BothSides & PosHyp_Pointer->GenInHyp; // these are the potential vertices in an intersection
nr_RelGen_PosHyp = 0;
int last_existing = -1;
for (size_t jj = 0; jj < nrGensInCone; jj++) // we make a "key" of the potential vertices in the intersection
{
j = GensInCone[jj];
if (RelGen_PosHyp.test(j)) {
key[nr_RelGen_PosHyp] = static_cast<key_t>(j);
for (size_t kk = last_existing + 1; kk <= jj; kk++) // used in the extension test
key_start[kk] = static_cast<int>(nr_RelGen_PosHyp); // to find out from which generator on both have existed
nr_RelGen_PosHyp++;
last_existing = static_cast<int>(jj);
}
}
if (last_existing < (int)nrGensInCone - 1)
for (size_t kk = last_existing + 1; kk < nrGensInCone; kk++)
key_start[kk] = static_cast<int>(nr_RelGen_PosHyp);
if (nr_RelGen_PosHyp < subfacet_dim)
continue;
// now nr_RelGen_PosHyp is the number of vertices in PosHyp_Pointer that have a chance to lie in a negative
// facet and key contains the indices
missing_bound = nr_RelGen_PosHyp - subfacet_dim; // at most this number of generators can be missing
// to have a chance for common subfacet
for (j = 0; j < nr_NegNonSimp; j++) {
NegHyp_Pointer = Neg_Non_Simp[j];
if (PosHyp_Pointer->Ident == NegHyp_Pointer->Mother ||
NegHyp_Pointer->Ident == PosHyp_Pointer->Mother) { // mother and daughter coming together
add_hyperplane(new_generator, *PosHyp_Pointer, *NegHyp_Pointer, NewHypsNonSimp[i],
false); // their intersection is a subfacet
continue; // simplicial set in add_hyperplane
}
bool extension_test = PosHyp_Pointer->BornAt == NegHyp_Pointer->BornAt ||
(PosHyp_Pointer->BornAt < NegHyp_Pointer->BornAt && NegHyp_Pointer->Mother != 0) ||
(NegHyp_Pointer->BornAt < PosHyp_Pointer->BornAt && PosHyp_Pointer->Mother != 0);
// extension_test=false;
size_t both_existing_from = key_start[max(PosHyp_Pointer->BornAt, NegHyp_Pointer->BornAt)];
nr_missing = 0;
nr_CommonGens = 0;
common_key.clear();
size_t second_loop_bound = nr_RelGen_PosHyp;
common_subfacet = true;
// We use the following criterion:
// if the two facets are not mother and daughter (taken care of already), then
// they cannot have intersected in a subfacet at the time when the second was born.
// In other words: they can only intersect in a subfacet now, if at least one common vertex
// has been added after the birth of the younger one.
// this is indicated by "extended".
if (extension_test) {
bool extended = false;
second_loop_bound = both_existing_from; // first we find the common vertices inserted from the step
// where both facets existed the first time
for (k = both_existing_from; k < nr_RelGen_PosHyp; k++) {
if (!NegHyp_Pointer->GenInHyp.test(key[k])) {
nr_missing++;
if (nr_missing > missing_bound) {
common_subfacet = false;
break;
}
}
else {
extended = true; // in this case they have a common vertex added after their common existence
common_key.push_back(key[k]);
nr_CommonGens++;
}
}
if (!extended || !common_subfacet) //
continue;
}
for (k = 0; k < second_loop_bound; k++) { // now the remaining
if (!NegHyp_Pointer->GenInHyp.test(key[k])) {
nr_missing++;
if (nr_missing > missing_bound) {
common_subfacet = false;
break;
}
}
else {
common_key.push_back(key[k]);
nr_CommonGens++;
}
}
if (!common_subfacet)
continue;
if (subfacet_dim <= 2) { // intersection of i and j is a subfacet
add_hyperplane(new_generator, *PosHyp_Pointer, *NegHyp_Pointer, NewHypsNonSimp[i],
false); // simplicial set in add_hyperplane
/* #pragma omp atomic
NrNewF++; */
// Indi[j]=true;
// cout << "Subfacet" << endl;
continue;
}
/* #pragma omp atomic
NrCSF++;*/
// clock_t cl=clock();
// a priori values
if (using_GMP<Integer>())
ranktest = (nr_NonSimp > GMP_time_factor * dim * dim * nr_CommonGens /
3); // in this case the rank computation takes longer
else {
if (using_renf<Integer>())
ranktest = (nr_NonSimp > renf_time_factor * dim * dim * nr_CommonGens / 3);
else
ranktest = (nr_NonSimp > dim * dim * nr_CommonGens / 3);
}
#ifdef NMZ_EXTENDED_TESTS
if (test_linear_algebra_GMP)
ranktest = true;
#endif
if (Generators_float.nr_of_rows() > 0) {
Matrix<nmz_float>& Test_float = Top_Cone->RankTest_float[tn];
if (Test_float.rank_submatrix(Generators_float, common_key) < subfacet_dim) {
ranktest = false;
}
}
if (ranktest) { //
// cout << "Rang" << endl;
Matrix<Integer>& Test = Top_Cone->RankTest[tn];
// #pragma omp atomic
// count_rank_test_small++;
if (Test.rank_submatrix(Generators, common_key) < subfacet_dim) {
common_subfacet = false;
}
} // ranktest
else { // now the comparison test
//#pragma omp atomic
// count_comp_test_small++;
// cout << "comp " << Facets_0_1_thread.size() << endl;
/* #pragma omp atomic
NrComp++; */
auto a = Facets_0_1_thread.begin();
CommonGens = RelGen_PosHyp & NegHyp_Pointer->GenInHyp;
/*for (; a != Facets_0_1_thread.end(); ++a) {
bool contains = true;
for(size_t i=0; i< nr_CommonGens; ++i){
if(!(*a)[common_key[i]]){
contains = false;
break;
}
}
if ((contains && *a != PosHyp_Pointer->GenInHyp) && (*a != NegHyp_Pointer->GenInHyp)) {
common_subfacet = false;
Facets_0_1_thread.splice(Facets_0_1_thread.begin(), Facets_0_1_thread,
a); // for the "darwinistic" mewthod
break;
}
}*/
for (; a != Facets_0_1_thread.end(); ++a) {
if (CommonGens.is_subset_of(*a) && (*a != PosHyp_Pointer->GenInHyp) &&
(*a != NegHyp_Pointer->GenInHyp)) {
common_subfacet = false;
Facets_0_1_thread.splice(Facets_0_1_thread.begin(), Facets_0_1_thread,
a); // for the "darwinistic" mewthod
break;
}
}
} // else
// cout << nr_CommonGens*ticks_rank_per_row << " " << nr_NonSimp*ticks_comp_per_supphyp << " " <<
// clock()-cl << endl;
if (common_subfacet) { // intersection of i and j is a subfacet
add_hyperplane(new_generator, *PosHyp_Pointer, *NegHyp_Pointer, NewHypsNonSimp[i],
false); // simplicial set in add_hyperplane
/* #pragma omp atomic
NrNewF++; */
// Indi[j]=true;
// cout << "Subfacet" << endl;
}
}
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
} // end for
} // end !skip_remaining
} // END parallel
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
//=====================================================================
// parallel until here
/* if(!is_pyramid)
cout << "Matches " << NrMatches << " pot. common subf " << NrCSF << " rank test " << NrRank << " comp test "
<< NrComp << " neww hyps " << NrNewF << endl; */
for (i = 0; i < nr_PosSimp; i++)
Facets.splice(Facets.end(), NewHypsSimp[i]);
for (i = 0; i < nr_PosNonSimp; i++)
Facets.splice(Facets.end(), NewHypsNonSimp[i]);
// removing the negative hyperplanes
// now done in build_cone
if (tv_verbose)
verboseOutput() << "find_new_facets: done" << endl;
}
//---------------------------------------------------------------------------
// Pulloing triangulations are treated separately: they are not used for the computation of
// other data. Determinants will be added in evaluate_triangulation.
// Pyramid decomposition is not possible since the triangulation is not incremenral.
// Therefore the fouble loop over support hyperplanes and simplices computed before
// produces the new triangulation that replaces the triangulation computed before.
//
// The only alternative we see would be to form the pyramids of the new generator
// and the invisible support hyperplanes. Done consequently this results in a
// recursive algorithm over the face lattice.
template <typename Integer>
void Full_Cone<Integer>::update_pulling_triangulation(const size_t& new_generator) {
size_t listsize = old_nr_supp_hyps; // Facets.size();
vector<typename list<FACETDATA<Integer>>::iterator> invisible;
invisible.reserve(listsize);
listsize = 0;
for (auto i = Facets.begin(); i != Facets.end(); ++i) {
if (i->positive) { // invisible facet
invisible.push_back(i);
listsize++;
}
}
list<SHORTSIMPLEX<Integer>> NewTriangulationBuffer;
std::exception_ptr tmp_exception;
bool skip_remaining = false;
// Integer TotalDetSum = 0;
#pragma omp parallel
{
list<SHORTSIMPLEX<Integer>> Triangulation_kk;
vector<key_t> key(dim);
// Integer DetSum = 0;
// if we only want a partial triangulation but came here because of a deep level
// mark if this part of the triangulation has not to be evaluated
#pragma omp for schedule(dynamic)
for (size_t kk = 0; kk < listsize; ++kk) {
if (skip_remaining)
continue;
try {
INTERRUPT_COMPUTATION_BY_EXCEPTION
auto H = invisible[kk];
if (H->simplicial) { // simplicial
size_t l = 0;
for (size_t k = 0; k < nr_gen; k++) {
if (H->GenInHyp[k] == 1) {
key[l] = static_cast<key_t>(k);
l++;
}
}
key[dim - 1] = static_cast<key_t>(new_generator);
// Integer test_vol = Generators.submatrix(key).vol();
// DetSum += test_vol;
store_key(key, 0, 0, Triangulation_kk);
continue;
} // end simplicial
for (auto& S : TriangulationBuffer) {
bool one_vertex_not_in_hyp = false;
bool no_facet_in_hyp = false;
key_t not_in_hyp = 0; // to make the compiler happy
key = S.key;
for (size_t k = 0; k < dim; ++k) {
if (!H->GenInHyp.test(key[k])) {
if (one_vertex_not_in_hyp) {
no_facet_in_hyp = true;
break;
}
one_vertex_not_in_hyp = true;
not_in_hyp = static_cast<key_t>(k);
}
}
if (no_facet_in_hyp)
continue;
key[not_in_hyp] = static_cast<key_t>(new_generator);
store_key(key, 0, 0, Triangulation_kk);
// DetSum += Generators.submatrix(key).vol();
} // S
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
} // omp for kk
if (multithreaded_pyramid) {
#pragma omp critical(TRIANG)
{
NewTriangulationBuffer.splice(NewTriangulationBuffer.end(), Triangulation_kk);
// TotalDetSum += DetSum;
}
}
else {
NewTriangulationBuffer.splice(NewTriangulationBuffer.end(), Triangulation_kk);
// TotalDetSum += DetSum;
}
} // parallel
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
TriangulationBuffer.clear();
TriangulationBuffer.splice(TriangulationBuffer.begin(), NewTriangulationBuffer);
/* cout << "DDDDDD " << TotalDetSum << endl;
vector<bool> GenInd = in_triang;
GenInd[new_generator] = true;
Cone<Integer> TestCone(Type::cone,Generators.submatrix(GenInd));
TestCone.setVerbose(false);
TestCone.compute(ConeProperty::Multiplicity,ConeProperty::Descent);
cout << "CCCCCC " << TestCone.getMultiplicity() << endl; */
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::extend_triangulation(const size_t& new_generator) {
// extends the triangulation of this cone by including new_generator
// simplicial facets save us from searching the "brother" in the existing triangulation
// to which the new simplex gets attached
if (pulling_triangulation) {
update_pulling_triangulation(new_generator);
return;
}
size_t listsize = old_nr_supp_hyps; // Facets.size();
vector<typename list<FACETDATA<Integer>>::iterator> visible;
visible.reserve(listsize);
listsize = 0;
for (auto i = Facets.begin(); i != Facets.end(); ++i) {
if (i->negative) { // visible facet
visible.push_back(i);
listsize++;
}
}
std::exception_ptr tmp_exception;
auto oldTriBack = --TriangulationBuffer.end();
#pragma omp parallel
{
size_t k, l;
bool one_not_in_i, not_in_facet;
size_t not_in_i = 0;
// size_t facet_dim=dim-1;
// size_t nr_in_i=0;
list<SHORTSIMPLEX<Integer>> Triangulation_kk;
vector<key_t> key(dim);
// if we only want a partial triangulation but came here because of a deep level
// mark if this part of the triangulation has not to be evaluated
bool skip_eval = false;
bool skip_remaining = false;
#pragma omp for schedule(dynamic)
for (size_t kk = 0; kk < listsize; ++kk) {
if (skip_remaining)
continue;
try {
INTERRUPT_COMPUTATION_BY_EXCEPTION
auto i = visible[kk];
skip_eval = Top_Cone->do_partial_triangulation && i->ValNewGen == -1 && is_hyperplane_included(*i);
if (i->simplicial) { // simplicial
l = 0;
for (k = 0; k < nr_gen; k++) {
if (i->GenInHyp[k] == 1) {
key[l] = static_cast<key_t>(k);
l++;
}
}
key[dim - 1] = static_cast<key_t>(new_generator);
if (skip_eval)
store_key(key, 0, 0, Triangulation_kk);
else
store_key(key, -i->ValNewGen, 0, Triangulation_kk);
continue;
} // end simplicial
size_t irrelevant_vertices = 0;
for (size_t vertex = 0; vertex < nrGensInCone; ++vertex) {
if (i->GenInHyp[GensInCone[vertex]] == 0) // lead vertex not in hyperplane
continue;
if (irrelevant_vertices < dim - 2) {
++irrelevant_vertices;
continue;
}
auto j = TriSectionFirst[vertex];
bool done = false;
for (; !done; j++) {
done = (j == TriSectionLast[vertex]);
key = j->key;
one_not_in_i = false; // true indicates that one gen of simplex is not in hyperplane
not_in_facet = false; // true indicates that a second gen of simplex is not in hyperplane
for (k = 0; k < dim; k++) {
if (!i->GenInHyp.test(key[k])) {
if (one_not_in_i) {
not_in_facet = true;
break;
}
one_not_in_i = true;
not_in_i = k;
}
}
if (not_in_facet) // simplex does not share facet with hyperplane
continue;
key[not_in_i] = static_cast<key_t>(new_generator);
if (skip_eval)
store_key(key, 0, j->vol, Triangulation_kk);
else
store_key(key, -i->ValNewGen, j->vol, Triangulation_kk);
} // j
} // for vertex
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
} // omp for kk
if (multithreaded_pyramid) {
#pragma omp critical(TRIANG)
TriangulationBuffer.splice(TriangulationBuffer.end(), Triangulation_kk);
}
else
TriangulationBuffer.splice(TriangulationBuffer.end(), Triangulation_kk);
} // parallel
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
// GensInCone.push_back(new_generator); // now in extend_cone
TriSectionFirst.push_back(++oldTriBack);
TriSectionLast.push_back(--TriangulationBuffer.end());
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::store_key(const vector<key_t>& key,
const Integer& height,
const Integer& mother_vol,
list<SHORTSIMPLEX<Integer>>& Triangulation) {
// stores a simplex given by key and height in Triangulation
// mother_vol is the volume of the simplex to which the new one is attached
SHORTSIMPLEX<Integer> newsimplex;
newsimplex.key = key;
newsimplex.height = height;
newsimplex.vol = 0;
if (multithreaded_pyramid) {
#pragma omp atomic
TriangulationBufferSize++;
}
else {
TriangulationBufferSize++;
}
int tn;
if (omp_get_level() == omp_start_level)
tn = 0;
else
tn = omp_get_ancestor_thread_num(omp_start_level + 1);
if (do_only_multiplicity) {
// directly compute the volume
if (mother_vol == 1)
newsimplex.vol = height;
// the multiplicity is computed in SimplexEvaluator
for (size_t i = 0; i < dim; i++) // and needs the key in TopCone numbers
newsimplex.key[i] = Top_Key[newsimplex.key[i]];
if (keep_triangulation)
sort(newsimplex.key.begin(), newsimplex.key.end());
Top_Cone->SimplexEval[tn].evaluate(newsimplex);
// restore the local generator numbering, needed in extend_triangulation
newsimplex.key = key;
}
if (height == 0)
Top_Cone->triangulation_is_partial = true;
if (keep_triangulation) {
Triangulation.push_back(newsimplex);
return;
}
bool Simpl_available = true;
if (Top_Cone->FS[tn].empty()) {
if (Top_Cone->FreeSimpl.empty()) {
Simpl_available = false;
}
else {
#pragma omp critical(FREESIMPL)
{
if (Top_Cone->FreeSimpl.empty()) {
Simpl_available = false;
}
else {
// take 1000 simplices from FreeSimpl or what you can get
auto F = Top_Cone->FreeSimpl.begin();
size_t q;
for (q = 0; q < 1000; ++q, ++F) {
if (F == Top_Cone->FreeSimpl.end())
break;
}
if (q < 1000)
Top_Cone->FS[tn].splice(Top_Cone->FS[tn].begin(), Top_Cone->FreeSimpl);
else
Top_Cone->FS[tn].splice(Top_Cone->FS[tn].begin(), Top_Cone->FreeSimpl, Top_Cone->FreeSimpl.begin(), F);
} // if empty global (critical)
} // critical
} // if empty global
} // if empty thread
if (Simpl_available) {
Triangulation.splice(Triangulation.end(), Top_Cone->FS[tn], Top_Cone->FS[tn].begin());
Triangulation.back() = newsimplex;
}
else {
Triangulation.push_back(newsimplex);
}
}
#ifdef ENFNORMALIZ
template <>
void Full_Cone<renf_elem_class>::store_key(const vector<key_t>& key,
const renf_elem_class& height,
const renf_elem_class& mother_vol,
list<SHORTSIMPLEX<renf_elem_class>>& Triangulation) {
// stores a simplex given by key and height in Triangulation
// mother_vol is the volume of the simplex to which the new one is attached
SHORTSIMPLEX<renf_elem_class> newsimplex;
newsimplex.key = key;
newsimplex.height = height;
newsimplex.vol = 0;
if (multithreaded_pyramid) {
#pragma omp atomic
TriangulationBufferSize++;
}
else {
TriangulationBufferSize++;
}
int tn;
if (omp_get_level() == 0)
tn = 0;
else
tn = omp_get_ancestor_thread_num(1);
if (height == 0)
Top_Cone->triangulation_is_partial = true;
if (keep_triangulation) {
Triangulation.push_back(newsimplex);
return;
}
bool Simpl_available = true;
if (Top_Cone->FS[tn].empty()) {
if (Top_Cone->FreeSimpl.empty()) {
Simpl_available = false;
}
else {
#pragma omp critical(FREESIMPL)
{
if (Top_Cone->FreeSimpl.empty()) {
Simpl_available = false;
}
else {
// take 1000 simplices from FreeSimpl or what you can get
auto F = Top_Cone->FreeSimpl.begin();
size_t q;
for (q = 0; q < 1000; ++q, ++F) {
if (F == Top_Cone->FreeSimpl.end())
break;
}
if (q < 1000)
Top_Cone->FS[tn].splice(Top_Cone->FS[tn].begin(), Top_Cone->FreeSimpl);
else
Top_Cone->FS[tn].splice(Top_Cone->FS[tn].begin(), Top_Cone->FreeSimpl, Top_Cone->FreeSimpl.begin(), F);
} // if empty global (critical)
} // critical
} // if empty global
} // if empty thread
if (Simpl_available) {
Triangulation.splice(Triangulation.end(), Top_Cone->FS[tn], Top_Cone->FS[tn].begin());
Triangulation.back() = newsimplex;
}
else {
Triangulation.push_back(newsimplex);
}
}
#endif
//---------------------------------------------------------------------------
// We measure times for small and large pyramids in order to better control
// which pyramids should be declared large.
//
// THIS IS A CRITICAL SUBROUTINE because of evaluate_large_rec_pyramids.
// One must take care that it does not change the state of *this.
// don_t_add_hyperplanes should keep it under control.
// One must not only avoid adding hyperplanes, but also changing the
// numbering scheme for hyperplanes.
//
template <typename Integer>
void Full_Cone<Integer>::small_vs_large(const size_t new_generator) {
IsLarge = vector<bool>(nr_gen, false);
don_t_add_hyperplanes = true; // during time measurement the addition of hyperplanes is blocked
int save_nr_threads = omp_get_max_threads(); // must block parallelization
omp_set_num_threads(1); // in small pyramids
nr_pyrs_timed = vector<size_t>(nr_gen);
time_of_large_pyr = vector<chrono::nanoseconds>(nr_gen);
time_of_small_pyr = vector<chrono::nanoseconds>(nr_gen);
auto hyp = Facets.begin();
vector<key_t> Pyramid_key;
size_t start_level = omp_get_level();
size_t check_period = 25;
for (size_t kk = 0; kk < old_nr_supp_hyps; ++kk, ++hyp) {
if (kk % check_period != 0)
continue;
if (hyp->ValNewGen >= 0) // facet not visible
continue;
Pyramid_key.clear(); // make data of new pyramid
Pyramid_key.push_back(static_cast<key_t>(new_generator));
for (size_t i = 0; i < nr_gen; i++) {
if (in_triang[i] && hyp->GenInHyp.test(i)) {
Pyramid_key.push_back(static_cast<key_t>(i));
}
}
bool large = (largePyramidFactor * Comparisons[Pyramid_key.size() - dim] > old_nr_supp_hyps); // a priori decision
if (large)
continue;
if (nr_pyrs_timed[Pyramid_key.size()] >= 5)
continue;
// we first treat it as small pyramid
auto cl0 = chrono::high_resolution_clock::now();
process_pyramid(Pyramid_key, new_generator, store_level, 0, true, hyp,
start_level); // is recursive, 0 blocks triangulation
auto cl1 = chrono::high_resolution_clock::now();
time_of_small_pyr[Pyramid_key.size()] += cl1 - cl0;
nr_pyrs_timed[Pyramid_key.size()]++;
// now as large pyramid
LargeRecPyrs.push_back(*hyp);
}
take_time_of_large_pyr = true;
bool save_verbose = verbose;
verbose = false;
evaluate_large_rec_pyramids(new_generator);
verbose = save_verbose;
take_time_of_large_pyr = false;
ssize_t kk;
for (kk = nr_gen - 1; kk >= (ssize_t)dim; --kk) {
if (time_of_small_pyr[kk].count() == 0)
continue;
if (time_of_small_pyr[kk] > time_of_large_pyr[kk])
IsLarge[kk] = true;
else
break;
}
// cout << "First large " << kk+1 << endl;
don_t_add_hyperplanes = false;
omp_set_num_threads(save_nr_threads);
assert(Facets.size() == old_nr_supp_hyps);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::process_pyramids(const size_t new_generator, const bool recursive) {
/*
We distinguish two types of pyramids:
(i) recursive pyramids that give their support hyperplanes back to the mother.
(ii) independent pyramids that are not linked to the mother.
The parameter "recursive" indicates whether the pyramids that will be created
in process_pyramid(s) are of type (i) or (ii).
Every pyramid can create subpyramids of both types (not the case in version 2.8 - 2.10).
Whether "this" is of type (i) or (ii) is indicated by do_all_hyperplanes.
The creation of (sub)pyramids of type (i) can be blocked by setting subpyramids_allowed=false.
(Not done in this version.)
is_pyramid==false for the top_cone and ==true else.
multithreaded_pyramid indicates whether parallelization takes place within the
computation of a pyramid or whether it is computed in a single thread (defined in build_cone).
Recursie pyramids are processed immediately after creation (as in 2.8). However, there
are two exceptions:
(a) In order to avoid very long waiting times for the computation of the "large" ones,
these are treated as follows: the support hyperplanes of "this" coming from their bases
(as negative hyperplanes of "this") are computed by matching them with the
positive hyperplanes of "this". This Fourier-Motzkin step is much more
efficient if a pyramid is large. For triangulation a large recursive
pyramid is then stored as a pyramid of type (ii).
(b) If "this" is processed in a parallelized loop calling process_pyramids, then
the loop in process_pyramids cannot be interrupted for the evaluation of simplices. As a
consequence an extremely long list of simplices could arise if many small subpyramids of "this"
are created in process_pyramids. In order to prevent this dangeous effect, small recursive
subpyramids are stored for later triangulation if the simplex buffer has reached its
size bound.
Pyramids of type (ii) are stpred in Pyramids. The store_level of the created pyramids is 0
for all pyramids created (possibly recursively) from the top cone. Pyramids created
in evaluate_stored_pyramids get the store level for their subpyramids in that routine and
transfer it to their recursive daughters. (correction March 4, 2015).
Note: the top cone has pyr_level=-1. The pyr_level has no algorithmic relevance
at present, but it shows the depth of the pyramid recursion at which the pyramid has been
created.
*/
if ((using_renf<Integer>() || using_GMP<Integer>()) && Generators_float.nr_of_rows() == 0) {
// Generators.pretty_print(cout);
convert(Generators_float, Generators);
}
if (!is_pyramid && !time_measured && recursive) { // (using_GMP<Integer>() || using_renf<Integer>()) &&
rank_time();
cmp_time();
/* ticks_quot=(ticks_rank_per_row/ticks_comp_per_supphyp)/ticks_norm_quot;
if(verbose)
verboseOutput() << "Normed quotient " << ticks_quot << endl;*/
time_measured = true;
}
IsLarge.clear();
if (using_renf<Integer>() && recursive && !is_pyramid && (!do_partial_triangulation || do_triangulation)) {
/*if(verbose)
verboseOutput() << "ticks_rank_per_row "
<< ticks_rank_per_row.count() << " (nanoseconds)" << endl;*/
if (ticks_rank_per_row.count() > 2000) // In such an arithmetically difficult situation we
small_vs_large(new_generator); // try to decide small vs. pyramids based on time time_measured
}
size_t start_level = omp_get_level(); // allows us to check that we are on level 0
// outside the loop and can therefore call evaluation
// in order to empty the buffers
if (!is_pyramid && verbose) {
verboseOutput() << "Building pyramids";
if (recursive) {
verboseOutput() << " for support hyperplanes";
if (do_triangulation || do_partial_triangulation)
verboseOutput() << " and triangulation";
}
else
verboseOutput() << " for triangulation";
verboseOutput() << endl;
}
vector<key_t> Pyramid_key;
Pyramid_key.reserve(nr_gen);
bool skip_triang; // make hyperplanes but skip triangulation (recursive pyramids only)
// deque<bool> done(old_nr_supp_hyps, false);
bool skip_remaining;
std::exception_ptr tmp_exception;
size_t start_kk = 0;
size_t ii = 0;
deque<typename list<FACETDATA<Integer>>::iterator> FacetIts(old_nr_supp_hyps);
for (auto F = Facets.begin(); F != Facets.end(); ++F, ++ii) {
FacetIts[ii] = F;
}
const long VERBOSE_STEPS = 50;
long step_x_size = old_nr_supp_hyps - VERBOSE_STEPS;
const size_t RepBound = 10000;
string collected_points;
do { // repeats processing until all hyperplanes have been processed
auto hyp = Facets.begin();
skip_remaining = false;
bool fresh_loop_start = true;
#pragma omp parallel for private(skip_triang, hyp) firstprivate(Pyramid_key, collected_points) schedule(dynamic)
for (size_t kk = start_kk; kk < old_nr_supp_hyps; ++kk) {
if (skip_remaining)
continue;
if (verbose && old_nr_supp_hyps >= RepBound) {
#pragma omp critical(VERBOSE)
{
if (fresh_loop_start)
cout << collected_points;
fresh_loop_start = false;
while ((long)(kk * VERBOSE_STEPS) >= step_x_size) {
step_x_size += old_nr_supp_hyps;
verboseOutput() << "." << flush;
collected_points += ".";
}
}
}
try {
INTERRUPT_COMPUTATION_BY_EXCEPTION
// if (done[kk])
// continue;
if (FacetIts[kk] == Facets.end())
continue;
hyp = FacetIts[kk];
// done[kk] = true;
FacetIts[kk] = Facets.end();
if (hyp->ValNewGen == 0) { // MUST BE SET HERE
hyp->GenInHyp.set(new_generator);
if (recursive)
hyp->simplicial = false; // in the recursive case
}
if (hyp->ValNewGen >= 0) { // facet not visible
if (pyramids_for_last_built_directly)
make_pyramid_for_last_generator(*hyp);
continue;
}
skip_triang = false;
if (Top_Cone->do_partial_triangulation && hyp->ValNewGen >= -1) { // ht1 criterion
skip_triang = is_hyperplane_included(*hyp);
if (skip_triang) {
Top_Cone->triangulation_is_partial = true;
if (!recursive) {
continue;
}
}
}
Pyramid_key.clear(); // make data of new pyramid
Pyramid_key.push_back(static_cast<key_t>(new_generator));
for (size_t i = 0; i < nr_gen; i++) {
if (in_triang[i] && hyp->GenInHyp.test(i)) {
Pyramid_key.push_back(static_cast<key_t>(i));
}
}
// now we can store the new pyramid at the right place (or finish the simplicial ones)
if (recursive && skip_triang) { // mark as "do not triangulate"
process_pyramid(Pyramid_key, new_generator, store_level, 0, recursive, hyp, start_level);
}
else { // default
process_pyramid(Pyramid_key, new_generator, store_level, -hyp->ValNewGen, recursive, hyp, start_level);
}
// interrupt parallel execution if it is really parallel
// to keep the triangulationand pyramid buffers under control
if (start_level == 0) {
if (check_evaluation_buffer_size() || Top_Cone->check_pyr_buffer(store_level) ||
Top_Cone->check_pyr_buffer(0)) {
if (verbose && !skip_remaining)
verboseOutput() << endl;
skip_remaining = true;
}
}
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
} // end parallel loop over hyperplanes
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
if (!omp_in_parallel())
try_offload(0);
if (start_level == 0 && check_evaluation_buffer_size()) {
Top_Cone->evaluate_triangulation();
}
if (start_level == 0 && Top_Cone->check_pyr_buffer(store_level)) {
Top_Cone->evaluate_stored_pyramids(store_level);
}
if (start_level == 0 && Top_Cone->check_pyr_buffer(0)) {
Top_Cone->evaluate_stored_pyramids(0);
}
if (verbose && old_nr_supp_hyps >= RepBound)
verboseOutput() << endl;
// for(;start_kk < old_nr_supp_hyps && done[start_kk]; ++start_kk);
for (; start_kk < old_nr_supp_hyps && FacetIts[start_kk] == Facets.end(); ++start_kk)
;
} while (start_kk < old_nr_supp_hyps);
// cout << float_comp << " " << wrong << " " << wrong_short << endl;
// wrong_positive=0;
// wrong_negative=0;
// total_comp_large_pyr=0;
evaluate_large_rec_pyramids(new_generator);
// cout << total_comp_large_pyr << " " << wrong_positive << " " << wrong_negative << endl;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::process_pyramid(const vector<key_t>& Pyramid_key,
const size_t new_generator,
const size_t store_level,
Integer height,
const bool recursive,
typename list<FACETDATA<Integer>>::iterator hyp,
size_t start_level) {
// processes simplicial pyramids directly, stores other pyramids into their depots
#pragma omp atomic
Top_Cone->totalNrPyr++;
#ifdef NMZ_EXTENDED_TESTS
if ((!test_small_pyramids || (test_small_pyramids && !test_large_pyramids)) && (Pyramid_key.size() == dim))
#else
if (Pyramid_key.size() == dim) // simplicial pyramid completely done here for saving memory
#endif
{
#pragma omp atomic
Top_Cone->nrSimplicialPyr++;
if (recursive) { // the facets may be facets of the mother cone and if recursive==true must be given back
Matrix<Integer> H(dim, dim);
Integer dummy_vol;
int tn;
if (omp_get_level() == omp_start_level)
tn = 0;
else
tn = omp_get_ancestor_thread_num(omp_start_level + 1);
Generators.simplex_data(Pyramid_key, H, dummy_vol, Top_Cone->WorkMat[tn], Top_Cone->UnitMat, false);
list<FACETDATA<Integer>> NewFacets;
FACETDATA<Integer> NewFacet;
NewFacet.GenInHyp.resize(nr_gen);
for (size_t i = 0; i < dim; i++) {
swap(NewFacet.Hyp, H[i]);
NewFacet.GenInHyp.set();
NewFacet.GenInHyp.reset(i);
NewFacet.simplicial = true;
// NewFacet.is_positive_on_all_original_gens = false;
// NewFacet.is_negative_on_some_original_gen = false;
NewFacets.push_back(NewFacet);
}
vector<bool> Pyr_in_triang(dim, true);
select_supphyps_from(NewFacets, new_generator, Pyramid_key,
Pyr_in_triang); // takes itself care of multithreaded_pyramid
}
if (height != 0 && (do_triangulation || do_partial_triangulation)) {
if (multithreaded_pyramid) {
std::exception_ptr tmp_exception;
#pragma omp critical(TRIANG)
{
try {
store_key(Pyramid_key, height, 0, TriangulationBuffer);
nrTotalComparisons += dim * dim / 2;
} catch (const std::exception&) {
tmp_exception = std::current_exception();
}
} // end critical
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
}
else {
store_key(Pyramid_key, height, 0, TriangulationBuffer);
nrTotalComparisons += dim * dim / 2;
}
}
}
else { // non-simplicial
bool large;
if (IsLarge.size() == 0) { // no measurement in Small_vs_large
long large_factor = largePyramidFactor;
if (time_measured && (using_renf<Integer>() || using_GMP<Integer>())) { // we try evaluate
// the complexity of the arithmetic
mpq_class large_factor_mpq((double)ticks_rank_per_row.count() / 1000); // 1000 because of nanosecinds
mpz_class add = round(large_factor_mpq);
large_factor += convertToLong(add);
}
large = (large_factor * Comparisons[Pyramid_key.size() - dim] > old_nr_supp_hyps);
}
else { // with measurement in Small_vs_large
large = (largePyramidFactor * Comparisons[Pyramid_key.size() - dim] > old_nr_supp_hyps);
large = large || IsLarge[Pyramid_key.size()];
}
#ifdef NMZ_EXTENDED_TESTS
if (test_large_pyramids) {
large = true;
}
#endif
if (!recursive || (large && (do_triangulation || do_partial_triangulation) &&
height != 0)) { // must also store for triangulation if recursive and large
vector<key_t> key_wrt_top(Pyramid_key.size());
for (size_t i = 0; i < Pyramid_key.size(); i++)
key_wrt_top[i] = Top_Key[Pyramid_key[i]];
#pragma omp critical(STOREPYRAMIDS)
{
// cout << "store_level " << store_level << " large " << large << " pyr level " << pyr_level << endl;
Top_Cone->Pyramids[store_level].push_back(key_wrt_top);
Top_Cone->nrPyramids[store_level]++;
} // critical
if (!recursive) // in this case we need only store for future triangulation, and that has been done
return;
}
// now we are in the recursive case and must compute support hyperplanes of the subpyramid
if (large) { // large recursive pyramid
if (multithreaded_pyramid) {
#pragma omp critical(LARGERECPYRS)
LargeRecPyrs.push_back(*hyp); // LargeRecPyrs are kept and evaluated locally
}
else
LargeRecPyrs.push_back(*hyp);
return; // done with the large recursive pyramids
}
// only recursive small ones left
// pyrtime=clock();
Full_Cone<Integer> Pyramid(*this, Pyramid_key);
Pyramid.Mother = this;
Pyramid.Mother_Key = Pyramid_key; // need these data to give back supphyps
Pyramid.apex = new_generator;
if (height == 0) { // indicates "do not triangulate"
Pyramid.do_triangulation = false;
Pyramid.do_partial_triangulation = false;
Pyramid.do_Hilbert_basis = false;
Pyramid.do_deg1_elements = false;
}
bool store_for_triangulation =
(store_level != 0) // loop in process_pyramids cannot be interrupted
&& (Pyramid.do_triangulation || Pyramid.do_partial_triangulation) // we must (partially) triangulate
&& (start_level != 0 &&
Top_Cone->TriangulationBufferSize > 2 * EvalBoundTriang); // evaluation buffer already full // EvalBoundTriang
if (store_for_triangulation) {
vector<key_t> key_wrt_top(Pyramid_key.size());
for (size_t i = 0; i < Pyramid_key.size(); i++)
key_wrt_top[i] = Top_Key[Pyramid_key[i]];
#pragma omp critical(STOREPYRAMIDS)
{
Top_Cone->Pyramids[store_level].push_back(key_wrt_top);
Top_Cone->nrPyramids[store_level]++;
} // critical
// Now we must suppress immediate triangulation
Pyramid.do_triangulation = false;
Pyramid.do_partial_triangulation = false;
Pyramid.do_Hilbert_basis = false;
Pyramid.do_deg1_elements = false;
}
Pyramid.build_cone();
// cout << "Pyramid ticks " << clock() - pyrtime << endl;
if (multithreaded_pyramid) {
#pragma omp atomic
nrTotalComparisons += Pyramid.nrTotalComparisons;
}
else
nrTotalComparisons += Pyramid.nrTotalComparisons;
} // else non-simplicial
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_and_evaluate_start_simplex() {
// it is absolutely necessary to chooses the start simplex as the lex smallest+
// in order to be consistent with pyramid decomposition
size_t i, j;
vector<key_t> key = find_start_simplex();
if(key.size() != dim){ // safety heck
throw ArithmeticException("Most likely an overflow occurred. Rerunning with indefinite precision if possible. If you have used LOngLong, omit it. If the problem persists, iform the authors.");
}
if (verbose) {
verboseOutput() << "Start simplex ";
for (unsigned int i : key)
verboseOutput() << i + 1 << " ";
verboseOutput() << endl;
}
Matrix<Integer> H(dim, dim);
Integer vol;
int tn;
if (omp_get_level() == omp_start_level)
tn = 0;
else
tn = omp_get_ancestor_thread_num(omp_start_level + 1);
Generators.simplex_data(key, H, vol, Top_Cone->WorkMat[tn], Top_Cone->UnitMat, do_partial_triangulation || do_triangulation);
assert(key.size() == dim); // safety heck
// cout << "Nach First " << clock()-pyrtime << endl;
// cout << "Nach LinAl " << clock()-pyrtime << endl;
// H.pretty_print(cout);
for (i = 0; i < dim; i++) {
in_triang[key[i]] = true;
GensInCone.push_back(key[i]);
if (deg1_triangulation && isComputed(ConeProperty::Grading))
deg1_triangulation = (gen_degrees[key[i]] == 1);
}
nrGensInCone = dim;
nrTotalComparisons = dim * dim / 2;
// if(!time_measured){
if (using_GMP<Integer>())
nrTotalComparisons *= (GMP_time_factor / 4); // because of the linear algebra involved in this routine
if (using_renf<Integer>())
nrTotalComparisons *= (renf_time_factor / 4);
/*}
else{
if(using_GMP<Integer>())
nrTotalComparisons*=(GMP_time_factor/4)*ticks_quot;
if(using_renf<Integer>())
nrTotalComparisons*=(renf_time_factor/4)*ticks_quot;
}*/
Comparisons.push_back(nrTotalComparisons);
for (i = 0; i < dim; i++) {
FACETDATA<Integer> NewFacet;
NewFacet.GenInHyp.resize(nr_gen);
// NewFacet.is_positive_on_all_original_gens = false;
// NewFacet.is_negative_on_some_original_gen = false;
swap(NewFacet.Hyp, H[i]);
NewFacet.simplicial = true; // indeed, the start simplex is simplicial
for (j = 0; j < dim; j++)
if (j != i)
NewFacet.GenInHyp.set(key[j]);
NewFacet.ValNewGen = -1; // must be taken negative since opposite facet
number_hyperplane(NewFacet, 0, 0); // created with gen 0
Facets.emplace_back(std::move(NewFacet)); // was visible before adding this vertex
}
Integer factor;
if (!is_pyramid) {
// define Order_Vector, decides which facets of the simplices are excluded
Order_Vector = vector<Integer>(dim, 0);
// Matrix<Integer> G=S.read_generators();
for (i = 0; i < dim; i++) {
factor = (unsigned long)(1 + i % 10); // (2*(rand()%(2*dim))+3);
for (j = 0; j < dim; j++)
Order_Vector[j] += factor * Generators[key[i]][j];
}
}
// the volume is an upper bound for the height
if (do_triangulation || (do_partial_triangulation && vol > 1)) {
store_key(key, vol, 1, TriangulationBuffer);
if (do_only_multiplicity && !using_renf<Integer>()) {
#pragma omp atomic
TotDet++;
}
}
else if (do_partial_triangulation) {
triangulation_is_partial = true;
}
if (do_triangulation) { // we must prepare the sections of the triangulation
for (i = 0; i < dim; i++) {
// GensInCone.push_back(key[i]); // now done in first loop since always needed
TriSectionFirst.push_back(TriangulationBuffer.begin());
TriSectionLast.push_back(TriangulationBuffer.begin());
}
}
// cout << "Nach Start " << clock()-pyrtime << endl;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::select_supphyps_from(list<FACETDATA<Integer>>& NewFacets,
const size_t new_generator,
const vector<key_t>& Pyramid_key,
const vector<bool>& Pyr_in_triang) {
// the mother cone (=this) selects supphyps from the list NewFacets supplied by the daughter
// the daughter provides the necessary information via the parameters
size_t i;
dynamic_bitset in_Pyr(nr_gen);
for (i = 0; i < Pyramid_key.size(); i++) {
in_Pyr.set(Pyramid_key[i]);
}
// the new generator is always the first in the pyramid
assert(Pyramid_key[0] == new_generator);
bool new_global_hyp;
FACETDATA<Integer> NewFacet;
// NewFacet.is_positive_on_all_original_gens = false;
// NewFacet.is_negative_on_some_original_gen = false;
NewFacet.GenInHyp.resize(nr_gen);
Integer test;
for (auto& pyr_hyp : NewFacets) {
if (!pyr_hyp.GenInHyp.test(0)) // new gen not in hyp
continue;
new_global_hyp = true;
for (i = 0; i < nr_gen; ++i) {
if (in_Pyr.test(i) || !in_triang[i])
continue;
test = v_scalar_product(Generators[i], pyr_hyp.Hyp);
if (test <= 0) {
new_global_hyp = false;
break;
}
}
if (new_global_hyp) {
swap(NewFacet.Hyp, pyr_hyp.Hyp);
NewFacet.GenInHyp.reset();
// size_t gens_in_facet=0;
for (i = 0; i < Pyramid_key.size(); ++i) {
if (in_triang[Pyramid_key[i]]) // this satisfied in the standard setting where the pyramid key is strictly
// ascending after
assert(Pyr_in_triang[i]); // the first entry and the start simplex of the pyramid is lex smallest
if (pyr_hyp.GenInHyp.test(i) && in_triang[Pyramid_key[i]]) {
NewFacet.GenInHyp.set(Pyramid_key[i]);
// gens_in_facet++;
}
}
/* for (i=0; i<nr_gen; ++i) {
if (NewFacet.GenInHyp.test(i) && in_triang[i]) {
gens_in_facet++;
}
}*/
// gens_in_facet++; // Note: new generator not yet in in_triang
NewFacet.GenInHyp.set(new_generator);
NewFacet.simplicial = pyr_hyp.simplicial; // (gens_in_facet==dim-1);
// check_simpliciality_hyperplane(NewFacet);
number_hyperplane(NewFacet, nrGensInCone, 0); // mother unknown
if (don_t_add_hyperplanes)
continue;
if (!pyramids_for_last_built_directly) {
if (multithreaded_pyramid) {
#pragma omp critical(GIVEBACKHYPS)
Facets.push_back(NewFacet);
}
else {
Facets.push_back(NewFacet);
}
}
else
make_pyramid_for_last_generator(NewFacet);
}
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::match_neg_hyp_with_pos_hyps(const FACETDATA<Integer>& Neg,
size_t new_generator,
const vector<FACETDATA<Integer>*>& PosHyps,
dynamic_bitset& GenIn_PosHyp,
vector<list<dynamic_bitset>>& Facets_0_1) {
// #pragma omp atomic
// count_large_pyrs++;
size_t missing_bound, nr_common_gens;
vector<key_t> common_key;
common_key.reserve(nr_gen);
vector<key_t> key(nr_gen);
bool common_subfacet;
// list<FACETDATA<Integer>> NewHyp;
size_t subfacet_dim = dim - 2;
size_t nr_missing;
list<FACETDATA<Integer>> NewHyps;
Matrix<Integer> Test(0, dim);
int tn;
if (omp_get_level() == omp_start_level)
tn = 0;
else
tn = omp_get_ancestor_thread_num(omp_start_level + 1);
dynamic_bitset RelGens_InNegHyp = Neg.GenInHyp & GenIn_PosHyp; // we intersect with the set of gens in positive hyps
vector<int> key_start(nrGensInCone);
size_t nr_RelGens_InNegHyp = 0;
size_t j;
int last_existing = -1;
for (size_t jj = 0; jj < nrGensInCone; jj++) {
j = GensInCone[jj];
if (RelGens_InNegHyp.test(j)) {
key[nr_RelGens_InNegHyp] = static_cast<key_t>(j);
for (size_t kk = last_existing + 1; kk <= jj; kk++)
key_start[kk] = static_cast<int>(nr_RelGens_InNegHyp);
nr_RelGens_InNegHyp++;
last_existing = static_cast<int>(jj);
}
}
if (last_existing < (int)nrGensInCone - 1)
for (size_t kk = last_existing + 1; kk < nrGensInCone; kk++)
key_start[kk] = static_cast<int>(nr_RelGens_InNegHyp);
if (nr_RelGens_InNegHyp < dim - 2)
return;
missing_bound = nr_RelGens_InNegHyp - subfacet_dim; // at most this number of generators can be missing
// to have a chance for common subfacet
for (const auto& Pos : PosHyps) { // match Neg with the given Pos
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (Neg.Ident == Pos->Mother || Pos->Ident == Neg.Mother) { // mother and daughter coming together
// their intersection is a subfacet
add_hyperplane(new_generator, *Pos, Neg, NewHyps, false); // simplicial set in add_hyperplane
continue;
}
bool extension_test = Neg.BornAt == Pos->BornAt || (Neg.BornAt < Pos->BornAt && Pos->Mother != 0) ||
(Pos->BornAt < Neg.BornAt && Neg.Mother != 0);
size_t both_existing_from = key_start[max(Neg.BornAt, Pos->BornAt)];
nr_missing = 0;
nr_common_gens = 0;
common_key.clear();
size_t second_loop_bound = nr_RelGens_InNegHyp;
common_subfacet = true;
dynamic_bitset common_gens(nr_gen);
if (extension_test) {
bool extended = false;
second_loop_bound = both_existing_from;
for (size_t k = both_existing_from; k < nr_RelGens_InNegHyp; k++) {
if (!Pos->GenInHyp.test(key[k])) {
nr_missing++;
if (nr_missing > missing_bound) {
common_subfacet = false;
break;
}
}
else {
extended = true;
common_key.push_back(key[k]);
common_gens.set(key[k]);
nr_common_gens++;
}
}
if (!extended || !common_subfacet) //
continue;
}
for (size_t k = 0; k < second_loop_bound; k++) {
if (!Pos->GenInHyp.test(key[k])) {
nr_missing++;
if (nr_missing > missing_bound) {
common_subfacet = false;
break;
}
}
else {
common_key.push_back(key[k]);
common_gens.set(key[k]);
nr_common_gens++;
}
}
if (!common_subfacet)
continue;
assert(nr_common_gens >= subfacet_dim);
if (!Pos->simplicial) {
bool ranktest = true; // and remains so if we are using long long or long
if (using_GMP<Integer>() || using_renf<Integer>()) {
if (time_measured) {
ranktest = (ticks_rank_per_row.count() * nr_common_gens < (unsigned long)ticks_per_cand.count());
// casting ticks_per_cand.count() as unsigned long should be harmless
}
else { // a priori values
if (using_GMP<Integer>())
ranktest = (old_nr_supp_hyps > GMP_time_factor * dim * dim * nr_common_gens / 3);
// in this case the rank computation is expected to be faster
else
ranktest = (old_nr_supp_hyps > renf_time_factor * dim * dim * nr_common_gens / 3);
}
}
#ifdef NMZ_EXTENDED_TESTS
if (using_GMP<Integer>() || using_renf<Integer>()) {
int help = rand() % 2;
if (help == 0)
ranktest = true;
else
ranktest = false; // not allowed for long long
}
#endif
// Additionally we use a float computation as a prdeictor.
// If it says "not a common subfacet", then the comparison test is usually very fast.
// In the positive case, it is better to use the rank test.
if (ranktest && Generators_float.nr_of_rows() > 0) {
Matrix<nmz_float>& Test_float = Top_Cone->RankTest_float[tn];
if (Test_float.rank_submatrix(Generators_float, common_key) < subfacet_dim) {
ranktest = false;
}
}
assert(ranktest == true || Facets_0_1.size() > 0);
if (ranktest) {
Matrix<Integer>& Test = Top_Cone->RankTest[tn];
// #pragma omp atomic
// count_rank_test_large++;
if (Test.rank_submatrix(Generators, common_key) < subfacet_dim)
common_subfacet = false; // don't make a hyperplane
}
else { // now the comparison test
// #pragma omp atomic
// count_comp_test_large++;
for (auto hp_t = Facets_0_1[tn].begin(); hp_t != Facets_0_1[tn].end(); ++hp_t) {
if (common_gens.is_subset_of(*hp_t) && (*hp_t != Neg.GenInHyp) && (*hp_t != Pos->GenInHyp)) {
Facets_0_1[tn].splice(Facets_0_1[tn].begin(), Facets_0_1[tn], hp_t); // successful reducer to the front
common_subfacet = false;
break;
}
}
}
} // !simplicial
if (common_subfacet) {
add_hyperplane(new_generator, *Pos, Neg, NewHyps, false); // simplicial set in add_hyperplane
}
} // for
if (multithreaded_pyramid)
#pragma omp critical(GIVEBACKHYPS)
Facets.splice(Facets.end(), NewHyps);
else
Facets.splice(Facets.end(), NewHyps);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::collect_pos_supphyps(vector<FACETDATA<Integer>*>& PosHyps,
dynamic_bitset& GenIn_PosHyp,
size_t& nr_pos) {
// positive facets are collected in a list
auto ii = Facets.begin();
nr_pos = 0;
for (size_t ij = 0; ij < old_nr_supp_hyps; ++ij, ++ii)
if (ii->ValNewGen > 0) {
GenIn_PosHyp |= ii->GenInHyp;
PosHyps.push_back(&(*ii));
nr_pos++;
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::evaluate_large_rec_pyramids(size_t new_generator) {
size_t nrLargeRecPyrs = LargeRecPyrs.size();
if (nrLargeRecPyrs == 0)
return;
vector<list<dynamic_bitset>> Facets_0_1(omp_get_max_threads());
size_t nr_non_simplicial = 0;
if (using_GMP<Integer>() || using_renf<Integer>()) {
auto Fac = Facets.begin();
for (size_t i = 0; i < old_nr_supp_hyps; ++i, ++Fac) {
if (Fac->simplicial)
continue;
Facets_0_1[0].push_back(Fac->GenInHyp);
nr_non_simplicial++;
}
for (int j = 1; j < omp_get_max_threads(); ++j)
Facets_0_1[j] = Facets_0_1[0];
}
if (verbose)
verboseOutput() << "large pyramids " << nrLargeRecPyrs << endl;
vector<FACETDATA<Integer>*> PosHyps;
dynamic_bitset GenIn_PosHyp(nr_gen);
size_t nr_pos;
collect_pos_supphyps(PosHyps, GenIn_PosHyp, nr_pos);
nrTotalComparisons += nr_pos * nrLargeRecPyrs;
std::exception_ptr tmp_exception;
const long VERBOSE_STEPS = 50;
long step_x_size = nrLargeRecPyrs - VERBOSE_STEPS;
const size_t RepBound = 100;
// clock_t cl=clock();
/* auto LP=LargeRecPyrs.begin();
for(size_t i=0; i<nrLargeRecPyrs; i++,++LP){
if(i%100 ==1)
match_neg_hyp_with_pos_hyps(*LP,new_generator,PosHyps,GenIn_PosHyp,true,nr_cand,Facets_0_1);
}
cl=clock()-cl;
ticks_per_cand=(double) cl/(double) nr_cand;
if(verbose)
verboseOutput() << "Ticks per cand " << ticks_per_cand << endl;*/
ticks_per_cand = ticks_comp_per_supphyp * nr_non_simplicial; // estimated time for testing an irreducible by comparison
bool skip_remaining = false;
#pragma omp parallel if (!take_time_of_large_pyr)
{
size_t ppos = 0;
auto p = LargeRecPyrs.begin();
#pragma omp for schedule(dynamic)
for (size_t i = 0; i < nrLargeRecPyrs; i++) {
if (skip_remaining)
continue;
for (; i > ppos; ++ppos, ++p)
;
for (; i < ppos; --ppos, --p)
;
if (verbose && nrLargeRecPyrs >= RepBound) {
#pragma omp critical(VERBOSE)
while ((long)(i * VERBOSE_STEPS) >= step_x_size) {
step_x_size += nrLargeRecPyrs;
verboseOutput() << "." << flush;
}
}
// cout << "=================================" << endl;
// cout << "Neg Hyp " << i << endl;
// clock_t cl;
// cl= clock();
try {
INTERRUPT_COMPUTATION_BY_EXCEPTION
chrono::time_point<chrono::high_resolution_clock> cl_large_0(chrono::nanoseconds(0));
if (take_time_of_large_pyr) {
cl_large_0 = chrono::high_resolution_clock::now();
}
match_neg_hyp_with_pos_hyps(*p, new_generator, PosHyps, GenIn_PosHyp, Facets_0_1);
if (take_time_of_large_pyr) {
auto cl_large_1 = chrono::high_resolution_clock::now();
size_t nr_pyr_gens = 0;
for (size_t i = 0; i < nr_gen; ++i)
if (p->GenInHyp[i])
nr_pyr_gens++;
nr_pyr_gens++; // for the apex of the pyramid
time_of_large_pyr[nr_pyr_gens] += cl_large_1 - cl_large_0;
}
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
// cl=clock()-cl;
// cout << "Neg Hyp " << i << " ticks " << cl << endl;
}
} // parallel
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
if (verbose && nrLargeRecPyrs >= RepBound)
verboseOutput() << endl;
LargeRecPyrs.clear();
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::check_pyr_buffer(const size_t level) {
if (level == 0)
return (nrPyramids[0] > EvalBoundLevel0Pyr);
else
return (nrPyramids[level] > EvalBoundPyr);
}
//---------------------------------------------------------------------------
#ifdef NMZ_MIC_OFFLOAD
template <>
void Full_Cone<long long>::try_offload(size_t max_level) {
if (!is_pyramid && _Offload_get_device_number() < 0) // dynamic check for being on CPU (-1)
{
if (max_level >= nrPyramids.size())
max_level = nrPyramids.size() - 1;
for (size_t level = 0; level <= max_level; ++level) {
if (nrPyramids[level] >= 100) {
// cout << "XXX: Try offload of level " << level << " pyramids ..." << endl;
mic_offloader.offload_pyramids(*this, level);
break;
}
}
}
}
template <typename Integer>
void Full_Cone<Integer>::try_offload(size_t max_level) {
}
// else it is implemented in the header
template <typename Integer>
void Full_Cone<Integer>::try_offload_loc(long place, size_t max_level) {
verboseOutput() << "From place " << place << " "
<< "level " << max_level << endl;
try_offload(max_level);
}
#endif // NMZ_MIC_OFFLOAD
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::evaluate_stored_pyramids(const size_t level) {
// evaluates the stored non-recursive pyramids
#ifdef NMZ_MIC_OFFLOAD
Pyramids_scrambled[level] = false;
if (level == 0 && _Offload_get_device_number() >= 0) {
verboseOutput() << "Start evaluation of " << nrPyramids[level] << " pyrs on level " << level << endl;
// verboseOutput() << "In parallel " << omp_in_parallel() << endl;
}
#endif // NMZ_MIC_OFFLOAD
if (Pyramids[level].empty())
return;
assert(omp_get_level() == omp_start_level); // assert(!omp_in_parallel());
assert(!is_pyramid);
if (Pyramids.size() < level + 2) {
Pyramids.resize(level + 2); // provide space for a new generation
nrPyramids.resize(level + 2, 0);
Pyramids_scrambled.resize(level + 2, false);
}
size_t eval_down_to = 0;
#ifdef NMZ_MIC_OFFLOAD
#ifndef __MIC__
// only on host and if offload is available
if (level == 0 && nrPyramids[0] > EvalBoundLevel0Pyr) {
eval_down_to = EvalBoundLevel0Pyr;
}
#endif
#endif
vector<char> Done(nrPyramids[level], 0);
if (verbose) {
verboseOutput() << "**************************************************" << endl;
for (size_t l = 0; l <= level; ++l) {
if (nrPyramids[l] > 0) {
verboseOutput() << "level " << l << " pyramids remaining: " << nrPyramids[l] << endl;
}
}
verboseOutput() << "**************************************************" << endl;
}
size_t ppos;
bool skip_remaining;
std::exception_ptr tmp_exception;
while (nrPyramids[level] > eval_down_to) {
auto p = Pyramids[level].begin();
ppos = 0;
skip_remaining = false;
#pragma omp parallel for firstprivate(p, ppos) schedule(dynamic)
for (size_t i = 0; i < nrPyramids[level]; i++) {
if (skip_remaining)
continue;
for (; i > ppos; ++ppos, ++p)
;
for (; i < ppos; --ppos, --p)
;
if (Done[i])
continue;
Done[i] = 1;
try {
INTERRUPT_COMPUTATION_BY_EXCEPTION
Full_Cone<Integer> Pyramid(*this, *p);
// Pyramid.subpyramids_allowed=false;
Pyramid.do_all_hyperplanes = false;
if (level >= 2 && do_partial_triangulation) { // limits the descent of do_partial_triangulation
Pyramid.do_triangulation = true;
Pyramid.do_partial_triangulation = false;
}
Pyramid.store_level = level + 1;
Pyramid.build_cone();
if (check_evaluation_buffer_size() || Top_Cone->check_pyr_buffer(level + 1)) {
// interrupt parallel execution to keep the buffer under control
skip_remaining = true;
}
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
} // end parallel for
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
// remove done pyramids
p = Pyramids[level].begin();
for (size_t i = 0; p != Pyramids[level].end(); i++) {
if (Done[i]) {
p = Pyramids[level].erase(p);
nrPyramids[level]--;
Done[i] = 0;
}
else {
++p;
}
}
try_offload(level + 1);
if (check_evaluation_buffer_size()) {
if (verbose)
verboseOutput() << nrPyramids[level] << " pyramids remaining on level " << level << ", ";
Top_Cone->evaluate_triangulation();
try_offload(level + 1);
}
if (Top_Cone->check_pyr_buffer(level + 1)) {
evaluate_stored_pyramids(level + 1);
}
} // end while (nrPyramids[level] > 0)
if (verbose) {
verboseOutput() << "**************************************************" << endl;
verboseOutput() << "all pyramids on level " << level << " done!" << endl;
if (nrPyramids[level + 1] == 0) {
for (size_t l = 0; l <= level; ++l) {
if (nrPyramids[l] > 0) {
verboseOutput() << "level " << l << " pyramids remaining: " << nrPyramids[l] << endl;
}
}
verboseOutput() << "**************************************************" << endl;
}
}
if (check_evaluation_buffer()) {
Top_Cone->evaluate_triangulation();
}
evaluate_stored_pyramids(level + 1);
}
//---------------------------------------------------------------------------
/* builds the cone successively by inserting generators */
template <typename Integer>
void Full_Cone<Integer>::build_cone() {
// if(dim>0){ //correction needed to include the 0 cone;
// cout << "Pyr " << pyr_level << endl;
Matrix<Integer> FinalHyps(0,dim);
if (start_from == 0)
in_triang = vector<bool>(nr_gen, false);
size_t RecBoundSuppHyp;
RecBoundSuppHyp = dim * SuppHypRecursionFactor;
if (using_GMP<Integer>())
RecBoundSuppHyp *= GMP_time_factor; // pyramid building is more difficult for complicated arithmetic
if (using_renf<Integer>())
RecBoundSuppHyp *= renf_time_factor_pyr * renf_degree * renf_degree;
size_t RecBoundTriang = 1000000; // if number(supphyps)*size(triang) > RecBoundTriang pass to pyramids
if (using_GMP<Integer>())
RecBoundTriang *= GMP_time_factor;
if (using_renf<Integer>())
RecBoundTriang *= renf_time_factor;
tri_recursion = false;
multithreaded_pyramid = (omp_get_level() == omp_start_level);
if (!use_existing_facets) {
if (multithreaded_pyramid) {
HypCounter.resize(omp_get_max_threads());
for (size_t i = 0; i < HypCounter.size(); ++i)
HypCounter[i] = i + 1;
}
else {
HypCounter.resize(1);
HypCounter[0] = 1;
}
find_and_evaluate_start_simplex();
/*if(!is_pyramid){
auto l = Facets.begin();
for (size_t j = 0 ; j < Facets.size(); j++) {
bool is_final_hyp = true;
for(size_t k = 0; k < Generators.nr_of_rows(); ++k){
if(v_scalar_product(Generators[k], l->Hyp) < 0){
is_final_hyp = false;
break;
}
}
if(is_final_hyp){
FinalHyps.append(l->Hyp);
}
l++;
}
if(verbose)
verboseOutput() << "FINAL HYPS " << FinalHyps.nr_of_rows() << endl;
FinalHyps.print(global_project,"fin_hyps");
}*/
}
long last_to_be_inserted = nr_gen - 1; // because we don't need to compute support hyperplanes in this case
for (ssize_t j = nr_gen - 1; j >= 0; --j) {
if (!in_triang[j]) {
last_to_be_inserted = j;
break;
}
} // last_to_be_inserted now determined
if (!is_pyramid)
top_last_to_be_inserted = last_to_be_inserted;
long second_last_to_be_inserted = nr_gen; // indicates: will be disregarded if = nr_gen
if (do_signed_dec && !is_pyramid) {
for (long j = last_to_be_inserted - 1; j >= 0; --j) {
if (!in_triang[j]) {
second_last_to_be_inserted = j;
break;
}
} // last_to_be_inserted now determined
}
// cout << "Last " << Top_Cone->top_last_to_be_inserted << " Second " << second_last_to_be_inserted << " nr_gen " << nr_gen <<
// endl;
if (is_pyramid && pyramids_for_last_built_directly) // no higher level pyramids in this case
subpyramids_allowed = false;
bool is_new_generator;
// RecBoundSuppHyp = 1000; // for tests
for (long i = start_from; i < (long)nr_gen; ++i) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (i == last_to_be_inserted && pyramids_for_last_built_directly) {
break; // in this case we have all pyramids with apex the last generator to be inserted
}
// time_t start, end;
// time(&start);
start_from = i;
if (in_triang[i])
continue;
if (do_triangulation && TriangulationBufferSize > 2 * RecBoundTriang) // emermergency brake
tri_recursion = true; // to switch off production of simplices in favor
// of non-recursive pyramids
#ifdef NMZ_EXTENDED_TESTS
if (test_small_pyramids)
tri_recursion = true;
#endif
Integer scalar_product;
is_new_generator = false;
auto l = Facets.begin();
old_nr_supp_hyps = Facets.size(); // Facets will be extended in the loop
long long nr_pos = 0, nr_neg = 0;
long long nr_neg_simp = 0, nr_pos_simp = 0;
vector<Integer> L;
std::exception_ptr tmp_exception;
size_t lpos = 0;
#pragma omp parallel for private(L, scalar_product) firstprivate(lpos, l) reduction(+ : nr_pos, nr_neg)
for (size_t k = 0; k < old_nr_supp_hyps; k++) {
try {
for (; k > lpos; lpos++, l++)
;
for (; k < lpos; lpos--, l--)
;
L = Generators[i];
scalar_product = v_scalar_product(L, (*l).Hyp);
l->ValNewGen = scalar_product;
l->negative = false;
l->positive = false;
l->neutral = false;
if (scalar_product < 0) {
is_new_generator = true;
l->negative = true;
nr_neg++;
if (l->simplicial)
#pragma omp atomic
nr_neg_simp++;
continue;
}
if (scalar_product == 0) {
l->neutral = true;
continue;
}
// if (scalar_product>0) {
nr_pos++;
l->positive = true;
if (l->simplicial)
#pragma omp atomic
nr_pos_simp++;
//}
} catch (const std::exception&) {
tmp_exception = std::current_exception();
}
} // end parallel for
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
if (!is_new_generator && !pulling_triangulation)
continue;
// the i-th generator is used in the triangulation
// in_triang[i]=true; // now at end of loop
if (deg1_triangulation && isComputed(ConeProperty::Grading))
deg1_triangulation = (gen_degrees[i] == 1);
if (!omp_in_parallel())
try_offload(0);
/* if(!is_pyramid && verbose )
verboseOutput() << "Neg " << nr_neg << " Pos " << nr_pos << " NegSimp " <<nr_neg_simp << " PosSimp " <<nr_pos_simp <<
endl; */
// First we test whether to go to recursive pyramids because of too many supphyps
if ((do_all_hyperplanes || (i != last_to_be_inserted)) && subpyramids_allowed &&
((nr_neg * nr_pos - (nr_neg_simp * nr_pos_simp) >= (long)RecBoundSuppHyp)
#ifdef NMZ_EXTENDED_TESTS
|| test_small_pyramids
#endif
)) { // use pyramids because of supphyps
if (i == second_last_to_be_inserted)
pyramids_for_last_built_directly = true;
if (do_triangulation)
tri_recursion = true; // We can not go back to classical triangulation
if (check_evaluation_buffer()) {
Top_Cone->evaluate_triangulation();
}
process_pyramids(i, true); // recursive
// lastGen=i;
// nextGen=i+1;
}
else { // now we check whether to go to pyramids because of the size of triangulation
// once we have done so, we must stay with it
if (subpyramids_allowed &&
(tri_recursion || (do_triangulation && (nr_neg * TriangulationBufferSize > RecBoundTriang ||
3 * omp_get_max_threads() * TriangulationBufferSize >
EvalBoundTriang)))) { // go to pyramids because of triangulation
if (check_evaluation_buffer()) {
Top_Cone->evaluate_triangulation();
}
tri_recursion = true;
process_pyramids(i, false); // non-recursive
}
else { // no pyramids necessary or allowed
if (do_partial_triangulation)
process_pyramids(i, false); // non-recursive
if (do_triangulation)
extend_triangulation(i);
}
if (is_new_generator && (do_all_hyperplanes || i != last_to_be_inserted))
find_new_facets(i);
}
size_t nr_new_facets = Facets.size() - old_nr_supp_hyps;
// time(&end);
/* double dif = difftime (end,start);
if (verbose) {
verboseOutput() << "Generator took " << dif << " sec " <<endl;
}*/
//we try to find the already computed facets of the full cone
// first navigate to first new preliminary faxet
/*if(!is_pyramid){
bool a_new_one = false;
l = Facets.begin();
for (size_t j = 0; j < old_nr_supp_hyps; j++, l++);
for (size_t j = old_nr_supp_hyps ; j < Facets.size(); j++) {
bool is_final_hyp = true;
for(size_t k = 0; k < Generators.nr_of_rows(); ++k){
if(v_scalar_product(Generators[k], l->Hyp) < 0){
is_final_hyp = false;
break;
}
}
if(is_final_hyp){
FinalHyps.append(l->Hyp);
a_new_one = true;
}
l++;
}
if(verbose){
verboseOutput() << "FINAL HYPS " << FinalHyps.nr_of_rows() << endl;
verboseOutput() << "=========================" << endl;
}
if(a_new_one){
FinalHyps.print(global_project,"fin_hyps");
}
}*/
// removing the negative hyperplanes if necessary
if (do_all_hyperplanes || i != last_to_be_inserted) {
l = Facets.begin();
for (size_t j = 0; j < old_nr_supp_hyps; j++) {
if (l->negative) {
l = Facets.erase(l);
}
else
++l;
}
}
GensInCone.push_back(static_cast<key_t>(i));
nrGensInCone++;
Comparisons.push_back(nrTotalComparisons);
in_triang[i] = true;
if (verbose) {
verboseOutput() << "gen=" << i + 1 << ", ";
if (do_all_hyperplanes || i != last_to_be_inserted) {
verboseOutput() << Facets.size() << " hyp, " << nr_new_facets << " new";
}
else {
verboseOutput() << Support_Hyperplanes.nr_of_rows() << " hyp";
}
if (nrPyramids[0] > 0)
verboseOutput() << ", " << nrPyramids[0] << " pyr";
if (do_triangulation || do_partial_triangulation) {
size_t trisize;
if (pulling_triangulation)
trisize = TriangulationBuffer.size();
else
trisize = TriangulationBufferSize;
verboseOutput() << ", " << trisize << " simpl";
}
verboseOutput() << endl;
}
} // loop over i
start_from = 0; // in order that we can restart the primal algorithm again
if (is_pyramid && do_all_hyperplanes) // must give supphyps back to mother
Mother->select_supphyps_from(Facets, apex, Mother_Key, in_triang);
INTERRUPT_COMPUTATION_BY_EXCEPTION
// transfer Facets --> SupportHyperplanes
if (do_all_hyperplanes) {
nrSupport_Hyperplanes = Facets.size();
Support_Hyperplanes = Matrix<Integer>(nrSupport_Hyperplanes, 0);
auto IHV = Facets.begin();
for (size_t i = 0; i < nrSupport_Hyperplanes; ++i, ++IHV) {
if (keep_convex_hull_data)
Support_Hyperplanes[i] = IHV->Hyp;
else
swap(Support_Hyperplanes[i], IHV->Hyp);
}
setComputed(ConeProperty::SupportHyperplanes);
}
Support_Hyperplanes.set_nr_of_columns(dim);
if (do_extreme_rays && do_all_hyperplanes && !do_supphyps_dynamic)
compute_extreme_rays(true);
INTERRUPT_COMPUTATION_BY_EXCEPTION
transfer_triangulation_to_top(); // transfer remaining simplices to top
if (check_evaluation_buffer()) {
Top_Cone->evaluate_triangulation();
}
if (!keep_convex_hull_data)
Facets.clear();
/* if(!is_pyramid){
cout << "NR TESTS " << count_rank_test_small << " " << count_rank_test_large << " " << count_comp_test_small << " " <<
count_comp_test_large << endl; cout << "NR'LARGE PYRS " << count_large_pyrs << " of " << totalNrPyr << endl;
} */
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_bottom_facets() {
if (verbose)
verboseOutput() << "Computing bottom decomposition" << endl;
vector<key_t> start_simpl = Generators.max_rank_submatrix_lex();
Order_Vector = vector<Integer>(dim, 0);
for (size_t i = 0; i < dim; ++i)
for (size_t j = 0; j < dim; ++j)
Order_Vector[j] += ((unsigned long)(1 + i % 10)) * Generators[start_simpl[i]][j];
// First the generators for the recession cone = our cone
Matrix<Integer> BottomGen(0, dim + 1);
vector<Integer> help(dim + 1);
for (size_t i = 0; i < nr_gen; ++i) {
for (size_t j = 0; j < dim; ++j)
help[j] = Generators[i][j];
help[dim] = 0;
BottomGen.append(help);
}
// then the same vectors as generators of the bottom polyhedron
for (size_t i = 0; i < nr_gen; ++i) {
for (size_t j = 0; j < dim; ++j)
help[j] = Generators[i][j];
help[dim] = 1;
BottomGen.append(help);
}
Full_Cone BottomPolyhedron(BottomGen);
BottomPolyhedron.verbose = verbose;
BottomPolyhedron.do_extreme_rays = true;
BottomPolyhedron.keep_order = true;
try {
BottomPolyhedron.dualize_cone(); // includes finding extreme rays
} catch (const NonpointedException&) {
};
// transfer pointedness
assert(BottomPolyhedron.isComputed(ConeProperty::IsPointed));
pointed = BottomPolyhedron.pointed;
setComputed(ConeProperty::IsPointed);
// BottomPolyhedron.Support_Hyperplanes.pretty_print(cout);
help.resize(dim);
// find extreme rays of Bottom among the generators
vector<key_t> BottomExtRays;
for (size_t i = 0; i < nr_gen; ++i)
if (BottomPolyhedron.Extreme_Rays_Ind[i + nr_gen])
BottomExtRays.push_back(static_cast<key_t>(i));
/* vector<key_t> BottomExtRays; // can be used if the bool vector should not exist anymore
size_t start_search=0;
for(size_t i=0;i<ExtStrahl.nr_of_rows();++i){
if(BottomPolyhedron.ExtStrahl[i][dim]==1){
BottomPolyhedron.ExtStrahl[i].resize(dim);
for(size_t j=0;j<nr_gen;++j){
size_t k=(j+start_search) % nr_gen;
if(BottomPolyhedron.ExtStrahl[i]==Generators[k]){
BottomExtRays.push_back(k);
start_search++;
}
}
}
}*/
if (verbose)
verboseOutput() << "Bottom has " << BottomExtRays.size() << " extreme rays" << endl;
INTERRUPT_COMPUTATION_BY_EXCEPTION
Matrix<Integer> BottomFacets(0, dim);
vector<Integer> BottomDegs(0, static_cast<unsigned long>(dim));
if (!isComputed(ConeProperty::SupportHyperplanes)) {
Support_Hyperplanes = Matrix<Integer>(0, dim);
nrSupport_Hyperplanes = 0;
}
for (size_t i = 0; i < BottomPolyhedron.nrSupport_Hyperplanes; ++i) {
Integer test = BottomPolyhedron.Support_Hyperplanes[i][dim];
for (size_t j = 0; j < dim; ++j)
help[j] = BottomPolyhedron.Support_Hyperplanes[i][j];
if (test == 0 && !isComputed(ConeProperty::SupportHyperplanes)) {
Support_Hyperplanes.append(help);
nrSupport_Hyperplanes++;
}
if (test < 0) {
BottomFacets.append(help);
BottomDegs.push_back(-test);
}
}
setComputed(ConeProperty::SupportHyperplanes);
if (!pointed)
throw NonpointedException();
INTERRUPT_COMPUTATION_BY_EXCEPTION
vector<key_t> facet;
for (size_t i = 0; i < BottomFacets.nr_of_rows(); ++i) {
facet.clear();
for (unsigned int& BottomExtRay : BottomExtRays)
if (v_scalar_product(Generators[BottomExtRay], BottomFacets[i]) == BottomDegs[i])
facet.push_back(BottomExtRay);
Pyramids[0].push_back(facet);
nrPyramids[0]++;
}
if (verbose)
verboseOutput() << "Bottom decomposition computed, " << nrPyramids[0] << " subcones" << endl;
}
template <typename Integer>
void Full_Cone<Integer>::start_message() {
if (verbose) {
verboseOutput() << "*************************************************************" << endl;
verboseOutput() << "starting full cone computation" << endl;
}
}
//
template <typename Integer>
void Full_Cone<Integer>::end_message() {
if (verbose) {
verboseOutput() << "-------------------------------------------------------------" << endl;
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::build_cone_dynamic() {
// Generators.debug_print('*');
// Basis_Max_Subspace.debug_print('+');
// We first select elements: (i) a basis of the space generated by the Generators
// (ii) elements in the maximal subspace by evaluating equations
// (iii) elements that are for sure extreme
// (i) and (ii) are replaced by zero vectors in Generators
vector<key_t> indices_basis = Generators.max_rank_submatrix_lex();
Matrix<Integer> GensPreChoice = Generators.submatrix(indices_basis);
for(size_t i = 0; i < indices_basis.size(); ++i)
Generators[indices_basis[i]] = vector<Integer>(dim);
Matrix<Integer> EquationsMaxSubspace = Basis_Max_Subspace.kernel();
if(Basis_Max_Subspace.nr_of_rows() > 0){
for(size_t i = 0; i < Generators.nr_of_rows(); ++i){
if(EquationsMaxSubspace.MxV(Generators[i]) == vector<Integer>(EquationsMaxSubspace.nr_of_rows())){
GensPreChoice.append(Generators[i]);
Generators[i] = vector<Integer>(dim);
}
}
}
GensPreChoice.append( RationalExtremeRays);
GensPreChoice.remove_duplicate_and_zero_rows();
Generators.remove_duplicate_and_zero_rows();
// IntExtremeRays.debug_print('#');
// Gnenerators will be built incrementally
// original generators go into OrGens
Matrix<Integer> OriGens(0, dim);
swap(Generators, OriGens);
// We use float in our heuristic search for extreme rays
Matrix<nmz_float> OriGensFloat(OriGens.nr_of_rows(),dim);
convert(OriGensFloat, OriGens);
vector<nmz_float> IntHullNormFloat(dim);
convert(IntHullNormFloat, IntHullNorm);
// the float generators go into the hyperplane InHullNorm = 1
// if they aren't in a hyperplane anyway
if(IntHullNorm.size() > 0){
#pragma omp parallel for
for (size_t i = 0; i< OriGens.nr_of_rows(); ++i){
// cout << "i " << i << " -- " << OriGensFloat[i];
nmz_float norm = v_scalar_product(OriGensFloat[i], IntHullNormFloat);
v_scalar_division(OriGensFloat[i], norm);
}
}
bool first = true;
while (true) {
size_t nr_extr;
if(first){
swap(Generators,GensPreChoice);
}
else {
vector<key_t> perm;
nr_extr = OriGensFloat.extreme_points_first(verbose, perm);
OriGens.order_rows_by_perm(perm);
OriGensFloat.order_rows_by_perm(perm);
}
size_t old_nr_rows = Generators.nr_of_rows();
size_t new_nr_rows = old_nr_rows; // will be changed if !first
if(!first){
for (size_t i = 0; i < nr_extr; ++i)
Generators.append(OriGens[i]);
new_nr_rows= Generators.nr_of_rows();
for (auto& F : Facets) {
F.GenInHyp.resize(new_nr_rows);
}
in_triang.resize(new_nr_rows);
use_existing_facets = true;
start_from = old_nr_rows;
}
first = false;
keep_convex_hull_data = true;
nr_gen = new_nr_rows;
Extreme_Rays_Ind.resize(nr_gen);
build_cone();
if (verbose)
verboseOutput() << "Selecting remaining generators" << endl;
deque<bool> not_contained(OriGens.nr_of_rows(), false);
#pragma omp parallel for
for (size_t i = 0; i < OriGens.nr_of_rows(); ++i) {
if (!contains(OriGens[i]))
not_contained[i] = true;
}
vector<key_t> selection;
for (size_t i = 0; i < OriGens.nr_of_rows(); ++i) {
if (not_contained[i])
selection.push_back(static_cast<key_t>(i));
}
OriGens = OriGens.submatrix(selection);
OriGensFloat = OriGensFloat.submatrix(selection);
if (verbose)
verboseOutput() << OriGens.nr_of_rows() << " old generators remaining" << endl;
if (OriGens.nr_of_rows() == 0)
break;
}
compute_extreme_rays(true);
}
//--------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_multiplicity_or_integral_by_signed_dec() {
// assert(isComputed(ConeProperty::Triangulation));
// for(auto& T: Triangulation)
// Triangulation_ind.push_back(key_to_bitset(T.key, nr_gen));
MeasureTime(verbose, "Triangulation");
if (verbose)
verboseOutput() << "Computing by signaed decomposition" << endl;
if (verbose)
verboseOutput() << "Making hollow triangulation" << endl;
HollowTriangulation HTri(Triangulation_ind, dim, nr_gen, verbose);
size_t nr_subfacets = HTri.make_hollow_triangulation();
swap(HTri.Triangulation_ind, Triangulation_ind);
MeasureTime(verbose, "Hollow triangulation");
if (verbose)
verboseOutput() << "Size of triangulation " << Triangulation_ind.size() << endl;
if (verbose)
verboseOutput() << "Size of hollow triangulation " << nr_subfacets << endl;
vector<key_t> FirstSimplex = Generators.max_rank_submatrix_lex();
Matrix<mpz_class> Generators_mpz(nr_gen, dim);
convert(Generators_mpz, Generators);
vector<mpz_class> GradingOnPrimal_mpz;
convert(GradingOnPrimal_mpz, GradingOnPrimal);
size_t nr_attempts = 0;
vector<long> Powers10(15);
Powers10[0] = 1;
for (size_t i = 1; i < Powers10.size(); i++) {
Powers10[i] = 3 * Powers10[i - 1];
}
vector<mpz_class> add_vec;
long rand_module = 107;
vector<Integer> Dummy;
Matrix<mpz_class> CandidatesGeneric_mpz(2, dim);
Matrix<Integer> CandidatesGeneric(2, dim);
vector<mpz_class> Generic_mpz;
if (verbose)
verboseOutput() << "Trying to find geric vector" << endl;
// We exchange the roles of the generic vector v and the grading.
// This is possible since one must avoid that they span the same hyperplane
// over a subfacet of the hollow triangulation if and only if the choice of our vector
// is non-generic. This is a symmetric relation: grading generic for v <===> v generic for grading.
bool use_mpz = using_GMP<Integer>();
while (true) {
nr_attempts++;
if (nr_attempts > Powers10.size())
throw NotComputableException("SinedDec given up since generaic vector could not be found");
for (size_t k = 0; k < 2; ++k) {
for (size_t i = 0; i < dim; ++i) {
add_vec = Generators_mpz[FirstSimplex[i]];
long fact_1 = 1 + rand() % rand_module;
long fact_2 = rand() % rand_module;
mpz_class fact = convertTo<mpz_class>(fact_1);
fact *= Powers10[nr_attempts - 1];
fact += fact_2;
v_scalar_multiplication(add_vec, fact);
CandidatesGeneric_mpz[k] = v_add(CandidatesGeneric_mpz[k], add_vec);
}
}
if (!use_mpz) {
try {
convert(CandidatesGeneric, CandidatesGeneric_mpz);
} catch (const ArithmeticException& e) {
use_mpz = true;
}
}
bool found_generic = false;
if (!use_mpz) {
SignedDec<Integer> SDGen(Triangulation_ind, Generators, GradingOnPrimal, omp_start_level);
SDGen.verbose = verbose;
SDGen.CandidatesGeneric = CandidatesGeneric;
SDGen.Generic = GradingOnPrimal; // for the first round
try {
if (SDGen.FindGeneric()) { // found a generic vector
vector<Integer> Generic_Integer = SDGen.GenericComputed;
found_generic = true;
convert(Generic_mpz, Generic_Integer);
}
} catch (const ArithmeticException& e) {
if (verbose)
verboseOutput() << "******** Overflow in search for generic vector. I repeat with mpz_class. ********"
<< endl;
use_mpz = true;
}
}
if (use_mpz) {
SignedDec<mpz_class> SDGen(Triangulation_ind, Generators_mpz, GradingOnPrimal_mpz, omp_start_level);
SDGen.verbose = verbose;
SDGen.CandidatesGeneric = CandidatesGeneric_mpz;
SDGen.Generic = GradingOnPrimal_mpz; // for the first round
if (SDGen.FindGeneric()) { // found a generic vector
Generic_mpz = SDGen.GenericComputed;
found_generic = true;
}
}
if (found_generic)
break;
}
v_make_prime(Generic_mpz);
MeasureTime(verbose, "Generic");
if (block_size_hollow_tri > 0) {
string file_name = project_name + ".basic.data";
ofstream out(file_name.c_str());
out << "Project " << project_name << endl;
out << "Dim " << dim << endl << endl;
out << "Gen " << Generators_mpz.nr_of_rows() << endl;
Generators_mpz.pretty_print(out);
out << endl;
out << "Grad " << endl;
out << GradingOnPrimal_mpz << endl;
out << "Generic " << endl;
out << Generic_mpz << endl;
cout << "Generic " << endl;
cout << Generic_mpz << endl;
size_t nr_blocks = Triangulation_ind.size() / block_size_hollow_tri;
if (Triangulation_ind.size() % block_size_hollow_tri > 0)
nr_blocks++;
out << "Blocks " << nr_blocks << endl;
for (size_t i = 0; i < nr_blocks; ++i) {
size_t block_start = i * block_size_hollow_tri;
size_t block_end = block_start + block_size_hollow_tri;
if (block_end > Triangulation_ind.size())
block_end = Triangulation_ind.size();
out << i << " " << block_start << " " << block_end << endl;
}
out.close();
// Before we write the blocks, the simplices are scrambled in order to
// get more homogeneous computation times.
size_t nr_tri = Triangulation_ind.size();
for (size_t i = 0; i < nr_tri; ++i) {
size_t j = rand() % nr_tri;
size_t k = rand() % nr_tri;
std::swap(Triangulation_ind[j], Triangulation_ind[k]);
}
bool skip_remaining = false;
std::exception_ptr tmp_exception;
#pragma omp parallel for
for (size_t i = 0; i < nr_blocks; ++i) {
if (skip_remaining)
continue;
try {
size_t block_start = i * block_size_hollow_tri;
size_t block_end = block_start + block_size_hollow_tri;
if (block_end > Triangulation_ind.size())
block_end = Triangulation_ind.size();
string file_name = project_name + ".hollow_tri.";
file_name += to_string(i);
ofstream tri_out(file_name.c_str());
tri_out << "Project " << project_name << endl;
tri_out << "Block " << i << endl << endl;
for (size_t j = block_start; j < block_end; ++j) {
tri_out << Triangulation_ind[j].first << " " << Triangulation_ind[j].second << endl;
}
tri_out << "End" << endl;
tri_out.close();
string command = "gzip " + file_name;
int dummy = system(command.c_str());
if (dummy > 0)
throw NotComputableException("gzip can't be called");
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
}
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
if (verbose)
verboseOutput() << "Blocks of hollow triangulation written" << endl;
MeasureTime(verbose, "Writing blocks");
throw InterruptException("");
}
if (do_integral_by_signed_dec || do_virtual_multiplicity_by_signed_dec) {
SignedDec<mpz_class> SDInt(Triangulation_ind, Generators_mpz, GradingOnPrimal_mpz, omp_start_level);
SDInt.size_hollow_triangulation = nr_subfacets;
SDInt.verbose = verbose;
SDInt.Generic = Generic_mpz;
SDInt.Polynomial = Polynomial;
SDInt.dim = dim;
SDInt.decimal_digits = decimal_digits;
convert(SDInt.Embedding, Embedding);
if (do_integral_by_signed_dec) {
if (verbose)
verboseOutput() << "Computing integral" << endl;
if (!SDInt.ComputeIntegral(false)) // no virtual multiplicity
assert(false);
Integral = SDInt.Integral;
DegreeOfPolynomial = SDInt.DegreeOfPolynomial;
RawEuclideanIntegral = SDInt.RawEuclideanIntegral;
setComputed(ConeProperty::Integral);
}
if (do_virtual_multiplicity_by_signed_dec) {
if (verbose)
verboseOutput() << "Computing virtual multiplicity" << endl;
if (!SDInt.ComputeIntegral(true)) // with virtual multiplicity
assert(false);
VirtualMultiplicity = SDInt.VirtualMultiplicity;
DegreeOfPolynomial = SDInt.DegreeOfPolynomial;
setComputed(ConeProperty::VirtualMultiplicity);
}
}
if (!do_multiplicity_by_signed_dec)
return;
if (verbose)
verboseOutput() << "Computing multiplicity" << endl;
if (!use_mpz) {
SignedDec<Integer> SDMult(Triangulation_ind, Generators, GradingOnPrimal, omp_start_level);
SDMult.verbose = verbose;
SDMult.decimal_digits = decimal_digits;
vector<Integer> Generic;
convert(Generic, Generic_mpz);
SDMult.Generic = Generic; // for the first round
try {
if (SDMult.ComputeMultiplicity()) { // found a generic vector
multiplicity = SDMult.multiplicity;
}
else
assert(false);
} catch (const ArithmeticException& e) {
if (verbose)
verboseOutput() << "******** Overflow in computation of multiplicity. I repeat with mpz_class. ********" << endl;
use_mpz = true;
}
}
if (use_mpz) {
SignedDec<mpz_class> SDMult(Triangulation_ind, Generators_mpz, GradingOnPrimal_mpz, omp_start_level);
SDMult.verbose = verbose;
SDMult.decimal_digits = decimal_digits;
SDMult.Generic = Generic_mpz;
if (!SDMult.ComputeMultiplicity())
assert(false);
multiplicity = SDMult.multiplicity;
}
Integer corr_factorInteger = v_gcd(GradingOnPrimal); // search in code for corr_factor to find an explanation
mpz_class corr_factor = convertTo<mpz_class>(corr_factorInteger);
multiplicity *= corr_factor;
setComputed(ConeProperty::Multiplicity);
MeasureTime(verbose, "Multiplicity");
}
template <>
void Full_Cone<renf_elem_class>::compute_multiplicity_or_integral_by_signed_dec() {
assert(false);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::build_top_cone() {
primal_algorithm_initialize();
if (dim == 0)
return;
if (do_supphyps_dynamic) {
build_cone_dynamic();
return;
}
OldCandidates.verbose = verbose;
NewCandidates.verbose = verbose;
if ((!do_bottom_dec || deg1_generated || dim == 1 || (!do_triangulation && !do_partial_triangulation))) {
build_cone();
}
else {
find_bottom_facets();
start_from = nr_gen;
deg1_triangulation = false;
vector<list<vector<key_t>>::iterator> level0_order;
level0_order.reserve(nrPyramids[0]);
auto p = Pyramids[0].begin();
for (size_t k = 0; k < nrPyramids[0]; ++k, ++p) {
level0_order.push_back(p);
}
for (size_t k = 0; k < 5 * nrPyramids[0]; ++k) {
swap(level0_order[rand() % nrPyramids[0]], level0_order[rand() % nrPyramids[0]]);
}
list<vector<key_t>> new_order;
for (size_t k = 0; k < nrPyramids[0]; ++k) {
new_order.push_back(*level0_order[k]);
}
Pyramids[0].clear();
Pyramids[0].splice(Pyramids[0].begin(), new_order);
}
// try_offload(0); // superfluous since tried immediately in evaluate_stored_pyramids(0)
evaluate_stored_pyramids(0); // force evaluation of remaining pyramids
#ifdef NMZ_MIC_OFFLOAD
if (_Offload_get_device_number() < 0) // dynamic check for being on CPU (-1)
{
evaluate_stored_pyramids(0); // previous run could have left over pyramids
mic_offloader.evaluate_triangulation();
}
#endif // NMZ_MIC_OFFLOAD
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::check_evaluation_buffer() {
return (omp_get_level() == omp_start_level && check_evaluation_buffer_size());
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::check_evaluation_buffer_size() {
return (!Top_Cone->keep_triangulation && Top_Cone->TriangulationBufferSize > EvalBoundTriang);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::transfer_triangulation_to_top() {
size_t i;
// cout << "Pyr level " << pyr_level << endl;
if (!is_pyramid) { // we are in top cone
if (check_evaluation_buffer()) {
evaluate_triangulation();
}
return; // no transfer necessary
}
// now we are in a pyramid
// cout << "In pyramid " << endl;
int tn = 0;
if (omp_in_parallel())
tn = omp_get_ancestor_thread_num(omp_start_level + 1);
auto pyr_simp = TriangulationBuffer.begin();
while (pyr_simp != TriangulationBuffer.end()) {
if (pyr_simp->height == 0) { // it was marked to be skipped
Top_Cone->FS[tn].splice(Top_Cone->FS[tn].end(), TriangulationBuffer, pyr_simp++);
--TriangulationBufferSize;
}
else {
for (i = 0; i < dim; i++) // adjust key to topcone generators
pyr_simp->key[i] = Top_Key[pyr_simp->key[i]];
sort(pyr_simp->key.begin(), pyr_simp->key.end());
++pyr_simp;
}
}
// cout << "Keys transferred " << endl;
#pragma omp critical(TRIANG)
{
Top_Cone->TriangulationBuffer.splice(Top_Cone->TriangulationBuffer.end(), TriangulationBuffer);
Top_Cone->TriangulationBufferSize += TriangulationBufferSize;
}
TriangulationBufferSize = 0;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::get_supphyps_from_copy(bool from_scratch, bool with_extreme_rays) {
if (isComputed(ConeProperty::SupportHyperplanes)) { // we have them already
if (with_extreme_rays)
compute_extreme_rays();
return;
}
Full_Cone copy((*this).Generators);
copy.verbose = verbose;
if (!from_scratch) {
copy.start_from = start_from;
copy.use_existing_facets = true;
copy.keep_order = true;
copy.HypCounter = HypCounter;
copy.Extreme_Rays_Ind = Extreme_Rays_Ind;
copy.in_triang = in_triang;
copy.old_nr_supp_hyps = old_nr_supp_hyps;
if (isComputed(ConeProperty::ExtremeRays)) {
copy.setComputed(ConeProperty::ExtremeRays);
with_extreme_rays = false;
}
copy.GensInCone = GensInCone;
copy.nrGensInCone = nrGensInCone;
copy.Comparisons = Comparisons;
if (!Comparisons.empty())
copy.nrTotalComparisons = Comparisons[Comparisons.size() - 1];
typename list<FACETDATA<Integer>>::const_iterator l = Facets.begin();
for (size_t i = 0; i < old_nr_supp_hyps; ++i) {
copy.Facets.push_back(*l);
++l;
}
}
copy.dualize_cone();
if (with_extreme_rays) {
copy.do_extreme_rays = true;
copy.compute();
Extreme_Rays_Ind = copy.Extreme_Rays_Ind;
setComputed(ConeProperty::ExtremeRays);
}
std::swap(Support_Hyperplanes, copy.Support_Hyperplanes);
nrSupport_Hyperplanes = copy.nrSupport_Hyperplanes;
setComputed(ConeProperty::SupportHyperplanes);
do_all_hyperplanes = false;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::update_reducers(bool forced) {
if ((!do_Hilbert_basis || do_module_gens_intcl) && !forced)
return;
if (NewCandidates.Candidates.empty())
return;
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (hilbert_basis_rec_cone_known) {
NewCandidates.sort_by_deg();
NewCandidates.reduce_by(HBRC);
ModuleGensDepot.merge(NewCandidates);
return;
}
if (nr_gen == dim) // no global reduction in the simplicial case
NewCandidates.sort_by_deg();
if (nr_gen != dim || forced) { // global reduction in the nonsimplicial case (or forced)
NewCandidates.auto_reduce();
if (verbose) {
verboseOutput() << "reducing " << OldCandidates.Candidates.size() << " candidates by "
<< NewCandidates.Candidates.size() << " reducers" << endl;
}
OldCandidates.reduce_by(NewCandidates);
}
OldCandidates.merge(NewCandidates);
CandidatesSize = OldCandidates.Candidates.size();
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::prepare_old_candidates_and_support_hyperplanes() {
if (!isComputed(ConeProperty::SupportHyperplanes)) {
if (verbose) {
verboseOutput() << "**** Computing support hyperplanes for reduction:" << endl;
}
get_supphyps_from_copy(false);
}
check_pointed();
if (!pointed) {
throw NonpointedException();
}
int max_threads = omp_get_max_threads();
size_t Memory_per_gen = 8 * nrSupport_Hyperplanes;
size_t max_nr_gen = RAM_Size / (Memory_per_gen * max_threads);
// cout << "max_nr_gen " << max_nr_gen << endl;
AdjustedReductionBound = max_nr_gen;
if (AdjustedReductionBound < 2000)
AdjustedReductionBound = 2000;
Sorting = compute_degree_function();
bool save_do_module_gens_intcl = do_module_gens_intcl;
do_module_gens_intcl = false; // to avoid multiplying sort_deg by 2 for the original generators
// sort_deg of new candiadtes will be multiplied by 2
// so that all old candidates are tested for reducibility
for (size_t i = 0; i < nr_gen; i++) {
// cout << gen_levels[i] << " ** " << Generators[i];
if (!inhomogeneous || gen_levels[i] == 0 || (!save_do_module_gens_intcl && gen_levels[i] <= 1)) {
OldCandidates.Candidates.push_back(Candidate<Integer>(Generators[i], *this));
OldCandidates.Candidates.back().original_generator = true;
}
}
for (size_t i = 0; i < HilbertBasisRecCone.nr_of_rows(); ++i) {
HBRC.Candidates.push_back(Candidate<Integer>(HilbertBasisRecCone[i], *this));
}
do_module_gens_intcl = save_do_module_gens_intcl; // restore
if (HilbertBasisRecCone.nr_of_rows() > 0) { // early enough to avoid multiplictaion of sort_deg by 2 for the elements
// in HilbertBasisRecCone
hilbert_basis_rec_cone_known = true;
HBRC.sort_by_deg();
}
if (!do_module_gens_intcl) // if do_module_gens_intcl we don't want to change the original monoid
OldCandidates.auto_reduce();
else
OldCandidates.sort_by_deg();
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::evaluate_triangulation() {
// prepare reduction
if (do_Hilbert_basis && OldCandidates.Candidates.empty()) {
prepare_old_candidates_and_support_hyperplanes();
}
if (TriangulationBufferSize == 0)
return;
assert(omp_get_level() == omp_start_level);
if (pulling_triangulation)
TriangulationBufferSize = TriangulationBuffer.size(); // the bookkeeping does not work in this case
const long VERBOSE_STEPS = 50;
long step_x_size = TriangulationBufferSize - VERBOSE_STEPS;
if (verbose) {
verboseOutput() << "evaluating " << TriangulationBufferSize << " simplices" << endl;
/* verboseOutput() << "---------+---------+---------+---------+---------+"
<< " (one | per 2%)" << endl;*/
}
totalNrSimplices += TriangulationBufferSize;
if (do_Stanley_dec || keep_triangulation) { // in these cases sorting is necessary
for (auto& simp : TriangulationBuffer)
sort(simp.key.begin(), simp.key.end());
}
if (do_evaluation && !do_only_multiplicity) {
deque<bool> done(TriangulationBufferSize, false);
bool skip_remaining;
std::exception_ptr tmp_exception;
do { // allows multiple run of loop below in case of interruption for the update of reducers
skip_remaining = false;
step_x_size = TriangulationBufferSize - VERBOSE_STEPS;
#pragma omp parallel
{
auto s = TriangulationBuffer.begin();
size_t spos = 0;
int tn = omp_get_thread_num();
#pragma omp for schedule(dynamic) nowait
for (size_t i = 0; i < TriangulationBufferSize; i++) {
try {
if (skip_remaining)
continue;
for (; i > spos; ++spos, ++s)
;
for (; i < spos; --spos, --s)
;
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (done[spos])
continue;
done[spos] = true;
/* if(keep_triangulation || do_Stanley_dec) -- now done above
sort(s->key.begin(),s->key.end()); */
if (!SimplexEval[tn].evaluate(*s)) {
#pragma omp critical(LARGESIMPLEX)
LargeSimplices.push_back(SimplexEval[tn]);
}
if (verbose) {
#pragma omp critical(VERBOSE)
while ((long)(i * VERBOSE_STEPS) >= step_x_size) {
step_x_size += TriangulationBufferSize;
verboseOutput() << "|" << flush;
}
}
if (do_Hilbert_basis && Results[tn].get_collected_elements_size() > AdjustedReductionBound)
skip_remaining = true;
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
}
Results[tn].transfer_candidates();
} // end parallel
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
if (verbose)
verboseOutput() << endl;
update_reducers();
} while (skip_remaining);
} // do_evaluation
if (verbose) {
size_t tot_nr_simpl;
if (pulling_triangulation)
tot_nr_simpl = TriangulationBuffer.size();
else
tot_nr_simpl = totalNrSimplices;
verboseOutput() << tot_nr_simpl << " simplices";
if (do_Hilbert_basis)
verboseOutput() << ", " << CandidatesSize << " HB candidates";
if (do_deg1_elements)
verboseOutput() << ", " << CandidatesSize << " deg1 vectors";
verboseOutput() << " accumulated." << endl;
}
if (keep_triangulation_bitsets) {
for (auto& T : TriangulationBuffer)
Triangulation_ind.push_back(make_pair(key_to_bitset(T.key, nr_gen), dynamic_bitset()));
}
if (keep_triangulation) {
Triangulation.splice(Triangulation.end(), TriangulationBuffer);
}
else {
// #pragma omp critical(FREESIMPL)
FreeSimpl.splice(FreeSimpl.begin(), TriangulationBuffer);
}
TriangulationBufferSize = 0;
if (verbose && allow_simplex_dec) {
size_t lss = LargeSimplices.size();
if (lss > 0)
verboseOutput() << lss << " large simplices stored" << endl;
}
for (size_t i = 0; i < Results.size(); ++i)
Results[i].transfer_candidates(); // any remaining ones
update_reducers();
}
#ifdef ENFNORMALIZ
template <>
void Full_Cone<renf_elem_class>::evaluate_triangulation() {
assert(omp_get_level() == 0);
if (TriangulationBufferSize == 0)
return;
if (pulling_triangulation)
TriangulationBufferSize = TriangulationBuffer.size(); // the bookkeeping does not work in this case
totalNrSimplices += TriangulationBufferSize;
if (do_determinants) {
bool dummy;
bool skip_remaining = false;
std::exception_ptr tmp_exception;
long nr_simplices_done = 0;
#pragma omp parallel
{
Matrix<renf_elem_class> work;
auto t = TriangulationBuffer.begin();
size_t spos = 0;
#pragma omp for
for (size_t i = 0; i < TriangulationBufferSize; i++) {
try {
if (skip_remaining)
continue;
for (; i > spos; ++spos, ++t)
;
for (; i < spos; --spos, --t)
;
INTERRUPT_COMPUTATION_BY_EXCEPTION
work = Generators.submatrix(t->key);
work.row_echelon_inner_elem(dummy);
t->vol = 1;
for (size_t i = 0; i < dim; ++i)
t->vol *= work[i][i];
t->vol = Iabs(t->vol);
t->mult = t->vol;
#pragma omp atomic
TotDet++;
if (do_multiplicity) {
renf_elem_class deg_prod = 1;
for (size_t j = 0; j < dim; ++j) {
deg_prod *= gen_degrees[t->key[j]];
/* if(Truncation.size()>0){
renf_elem_class test=v_scalar_product(Generators[t->key[j]],Truncation);
assert(gen_degrees[t->key[j]]==test);
}*/
}
t->mult /= deg_prod;
}
#pragma omp atomic
nr_simplices_done++;
if (verbose && nr_simplices_done % 100 == 0) {
#pragma omp critical(PROGRESS)
verboseOutput() << nr_simplices_done << " simplices done" << endl;
}
} catch (const std::exception&) {
tmp_exception = std::current_exception();
skip_remaining = true;
#pragma omp flush(skip_remaining)
}
} // for
} // parallel
if (!(tmp_exception == 0))
std::rethrow_exception(tmp_exception);
auto t = TriangulationBuffer.begin();
for (; t != TriangulationBuffer.end(); ++t) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
// t->vol=Generators.submatrix(t->key).vol();
detSum += t->vol;
if (do_multiplicity) {
renf_multiplicity += t->mult;
}
}
}
if (keep_triangulation) {
Triangulation.splice(Triangulation.end(), TriangulationBuffer);
}
else {
// #pragma omp critical(FREESIMPL)
FreeSimpl.splice(FreeSimpl.begin(), TriangulationBuffer);
}
TriangulationBufferSize = 0;
}
#endif
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::evaluate_large_simplices() {
size_t lss = LargeSimplices.size();
if (lss == 0)
return;
assert(omp_get_level() == omp_start_level);
if (verbose) {
verboseOutput() << "Evaluating " << lss << " large simplices" << endl;
}
size_t j;
for (j = 0; j < lss; ++j) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
evaluate_large_simplex(j, lss);
}
// decomposition might have created new simplices -- NO LONGER, now in Pyramids[0]
// evaluate_triangulation();
// also new large simplices are possible
/* if (!LargeSimplices.empty()) {
allow_simplex_dec = false;
lss += LargeSimplices.size();
if (verbose) {
verboseOutput() << "Continue evaluation of " << lss << " large simplices without new decompositions of simplicial
cones." << endl;
}
for (; j < lss; ++j) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
evaluate_large_simplex(j, lss);
}
}*/
assert(LargeSimplices.empty());
for (size_t i = 0; i < Results.size(); ++i)
Results[i].transfer_candidates(); // any remaining ones
update_reducers();
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::evaluate_large_simplex(size_t j, size_t lss) {
if (verbose) {
verboseOutput() << "Large simplex " << j + 1 << " / " << lss << endl;
}
if (do_deg1_elements && !do_h_vector && !do_Stanley_dec && !deg1_triangulation) {
compute_deg1_elements_via_projection_simplicial(LargeSimplices.front().get_key());
// one could think abot a condition in terms of the degrees of the generators -- deg1triangulation is a little coarse
}
else {
LargeSimplices.front().Simplex_parallel_evaluation();
if (do_Hilbert_basis && Results[0].get_collected_elements_size() > AdjustedReductionBound) {
Results[0].transfer_candidates();
update_reducers();
}
}
LargeSimplices.pop_front();
}
#ifdef ENFNORMALIZ
template <>
void Full_Cone<renf_elem_class>::evaluate_large_simplex(size_t j, size_t lss) {
assert(false);
}
#endif
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_deg1_elements_via_projection_simplicial(const vector<key_t>& key) {
assert(!is_global_approximation); // allowed since we do not come here if deg1_triangulation
Matrix<Integer> Gens = Generators.submatrix(key);
Sublattice_Representation<Integer> NewCoordinates = LLL_coordinates<Integer, Integer>(Gens);
Matrix<Integer> Gred = NewCoordinates.to_sublattice(Gens);
vector<Integer> GradT = NewCoordinates.to_sublattice_dual(Grading);
Cone<Integer> ProjCone(Type::cone, Gred, Type::grading, Matrix<Integer>(GradT));
ConeProperties ForDeg1;
ForDeg1.set(ConeProperty::Projection);
ForDeg1.set(ConeProperty::NoLLL);
if (using_GMP<Integer>())
ForDeg1.set(ConeProperty::BigInt);
ForDeg1.set(ConeProperty::Deg1Elements);
ProjCone.setVerbose(verbose);
ProjCone.compute(ForDeg1);
/*if(using_GMP<Integer>())
ProjCone.compute(ConeProperty::Projection,ConeProperty::NoLLL,ConeProperty::BigInt,);
else
ProjCone.compute(ConeProperty::Projection,ConeProperty::NoLLL);*/
Matrix<Integer> Deg1 = ProjCone.getDeg1ElementsMatrix();
Deg1 = NewCoordinates.from_sublattice(Deg1); // back to the coordinates of the full cone
Matrix<Integer> Supp = ProjCone.getSupportHyperplanesMatrix();
Supp = NewCoordinates.from_sublattice_dual(Supp);
/*for(size_t i=0;i<dim;++i)
for(size_t j=0;j<dim;++j)
assert(v_scalar_product(Supp[i],Gens[j])>=0); */
vector<bool> Excluded(dim, false); // we want to discard duplicates
for (size_t i = 0; i < dim; ++i) { // first we find the excluded facets of our simplicial cone
Integer test = v_scalar_product(Supp[i], Order_Vector);
if (test > 0)
continue;
if (test < 0) {
Excluded[i] = true;
continue;
}
size_t j;
for (j = 0; j < dim; ++j) {
if (Supp[i][j] != 0)
break;
}
if (Supp[i][j] < 0)
Excluded[i] = true;
}
for (const auto& E : Deg1.get_elements()) { // Now the duplicates are excluded
size_t i;
for (i = 0; i < dim; ++i)
if (v_scalar_product(E, Supp[i]) == 0 && Excluded[i])
break;
if (i < dim) // E lies in an excluded facet
continue;
// if(is_global_approximation && !subcone_contains(E)) // not contained in approximated cone
// continue; // CANNOT HAPPEN SINCE ONLY USED IF !deg1_triangulation. See assert above
for (i = 0; i < dim; ++i) // exclude original generators -- will come in later
if (E == Gens[i])
break;
if (i == dim) {
Results[0].Deg1_Elements.push_back(E);
Results[0].collected_elements_size++;
}
}
Results[0].transfer_candidates();
}
#ifdef ENFNORMALIZ
template <>
void Full_Cone<renf_elem_class>::compute_deg1_elements_via_projection_simplicial(const vector<key_t>& key) {
assert(false);
}
#endif
//---------------------------------------------------------------------------
/*
template <typename Integer>
void Full_Cone<Integer>::remove_duplicate_ori_gens_from_HB() {
return; // TODO reactivate!
Generators.max_rank_submatrix_lex().size()
set<vector<Integer>> OriGens;
for (auto c = OldCandidates.Candidates.begin(); c != OldCandidates.Candidates.end();) {
if (!c->original_generator) {
++c;
continue;
}
auto found = OriGens.find(c->cand);
if (found != OriGens.end()) {
c = OldCandidates.Candidates.erase(c);
}
else {
if (c->original_generator)
OriGens.insert(c->cand);
++c;
}
}
}
*/
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::primal_algorithm() {
if (!(do_deg1_elements || do_Hilbert_basis || do_h_vector || do_multiplicity || do_determinants || do_triangulation_size ||
do_signed_dec || do_pure_triang))
return;
// primal_algorithm_initialize();
/***** Main Work is done in build_top_cone() *****/
build_top_cone(); // evaluates if keep_triangulation==false
/***** Main Work is done in build_top_cone() *****/
check_pointed();
if (!pointed) {
throw NonpointedException();
}
primal_algorithm_finalize();
primal_algorithm_set_computed();
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::set_primal_algorithm_control_variables() {
do_triangulation = false;
do_partial_triangulation = false;
// stop_after_cone_dec = false;
do_evaluation = false;
triangulation_is_nested = false;
triangulation_is_partial = false;
if (do_multiplicity)
do_determinants = true;
if (do_determinants)
do_triangulation = true;
if (do_pure_triang)
do_triangulation = true;
if (do_triangulation_size)
do_triangulation = true;
if (do_h_vector)
do_triangulation = true;
if (do_deg1_elements)
do_partial_triangulation = true;
if (do_Hilbert_basis)
do_partial_triangulation = true;
// activate
do_only_multiplicity = do_determinants || do_multiplicity;
stop_after_cone_dec = true;
if (do_cone_dec)
do_only_multiplicity = false;
if (do_Stanley_dec || do_h_vector || do_deg1_elements || do_Hilbert_basis) {
do_only_multiplicity = false;
stop_after_cone_dec = false;
do_evaluation = true;
}
if (do_determinants)
do_evaluation = true;
if (pulling_triangulation) {
no_subdivision = true; // see below
do_triangulation = true;
do_only_multiplicity = false;
}
// deactivate
if (do_triangulation)
do_partial_triangulation = false;
// no_subdision blocks simplex decomposaition
if(no_subdivision){
allow_simplex_dec = false;
}
assert(!(do_evaluation && do_pure_triang));
// cout << "DOM " << do_only_multiplicity << " Tri " << do_triangulation << " Wit " << do_integrally_closed << endl;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::primal_algorithm_initialize() {
set_primal_algorithm_control_variables();
if (verbose) {
verboseOutput() << "Starting primal algorithm ";
if (do_partial_triangulation)
verboseOutput() << "with partial triangulation ";
if (do_triangulation)
verboseOutput() << "with full triangulation ";
if (!do_triangulation && !do_partial_triangulation)
verboseOutput() << "(only support hyperplanes) ";
verboseOutput() << "..." << endl;
}
prepare_inclusion_exclusion();
SimplexEval = vector<SimplexEvaluator<Integer>>(omp_get_max_threads(), SimplexEvaluator<Integer>(*this));
for (int i = 0; i < SimplexEval.size(); ++i)
SimplexEval[i].set_evaluator_tn(i);
Results = vector<Collector<Integer>>(omp_get_max_threads(), Collector<Integer>(*this));
Hilbert_Series.setVerbose(verbose);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::primal_algorithm_finalize() {
if (isComputed(ConeProperty::Grading) && !deg1_generated) {
deg1_triangulation = false;
}
if (keep_triangulation) {
setComputed(ConeProperty::Triangulation);
if (pulling_triangulation)
setComputed(ConeProperty::PullingTriangulation);
}
if (do_cone_dec) {
setComputed(ConeProperty::ConeDecomposition);
}
evaluate_triangulation();
assert(nrPyramids[0] == 0);
evaluate_large_simplices(); // can produce level 0 pyramids
allow_simplex_dec = false; // block new attempts for subdivision
evaluate_stored_pyramids(0); // in case subdivision took place
evaluate_triangulation();
FreeSimpl.clear();
// collect accumulated data from the SimplexEvaluators
for (int zi = 0; zi < omp_get_max_threads(); zi++) {
detSum += Results[zi].getDetSum();
multiplicity += Results[zi].getMultiplicitySum();
if (do_h_vector) {
Hilbert_Series += Results[zi].getHilbertSeriesSum();
}
}
#ifdef NMZ_MIC_OFFLOAD
// collect accumulated data from mics
if (_Offload_get_device_number() < 0) // dynamic check for being on CPU (-1)
{
mic_offloader.finalize();
}
#endif // NMZ_MIC_OFFLOAD
if (do_h_vector) {
Hilbert_Series.collectData();
}
if (verbose) {
verboseOutput() << "Total number of pyramids = " << totalNrPyr << ", among them simplicial " << nrSimplicialPyr << endl;
// cout << "Uni "<< Unimod << " Ht1NonUni " << Ht1NonUni << " NonDecided " << NonDecided << " TotNonDec " <<
// NonDecidedHyp<< endl;
if (do_only_multiplicity)
verboseOutput() << "Determinants computed = " << TotDet << endl;
/* if(NrCompVect>0)
cout << "Vector comparisons " << NrCompVect << " Value comparisons " << NrCompVal
<< " Average " << NrCompVal/NrCompVect+1 << endl; */
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::make_module_gens() {
if (!inhomogeneous) {
NewCandidates.extract(ModuleGeneratorsOverOriginalMonoid);
vector<Integer> Zero(dim, 0);
ModuleGeneratorsOverOriginalMonoid.push_front(Zero);
// cout << "Mod " << endl;
// Matrix<Integer>(ModuleGeneratorsOverOriginalMonoid).pretty_print(cout);
// cout << "--------" << endl;
setComputed(ConeProperty::ModuleGeneratorsOverOriginalMonoid, true);
return;
}
CandidateList<Integer> Level1OriGens;
for (size_t i = 0; i < nr_gen; ++i) {
if (gen_levels[i] == 1) {
Level1OriGens.push_back(Candidate<Integer>(Generators[i], *this));
}
}
CandidateList<Integer> Level1Generators = Level1OriGens;
Candidate<Integer> new_cand(dim, Support_Hyperplanes.nr_of_rows());
for (const auto& lnew : NewCandidates.Candidates) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
Integer level = v_scalar_product(lnew.cand, Truncation);
if (level == 1) {
new_cand = lnew;
Level1Generators.reduce_by_and_insert(new_cand, OldCandidates);
}
else {
for (const auto& l1 : Level1OriGens.Candidates) {
new_cand = sum(l1, lnew);
Level1Generators.reduce_by_and_insert(new_cand, OldCandidates);
}
}
}
Level1Generators.extract(ModuleGeneratorsOverOriginalMonoid);
ModuleGeneratorsOverOriginalMonoid.sort();
ModuleGeneratorsOverOriginalMonoid.unique();
setComputed(ConeProperty::ModuleGeneratorsOverOriginalMonoid, true);
for (size_t i = 0; i < nr_gen; i++) { // the level 1 input generators have not yet ben inserted into OldCandidates
if (gen_levels[i] == 1) { // but they are needed for the truncated Hilbert basis com?putation
NewCandidates.Candidates.push_back(Candidate<Integer>(Generators[i], *this));
NewCandidates.Candidates.back().original_generator = true;
}
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::reset_degrees_and_merge_new_candidates() {
make_module_gens();
NewCandidates.divide_sortdeg_by2(); // was previously multiplied by 2
NewCandidates.sort_by_deg();
OldCandidates.merge(NewCandidates);
OldCandidates.auto_reduce();
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::finish_Hilbert_series() {
if (do_h_vector) {
Hilbert_Series.setShift(convertToLong(shift));
Hilbert_Series.adjustShift();
// now the shift in the HilbertSeries may change and we would have to adjust
// the shift, the grading and more in the Full_Cone to continue to add data!
// COMPUTE HSOP here
if (do_hsop) {
compute_hsop();
setComputed(ConeProperty::HSOP);
}
Hilbert_Series.simplify();
setComputed(ConeProperty::HilbertSeries);
}
}
template <>
void Full_Cone<renf_elem_class>::finish_Hilbert_series() {
assert(false);
}
template <typename Integer>
void Full_Cone<Integer>::primal_algorithm_set_computed() {
extreme_rays_and_deg1_check();
if (!pointed) {
throw NonpointedException();
}
if (do_triangulation || do_partial_triangulation) {
setComputed(ConeProperty::TriangulationSize, true);
if (do_evaluation) {
setComputed(ConeProperty::TriangulationDetSum);
}
}
if ((do_triangulation && do_evaluation && isComputed(ConeProperty::Grading)) || (do_multiplicity && using_renf<Integer>()))
setComputed(ConeProperty::Multiplicity);
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (do_Hilbert_basis) {
if (hilbert_basis_rec_cone_known) {
// OldCandidates.Candidates.clear();
OldCandidates.merge(HBRC);
OldCandidates.merge(ModuleGensDepot);
}
if (do_module_gens_intcl) {
reset_degrees_and_merge_new_candidates();
}
else {
OldCandidates.sort_by_val();
}
OldCandidates.extract(Hilbert_Basis);
OldCandidates.Candidates.clear();
Hilbert_Basis.unique();
setComputed(ConeProperty::HilbertBasis, true);
}
if (isComputed(ConeProperty::Grading) && isComputed(ConeProperty::HilbertBasis)
&& !isComputed(ConeProperty::Deg1Elements)) {
select_deg1_elements();
check_deg1_hilbert_basis();
}
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (do_deg1_elements) {
for (size_t i = 0; i < nr_gen; i++)
if (v_scalar_product(Grading, Generators[i]) == 1 && (!is_global_approximation || subcone_contains(Generators[i])))
Deg1_Elements.push_front(Generators[i]);
setComputed(ConeProperty::Deg1Elements, true);
Deg1_Elements.sort();
Deg1_Elements.unique();
}
INTERRUPT_COMPUTATION_BY_EXCEPTION
if (do_h_vector)
finish_Hilbert_series();
if (do_Stanley_dec) {
setComputed(ConeProperty::StanleyDec);
}
// If the grading has gcd > 1 on the recession monoid,
// we must multiply the multiplicity by it.
// Without this correction, the multiplicity (relative to deg/g)
// is divided by g^r, but it must be g^{r-1}.
// We determine g and multiply by it.
//
// The reason behind this correction is that the determinants
// are computed with respect to a basis in which the
// basic simplex has volume 1/g instead of 1.
// The correction above takes care of this "mistake"
// that we are forced to make in order to keep data integral.
if (isComputed(ConeProperty::Multiplicity)) {
Integer corr_factor;
if (!inhomogeneous)
corr_factor = v_gcd(Grading);
if (inhomogeneous && level0_dim == 0)
corr_factor = 1;
if (inhomogeneous && level0_dim > 0) {
Matrix<Integer> Level0Space = ProjToLevel0Quot.kernel();
corr_factor = 0;
for (size_t i = 0; i < Level0Space.nr_of_rows(); ++i)
corr_factor = libnormaliz::gcd(corr_factor, v_scalar_product(Grading, Level0Space[i]));
}
multiplicity *= convertTo<mpz_class>(corr_factor);
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::set_degrees() {
// Generators.pretty_print(cout);
// cout << "Grading " << Grading;
if (gen_degrees.size() != nr_gen && isComputed(ConeProperty::Grading)) // now we set the degrees
{
gen_degrees.resize(nr_gen);
if (do_h_vector || (!using_GMP<Integer>() && !using_renf<Integer>()))
gen_degrees_long.resize(nr_gen);
gen_degrees = Generators.MxV(Grading);
for (size_t i = 0; i < nr_gen; i++) {
if (gen_degrees[i] <= 0) {
throw BadInputException("Grading gives non-positive value " + toString(gen_degrees[i]) + " for generator " +
toString(i + 1) + ".");
}
if (do_h_vector || (!using_GMP<Integer>() && !using_renf<Integer>()))
convert(gen_degrees_long[i], gen_degrees[i]);
}
}
}
#ifdef ENFNORMALIZ
template <>
void Full_Cone<renf_elem_class>::set_degrees() {
if (!isComputed(ConeProperty::Grading) && !inhomogeneous)
return;
vector<renf_elem_class> GradHelp = Grading;
if (inhomogeneous)
GradHelp = Truncation;
gen_degrees = Generators.MxV(GradHelp);
for (size_t i = 0; i < Generators.nr_of_rows(); ++i)
if (gen_degrees[i] <= 0 && (do_multiplicity || do_automorphisms))
throw BadInputException("Volume or automorphism group not computable for unbounded nalgebraic polyhedra");
}
#endif
//---------------------------------------------------------------------------
// Normaliz modes (public)
//---------------------------------------------------------------------------
// check the do_* bools, they must be set in advance
// this method (de)activates them according to dependencies between them
template <typename Integer>
void Full_Cone<Integer>::set_preconditions() {
do_extreme_rays = true; // we always want to do this if compute() is called
/* if (do_default_mode && with_default) {
do_Hilbert_basis = true;
do_h_vector = true;
if(!inhomogeneous)
do_class_group=true;
}
*/
if (do_integrally_closed) {
if (do_Hilbert_basis) {
do_integrally_closed = false; // don't interrupt the computation
}
else {
do_Hilbert_basis = true;
}
}
// activate implications
if (do_module_gens_intcl)
do_Hilbert_basis = true;
if (do_module_gens_intcl)
allow_simplex_dec = false; // extra bottom points change the originalmonoid
if (do_Stanley_dec)
keep_triangulation = true;
if (do_pure_triang)
keep_triangulation = true;
if (pulling_triangulation) {
keep_triangulation = true;
keep_order = true;
}
if (do_cone_dec)
keep_triangulation = true;
if (keep_triangulation)
do_determinants = true;
do_signed_dec = do_multiplicity_by_signed_dec || do_integral_by_signed_dec || do_virtual_multiplicity_by_signed_dec;
if (include_dualization)
assert(do_signed_dec);
if (do_signed_dec) {
keep_triangulation_bitsets = true;
keep_order = true; // ???
do_pure_triang = true;
if (!include_dualization) {
do_all_hyperplanes = false;
do_extreme_rays = false;
believe_pointed = true;
}
}
if (keep_order)
suppress_bottom_dec = true;
// if (do_multiplicity) do_determinants = true; // removed because of automorphisms
if ((do_multiplicity || do_h_vector) && inhomogeneous)
do_module_rank = true;
if (do_Hilbert_basis)
do_deg1_elements = false; // after the Hilbert basis computation, deg 1 elements will be extracted
if (keep_convex_hull_data)
suppress_bottom_dec = true;
// to exclude descent to facets in the exploitation of automorphism groups: we must use the primal algorithm directly
no_descent_to_facets = do_h_vector || do_module_gens_intcl || keep_triangulation || do_triangulation_size || do_Stanley_dec ||
do_cone_dec || do_determinants || do_excluded_faces || do_bottom_dec;
do_only_supp_hyps_and_aux =
!do_pure_triang && !no_descent_to_facets && !do_multiplicity && !do_deg1_elements && !do_Hilbert_basis && !do_signed_dec;
}
// We set the do* variables to false if the corresponding task has been done
template <typename Integer>
void Full_Cone<Integer>::deactivate_completed_tasks() {
if (isComputed(ConeProperty::IsPointed))
do_pointed = false;
if (isComputed(ConeProperty::ExtremeRays))
do_extreme_rays = false;
if (isComputed(ConeProperty::HilbertBasis)) {
do_Hilbert_basis = false;
do_integrally_closed = false;
}
if (isComputed(ConeProperty::Deg1Elements))
do_deg1_elements = false;
if (isComputed(ConeProperty::ModuleGeneratorsOverOriginalMonoid))
do_module_gens_intcl = false;
if (isComputed(ConeProperty::HilbertSeries))
do_h_vector = false;
if (isComputed(ConeProperty::Multiplicity))
do_multiplicity = false;
if (isComputed(ConeProperty::StanleyDec))
do_Stanley_dec = false;
if (isComputed(ConeProperty::ConeDecomposition))
do_cone_dec = false;
if (isComputed(ConeProperty::Triangulation))
keep_triangulation = false;
if (isComputed(ConeProperty::TriangulationDetSum))
do_determinants = false;
if (isComputed(ConeProperty::ModuleRank))
do_module_rank = false;
if (isComputed(ConeProperty::ClassGroup))
do_class_group = false;
}
//---------------------------------------------------------------------------
// do computations using automorphisms
// Niote: exploit_automs_mult is ALWAYS false at present. Done via descent and ExploitIsosMult
template <typename Integer>
void Full_Cone<Integer>::compute_by_automorphisms() {
if ((!exploit_automs_mult && !exploit_automs_vectors) || no_descent_to_facets)
return;
if (descent_level == 0) {
if (do_Hilbert_basis) {
for (size_t i = 0; i < nr_gen; ++i)
Generator_Set.insert(Generators[i]);
}
if (autom_codim_vectors < 0) // set default values if not set by Cone
autom_codim_vectors = 1;
/* if (autom_codim_mult < 0)
autom_codim_mult = min((int)dim / 4, 6);*/
}
/*
if (exploit_automs_mult && do_multiplicity) {
if (descent_level < autom_codim_mult && nr_gen >= dim + 4) { // otherwise direct computation
if (inhomogeneous)
compute_multiplicity_via_recession_cone();
else
compute_multiplicity_via_automs();
}
setComputed(ConeProperty::ExploitIsosMult);
}
deactivate_completed_tasks();
*/
if (exploit_automs_vectors && do_Hilbert_basis) {
if (descent_level < autom_codim_vectors){ // && nr_gen >= dim + 4) { // otherwise direct computation
compute_HB_via_automs();
}
setComputed(ConeProperty::ExploitAutomsVectors);
}
deactivate_completed_tasks();
if (exploit_automs_vectors && do_deg1_elements) {
if (descent_level < God_Father->autom_codim_vectors){ // && nr_gen >= dim + 4) { // otherwise direct computation
compute_Deg1_via_automs();
}
setComputed(ConeProperty::ExploitAutomsVectors);
}
deactivate_completed_tasks();
}
/* deactivated at present
*
size_t nr_revlex_simpl = 0;
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::recursive_revlex_triangulation(
vector<key_t> simplex_so_far,
const vector<key_t>& face_key,
const vector<typename list<FACETDATA<Integer>>::const_iterator>& mother_facets,
size_t dim) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
// cout << "FACE KEY "<< face_key;
// cout << "SIMPLex " << simplex_so_far;
// handle simplex case first since no further descent is necessary
if (face_key.size() == dim) {
simplex_so_far.insert(simplex_so_far.end(), face_key.begin(), face_key.end());
nr_revlex_simpl++;
if (nr_revlex_simpl % 10000 == 0) {
cout << "NR REVLEX SIMPL " << nr_revlex_simpl << endl;
}
return;
}
// We first find the support hyperplanes of our top cone that cut out the
// facets of our face
vector<vector<bool>> facet_candidates;
vector<typename list<FACETDATA<Integer>>::const_iterator> candidates_iterators;
for (size_t i = 0; i < mother_facets.size(); ++i) {
auto F = mother_facets[i];
vector<bool> intersection(nr_gen);
size_t nr_intersection = 0;
for (unsigned int j : face_key) {
if (F->GenInHyp[j]) {
intersection[j] = true;
nr_intersection++;
}
}
// cout << "NR " << nr_intersection << endl;
if (nr_intersection < dim - 1 || nr_intersection == face_key.size()) // too small or everything
continue;
facet_candidates.push_back(intersection);
candidates_iterators.push_back(F);
}
vector<bool> the_facets(facet_candidates.size(), true);
maximal_subsets(facet_candidates, the_facets);
vector<typename list<FACETDATA<Integer>>::const_iterator> facets_of_this_face;
for (size_t i = 0; i < the_facets.size(); ++i)
if (the_facets[i])
facets_of_this_face.push_back(candidates_iterators[i]);
// now we have the facets of our face via support hyperplanes of the top cone
// Next we go over those facets that are opposite to next_vert
key_t next_vert = face_key[0];
simplex_so_far.push_back(next_vert);
for (size_t i = 0; i < facets_of_this_face.size(); ++i) {
auto F = facets_of_this_face[i];
if (F->GenInHyp[next_vert]) // want only those opposite to next_vert
continue;
vector<key_t> intersection;
for (unsigned int j : face_key) {
if (F->GenInHyp[j])
intersection.push_back(j);
}
recursive_revlex_triangulation(simplex_so_far, intersection, facets_of_this_face, dim - 1);
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::make_facets() {
if (!isComputed(ConeProperty::SupportHyperplanes))
support_hyperplanes();
assert(Facets.empty());
for (size_t i = 0; i < Support_Hyperplanes.nr_of_rows(); ++i) {
FACETDATA<Integer> NewFacet;
NewFacet.Hyp.resize(dim);
NewFacet.GenInHyp.resize(nr_gen);
for (size_t j = 0; j < nr_gen; ++j)
if (v_scalar_product(Support_Hyperplanes[i], Generators[j]) == 0)
NewFacet.GenInHyp[j] = true;
NewFacet.Hyp = Support_Hyperplanes[i];
Facets.push_back(NewFacet);
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::revlex_triangulation() {
make_facets();
compute_extreme_rays(true);
vector<key_t> simplex_so_far;
simplex_so_far.reserve(dim);
vector<key_t> Extreme_Rays_Key;
for (size_t i = 0; i < nr_gen; ++i)
if (Extreme_Rays_Ind[i])
Extreme_Rays_Key.push_back(i);
vector<typename list<FACETDATA<Integer>>::const_iterator> mother_facets;
typename list<FACETDATA<Integer>>::const_iterator F;
for (F = Facets.begin(); F != Facets.end(); ++F)
mother_facets.push_back(F);
recursive_revlex_triangulation(simplex_so_far, Extreme_Rays_Key, mother_facets, dim);
cout << "FINAL NR REVLEX SIMPL " << nr_revlex_simpl << endl;
exit(0);
}
*/
//---------------------------------------------------------------------------
// general purpose compute method
// do_* bools must be set in advance, this method does sanity checks for it
// if no bool is set it does support hyperplanes and extreme rays
template <typename Integer>
void Full_Cone<Integer>::compute() {
InputGenerators = Generators; // purified input -- in case we get an exception
// Safeguard against the removal of input generators despite that extreme rays
// had been computed in the cone.
if (Extreme_Rays_Ind.size() != 0 && Extreme_Rays_Ind.size() != Generators.nr_of_rows()) {
is_Computed.reset(ConeProperty::ExtremeRays);
Extreme_Rays_Ind.resize(0);
}
omp_start_level = omp_get_level();
/*cout << "==============" << endl;
Generators.pretty_print(cout);
cout << "==============" << endl;*/
if (dim == 0) {
set_zero_cone();
deactivate_completed_tasks();
prepare_inclusion_exclusion();
return;
}
if (using_renf<Integer>()) {
assert(Truncation.size() == 0 || Grading.size() == 0);
Norm = Truncation;
if (Grading.size() > 0)
Norm = Grading;
}
set_preconditions();
start_message();
if (do_signed_dec) {
primal_algorithm();
compute_multiplicity_or_integral_by_signed_dec();
return;
}
if (!do_Hilbert_basis && !do_h_vector && !do_multiplicity && !do_deg1_elements && !do_Stanley_dec && !keep_triangulation &&
!do_determinants)
assert(Generators.max_rank_submatrix_lex().size() == dim);
if (do_integrally_closed) {
for (size_t i = 0; i < nr_gen; ++i)
Generator_Set.insert(Generators[i]);
}
minimize_support_hyperplanes(); // if they are given
if (inhomogeneous)
set_levels();
check_given_grading();
// look for a grading if it is needed
if (!using_renf<Integer>())
find_grading();
if (isComputed(ConeProperty::IsPointed) && !pointed) {
end_message();
return;
}
if (!isComputed(ConeProperty::Grading) && !using_renf<Integer>())
disable_grading_dep_comp();
// revlex_triangulation(); was here for test
if (do_only_supp_hyps_and_aux || (Grading.size() > 0 && !isComputed(ConeProperty::Grading))) {
// in the last case there are only two possibilities:
// either nonpointed or bad grading
// primal_algorithm_initialize();
support_hyperplanes();
InputGenerators = Generators; // purified input
if (check_semiopen_empty)
prepare_inclusion_exclusion();
if (!using_renf<Integer>())
compute_class_group();
compute_automorphisms();
deactivate_completed_tasks();
end_message();
return;
}
if (isComputed(ConeProperty::IsPointed) && !pointed) {
end_message();
return;
}
set_degrees();
sort_gens_by_degree(true);
InputGenerators = Generators; // purified input
bool polyhedron_is_polytope = inhomogeneous;
if (inhomogeneous) {
find_level0_dim();
for (size_t i = 0; i < nr_gen; ++i)
if (gen_levels[i] == 0) {
polyhedron_is_polytope = false;
break;
}
}
if (polyhedron_is_polytope && (do_Hilbert_basis || do_h_vector)) { // inthis situation we must just find the
convert_polyhedron_to_polytope(); // degree 1 points
deactivate_completed_tasks();
}
compute_by_automorphisms();
deactivate_completed_tasks();
primal_algorithm(); // here plays the music
deactivate_completed_tasks();
if (!using_renf<Integer>() && inhomogeneous && descent_level == 0) {
find_module_rank();
}
if (!using_renf<Integer>())
compute_class_group();
compute_automorphisms();
deactivate_completed_tasks();
end_message();
}
// compute the degree vector of a hsop
template <typename Integer>
vector<Integer> degrees_hsop(const vector<Integer> gen_degrees, const vector<size_t> heights) {
vector<Integer> hsop(heights.back());
hsop[0] = gen_degrees[0];
size_t k = 1;
while (k < heights.size() && heights[k] > heights[k - 1]) {
hsop[k] = gen_degrees[k];
k++;
}
size_t j = k;
for (size_t i = k; i < heights.size(); i++) {
if (heights[i] > heights[i - 1]) {
hsop[j] = v_lcm_to(gen_degrees, k, i);
j++;
}
}
return hsop;
}
/*
//---------------------------------------------------------------------------
template<typename Integer>
Matrix<Integer> Full_Cone<Integer>::copy_basic_data_from(const Full_Cone<Integer>& C){
if(C.isComputed(ConeProperty::SupportHyperplanes)){
Support_Hyperplanes=C.Support_Hyperplanes;
nrSupport_Hyperplanes=C.nrSupport_Hyperplanes;
setComputed(ConeProperty::SupportHyperplanes);
}
if(C.isComputed(ConeProperty::ExtremeRays)){
Extreme_Rays_Ind=C.Extreme_Rays_Ind;
setComputed(ConeProperty::ExtremeRays);
}
if(C.isComputed(ConeProperty::Automorphisms)){
Automs=C.Automs;
setComputed(ConeProperty::Automorphisms);
}
exploit_automorphisms=C.exploit_automorphisms;
keep_order=true;
verbose=C.verbose;
descent_level=C.descent_level;
Facet_2.Grading=Facet_Sub.to_sublattice_dual_no_div(Grading);
Facet_2.setComputed(ConeProperty::Grading);
Facet_2.Mother=&(*this);
Facet_2.God_Father=God_Father;
Facet_2.do_multiplicity=true;
}
*/
//---------------------------------------------------------------------------
template <typename Integer>
Matrix<Integer> Full_Cone<Integer>::push_supphyps_to_cone_over_facet(const vector<Integer>& fixed_point, const key_t facet_nr) {
Matrix<Integer> SuppHyps(0, dim);
vector<Integer> Facet = Support_Hyperplanes[facet_nr];
SuppHyps.append(Facet);
Integer h = v_scalar_product(fixed_point, Facet);
vector<Integer> NewFacet(dim);
for (key_t i = 0; i < nrSupport_Hyperplanes; ++i) {
if (i == facet_nr)
continue;
Integer hN = v_scalar_product(fixed_point, Support_Hyperplanes[i]);
NewFacet = FM_comb(Facet, h, Support_Hyperplanes[i], hN);
SuppHyps.append(NewFacet);
}
return SuppHyps;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::copy_autom_params(const Full_Cone<Integer>& C) {
exploit_automs_mult = C.exploit_automs_mult;
exploit_automs_vectors = C.exploit_automs_vectors;
quality_of_automorphisms = C.quality_of_automorphisms;
do_automorphisms = C.do_automorphisms;
keep_order = true;
}
//---------------------------------------------------------------------------
// We want to replace the fixed point by a generator of the cone that has smaller height
// over the base facet of the pyramid such that the fixed point is contained in the_facets
// pyramid with base the facet and apex the generator
template<typename Integer>
vector<Integer> Full_Cone<Integer>::replace_fixed_point_by_generator(const vector<Integer>& fixed_point,
const key_t facet_nr, const vector<Integer>& help_grading){
Integer height_fixed_pt=v_scalar_product(Support_Hyperplanes[facet_nr],fixed_point);
if(height_fixed_pt<=1)
return fixed_point;
Integer deg_fp=v_scalar_product(fixed_point,help_grading);
Integer height_fp=v_scalar_product(fixed_point,Support_Hyperplanes[facet_nr]);
bool first=true;
Integer min_height;
vector<Integer> min_ht_gen;
for(size_t i=0;i<nr_gen;++i){
Integer height_gen=v_scalar_product(Support_Hyperplanes[facet_nr],Generators[i]);
Integer deg_gen=v_scalar_product(Generators[i],help_grading);
if(deg_fp*height_gen<=deg_gen*height_fp)
continue;
vector<Integer> test=FM_comb(fixed_point,height_fp,Generators[i],height_gen,false);
bool in_cone=true;
for(size_t j=0;j<Support_Hyperplanes.nr_of_rows();++j){
if(v_scalar_product(test,Support_Hyperplanes[j])<0){
in_cone=false;
break;
}
}
if(!in_cone)
continue;
if(first || height_gen<min_height){
first=false;
min_ht_gen=Generators[i];
min_height=height_gen;
}
}
if(!first && min_height<height_fp)
return min_ht_gen;
else{
cout << "No generator found" << endl;
return fixed_point;
}
} // inner C comment ends here
//---------------------------------------------------------------------------
// version without iso classes
template <typename Integer>
void Full_Cone<Integer>::get_cone_over_facet_vectors(const vector<Integer>& fixed_point,
const vector<key_t>& facet_key,
const key_t facet_nr,
list<vector<Integer>>& Facet_vectors) {
vector<Integer> help_grading = compute_degree_function();
Matrix<Integer> Facet_Gens(0, dim);
// vector<Integer> selected_gen=replace_fixed_point_by_generator(fixed_point,facet_nr,help_grading);
// could be the fixed point
Facet_Gens.append(fixed_point);
Facet_Gens.append(Generators.submatrix(facet_key));
if (verbose) {
verboseOutput() << "Finding Hilbert basis/deg 1 elements for cone over codim " << descent_level + 1 << " face" << endl;
verboseOutput() << "Height of pyramid apex over face " << v_scalar_product(fixed_point, Support_Hyperplanes[facet_nr])
<< endl;
}
Full_Cone ConeOverFacet(Facet_Gens);
ConeOverFacet.verbose = verbose;
if (isComputed(ConeProperty::Grading)) {
ConeOverFacet.Grading = Grading;
ConeOverFacet.setComputed(ConeProperty::Grading);
}
ConeOverFacet.descent_level = descent_level + 1;
ConeOverFacet.Mother = &(*this);
ConeOverFacet.God_Father = God_Father;
if (ConeOverFacet.descent_level < God_Father->autom_codim_vectors) { // otherwise dirct computation of HB
ConeOverFacet.copy_autom_params(*this);
ConeOverFacet.Embedding = Embedding;
}
ConeOverFacet.Support_Hyperplanes = push_supphyps_to_cone_over_facet(fixed_point, facet_nr);
ConeOverFacet.do_Hilbert_basis = do_Hilbert_basis;
ConeOverFacet.do_deg1_elements = do_deg1_elements;
ConeOverFacet.inhomogeneous = inhomogeneous;
if (inhomogeneous) {
ConeOverFacet.Truncation = Truncation;
}
ConeOverFacet.autom_codim_vectors = autom_codim_vectors;
ConeOverFacet.compute();
Facet_vectors.clear();
if (do_Hilbert_basis)
Facet_vectors.splice(Facet_vectors.begin(), ConeOverFacet.Hilbert_Basis);
else
Facet_vectors.splice(Facet_vectors.begin(), ConeOverFacet.Deg1_Elements);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_Deg1_via_automs() {
do_automorphisms = true;
quality_of_automorphisms = AutomParam::integral;
compute_automorphisms(descent_level);
if (!do_deg1_elements || isComputed(ConeProperty::Deg1Elements) || !isComputed(ConeProperty::Automorphisms) ||
Automs.getOrder() == 1)
return;
list<vector<Integer>> union_of_facets; // collects all candidates from the orbits of the HBs of the facets
vector<Integer> fixed_point = get_fixed_point(descent_level);
if (verbose) {
verboseOutput() << "Computing deg1 elements via automorphisms in codim " << descent_level << endl;
verboseOutput() << "Fixed point " << fixed_point;
}
vector<vector<key_t>> facet_keys = get_facet_keys_for_orbits(fixed_point, false);
for (auto& facet_key : facet_keys) {
list<vector<Integer>> facet_Deg1;
key_t facet_nr = facet_key.back();
facet_key.pop_back();
get_cone_over_facet_vectors(fixed_point, facet_key, facet_nr, facet_Deg1);
list<vector<Integer>> union_of_orbits; // we must spread the deg 1 elements over their orbit
for (const auto& c : facet_Deg1) {
list<vector<Integer>> orbit_of_deg1 = Automs.orbit_primal(c);
union_of_orbits.splice(union_of_orbits.end(), orbit_of_deg1);
}
union_of_orbits.sort();
union_of_facets.merge(union_of_orbits);
}
union_of_facets.unique(); // necessary since dupocates cannot be avoided
Deg1_Elements.splice(Deg1_Elements.begin(), union_of_facets);
setComputed(ConeProperty::Deg1Elements);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_HB_via_automs() {
do_automorphisms = true;
quality_of_automorphisms = AutomParam::integral;
compute_automorphisms(descent_level);
if (!do_Hilbert_basis || isComputed(ConeProperty::HilbertBasis) || !isComputed(ConeProperty::Automorphisms) ||
Automs.getOrder() == 1)
return;
prepare_old_candidates_and_support_hyperplanes();
set<vector<Integer>> union_of_facets; // collects all candidates from the orbits of the HBs of the facets
vector<Integer> fixed_point = get_fixed_point(descent_level); // this is the number of cone points so far
if (verbose) {
verboseOutput() << "Computing Hilbert basis via automorphisms in codim " << descent_level << endl;
verboseOutput() << "Fixed point " << fixed_point;
}
vector<vector<key_t>> facet_keys = get_facet_keys_for_orbits(fixed_point, false);
for (auto& facet_key : facet_keys) {
list<vector<Integer>> facet_HB;
key_t facet_nr = facet_key.back();
facet_key.pop_back();
get_cone_over_facet_vectors(fixed_point, facet_key, facet_nr, facet_HB);
CandidateList<Integer> Cands_from_facet; // first we sort out the reducible elements
for (const auto& jj : facet_HB)
Cands_from_facet.reduce_by_and_insert(jj, *this, OldCandidates);
// set<vector<Integer> > union_of_orbits; // we must spread the irreducibles over their orbit
for (const auto& c : Cands_from_facet.Candidates) {
auto fc = union_of_facets.find(c.cand);
if (fc != union_of_facets.end())
continue;
list<vector<Integer>> orbit_of_cand = Automs.orbit_primal(c.cand);
for (const auto& cc : orbit_of_cand)
union_of_facets.insert(cc);
}
}
if(verbose)
verboseOutput() << "Union unique size " << union_of_facets.size() << endl;
for (const auto& v : union_of_facets)
NewCandidates.push_back(Candidate<Integer>(v, *this));
update_reducers(true); // we always want reduction
OldCandidates.extract(Hilbert_Basis);
Hilbert_Basis.sort();
Hilbert_Basis.unique();
setComputed(ConeProperty::HilbertBasis);
if (isComputed(ConeProperty::Grading)) {
select_deg1_elements();
check_deg1_hilbert_basis();
}
}
//---------------------------------------------------------------------------
template <typename Integer>
vector<Integer> Full_Cone<Integer>::get_fixed_point(size_t nr_cone_points) {
// find fixed ppoint of low degree
size_t mini = 0;
key_t min_orbit = 0;
for (size_t i = 0; i < Automs.GenOrbits.size(); ++i)
if ((mini == 0 || Automs.GenOrbits[i].size() < mini) && Automs.GenOrbits[i][0] >= nr_cone_points) {
mini = Automs.GenOrbits[i].size();
min_orbit = i;
}
vector<Integer> fixed_point(dim);
Matrix<Integer> Extreme_Rays = Generators.submatrix(Extreme_Rays_Ind);
// Extreme_Rays.pretty_print(cout);
for (size_t i = 0; i < Automs.GenOrbits[min_orbit].size(); ++i) {
fixed_point = v_add(fixed_point, Extreme_Rays[Automs.GenOrbits[min_orbit][i]]);
}
v_make_prime(fixed_point);
return fixed_point;
}
//---------------------------------------------------------------------------
template <typename Integer>
vector<vector<key_t>> Full_Cone<Integer>::get_facet_keys_for_orbits(const vector<Integer>& fixed_point, bool with_orbit_sizes) {
// We collect only the facets that do not contain the fixed point.
// The last one (or two) entries of each key vector are abused for
// (the orbit size and ) the number of the support hyperplane.
// Everything for the first hyperplane in the orbit.
vector<vector<key_t>> facet_keys;
for (size_t k = 0; k < Automs.LinFormOrbits.size(); ++k) {
key_t facet_nr = Automs.LinFormOrbits[k][0];
assert(facet_nr < nrSupport_Hyperplanes); // for safety
Integer ht = v_scalar_product(fixed_point, Support_Hyperplanes[facet_nr]);
if (ht == 0) // fixed point in facet, does not contribute to multiplicity
continue;
vector<key_t> facet_gens;
for (size_t i = 0; i < nr_gen; ++i) {
if (Extreme_Rays_Ind[i] && v_scalar_product(Generators[i], Support_Hyperplanes[facet_nr]) == 0)
facet_gens.push_back(i);
}
facet_keys.push_back(facet_gens);
if (with_orbit_sizes)
facet_keys.back().push_back(Automs.LinFormOrbits[k].size());
facet_keys.back().push_back(facet_nr);
}
return facet_keys;
}
/*
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_multiplicity_via_automs() {
compute_automorphisms(0);
if (!do_multiplicity || isComputed(ConeProperty::Multiplicity) || !isComputed(ConeProperty::Grading) ||
!isComputed(ConeProperty::Automorphisms) || Automs.getOrder() == 1)
return;
vector<Integer> fixed_point = get_fixed_point(0); // no cone points in this case
Integer deg_fixed_point = v_scalar_product(fixed_point, Grading);
vector<vector<key_t>> facet_keys = get_facet_keys_for_orbits(fixed_point, true);
if (verbose) {
verboseOutput() << "Computing multiplicity via automorphisms in codim " << descent_level << endl;
verboseOutput() << "Fixed point " << fixed_point;
}
for (auto& facet_key : facet_keys) {
key_t facet_nr = facet_key.back();
facet_key.pop_back();
Integer ht = v_scalar_product(fixed_point, Support_Hyperplanes[facet_nr]);
long long orbit_size = facet_key.back();
facet_key.pop_back();
multiplicity += convertTo<mpz_class>(orbit_size) * convertTo<mpz_class>(ht) * facet_multiplicity(facet_key) /
convertTo<mpz_class>(deg_fixed_point);
}
setComputed(ConeProperty::Multiplicity);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_multiplicity_via_recession_cone() {
Matrix<Integer> Level0Gens(0, dim);
for (size_t i = 0; i < nr_gen; ++i) {
if (gen_levels[i] == 0)
Level0Gens.append(Generators[i]);
}
Sublattice_Representation<Integer> Level0Sub(Level0Gens, true);
Matrix<Integer> RecGens = Level0Sub.to_sublattice(Level0Gens);
Full_Cone<Integer> RecCone(RecGens);
RecCone.Grading = Level0Sub.to_sublattice_dual_no_div(Grading);
RecCone.setComputed(ConeProperty::Grading);
RecCone.do_multiplicity = true;
RecCone.verbose = verbose;
RecCone.copy_autom_params(*this);
if (quality_of_automorphisms == AutomParam::ambient_gen) {
RecCone.Embedding = Level0Sub.getEmbeddingMatrix().multiplication(Embedding);
}
RecCone.compute();
multiplicity = RecCone.multiplicity;
setComputed(ConeProperty::Multiplicity);
}
//---------------------------------------------------------------------------
template <typename Integer>
mpq_class Full_Cone<Integer>::facet_multiplicity(const vector<key_t>& facet_key) {
Matrix<Integer> Facet_Gens = Generators.submatrix(facet_key);
if (verbose) {
verboseOutput() << "Finding multiplicity for face of codim " << descent_level + 1 << endl;
}
Sublattice_Representation<Integer> Facet_Sub(Facet_Gens, false);
// By this choice we guarantee that the extreme Rays that generate the facet also
// generate the lattice in which the multiplicity is computed.
// This allows for more efficient isomorphism check.
// The lattice can be smaller than the intersection of the facet with the full lattice.
// We take care of this by mutiplying the computed multiplicity with the external index (see below).
Matrix<Integer> Transformed_Facet_Gens = Facet_Sub.to_sublattice(Facet_Gens);
Full_Cone Facet(Transformed_Facet_Gens);
Facet.verbose = verbose;
Facet.Grading = Facet_Sub.to_sublattice_dual_no_div(Grading);
Facet.setComputed(ConeProperty::Grading);
Facet.Mother = &(*this);
Facet.God_Father = God_Father;
Facet.copy_autom_params(*this);
if (quality_of_automorphisms == AutomParam::ambient_gen) {
Facet.Embedding = Facet_Sub.getEmbeddingMatrix().multiplication(Embedding);
}
Facet.inhomogeneous = inhomogeneous;
if (inhomogeneous) {
Facet.Truncation = Facet_Sub.to_sublattice_dual_no_div(Truncation);
}
Facet.descent_level = descent_level + 1;
Facet.keep_order = true;
Facet.Support_Hyperplanes = Facet_Sub.to_sublattice_dual(Support_Hyperplanes);
Facet.compute();
bool found;
const IsoType<Integer>& face_class = God_Father->FaceClasses.find_type(Facet, found);
if (found) {
if (verbose) {
verboseOutput() << "Found isomorphism class" << endl;
}
mpq_class mmm = face_class.getMultiplicity();
return mmm * Facet_Sub.getExternalIndex();
}
else {
if (verbose) {
verboseOutput() << "New isomorphism class" << endl;
}
Full_Cone Facet_2(Transformed_Facet_Gens);
Facet_2.Automs = Facet.Automs;
Facet_2.setComputed(ConeProperty::Automorphisms);
Facet_2.Extreme_Rays_Ind = Facet.Extreme_Rays_Ind;
Facet_2.setComputed(ConeProperty::ExtremeRays);
Facet_2.Support_Hyperplanes = Facet.Support_Hyperplanes;
Facet_2.nrSupport_Hyperplanes = Facet.nrSupport_Hyperplanes;
Facet_2.setComputed(ConeProperty::SupportHyperplanes);
Facet_2.copy_autom_params(*this);
Facet_2.inhomogeneous = inhomogeneous;
Facet_2.Truncation = Facet.Truncation;
if (quality_of_automorphisms == AutomParam::ambient) {
Facet_2.Embedding = Facet_Sub.getEmbeddingMatrix().multiplication(Embedding);
}
Facet_2.verbose = verbose;
Facet_2.descent_level = descent_level + 1;
Facet_2.Grading = Facet_Sub.to_sublattice_dual_no_div(Grading);
Facet_2.setComputed(ConeProperty::Grading);
Facet_2.Mother = &(*this);
Facet_2.God_Father = God_Father;
Facet_2.do_multiplicity = true;
Facet_2.verbose = true;
Facet_2.autom_codim_mult = autom_codim_mult;
Facet_2.compute();
mpq_class mult_before = Facet_2.multiplicity;
bool added;
God_Father->FaceClasses.add_type(Facet_2, added);
assert(mult_before == Facet_2.multiplicity);
return Facet_2.multiplicity * Facet_Sub.getExternalIndex();
}
}
*/
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_hsop() {
vector<long> hsop_deg(dim, 1);
// if all extreme rays are in degree one, there is nothing to compute
if (!isDeg1ExtremeRays()) {
if (verbose) {
verboseOutput() << "Computing heights ... " << flush;
}
vector<bool> choice = Extreme_Rays_Ind;
if (inhomogeneous) {
for (size_t i = 0; i < Generators.nr_of_rows(); i++) {
if (Extreme_Rays_Ind[i] && v_scalar_product(Generators[i], Truncation) != 0) {
choice[i] = false;
}
}
}
Matrix<Integer> ER = Generators.submatrix(choice);
Matrix<Integer> SH = getSupportHyperplanes();
if (inhomogeneous) {
Sublattice_Representation<Integer> recession_lattice(ER, true,false);
Matrix<Integer> SH_raw = recession_lattice.to_sublattice_dual(SH);
Matrix<Integer> ER_embedded = recession_lattice.to_sublattice(ER);
Full_Cone<Integer> recession_cone(ER_embedded);
recession_cone.Support_Hyperplanes = SH_raw;
recession_cone.dualize_cone();
SH = recession_lattice.from_sublattice_dual(recession_cone.getSupportHyperplanes());
}
vector<size_t> ideal_heights(ER.nr_of_rows(), 1);
// the heights vector is clear in the simplicial case
if (is_simplicial) {
for (size_t j = 0; j < ideal_heights.size(); j++)
ideal_heights[j] = j + 1;
}
else {
list<pair<dynamic_bitset, size_t>> facet_list;
list<vector<key_t>> facet_keys;
vector<key_t> key;
size_t d = dim;
if (inhomogeneous)
d = level0_dim;
assert(d > 0); // we want to use d-1
for (size_t i = SH.nr_of_rows(); i-- > 0;) {
dynamic_bitset new_facet(ER.nr_of_rows());
key.clear();
for (size_t j = 0; j < ER.nr_of_rows(); j++) {
if (v_scalar_product(SH[i], ER[j]) == 0) {
new_facet[new_facet.size() - 1 - j] = 1;
}
else {
key.push_back(static_cast<key_t>(j));
}
}
facet_list.push_back(make_pair(new_facet, d - 1));
facet_keys.push_back(key);
}
facet_list.sort(); // should be sorted lex
//~ cout << "FACETS:" << endl;
//~ //cout << "size: " << facet_list.size() << " | " << facet_list << endl;
//~ for (auto jt=facet_list.begin();jt!=facet_list.end();++jt){
//~ cout << jt->first << " | " << jt->second << endl;
//~ }
// cout << "facet non_keys: " << facet_keys << endl;
heights(facet_keys, facet_list, ER.nr_of_rows() - 1, ideal_heights, d - 1);
}
if (verbose) {
verboseOutput() << "done." << endl;
if (!inhomogeneous)
assert(ideal_heights[ER.nr_of_rows() - 1] == dim);
else
assert(ideal_heights[ER.nr_of_rows() - 1] == level0_dim);
verboseOutput() << "Heights vector: " << ideal_heights;
}
vector<Integer> er_deg = ER.MxV(Grading);
hsop_deg = convertTo<vector<long>>(degrees_hsop(er_deg, ideal_heights));
}
if (verbose) {
verboseOutput() << "Degrees of HSOP: " << hsop_deg;
}
Hilbert_Series.setHSOPDenom(hsop_deg);
}
template <>
void Full_Cone<renf_elem_class>::compute_hsop() {
assert(false);
}
// recursive method to compute the heights
// TODO: at the moment: facets are a parameter. global would be better
template <typename Integer>
void Full_Cone<Integer>::heights(list<vector<key_t>>& facet_keys,
list<pair<dynamic_bitset, size_t>> faces,
size_t index,
vector<size_t>& ideal_heights,
size_t max_dim) {
// since we count the index backwards, this is the actual nr of the extreme ray
do {
size_t ER_nr = ideal_heights.size() - index - 1;
// cout << "starting calculation for extreme ray nr " << ER_nr << endl;
list<pair<dynamic_bitset, size_t>> not_faces;
auto face_it = faces.begin();
for (; face_it != faces.end(); ++face_it) {
if (face_it->first.test(index)) { // check whether index is set
break;
}
// resize not_faces
face_it->first.resize(index);
}
not_faces.splice(not_faces.begin(), faces, faces.begin(), face_it);
auto not_faces_it = not_faces.begin();
// update the heights
if (ER_nr > 0) {
if (!not_faces.empty()) {
ideal_heights[ER_nr] = ideal_heights[ER_nr - 1];
// compute the dimensions of not_faces
vector<bool> choice = Extreme_Rays_Ind;
if (inhomogeneous) {
for (size_t i = 0; i < Generators.nr_of_rows(); i++) {
if (Extreme_Rays_Ind[i] && v_scalar_product(Generators[i], Truncation) != 0) {
choice[i] = false;
}
}
}
Matrix<Integer> ER = Generators.submatrix(choice);
int tn;
if (omp_get_level() == omp_start_level)
tn = 0;
else
tn = omp_get_ancestor_thread_num(omp_start_level + 1);
Matrix<Integer>& Test = Top_Cone->RankTest[tn];
vector<key_t> face_key;
for (; not_faces_it != not_faces.end(); ++not_faces_it) {
if (not_faces_it->second == 0) { // dimension has not yet been computed
// generate the key vector
face_key.resize(0);
for (size_t i = 0; i < not_faces_it->first.size(); ++i) {
if (not_faces_it->first.test(i)) {
face_key.push_back(static_cast<key_t>(ER.nr_of_rows() - 1 - i));
}
}
not_faces_it->second = Test.rank_submatrix(ER, face_key);
}
if (not_faces_it->second == max_dim)
break;
}
if (not_faces_it == not_faces.end()) {
--max_dim;
ideal_heights[ER_nr] = ideal_heights[ER_nr - 1] + 1;
}
}
else {
ideal_heights[ER_nr] = ideal_heights[ER_nr - 1] + 1;
--max_dim;
}
}
// we computed all the heights
if (index == 0)
return;
// if inner point, we can skip now
// take the union of all faces not containing the current extreme ray
dynamic_bitset union_faces(index);
not_faces_it = not_faces.begin();
for (; not_faces_it != not_faces.end(); ++not_faces_it) {
union_faces |= not_faces_it->first; // take the union
}
// cout << "Their union: " << union_faces << endl;
// the not_faces now already have a size one smaller
union_faces.resize(index + 1);
list<pair<dynamic_bitset, size_t>> new_faces;
// delete all facets which only consist of the previous extreme rays
auto facet_it = facet_keys.begin();
size_t counter = 0;
while (facet_it != facet_keys.end()) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
counter = 0;
for (size_t i = 0; i < facet_it->size(); i++) {
if (facet_it->at(i) <= ER_nr)
continue;
// now we only have new extreme rays
counter = i;
break;
}
size_t j = ER_nr + 1;
for (; j < ideal_heights.size(); j++) {
if (facet_it->at(counter) != j) { // facet contains the element j
break;
}
else if (counter < facet_it->size() - 1)
counter++;
}
if (j == ideal_heights.size()) {
facet_it = facet_keys.erase(facet_it);
}
else
++facet_it;
}
facet_it = facet_keys.begin();
// main loop
for (; facet_it != facet_keys.end(); ++facet_it) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
// check whether the facet is contained in the faces not containing the generator
// and the previous generators
// and check whether the generator is in the facet
// check whether intersection with facet contributes
bool not_containing_el = false;
// bool whether the facet contains an element which is NOT in the faces not containing the current extreme ray
bool containing_critical_el = false;
counter = 0;
// cout << "check critical for facet " << *it << endl;
for (size_t i = 0; i < facet_it->size(); i++) {
if (facet_it->at(i) == ER_nr) {
not_containing_el = true;
}
if (facet_it->at(i) <= ER_nr && i < facet_it->size() - 1)
continue;
counter = i; // now we have elements which are bigger than the current extreme ray
if (not_containing_el) {
for (size_t j = ER_nr + 1; j < ideal_heights.size(); j++) {
if (facet_it->at(counter) != j) { // i.e. j is in the facet
if (!union_faces.test(ideal_heights.size() - 1 - j)) {
containing_critical_el = true;
break;
}
}
else if (counter < facet_it->size() - 1)
counter++;
}
}
break;
}
if (not_containing_el && containing_critical_el) { // facet contributes
// cout << "Taking intersections with the facet " << *facet_it << endl;
face_it = faces.begin();
for (; face_it != faces.end(); ++face_it) {
dynamic_bitset intersection(face_it->first);
for (unsigned int i : *facet_it) {
if (i > ER_nr)
intersection.set(ideal_heights.size() - 1 - i, false);
}
intersection.resize(index);
if (intersection.any()) {
// check whether the intersection lies in any of the not_faces
not_faces_it = not_faces.begin();
for (; not_faces_it != not_faces.end(); ++not_faces_it) {
if (intersection.is_subset_of(not_faces_it->first))
break;
}
if (not_faces_it == not_faces.end())
new_faces.push_back(make_pair(intersection, 0));
}
}
}
}
// the new faces need to be sort in lex order anyway. this can be used to reduce operations
// for subset checking
new_faces.sort();
auto outer_it = new_faces.begin();
auto inner_it = new_faces.begin();
for (; outer_it != new_faces.end(); ++outer_it) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
// work with a not-key vector
vector<key_t> face_not_key;
for (size_t i = 0; i < outer_it->first.size(); i++) {
if (!outer_it->first.test(i)) {
face_not_key.push_back(static_cast<key_t>(i));
}
}
inner_it = new_faces.begin();
size_t i = 0;
while (inner_it != outer_it) {
i = 0;
for (; i < face_not_key.size(); ++i) {
if (inner_it->first.test(face_not_key[i]))
break; // inner_it has an element which is not in outer_it
}
if (i == face_not_key.size()) {
inner_it = new_faces.erase(inner_it); // inner_it is a subface of outer_it
}
else
++inner_it;
}
}
new_faces.merge(not_faces);
// cout << "The new faces: " << endl;
// for (const auto& jt : new_faces){
// cout << jt.first << " | " << jt.second << endl;
// }
// heights(facet_keys, new_faces, index - 1, ideal_heights, max_dim);
swap(faces, new_faces);
--index;
} while (true);
}
template <typename Integer>
void Full_Cone<Integer>::convert_polyhedron_to_polytope() {
if (verbose) {
verboseOutput() << "Converting polyhedron to polytope" << endl;
verboseOutput() << "Pointed since cone over polytope" << endl;
}
pointed = true;
setComputed(ConeProperty::IsPointed);
Full_Cone Polytope(Generators);
Polytope.pointed = true;
Polytope.setComputed(ConeProperty::IsPointed);
Polytope.keep_order = true;
Polytope.Grading = Truncation;
Polytope.setComputed(ConeProperty::Grading);
if (isComputed(ConeProperty::SupportHyperplanes)) {
Polytope.Support_Hyperplanes = Support_Hyperplanes;
Polytope.nrSupport_Hyperplanes = nrSupport_Hyperplanes;
Polytope.setComputed(ConeProperty::SupportHyperplanes);
}
if (isComputed(ConeProperty::ExtremeRays)) {
Polytope.Extreme_Rays_Ind = Extreme_Rays_Ind;
Polytope.setComputed(ConeProperty::ExtremeRays);
}
Polytope.do_deg1_elements = true;
Polytope.verbose = verbose;
Polytope.compute();
if (Polytope.isComputed(ConeProperty::SupportHyperplanes) && !isComputed(ConeProperty::SupportHyperplanes)) {
Support_Hyperplanes = Polytope.Support_Hyperplanes;
nrSupport_Hyperplanes = Polytope.nrSupport_Hyperplanes;
setComputed(ConeProperty::SupportHyperplanes);
}
if (Polytope.isComputed(ConeProperty::ExtremeRays) && !isComputed(ConeProperty::ExtremeRays)) {
Extreme_Rays_Ind = Polytope.Extreme_Rays_Ind;
setComputed(ConeProperty::ExtremeRays);
}
if (Polytope.isComputed(ConeProperty::Deg1Elements)) {
module_rank = Polytope.Deg1_Elements.size();
if (do_Hilbert_basis) {
Hilbert_Basis = Polytope.Deg1_Elements;
setComputed(ConeProperty::HilbertBasis);
}
setComputed(ConeProperty::ModuleRank);
if (isComputed(ConeProperty::Grading)) {
multiplicity = 1; // of the recession cone;
setComputed(ConeProperty::Multiplicity);
if (do_h_vector) {
vector<num_t> hv(1);
typename list<vector<Integer>>::const_iterator hb = Polytope.Deg1_Elements.begin();
for (; hb != Polytope.Deg1_Elements.end(); ++hb) {
size_t deg = convertToLong(v_scalar_product(Grading, *hb));
if (deg + 1 > hv.size())
hv.resize(deg + 1);
hv[deg]++;
}
Hilbert_Series.add(hv, vector<denom_t>());
Hilbert_Series.setShift(convertToLong(shift));
Hilbert_Series.adjustShift();
Hilbert_Series.simplify();
setComputed(ConeProperty::HilbertSeries);
}
}
}
}
template <>
void Full_Cone<renf_elem_class>::convert_polyhedron_to_polytope() {
assert(false);
}
//---------------------------------------------------------------------------
// -s
template <typename Integer>
void Full_Cone<Integer>::support_hyperplanes() {
if (!isComputed(ConeProperty::SupportHyperplanes)) {
sort_gens_by_degree(false); // we do not want to triangulate here
build_top_cone();
}
extreme_rays_and_deg1_check();
if (inhomogeneous) {
find_level0_dim();
if (do_module_rank)
find_module_rank();
}
if (verbose) {
verboseOutput() << "Total number of pyramids = " << totalNrPyr << ", among them simplicial " << nrSimplicialPyr << endl;
}
}
//---------------------------------------------------------------------------
// Checks and auxiliary algorithms
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::extreme_rays_and_deg1_check() {
check_pointed();
if (!pointed) {
throw NonpointedException();
}
compute_extreme_rays();
deg1_check();
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::check_given_grading() {
if (Grading.size() == 0)
return;
bool positively_graded = true;
if (!isComputed(ConeProperty::Grading)) {
size_t neg_index = 0;
Integer neg_value;
bool nonnegative = true;
vector<Integer> degrees = Generators.MxV(Grading);
for (size_t i = 0; i < degrees.size(); ++i) {
if (degrees[i] <= 0 && (!inhomogeneous || gen_levels[i] == 0)) {
// in the inhomogeneous case: test only generators of tail cone
positively_graded = false;
;
if (degrees[i] < 0) {
nonnegative = false;
neg_index = i;
neg_value = degrees[i];
}
}
}
if (!nonnegative) {
throw BadInputException("Grading gives negative value " + toString(neg_value) + " for generator " +
toString(neg_index + 1) + "!");
}
}
if (positively_graded) {
setComputed(ConeProperty::Grading);
if (inhomogeneous)
find_grading_inhom();
set_degrees();
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_grading() {
if (inhomogeneous) // in the inhomogeneous case we do not allow implicit grading
return;
deg1_check(); // trying to find grading under which all generators have the same degree
if (!isComputed(ConeProperty::Grading) && (do_multiplicity || do_deg1_elements || do_h_vector)) {
if (!isComputed(ConeProperty::ExtremeRays)) {
if (verbose) {
verboseOutput() << "Cannot find grading s.t. all generators have the degree 1! Computing Extreme rays first:"
<< endl;
}
get_supphyps_from_copy(true);
extreme_rays_and_deg1_check();
if (!pointed) {
throw NonpointedException();
};
// We keep the SupportHyperplanes, so we do not need to recompute them
// for the last generator, and use them to make a global reduction earlier
}
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_level0_dim() {
if (isComputed(ConeProperty::RecessionRank))
return;
if (!isComputed(ConeProperty::Generators)) {
throw FatalException("Missing Generators.");
}
Matrix<Integer> Help(nr_gen, dim);
for (size_t i = 0; i < nr_gen; ++i)
if (gen_levels[i] == 0)
Help[i] = Generators[i];
ProjToLevel0Quot = Help.kernel(false); // Necessary for the module rank
// For level0_dim the rank of Help would be enough
level0_dim = dim - ProjToLevel0Quot.nr_of_rows();
// level0_dim=Help.rank();
setComputed(ConeProperty::RecessionRank);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_level0_dim_from_HB() {
// we use the Hilbert basis if we don't have the extreme reys.
// This is possible if the HB was computed by the dual algorithm.
// Would be enough if we would take the extreme reys of the recession cone,
// but they have not been extracted from the HB
if (isComputed(ConeProperty::RecessionRank))
return;
assert(isComputed(ConeProperty::HilbertBasis));
Matrix<Integer> Help(0, dim);
for (const auto& H : Hilbert_Basis)
if (v_scalar_product(H, Truncation) == 0)
Help.append(H);
ProjToLevel0Quot = Help.kernel(); // Necessary for the module rank
// For level0_dim the rank of Help would be enough
level0_dim = dim - ProjToLevel0Quot.nr_of_rows();
setComputed(ConeProperty::RecessionRank);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_module_rank() {
if (isComputed(ConeProperty::ModuleRank))
return;
if (level0_dim == dim) {
module_rank = 0;
setComputed(ConeProperty::ModuleRank);
return;
}
if (isComputed(ConeProperty::HilbertBasis)) {
find_module_rank_from_HB();
return;
}
// size_t HBrank = module_rank;
if (do_module_rank)
find_module_rank_from_proj();
/* if(isComputed(ConeProperty::HilbertBasis))
assert(HBrank==module_rank);
*/
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_module_rank_from_proj() {
if (verbose) {
verboseOutput() << "Computing projection to quotient mod level 0" << endl;
}
Matrix<Integer> ProjGen(nr_gen, dim - level0_dim);
for (size_t i = 0; i < nr_gen; ++i) {
ProjGen[i] = ProjToLevel0Quot.MxV(Generators[i]);
}
vector<Integer> GradingProj = ProjToLevel0Quot.transpose().solve_ZZ(Truncation);
Full_Cone<Integer> Cproj(ProjGen);
Cproj.verbose = false;
Cproj.Grading = GradingProj;
Cproj.setComputed(ConeProperty::Grading);
Cproj.do_deg1_elements = true;
Cproj.compute();
module_rank = Cproj.Deg1_Elements.size();
setComputed(ConeProperty::ModuleRank);
return;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_module_rank_from_HB() {
if (level0_dim == 0) {
module_rank = Hilbert_Basis.size();
setComputed(ConeProperty::ModuleRank);
return;
}
set<vector<Integer>> Quotient;
vector<Integer> v;
// cout << "=======================" << endl;
// ProjToLevel0Quot.print(cout);
// cout << "=======================" << endl;
for (const auto& h : Hilbert_Basis) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
v = ProjToLevel0Quot.MxV(h);
bool zero = true;
for (size_t j = 0; j < v.size(); ++j)
if (v[j] != 0) {
zero = false;
break;
}
if (!zero)
Quotient.insert(v);
}
module_rank = Quotient.size();
setComputed(ConeProperty::ModuleRank);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::find_grading_inhom() {
if (Grading.size() == 0 || Truncation.size() == 0) {
throw FatalException("Cannot find grading in the inhomogeneous case!");
}
if (shift != 0) // to avoid double computation
return;
bool first = true;
Integer level, degree, quot = 0, min_quot = 0;
for (size_t i = 0; i < nr_gen; ++i) {
level = v_scalar_product(Truncation, Generators[i]);
if (level == 0)
continue;
degree = v_scalar_product(Grading, Generators[i]);
quot = degree / level;
// cout << Generators[i];
// cout << "*** " << degree << " " << level << " " << quot << endl;
if (level * quot >= degree)
quot--;
if (first) {
min_quot = quot;
first = false;
}
if (quot < min_quot)
min_quot = quot;
// cout << "+++ " << min_quot << endl;
}
shift = min_quot;
for (size_t i = 0; i < dim; ++i) // under this grading all generators have positive degree
Grading[i] = Grading[i] - shift * Truncation[i];
// shift--; // NO LONGER correction for the Hilbert series computation to have it start in degree 0
}
#ifdef ENFNORMALIZ
template <>
void Full_Cone<renf_elem_class>::find_grading_inhom() {
assert(false);
}
#endif
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::set_levels() {
if (inhomogeneous && Truncation.size() != dim) {
throw FatalException("Truncation not defined in inhomogeneous case.");
}
if (gen_levels.size() != nr_gen) // now we compute the levels
{
gen_levels.resize(nr_gen);
vector<Integer> gen_levels_Integer = Generators.MxV(Truncation);
for (size_t i = 0; i < nr_gen; i++) {
if (gen_levels_Integer[i] < 0) {
throw FatalException("Truncation gives non-positive value " + toString(gen_levels_Integer[i]) +
" for generator " + toString(i + 1) + ".");
}
convert(gen_levels[i], gen_levels_Integer[i]);
// cout << "Gen " << Generators[i];
// cout << "level " << gen_levels[i] << endl << "----------------------" << endl;
}
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::sort_gens_by_degree(bool triangulate) {
// if(deg1_extreme_rays) // gen_degrees.size()==0 ||
// return;
if (keep_order)
return;
/* commented out since only used in exploitation of automorphisms
*
// we first order the generaors by "support hyperplanes" for computations using automorphisms
// in order to have an intrinsic useful sorting
if (isComputed(ConeProperty::SupportHyperplanes) && descent_level > 0) {
Matrix<Integer> TranspType(Support_Hyperplanes.nr_of_rows(), Generators.nr_of_rows());
#pragma omp parallel for
for (size_t i = 0; i < Support_Hyperplanes.nr_of_rows(); ++i)
for (size_t j = 0; j < Generators.nr_of_rows(); ++j)
TranspType[i][j] = v_scalar_product(Support_Hyperplanes[i], Generators[j]);
Matrix<Integer> OrderSupps = TranspType.sort_by_nr_of_zeroes();
Matrix<Integer> Type = TranspType.transpose();
vector<key_t> new_perm = Type.perm_by_lex();
Generators.order_rows_by_perm(new_perm);
compose_perm_gens(new_perm);
if (verbose)
verboseOutput() << "Generators sorted lexicographically by scalar products with support hyperplanes" << endl;
}
*/
Matrix<Integer> Weights(0, dim);
vector<bool> absolute;
if (triangulate) {
if (isComputed(ConeProperty::Grading)) {
Weights.append(Grading);
absolute.push_back(false);
}
}
vector<key_t> perm = Generators.perm_by_weights(Weights, absolute);
Generators.order_rows_by_perm(perm);
order_by_perm_bool(Extreme_Rays_Ind, perm);
if (isComputed(ConeProperty::Grading) || (inhomogeneous && using_renf<Integer>() && do_multiplicity)) {
order_by_perm(gen_degrees, perm);
if (do_h_vector || (!using_GMP<Integer>() && !using_renf<Integer>()))
order_by_perm(gen_degrees_long, perm);
}
if (inhomogeneous && gen_levels.size() == nr_gen)
order_by_perm(gen_levels, perm);
if (triangulate) {
Integer roughness;
if (isComputed(ConeProperty::Grading)) {
roughness = gen_degrees[nr_gen - 1] / gen_degrees[0];
}
else {
Integer max_norm = 0, min_norm = 0;
for (size_t i = 0; i < dim; ++i) {
max_norm += Iabs(Generators[nr_gen - 1][i]);
min_norm += Iabs(Generators[0][i]);
}
roughness = max_norm / min_norm;
}
if (verbose) {
verboseOutput() << "Roughness " << roughness << endl;
}
if (roughness >= 10 && !suppress_bottom_dec) {
do_bottom_dec = true;
if (verbose) {
verboseOutput() << "Bottom decomposition activated" << endl;
}
}
}
/*
if (exploit_automs_vectors && descent_level == 0 && isComputed(ConeProperty::Grading)) {
vector<key_t> inverse_order(nr_gen);
for (size_t i = 0; i < nr_gen; ++i)
inverse_order[i] = nr_gen - 1 - i;
vector<key_t> largest_simplex = Generators.max_rank_submatrix_lex(inverse_order);
HB_bound = -1;
for (size_t i = 0; i < dim; ++i)
HB_bound += convertTo<Integer>(gen_degrees[largest_simplex[i]]);
}
*/
if (verbose) {
if (triangulate) {
if (isComputed(ConeProperty::Grading)) {
verboseOutput() << "Generators sorted by degree and lexicographically" << endl;
verboseOutput() << "Generators per degree:" << endl;
verboseOutput() << count_in_map<Integer, long>(gen_degrees);
}
else
verboseOutput() << "Generators sorted lexicographically" << endl;
}
else {
verboseOutput() << "Generators sorted lexicographically" << endl;
}
}
keep_order = true;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compose_perm_gens(const vector<key_t>& perm) {
order_by_perm(PermGens, perm);
}
//---------------------------------------------------------------------------
// an alternative to compute() for the basic tasks that need no triangulation
template <typename Integer>
void Full_Cone<Integer>::dualize_cone(bool print_message) {
InputGenerators = Generators; // purified input -- in case we get an exception
// Safeguard against the removal of input generators despite that extreme rays
// had been computed in the cone.
if (Extreme_Rays_Ind.size() != 0 && Extreme_Rays_Ind.size() != Generators.nr_of_rows()) {
is_Computed.reset(ConeProperty::ExtremeRays);
Extreme_Rays_Ind.resize(0);
}
omp_start_level = omp_get_level();
if (dim == 0) {
set_zero_cone();
return;
}
// DO NOT CALL do_vars_check!!
bool save_tri = do_triangulation;
bool save_part_tri = do_partial_triangulation;
/* do_triangulation = false;
do_partial_triangulation = false; */
if (print_message)
start_message();
sort_gens_by_degree(false);
InputGenerators = Generators; // purified input
try {
if (!isComputed(ConeProperty::SupportHyperplanes))
build_top_cone();
} catch (const NonpointedException&) {
};
if (!pointed) { // we get rid of the duplcates now which can be produced in this case
vector<size_t> UniqueIndices = Support_Hyperplanes.remove_duplicate_and_zero_rows();
if (keep_convex_hull_data) { // in this case we must also get rid of duplicate members of Facets
set<key_t> UniquePositions; // go via a set for simplicity
UniquePositions.insert(UniqueIndices.begin(), UniqueIndices.end());
auto F = Facets.begin();
for (size_t i = 0; i < Facets.size(); ++i) {
if (UniquePositions.find(static_cast<key_t>(i)) == UniquePositions.end()) {
F = Facets.erase(F);
continue;
}
F++;
}
}
}
if (do_extreme_rays) // in case we have known the support hyperplanes
compute_extreme_rays();
do_triangulation = save_tri;
do_partial_triangulation = save_part_tri;
if (print_message)
end_message();
}
//---------------------------------------------------------------------------
template <typename Integer>
vector<key_t> Full_Cone<Integer>::find_start_simplex() const {
return Generators.max_rank_submatrix_lex();
}
//---------------------------------------------------------------------------
/*
template <typename Integer>
Matrix<Integer> Full_Cone<Integer>::select_matrix_from_list(const list<vector<Integer>>& S, vector<size_t>& selection) {
sort(selection.begin(), selection.end());
assert(selection.back() < S.size());
size_t i = 0, j = 0;
size_t k = selection.size();
Matrix<Integer> M(selection.size(), S.front().size());
for (auto ll = S.begin(); ll != S.end() && i < k; ++ll) {
if (j == selection[i]) {
M[i] = *ll;
i++;
}
j++;
}
return M;
}
*/
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::minimize_support_hyperplanes() {
if (Support_Hyperplanes.nr_of_rows() == 0) {
return;
}
if (isComputed(ConeProperty::SupportHyperplanes)) {
nrSupport_Hyperplanes = Support_Hyperplanes.nr_of_rows();
return;
}
if (verbose) {
verboseOutput() << "Minimize the given set of support hyperplanes by "
<< "computing the extreme rays of the dual cone" << endl;
}
Full_Cone<Integer> Dual(Support_Hyperplanes);
Dual.verbose = false; // verbose;
Dual.Support_Hyperplanes = Generators;
Dual.setComputed(ConeProperty::SupportHyperplanes);
Dual.do_extreme_rays = true;
Dual.compute_extreme_rays();
Support_Hyperplanes = Dual.Generators.submatrix(Dual.Extreme_Rays_Ind); // only essential hyperplanes
setComputed(ConeProperty::SupportHyperplanes);
nrSupport_Hyperplanes = Support_Hyperplanes.nr_of_rows();
do_all_hyperplanes = false;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_extreme_rays(bool use_facets) {
if (!do_extreme_rays)
return;
if (isComputed(ConeProperty::ExtremeRays))
return;
Extreme_Rays_Ind.resize(nr_gen);
assert(isComputed(ConeProperty::SupportHyperplanes));
check_pointed();
if (!pointed) {
throw NonpointedException();
}
if (dim * Support_Hyperplanes.nr_of_rows() < nr_gen) {
compute_extreme_rays_rank(use_facets);
}
else {
compute_extreme_rays_compare(use_facets);
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_extreme_rays_rank(bool use_facets) {
if (verbose)
verboseOutput() << "Select extreme rays via rank ... " << flush;
size_t i;
vector<key_t> gen_in_hyperplanes;
gen_in_hyperplanes.reserve(Support_Hyperplanes.nr_of_rows());
Matrix<Integer> M(Support_Hyperplanes.nr_of_rows(), dim);
deque<bool> Ext(nr_gen, false);
#pragma omp parallel for firstprivate(gen_in_hyperplanes, M)
for (i = 0; i < nr_gen; ++i) {
// if (isComputed(ConeProperty::Triangulation) && !in_triang[i])
// continue;
INTERRUPT_COMPUTATION_BY_EXCEPTION
gen_in_hyperplanes.clear();
if (use_facets) {
typename list<FACETDATA<Integer>>::const_iterator IHV = Facets.begin();
for (size_t j = 0; j < Support_Hyperplanes.nr_of_rows(); ++j, ++IHV) {
if (IHV->GenInHyp.test(i))
gen_in_hyperplanes.push_back(static_cast<key_t>(j));
}
}
else {
for (size_t j = 0; j < Support_Hyperplanes.nr_of_rows(); ++j) {
if (v_scalar_product(Generators[i], Support_Hyperplanes[j]) == 0)
gen_in_hyperplanes.push_back(static_cast<key_t>(j));
}
}
if (gen_in_hyperplanes.size() < dim - 1)
continue;
if (M.rank_submatrix(Support_Hyperplanes, gen_in_hyperplanes) >= dim - 1)
Ext[i] = true;
}
for (i = 0; i < nr_gen; ++i)
Extreme_Rays_Ind[i] = Ext[i];
setComputed(ConeProperty::ExtremeRays);
if (verbose)
verboseOutput() << "done." << endl;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_extreme_rays_compare(bool use_facets) {
if (verbose)
verboseOutput() << "Select extreme rays via comparison ... " << flush;
size_t i, j, k;
// Matrix<Integer> SH=getSupportHyperplanes().transpose();
// Matrix<Integer> Val=Generators.multiplication(SH);
size_t nc = Support_Hyperplanes.nr_of_rows();
vector<dynamic_bitset> Val(nr_gen);
for (i = 0; i < nr_gen; ++i)
Val[i].resize(nc);
// In this routine Val[i][j]==1, i.e. true, indicates that
// the i-th generator is contained in the j-th support hyperplane
vector<key_t> Zero(nc);
vector<key_t> nr_ones(nr_gen);
for (i = 0; i < nr_gen; i++) {
INTERRUPT_COMPUTATION_BY_EXCEPTION
k = 0;
Extreme_Rays_Ind[i] = true;
if (use_facets) {
typename list<FACETDATA<Integer>>::const_iterator IHV = Facets.begin();
for (j = 0; j < Support_Hyperplanes.nr_of_rows(); ++j, ++IHV) {
if (IHV->GenInHyp.test(i)) {
k++;
Val[i][j] = true;
}
else
Val[i][j] = false;
}
}
else {
for (j = 0; j < nc; ++j) {
if (v_scalar_product(Generators[i], Support_Hyperplanes[j]) == 0) {
k++;
Val[i][j] = true;
}
else
Val[i][j] = false;
}
}
nr_ones[i] = static_cast<key_t>(k);
if (k < dim - 1 || k == nc) // not contained in enough facets or in all (0 as generator)
Extreme_Rays_Ind[i] = false;
}
dynamic_bitset ERI = bool_to_bitset(Extreme_Rays_Ind);
maximal_subsets(Val, ERI);
Extreme_Rays_Ind = bitset_to_bool(ERI);
setComputed(ConeProperty::ExtremeRays);
if (verbose)
verboseOutput() << "done." << endl;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::compute_class_group() { // from the support hyperplanes
if (!do_class_group || !isComputed(ConeProperty::SupportHyperplanes) || isComputed(ConeProperty::ClassGroup) ||
descent_level != 0)
return;
Matrix<Integer> Trans = Support_Hyperplanes; // .transpose();
size_t rk;
Trans.SmithNormalForm(rk);
ClassGroup.push_back(static_cast<unsigned long>(Support_Hyperplanes.nr_of_rows() - rk));
for (size_t i = 0; i < rk; ++i)
if (Trans[i][i] != 1)
ClassGroup.push_back(Trans[i][i]);
setComputed(ConeProperty::ClassGroup);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::select_deg1_elements() { // from the Hilbert basis
if (inhomogeneous || descent_level > 0)
return;
for (const auto& h : Hilbert_Basis) {
if (v_scalar_product(Grading, h) == 1)
Deg1_Elements.push_back(h);
}
setComputed(ConeProperty::Deg1Elements, true);
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::subcone_contains(const vector<Integer>& v) {
for (size_t i = 0; i < Subcone_Support_Hyperplanes.nr_of_rows(); ++i)
if (v_scalar_product(Subcone_Support_Hyperplanes[i], v) < 0)
return false;
for (size_t i = 0; i < Subcone_Equations.nr_of_rows(); ++i)
if (v_scalar_product(Subcone_Equations[i], v) != 0)
return false;
if (is_global_approximation)
if (v_scalar_product(Subcone_Grading, v) != 1)
return false;
return true;
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::contains(const vector<Integer>& v) {
for (size_t i = 0; i < Support_Hyperplanes.nr_of_rows(); ++i)
if (v_scalar_product(Support_Hyperplanes[i], v) < 0)
return false;
return true;
}
//---------------------------------------------------------------------------
/*
template <typename Integer>
bool Full_Cone<Integer>::contains(const Full_Cone& C) {
for (size_t i = 0; i < C.nr_gen; ++i)
if (!contains(C.Generators[i])) {
cerr << "Missing generator " << C.Generators[i] << endl;
return (false);
}
return (true);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::select_deg1_elements(const Full_Cone& C) { // from vectors computed in
// the auxiliary cone C
assert(isComputed(ConeProperty::SupportHyperplanes));
assert(C.isComputed(ConeProperty::Deg1Elements));
for (const auto& h : C.Deg1_Elements) {
if (contains(h))
Deg1_Elements.push_back(h);
}
setComputed(ConeProperty::Deg1Elements, true);
}
*/
//---------------------------------------------------------------------------
// so far only for experiments
/*
template<typename Integer>
void Full_Cone<Integer>::select_Hilbert_Basis(const Full_Cone& C) { // from vectors computed in
// the auxiliary cone C
assert(isComputed(ConeProperty::SupportHyperplanes));
assert(C.isComputed(ConeProperty::Deg1Elements));
typename list<vector<Integer> >::const_iterator h = C.Hilbert_Basis.begin();
for(;h!=C.Hilbert_Basis.end();++h){
if(contains(*h))
// Deg1_Elements.push_back(*h);
cout << *h;
}
exit(0);
setComputed(ConeProperty::Deg1Elements,true);
}
*/
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::check_pointed() {
if (believe_pointed) { // sometimes we must cheat
pointed = true;
setComputed(ConeProperty::IsPointed);
return;
}
if (isComputed(ConeProperty::IsPointed))
return;
assert(isComputed(ConeProperty::SupportHyperplanes));
if (isComputed(ConeProperty::Grading)) {
pointed = true;
if (verbose)
verboseOutput() << "Pointed since graded" << endl;
setComputed(ConeProperty::IsPointed);
return;
}
if (verbose)
verboseOutput() << "Checking pointedness ... " << flush;
if (Support_Hyperplanes.nr_of_rows() <= dim * dim / 2) {
pointed = (Support_Hyperplanes.rank() == dim);
}
else {
vector<key_t> random_perm = random_key(Support_Hyperplanes.nr_of_rows());
pointed = (Support_Hyperplanes.max_rank_submatrix_lex().size() == dim);
}
setComputed(ConeProperty::IsPointed);
if (pointed && Grading.size() > 0) {
throw BadInputException("Grading not positive on pointed cone.");
}
if (verbose)
verboseOutput() << "done." << endl;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::disable_grading_dep_comp() {
if (do_multiplicity || do_deg1_elements || do_h_vector) {
if (do_default_mode) {
do_deg1_elements = false;
do_h_vector = false;
if (!explicit_full_triang) {
do_triangulation = false;
if (do_Hilbert_basis)
do_partial_triangulation = true;
}
}
else {
throw NotComputableException("No grading specified and cannot find one. Cannot compute some requested properties!");
}
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::deg1_check() {
if (inhomogeneous) // deg 1 check disabled since it makes no sense in this case
return;
if (!isComputed(ConeProperty::Grading) && Grading.size() == 0 // we still need it and
&& !isComputed(ConeProperty::IsDeg1ExtremeRays)) { // we have not tried it
if (isComputed(ConeProperty::ExtremeRays)) {
Matrix<Integer> Extreme = Generators.submatrix(Extreme_Rays_Ind);
if (has_generator_with_common_divisor)
Extreme.make_prime();
try {
Grading = Extreme.find_linear_form();
} catch (const ArithmeticException& e) { // if the exception has been thrown, the grading has
Grading.resize(0); // we consider the grafing as non existing -- though this may not be true
if (verbose)
verboseOutput() << "Giving up the check for a grading" << endl;
}
if (Grading.size() == dim && v_scalar_product(Grading, Extreme[0]) == 1) {
setComputed(ConeProperty::Grading);
}
else {
deg1_extreme_rays = false;
Grading.clear();
setComputed(ConeProperty::IsDeg1ExtremeRays);
}
}
else // extreme rays not known
if (!deg1_generated_computed) {
Matrix<Integer> GenCopy = Generators;
if (has_generator_with_common_divisor)
GenCopy.make_prime();
try {
Grading = GenCopy.find_linear_form();
} catch (const ArithmeticException& e) { // if the exception has been thrown,
Grading.resize(0); // we consider the grafing as non existing-- though this may not be true
if (verbose)
verboseOutput() << "Giving up the check for a grading" << endl;
}
if (Grading.size() == dim && v_scalar_product(Grading, GenCopy[0]) == 1) {
setComputed(ConeProperty::Grading);
}
else {
deg1_generated = false;
deg1_generated_computed = true;
Grading.clear();
}
}
}
// now we hopefully have a grading
if (!isComputed(ConeProperty::Grading)) {
if (isComputed(ConeProperty::ExtremeRays)) {
// there is no hope to find a grading later
deg1_generated = false;
deg1_generated_computed = true;
deg1_extreme_rays = false;
setComputed(ConeProperty::IsDeg1ExtremeRays);
disable_grading_dep_comp();
}
return; // we are done
}
set_degrees();
vector<Integer> divided_gen_degrees = gen_degrees;
if (has_generator_with_common_divisor) {
Matrix<Integer> GenCopy = Generators;
GenCopy.make_prime();
convert(divided_gen_degrees, GenCopy.MxV(Grading));
}
if (!deg1_generated_computed) {
deg1_generated = true;
for (size_t i = 0; i < nr_gen; i++) {
if (divided_gen_degrees[i] != 1) {
deg1_generated = false;
break;
}
}
deg1_generated_computed = true;
if (deg1_generated) {
deg1_extreme_rays = true;
setComputed(ConeProperty::IsDeg1ExtremeRays);
}
}
if (!isComputed(ConeProperty::IsDeg1ExtremeRays) && isComputed(ConeProperty::ExtremeRays)) {
deg1_extreme_rays = true;
for (size_t i = 0; i < nr_gen; i++) {
if (Extreme_Rays_Ind[i] && divided_gen_degrees[i] != 1) {
deg1_extreme_rays = false;
break;
}
}
setComputed(ConeProperty::IsDeg1ExtremeRays);
}
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::check_deg1_hilbert_basis() {
if (isComputed(ConeProperty::IsDeg1HilbertBasis) || inhomogeneous || descent_level > 0)
return;
if (!isComputed(ConeProperty::Grading) || !isComputed(ConeProperty::HilbertBasis)) {
if (verbose) {
errorOutput() << "WARNING: unsatisfied preconditions in check_deg1_hilbert_basis()!" << endl;
}
return;
}
if (isComputed(ConeProperty::Deg1Elements)) {
deg1_hilbert_basis = (Deg1_Elements.size() == Hilbert_Basis.size());
}
else {
deg1_hilbert_basis = true;
for (const auto& h : Hilbert_Basis) {
if (v_scalar_product(h, Grading) != 1) {
deg1_hilbert_basis = false;
break;
}
}
}
setComputed(ConeProperty::IsDeg1HilbertBasis);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::prepare_inclusion_exclusion() {
if (ExcludedFaces.nr_of_rows() == 0)
return;
do_excluded_faces = do_h_vector || do_Stanley_dec || check_semiopen_empty;
if ((isComputed(ConeProperty::ExcludedFaces) && isComputed(ConeProperty::InclusionExclusionData)) || !do_excluded_faces) {
return;
}
if (verbose)
verboseOutput() << "Computing inclusion/excluseion data" << endl;
// indicates which generators lie in the excluded faces
vector<dynamic_bitset> GensInExcl(ExcludedFaces.nr_of_rows());
index_covering_face = ExcludedFaces.nr_of_rows(); // if not changed: not covered by an exc luded face
for (size_t j = 0; j < ExcludedFaces.nr_of_rows(); ++j) {
bool empty_semiopen = true;
GensInExcl[j].resize(nr_gen);
for (size_t i = 0; i < nr_gen; ++i) {
Integer test = v_scalar_product(ExcludedFaces[j], Generators[i]);
if (test == 0) {
GensInExcl[j].set(i);
continue;
}
empty_semiopen = false;
}
if (empty_semiopen) { // not impossible if the hyperplane contains the vector space spanned by the cone
if (!check_semiopen_empty || do_h_vector || do_Stanley_dec)
throw BadInputException("An Excluded face covers the polyhedron. Not allowed unless ONLY checking emptyness.");
empty_semiopen = true;
index_covering_face = j;
setComputed(ConeProperty::IsEmptySemiOpen);
setComputed(ConeProperty::ExcludedFaces);
return;
}
}
if (check_semiopen_empty) {
setComputed(ConeProperty::IsEmptySemiOpen);
}
vector<bool> essential(ExcludedFaces.nr_of_rows(), true);
bool remove_one = false;
for (size_t i = 0; i < essential.size(); ++i)
for (size_t j = i + 1; j < essential.size(); ++j) {
if (GensInExcl[j].is_subset_of(GensInExcl[i])) {
essential[j] = false;
remove_one = true;
continue;
}
if (GensInExcl[i].is_subset_of(GensInExcl[j])) {
essential[i] = false;
remove_one = true;
}
}
if (remove_one) {
Matrix<Integer> Help(0, dim);
vector<dynamic_bitset> HelpGensInExcl;
for (size_t i = 0; i < essential.size(); ++i)
if (essential[i]) {
Help.append(ExcludedFaces[i]);
HelpGensInExcl.push_back(GensInExcl[i]);
}
ExcludedFaces = Help;
GensInExcl = HelpGensInExcl;
}
setComputed(ConeProperty::ExcludedFaces);
if (isComputed(ConeProperty::InclusionExclusionData) || !do_excluded_faces) {
return;
}
vector<pair<dynamic_bitset, long>> InExScheme; // now we produce the formal
dynamic_bitset all_gens(nr_gen); // inclusion-exclusion scheme
all_gens.set(); // by forming all intersections of
// excluded faces
InExScheme.push_back(pair<dynamic_bitset, long>(all_gens, 1));
size_t old_size = 1;
for (size_t i = 0; i < ExcludedFaces.nr_of_rows(); ++i) {
for (size_t j = 0; j < old_size; ++j)
InExScheme.push_back(pair<dynamic_bitset, long>(InExScheme[j].first & GensInExcl[i], -InExScheme[j].second));
old_size *= 2;
}
InExScheme.erase(InExScheme.begin()); // remove full cone
// map<dynamic_bitset, long> InExCollect;
InExCollect.clear();
for (size_t i = 0; i < old_size - 1; ++i) { // we compactify the list of faces
auto F = InExCollect.find(InExScheme[i].first); // obtained as intersections
if (F != InExCollect.end()) // by listing each face only once
F->second += InExScheme[i].second; // but with the right multiplicity
else
InExCollect.insert(InExScheme[i]);
}
for (auto F = InExCollect.begin(); F != InExCollect.end();) { // faces with multiplicity 0
if (F->second == 0) // can be erased
InExCollect.erase(F++);
else {
++F;
}
}
if (verbose) {
verboseOutput() << endl;
verboseOutput() << "InEx complete, " << InExCollect.size() << " faces involved" << endl;
}
setComputed(ConeProperty::InclusionExclusionData);
}
//---------------------------------------------------------------------------
/*
template <typename Integer>
bool Full_Cone<Integer>::check_extension_to_god_father() {
assert(dim == God_Father->dim);
vector<Integer> test(dim);
for (size_t k = 0; k < Automs.LinMaps.size(); ++k) {
for (size_t i = 0; i < God_Father->nr_gen; ++i) {
test = Automs.LinMaps[k].MxV(God_Father->Generators[i]);
if (God_Father->Generator_Set.find(test) == God_Father->Generator_Set.end())
return false;
}
}
return true;
}
*/
//---------------------------------------------------------------------------
/* computes a degree function, s.t. every generator has value >0 */
template <typename Integer>
vector<Integer> Full_Cone<Integer>::compute_degree_function() const {
size_t i;
vector<Integer> degree_function(dim, 0);
if (isComputed(ConeProperty::Grading)) { // use the grading if we have one
for (i = 0; i < dim; i++) {
degree_function[i] = Grading[i];
}
}
else { // add hyperplanes to get a degree function
if (verbose) {
verboseOutput() << "computing degree function... " << flush;
}
size_t h;
for (h = 0; h < Support_Hyperplanes.nr_of_rows(); ++h) {
for (i = 0; i < dim; i++) {
degree_function[i] += Support_Hyperplanes.get_elem(h, i);
}
}
v_make_prime(degree_function);
if (verbose) {
verboseOutput() << "done." << endl;
}
}
return degree_function;
}
//---------------------------------------------------------------------------
/* adds generators, they have to lie inside the existing cone */
template <typename Integer>
void Full_Cone<Integer>::add_generators(const Matrix<Integer>& new_points) {
is_simplicial = false;
size_t nr_new_points = new_points.nr_of_rows();
size_t nr_old_gen = nr_gen;
Generators.append(new_points);
nr_gen += nr_new_points;
set_degrees();
Top_Key.resize(nr_gen);
Extreme_Rays_Ind.resize(nr_gen);
for (size_t i = nr_old_gen; i < nr_gen; ++i) {
Top_Key[i] = static_cast<key_t>(i);
Extreme_Rays_Ind[i] = false;
}
// inhom cones
if (inhomogeneous) {
set_levels();
}
// excluded faces have to be reinitialized
setComputed(ConeProperty::ExcludedFaces, false);
setComputed(ConeProperty::InclusionExclusionData, false);
prepare_inclusion_exclusion();
if (do_Hilbert_basis) {
// add new points to HilbertBasis
for (size_t i = nr_old_gen; i < nr_gen; ++i) {
if (!inhomogeneous || gen_levels[i] <= 1) {
NewCandidates.reduce_by_and_insert(Generators[i], *this, OldCandidates);
NewCandidates.Candidates.back().original_generator = true;
}
}
// OldCandidates.auto_reduce();
}
}
//---------------------------------------------------------------------------
// Constructors
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::reset_tasks() {
do_triangulation_size = false;
do_determinants = false;
do_multiplicity = false;
do_integrally_closed = false;
do_Hilbert_basis = false;
do_deg1_elements = false;
keep_triangulation = false;
allow_simplex_dec = true;
pulling_triangulation = false;
keep_triangulation_bitsets = false;
do_Stanley_dec = false;
do_h_vector = false;
do_hsop = false;
do_excluded_faces = false;
do_approximation = false;
do_default_mode = false;
do_class_group = false;
do_module_gens_intcl = false;
do_module_rank = false;
do_cone_dec = false;
do_extreme_rays = false;
do_pointed = false;
do_all_hyperplanes = true;
do_supphyps_dynamic = false;
no_subdivision = false;
allow_simplex_dec = true;
check_semiopen_empty = false;
do_bottom_dec = false;
suppress_bottom_dec = false;
keep_order = false;
nrSimplicialPyr = 0;
totalNrPyr = 0;
is_pyramid = false;
exploit_automs_vectors = false;
exploit_automs_mult = false;
do_automorphisms = false;
autom_codim_vectors = -1;
autom_codim_mult = -1;
use_existing_facets = false;
triangulation_is_nested = false;
triangulation_is_partial = false;
hilbert_basis_rec_cone_known = false;
time_measured = false;
keep_convex_hull_data = false;
do_multiplicity_by_signed_dec = false;
do_integral_by_signed_dec = false;
do_signed_dec = false;
do_virtual_multiplicity_by_signed_dec = false;
do_pure_triang = false;
believe_pointed = false;
include_dualization = false;
pyramids_for_last_built_directly = false;
}
//---------------------------------------------------------------------------
template <typename Integer>
Full_Cone<Integer>::Full_Cone() {
reset_tasks();
}
template <typename Integer>
Full_Cone<Integer>::Full_Cone(const Matrix<Integer>& M, bool do_make_prime) { // constructor of the top cone
omp_start_level = omp_get_level();
dim = M.nr_of_columns();
if (dim > 0)
Generators = M;
/* cout << "------------------" << endl;
cout << "dim " << dim << endl;
M.pretty_print(cout);
// cout << "------------------" << endl;
// M.transpose().pretty_print(cout);
cout << "==================" << endl;*/
// assert(M.row_echelon()== dim); rank check now done later
/*index=1; // not used at present
for(size_t i=0;i<dim;++i)
index*=M[i][i];
index=Iabs(index); */
// make the generators coprime, remove 0 rows and duplicates
has_generator_with_common_divisor = false;
if (do_make_prime) {
Generators.make_prime();
}
else {
nr_gen = Generators.nr_of_rows();
for (size_t i = 0; i < nr_gen; ++i) {
if (v_gcd(Generators[i]) != 1) {
has_generator_with_common_divisor = true;
break;
}
}
}
Generators.remove_duplicate_and_zero_rows();
nr_gen = Generators.nr_of_rows();
if (nr_gen != static_cast<size_t>(static_cast<key_t>(nr_gen))) {
throw FatalException("Too many generators to fit in range of key_t!");
}
multiplicity = 0;
#ifdef ENFNORMALIZ
renf_multiplicity = 0;
#endif
is_Computed = bitset<ConeProperty::EnumSize>(); // initialized to false
setComputed(ConeProperty::Generators);
pointed = false;
is_simplicial = nr_gen == dim;
deg1_extreme_rays = false;
deg1_generated = false;
deg1_generated_computed = false;
deg1_hilbert_basis = false;
reset_tasks();
Extreme_Rays_Ind = vector<bool>(nr_gen, false); // now in compute_extreme_eays
// in_triang = vector<bool> (nr_gen,false); // now in build_cone
deg1_triangulation = true;
/*
if(dim==0){ //correction needed to include the 0 cone;
multiplicity = 1;
#ifdef ENFNORMALIZ
renf_multiplicity=1;
#endif
Hilbert_Series.add(vector<num_t>(1,1),vector<denom_t>());
setComputed(ConeProperty::HilbertSeries);
setComputed(ConeProperty::Triangulation);
}
*/
pyr_level = -1;
descent_level = 0;
Top_Cone = this;
God_Father = this;
Top_Key.resize(nr_gen);
for (size_t i = 0; i < nr_gen; i++)
Top_Key[i] = static_cast<key_t>(i);
totalNrSimplices = 0;
TriangulationBufferSize = 0;
CandidatesSize = 0;
detSum = 0;
shift = 0;
decimal_digits = -1;
block_size_hollow_tri = -1;
FS.resize(omp_get_max_threads());
Pyramids.resize(20); // prepare storage for pyramids
nrPyramids.resize(20, 0);
Pyramids_scrambled.resize(20, false);
subpyramids_allowed = true;
// nextGen=0;
store_level = 0;
Comparisons.reserve(nr_gen);
nrTotalComparisons = 0;
inhomogeneous = false;
level0_dim = dim; // must always be defined
start_from = 0;
old_nr_supp_hyps = 0;
verbose = false;
OldCandidates.dual = false;
OldCandidates.verbose = verbose;
NewCandidates.dual = false;
NewCandidates.verbose = verbose;
RankTest = vector<Matrix<Integer>>(omp_get_max_threads(), Matrix<Integer>(0, dim));
RankTest_float = vector<Matrix<nmz_float>>(omp_get_max_threads(), Matrix<nmz_float>(0, dim));
UnitMat = Matrix<Integer>(dim);
WorkMat = vector<Matrix<Integer>>(omp_get_max_threads(), Matrix<Integer>(dim, 2 * dim));
is_global_approximation = false;
PermGens.resize(nr_gen);
for (size_t i = 0; i < nr_gen; ++i)
PermGens[i] = static_cast<key_t>(i);
Mother = &(*this);
don_t_add_hyperplanes = false;
take_time_of_large_pyr = false;
renf_degree = 2; // default value to prevent disasters
}
//---------------------------------------------------------------------------
// converts a Cone_Dual_Mode into a Full_Cone
template <typename Integer>
Full_Cone<Integer>::Full_Cone(Cone_Dual_Mode<Integer>& C) {
omp_start_level = omp_get_level();
is_Computed = bitset<ConeProperty::EnumSize>(); // initialized to false
dim = C.dim;
Generators.swap(C.Generators);
InputGenerators = Generators;
nr_gen = Generators.nr_of_rows();
if (Generators.nr_of_rows() > 0)
setComputed(ConeProperty::Generators);
has_generator_with_common_divisor = false;
Extreme_Rays_Ind.swap(C.ExtremeRaysInd);
if (!Extreme_Rays_Ind.empty())
setComputed(ConeProperty::ExtremeRays);
multiplicity = 0;
#ifdef ENFNORMALIZ
renf_multiplicity = 0;
#endif
in_triang = vector<bool>(nr_gen, false);
Basis_Max_Subspace = C.BasisMaxSubspace;
setComputed(ConeProperty::MaximalSubspace);
pointed = (Basis_Max_Subspace.nr_of_rows() == 0);
setComputed(ConeProperty::IsPointed);
is_simplicial = nr_gen == dim;
deg1_extreme_rays = false;
deg1_generated = false;
deg1_generated_computed = false;
deg1_triangulation = false;
deg1_hilbert_basis = false;
reset_tasks();
if (!Extreme_Rays_Ind.empty()) { // only then we can assume that all entries on C.Supp.. are relevant
Support_Hyperplanes.swap(C.SupportHyperplanes);
// there may be duplicates in the coordinates of the Full_Cone
Support_Hyperplanes.remove_duplicate_and_zero_rows();
setComputed(ConeProperty::SupportHyperplanes);
}
if (!C.do_only_Deg1_Elements) {
Hilbert_Basis.swap(C.Hilbert_Basis);
setComputed(ConeProperty::HilbertBasis);
}
else {
Deg1_Elements.swap(C.Hilbert_Basis);
setComputed(ConeProperty::Deg1Elements);
}
if (dim == 0) { // correction needed to include the 0 cone;
multiplicity = 1;
#ifdef ENFNORMALIZ
renf_multiplicity = 1;
#endif
Hilbert_Series.add(vector<num_t>(1, 1), vector<denom_t>());
setComputed(ConeProperty::HilbertSeries);
}
pyr_level = -1;
Top_Cone = this;
// God_Father = this;
Top_Key.resize(nr_gen);
for (size_t i = 0; i < nr_gen; i++)
Top_Key[i] = static_cast<key_t>(i);
totalNrSimplices = 0;
TriangulationBufferSize = 0;
CandidatesSize = 0;
detSum = 0;
shift = 0;
tri_recursion = false;
// nextGen=0;
inhomogeneous = C.inhomogeneous;
level0_dim = dim; // must always be defined
use_existing_facets = false;
start_from = 0;
old_nr_supp_hyps = 0;
verbose = C.verbose;
OldCandidates.dual = false;
OldCandidates.verbose = verbose;
NewCandidates.dual = false;
NewCandidates.verbose = verbose;
descent_level = 0;
// approx_level = 1; ???? Noch gebraucht ???
don_t_add_hyperplanes = false;
take_time_of_large_pyr = false;
verbose = C.verbose;
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::check_grading_after_dual_mode() {
if (dim > 0 && Grading.size() > 0 && !isComputed(ConeProperty::Grading)) {
if (isComputed(ConeProperty::Generators)) {
vector<Integer> degrees = Generators.MxV(Grading);
vector<Integer> levels;
if (inhomogeneous)
levels = Generators.MxV(Truncation);
size_t i = 0;
for (; i < degrees.size(); ++i) {
if (degrees[i] <= 0 && (!inhomogeneous || levels[i] == 0))
break;
}
if (i == degrees.size())
setComputed(ConeProperty::Grading);
}
else if (isComputed(ConeProperty::HilbertBasis)) {
auto hb = Hilbert_Basis.begin();
for (; hb != Hilbert_Basis.end(); ++hb) {
if (v_scalar_product(*hb, Grading) <= 0 && (!inhomogeneous || v_scalar_product(*hb, Truncation) == 0))
break;
}
if (hb == Hilbert_Basis.end())
setComputed(ConeProperty::Grading);
}
}
if (isComputed(ConeProperty::Deg1Elements)) {
auto hb = Deg1_Elements.begin();
for (; hb != Deg1_Elements.end(); ++hb) {
if (v_scalar_product(*hb, Grading) <= 0)
break;
}
if (hb == Deg1_Elements.end())
setComputed(ConeProperty::Grading);
}
if (Grading.size() > 0 && !isComputed(ConeProperty::Grading)) {
throw BadInputException("Grading not positive on pointed cone.");
}
}
template <typename Integer>
void Full_Cone<Integer>::dual_mode() {
omp_start_level = omp_get_level();
if (dim == 0) {
set_zero_cone();
return;
}
use_existing_facets = false; // completely irrelevant here
start_from = 0;
old_nr_supp_hyps = 0;
INTERRUPT_COMPUTATION_BY_EXCEPTION
compute_class_group();
check_grading_after_dual_mode();
compute_automorphisms();
if (dim > 0 && !inhomogeneous) {
deg1_check();
if (isComputed(ConeProperty::Grading) && !isComputed(ConeProperty::Deg1Elements)) {
if (verbose) {
verboseOutput() << "Find degree 1 elements" << endl;
}
select_deg1_elements();
}
}
if (!inhomogeneous && isComputed(ConeProperty::HilbertBasis)) {
if (isComputed(ConeProperty::Grading))
check_deg1_hilbert_basis();
}
if (inhomogeneous && isComputed(ConeProperty::Generators)) {
set_levels();
find_level0_dim();
find_module_rank();
}
if (inhomogeneous && !isComputed(ConeProperty::Generators) && isComputed(ConeProperty::HilbertBasis)) {
find_level0_dim_from_HB();
find_module_rank();
}
use_existing_facets = false;
start_from = 0;
}
//---------------------------------------------------------------------------
/* constructor for pyramids */
template <typename Integer>
Full_Cone<Integer>::Full_Cone(Full_Cone<Integer>& C, const vector<key_t>& Key) {
omp_start_level = C.omp_start_level;
Generators = C.Generators.submatrix(Key);
if (using_renf<Integer>() && C.Generators_float.nr_of_rows() > 0)
Generators_float = C.Generators_float.submatrix(Key);
dim = Generators.nr_of_columns();
nr_gen = Generators.nr_of_rows();
has_generator_with_common_divisor = C.has_generator_with_common_divisor;
is_simplicial = nr_gen == dim;
Top_Cone = C.Top_Cone; // relate to top cone
// C.God_Father = C.God_Father;
Top_Key.resize(nr_gen);
for (size_t i = 0; i < nr_gen; i++)
Top_Key[i] = C.Top_Key[Key[i]];
multiplicity = 0;
#ifdef ENFNORMALIZ
renf_multiplicity = 0;
#endif
Extreme_Rays_Ind = vector<bool>(nr_gen, false);
setComputed(ConeProperty::ExtremeRays, C.isComputed(ConeProperty::ExtremeRays));
if (isComputed(ConeProperty::ExtremeRays))
for (size_t i = 0; i < nr_gen; i++)
Extreme_Rays_Ind[i] = C.Extreme_Rays_Ind[Key[i]];
// in_triang = vector<bool> (nr_gen,false); // now in build_cone
deg1_triangulation = true;
Grading = C.Grading;
setComputed(ConeProperty::Grading, C.isComputed(ConeProperty::Grading));
Order_Vector = C.Order_Vector;
// Note: For the computation of pyramids we do not call primal_algorithm.
// Therefore it is necessary to set do_triangulation etc. here (and not only
// the computation goals).
do_triangulation = C.do_triangulation;
do_partial_triangulation = C.do_partial_triangulation;
do_only_multiplicity = C.do_only_multiplicity;
stop_after_cone_dec = C.stop_after_cone_dec;
// now the computation goals
do_extreme_rays = false;
do_triangulation_size = C.do_triangulation_size;
do_determinants = C.do_determinants;
do_multiplicity = C.do_multiplicity;
do_deg1_elements = C.do_deg1_elements;
do_h_vector = C.do_h_vector;
do_Hilbert_basis = C.do_Hilbert_basis;
keep_triangulation = C.keep_triangulation;
keep_triangulation_bitsets = C.keep_triangulation_bitsets;
do_pure_triang = C.do_pure_triang;
do_evaluation = C.do_evaluation;
do_Stanley_dec = C.do_Stanley_dec;
do_bottom_dec = false;
keep_order = true;
do_all_hyperplanes = true; // must be reset for non-recursive pyramids
use_existing_facets = false;
do_supphyps_dynamic = false;
pulling_triangulation = false;
no_subdivision = C.no_subdivision;
allow_simplex_dec = C.allow_simplex_dec;
pyramids_for_last_built_directly = false;
// not used in a pyramid, but set for precaution
deg1_extreme_rays = false;
deg1_generated = false;
deg1_generated_computed = false;
deg1_hilbert_basis = false;
inhomogeneous = C.inhomogeneous; // at present not used in proper pyramids
is_pyramid = true;
pyr_level = C.pyr_level + 1;
descent_level = 0; // should never be used in pyramids
store_level = C.store_level;
totalNrSimplices = 0;
detSum = 0;
multiplicity = 0;
shift = C.shift;
level0_dim = C.level0_dim; // must always be defined
if (C.gen_degrees.size() > 0) { // now we copy the degrees
gen_degrees.resize(nr_gen);
if (C.do_h_vector || (!using_GMP<Integer>() && !using_renf<Integer>()))
gen_degrees_long.resize(nr_gen);
for (size_t i = 0; i < nr_gen; i++) {
gen_degrees[i] = C.gen_degrees[Key[i]];
if (C.do_h_vector || (!using_GMP<Integer>() && !using_renf<Integer>()))
gen_degrees_long[i] = C.gen_degrees_long[Key[i]];
}
}
if (C.gen_levels.size() > 0) { // now we copy the levels
gen_levels.resize(nr_gen);
for (size_t i = 0; i < nr_gen; i++) {
gen_levels[i] = C.gen_levels[Key[i]];
}
}
TriangulationBufferSize = 0; // not used in pyramids
CandidatesSize = 0; // ditto
subpyramids_allowed = C.subpyramids_allowed; // must be reset if necessary
// multithreaded_pyramid=false; // SEE ABOVE
Comparisons.reserve(nr_gen);
nrTotalComparisons = 0;
start_from = 0;
old_nr_supp_hyps = 0;
verbose = false;
OldCandidates.dual = false;
OldCandidates.verbose = verbose;
NewCandidates.dual = false;
NewCandidates.verbose = verbose;
is_global_approximation = C.is_global_approximation;
do_bottom_dec = false;
suppress_bottom_dec = false;
keep_order = true;
keep_convex_hull_data = false;
time_measured = C.time_measured;
ticks_comp_per_supphyp = C.ticks_comp_per_supphyp;
ticks_rank_per_row = C.ticks_rank_per_row;
don_t_add_hyperplanes = false;
take_time_of_large_pyr = false;
renf_degree = C.renf_degree;
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::isComputed(ConeProperty::Enum prop) const {
return is_Computed.test(prop);
}
template <typename Integer>
void Full_Cone<Integer>::setComputed(ConeProperty::Enum prop) {
is_Computed.set(prop);
}
template <typename Integer>
void Full_Cone<Integer>::setComputed(ConeProperty::Enum prop, bool value) {
is_Computed.set(prop, value);
}
//---------------------------------------------------------------------------
// Data access
//---------------------------------------------------------------------------
template <typename Integer>
size_t Full_Cone<Integer>::getDimension() const {
return dim;
}
//---------------------------------------------------------------------------
template <typename Integer>
size_t Full_Cone<Integer>::getNrGenerators() const {
return nr_gen;
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::isPointed() const {
return pointed;
}
//---------------------------------------------------------------------------
template <typename Integer>
bool Full_Cone<Integer>::isDeg1ExtremeRays() const {
return deg1_extreme_rays;
}
template <typename Integer>
bool Full_Cone<Integer>::isDeg1HilbertBasis() const {
return deg1_hilbert_basis;
}
//---------------------------------------------------------------------------
template <typename Integer>
vector<Integer> Full_Cone<Integer>::getGrading() const {
return Grading;
}
//---------------------------------------------------------------------------
template <typename Integer>
mpq_class Full_Cone<Integer>::getMultiplicity() const {
return multiplicity;
}
//---------------------------------------------------------------------------
template <typename Integer>
Integer Full_Cone<Integer>::getShift() const {
return shift;
}
//---------------------------------------------------------------------------
template <typename Integer>
size_t Full_Cone<Integer>::getModuleRank() const {
return module_rank;
}
//---------------------------------------------------------------------------
template <typename Integer>
const Matrix<Integer>& Full_Cone<Integer>::getInputGenerators() const {
return InputGenerators;
}
//---------------------------------------------------------------------------
template <typename Integer>
const Matrix<Integer>& Full_Cone<Integer>::getAllGenerators() const {
return Generators;
}
//---------------------------------------------------------------------------
template <typename Integer>
vector<bool> Full_Cone<Integer>::getExtremeRays() const {
vector<bool> ext = Extreme_Rays_Ind;
ext.resize(InputGenerators.nr_of_rows());
return ext;
}
//---------------------------------------------------------------------------
template <typename Integer>
size_t Full_Cone<Integer>::getNrExtremeRays() const {
size_t n = 0;
for (size_t j = 0; j < nr_gen; ++j)
if (Extreme_Rays_Ind[j])
++n;
return n;
}
//---------------------------------------------------------------------------
template <typename Integer>
Matrix<Integer> Full_Cone<Integer>::getSupportHyperplanes() const {
return Support_Hyperplanes;
}
//---------------------------------------------------------------------------
template <typename Integer>
Matrix<Integer> Full_Cone<Integer>::getHilbertBasis() const {
if (Hilbert_Basis.empty())
return Matrix<Integer>(0, dim);
else
return Matrix<Integer>(Hilbert_Basis);
}
//---------------------------------------------------------------------------
template <typename Integer>
Matrix<Integer> Full_Cone<Integer>::getModuleGeneratorsOverOriginalMonoid() const {
if (ModuleGeneratorsOverOriginalMonoid.empty())
return Matrix<Integer>(0, dim);
else
return Matrix<Integer>(ModuleGeneratorsOverOriginalMonoid);
}
//---------------------------------------------------------------------------
template <typename Integer>
Matrix<Integer> Full_Cone<Integer>::getDeg1Elements() const {
if (Deg1_Elements.empty())
return Matrix<Integer>(0, dim);
else
return Matrix<Integer>(Deg1_Elements);
}
//---------------------------------------------------------------------------
template <typename Integer>
Matrix<Integer> Full_Cone<Integer>::getExcludedFaces() const {
return (ExcludedFaces);
}
//---------------------------------------------------------------------------
template <typename Integer>
void Full_Cone<Integer>::error_msg(string s) const {
errorOutput() << "\nFull Cone " << s << "\n";
}
//---------------------------------------------------------------------------
/*
template <typename Integer>
void Full_Cone<Integer>::print() const {
verboseOutput() << "\ndim=" << dim << ".\n";
verboseOutput() << "\nnr_gen=" << nr_gen << ".\n";
// verboseOutput()<<"\nhyp_size="<<hyp_size<<".\n";
verboseOutput() << "\nGrading is:\n";
verboseOutput() << Grading;
verboseOutput() << "\nMultiplicity is " << multiplicity << ".\n";
verboseOutput() << "\nGenerators are:\n";
Generators.pretty_print(verboseOutput());
verboseOutput() << "\nExtreme_rays are:\n";
verboseOutput() << Extreme_Rays_Ind;
verboseOutput() << "\nSupport Hyperplanes are:\n";
Support_Hyperplanes.pretty_print(verboseOutput());
verboseOutput() << "\nHilbert basis is:\n";
verboseOutput() << Hilbert_Basis;
verboseOutput() << "\nDeg1 elements are:\n";
verboseOutput() << Deg1_Elements;
verboseOutput() << "\nHilbert Series is:\n";
verboseOutput() << Hilbert_Series;
}
*/
#ifndef NMZ_MIC_OFFLOAD // offload with long is not supported
template class Full_Cone<long>;
#endif
template class Full_Cone<long long>;
template class Full_Cone<mpz_class>;
#ifdef ENFNORMALIZ
template class Full_Cone<renf_elem_class>;
#endif
} // namespace libnormaliz
/*
//---------------------------------------------------------------------------
// version with isomorphism classes -- has no real effect
template<typename Integer>
void Full_Cone<Integer>::get_cone_over_facet_HB(const vector<Integer>& fixed_point, const vector<key_t>& facet_key,
const key_t facet_nr, list<vector<Integer> >& Facet_HB){
Matrix<Integer> Facet_Gens(0,dim);
Facet_Gens.append(fixed_point);
Facet_Gens.append(Generators.submatrix(facet_key));
for(long i=0;i<descent_level+1;++i)
cout << "$$$$$$ ";
cout << " " << Facet_Gens.nr_of_rows() << endl;
cout << "Height FP over facet " << v_scalar_product(fixed_point,Support_Hyperplanes[facet_nr]) << endl;
Full_Cone ConeOverFacet(Facet_Gens);
ConeOverFacet.verbose=verbose;
if(isComputed(ConeProperty::Grading)){
ConeOverFacet.Grading=Grading;
ConeOverFacet.setComputed(ConeProperty::Grading);
}
ConeOverFacet.descent_level=descent_level+1;
ConeOverFacet.Mother=&(*this);
ConeOverFacet.God_Father=God_Father;
ConeOverFacet.exploit_automorphisms=true;
ConeOverFacet.full_automorphisms=full_automorphisms;
ConeOverFacet.ambient_automorphisms=ambient_automorphisms;
ConeOverFacet.input_automorphisms=input_automorphisms;
ConeOverFacet.Embedding=Embedding;
ConeOverFacet.keep_order=true;
ConeOverFacet.Support_Hyperplanes=push_supphyps_to_cone_over_facet(fixed_point,facet_nr);
// ConeOverFacet.do_Hilbert_basis=true;
ConeOverFacet.compute();
if(ConeOverFacet.isComputed(ConeProperty::HilbertBasis)){
Facet_HB.splice(Facet_HB.begin(),ConeOverFacet.Hilbert_Basis);
return;
}
bool found;
const IsoType<Integer>& face_class=God_Father->FaceClasses.find_type(ConeOverFacet,found);
if(found){
ConeOverFacet.import_HB_from(face_class);
Facet_HB.clear();
Facet_HB.splice(Facet_HB.begin(),ConeOverFacet.Hilbert_Basis);
if(ConeOverFacet.isComputed(ConeProperty::HilbertBasis))
return;
}
Full_Cone Facet_2(Facet_Gens);
Facet_2.Automs=ConeOverFacet.Automs;
Facet_2.setComputed(ConeProperty::Automorphisms);
Facet_2.Embedding=Embedding;
Facet_2.full_automorphisms=full_automorphisms;
Facet_2.ambient_automorphisms=ambient_automorphisms;
Facet_2.input_automorphisms=input_automorphisms;
Facet_2.exploit_automorphisms=true;
Facet_2.keep_order=true;
Facet_2.Extreme_Rays_Ind=ConeOverFacet.Extreme_Rays_Ind;
Facet_2.setComputed(ConeProperty::ExtremeRays);
Facet_2.Support_Hyperplanes=ConeOverFacet.Support_Hyperplanes;
Facet_2.nrSupport_Hyperplanes=ConeOverFacet.nrSupport_Hyperplanes;
Facet_2.setComputed(ConeProperty::SupportHyperplanes);
Facet_2.verbose=verbose;
Facet_2.descent_level=descent_level+1;
Facet_2.full_automorphisms=full_automorphisms;
Facet_2.ambient_automorphisms=ambient_automorphisms;
Facet_2.input_automorphisms=input_automorphisms;
if(isComputed(ConeProperty::Grading)){
Facet_2.Grading=Grading;
Facet_2.setComputed(ConeProperty::Grading);
}
Facet_2.Mother=&(*this);
Facet_2.God_Father=God_Father;
Facet_2.do_Hilbert_basis=true;
Facet_2.compute();
bool added;
God_Father->FaceClasses.add_type(Facet_2, added);
Facet_HB.clear();
Facet_HB.splice(Facet_HB.begin(),Facet_2.Hilbert_Basis);
return;
}
*/
//---------------------------------------------------------------------------
/*
// not used at present
template<typename Integer>
void Full_Cone<Integer>::import_HB_from(const IsoType<Integer>& copy){
assert(isComputed(ConeProperty::Automorphisms));
size_t N=copy.getHilbertBasis().nr_of_rows();
if(N==0){
setComputed(ConeProperty::HilbertBasis);
return;
}
assert(Hilbert_Basis.empty());
for(size_t i=0;i<nr_gen;++i)
Hilbert_Basis.push_back(Generators[i]);
vector<key_t> CanBasisKey=Generators.max_rank_submatrix_lex(Automs.CanLabellingGens);
Matrix<Integer> Transform=copy.getCanTransform().multiplication(Generators.submatrix(CanBasisKey));
Integer D=Transform.matrix_gcd();
if(D!=copy.getCanDenom()) // not liftable
return;
Transform.scalar_division(D);
for(size_t i=0;i<N;++i){
Hilbert_Basis.push_back(Transform.VxM(copy.getHilbertBasis()[i]));
}
setComputed(ConeProperty::HilbertBasis);
return;
}
*/
|