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
|
/*
* Normaliz 2.7
* Copyright (C) 2007-2011 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 <http://www.gnu.org/licenses/>.
*
*/
//---------------------------------------------------------------------------
#include <stdlib.h>
#include <set>
#include <map>
#include <iostream>
#include <string>
#include <algorithm>
#include <time.h>
#include "full_cone.h"
#include "vector_operations.h"
#include "lineare_transformation.h"
#include "list_operations.h"
//---------------------------------------------------------------------------
namespace libnormaliz {
using namespace std;
//---------------------------------------------------------------------------
//private
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::add_hyperplane(const size_t& ind_gen, const FMDATA & positive,const FMDATA & negative){
size_t k;
// NEW: indgen is the index of the generator being inserted
// vector<Integer> hyperplane(hyp_size,0); // initialized with 0
FMDATA NewHypIndVal; NewHypIndVal.Hyp.resize(dim); NewHypIndVal.GenInHyp.resize(nr_gen);
Integer used_for_tests;
if (test_arithmetic_overflow) { // does arithmetic tests
for (k = 0; k <dim; k++) {
NewHypIndVal.Hyp[k]=positive.ValNewGen*negative.Hyp[k]-negative.ValNewGen*positive.Hyp[k];
used_for_tests =(positive.ValNewGen%overflow_test_modulus)*(negative.Hyp[k]%overflow_test_modulus)-(negative.ValNewGen%overflow_test_modulus)*(positive.Hyp[k]%overflow_test_modulus);
if (((NewHypIndVal.Hyp[k]-used_for_tests) % overflow_test_modulus)!=0) {
errorOutput()<<"Arithmetic failure in Full_cone::add_hyperplane. Possible arithmetic overflow.\n";
throw ArithmeticException();
}
}
}
else { // no arithmetic tests
for (k = 0; k <dim; k++) {
NewHypIndVal.Hyp[k]=positive.ValNewGen*negative.Hyp[k]-negative.ValNewGen*positive.Hyp[k];
}
}
NewHypIndVal.Hyp=v_make_prime(NewHypIndVal.Hyp);
NewHypIndVal.ValNewGen=0; // not really needed, only for completeness
NewHypIndVal.GenInHyp=positive.GenInHyp & negative.GenInHyp; // new hyperplane contains old gen iff both pos and neg do
NewHypIndVal.GenInHyp.set(ind_gen); // new hyperplane contains new generator
#pragma omp critical(HYPERPLANE)
HypIndVal.push_back(NewHypIndVal);
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::transform_values(const size_t& ind_gen){
//to see if possible to replace the function .end with constant iterator since push-back is performed.
// NEW: ind_gen is the index of the generator being inserted
register size_t i,k,nr_zero_i;
register size_t subfacet_dim=dim-2; // NEW dimension of subfacet
register size_t facet_dim=dim-1; // NEW dimension of facet
const bool tv_verbose = false; //verbose && Support_Hyperplanes.size()>10000; //verbose in this method call
// preparing the computations
list <FMDATA*> l_Pos_Simp,l_Pos_Non_Simp;
list <FMDATA*> l_Neg_Simp,l_Neg_Non_Simp;
list <FMDATA*> l_Neutral_Simp, l_Neutral_Non_Simp;
boost::dynamic_bitset<> Zero_Positive(nr_gen),Zero_Negative(nr_gen);
bool simplex;
bool ranktest;
if (tv_verbose) verboseOutput()<<"transform_values: create SZ,Z,PZ,P,NS,N"<<endl<<flush;
size_t ipos=0;
typename list<FMDATA>::iterator ii = HypIndVal.begin();
size_t listsize=HypIndVal.size();
for (size_t kk=0; kk<listsize; ++kk) {
for(;kk > ipos; ++ipos, ++ii) ;
for(;kk < ipos; --ipos, --ii) ;
simplex=false;
nr_zero_i=ii->GenInHyp.count();
if(ii->ValNewGen>0)
Zero_Positive|=ii->GenInHyp;
else if(ii->ValNewGen<0)
Zero_Negative|=ii->GenInHyp;
if (nr_zero_i==dim-1)
simplex=true;
if (ii->ValNewGen==0) {
ii->GenInHyp.set(ind_gen); // Must be set explicitly !!
if (simplex) {
l_Neutral_Simp.push_back(&(*ii));
} else {
l_Neutral_Non_Simp.push_back(&(*ii));
}
}
else if (ii->ValNewGen>0) {
if (simplex) {
l_Pos_Simp.push_back(&(*ii));
} else {
l_Pos_Non_Simp.push_back(&(*ii));
}
}
else if (ii->ValNewGen<0) {
if (simplex) {
l_Neg_Simp.push_back(&(*ii));
} else {
l_Neg_Non_Simp.push_back(&(*ii));
}
}
}
boost::dynamic_bitset<> Zero_PN(nr_gen);
Zero_PN=Zero_Positive & Zero_Negative;
if (tv_verbose) verboseOutput()<<"transform_values: copy to vector"<<endl;
size_t nr_PosSimp = l_Pos_Simp.size();
size_t nr_PosNSimp = l_Pos_Non_Simp.size();
size_t nr_NegSimp = l_Neg_Simp.size();
size_t nr_NegNSimp = l_Neg_Non_Simp.size();
size_t nr_NeuSimp = l_Neutral_Simp.size();
size_t nr_NeuNSimp = l_Neutral_Non_Simp.size();
ranktest=false;
if (nr_PosNSimp+nr_NegNSimp+nr_NeuNSimp > dim*dim*dim/6)
ranktest=true;
vector <FMDATA*> Pos_Simp(nr_PosSimp);
vector <FMDATA*> Pos_Non_Simp(nr_PosNSimp);
vector <FMDATA*> Neg_Simp(nr_NegSimp);
vector <FMDATA*> Neg_Non_Simp(nr_NegNSimp);
vector <FMDATA*> Neutral_Simp(nr_NeuSimp);
vector <FMDATA*> Neutral_Non_Simp(nr_NeuNSimp);
for (k = 0; k < Pos_Simp.size(); k++) {
Pos_Simp[k]=l_Pos_Simp.front();
l_Pos_Simp.pop_front();
}
for (k = 0; k < Pos_Non_Simp.size(); k++) {
Pos_Non_Simp[k]=l_Pos_Non_Simp.front();
l_Pos_Non_Simp.pop_front();
}
for (k = 0; k < Neg_Simp.size(); k++) {
Neg_Simp[k]=l_Neg_Simp.front();
l_Neg_Simp.pop_front();
}
for (k = 0; k < Neg_Non_Simp.size(); k++) {
Neg_Non_Simp[k]=l_Neg_Non_Simp.front();
l_Neg_Non_Simp.pop_front();
}
for (k = 0; k < Neutral_Simp.size(); k++) {
Neutral_Simp[k]=l_Neutral_Simp.front();
l_Neutral_Simp.pop_front();
}
for (k = 0; k < Neutral_Non_Simp.size(); k++) {
Neutral_Non_Simp[k]=l_Neutral_Non_Simp.front();
l_Neutral_Non_Simp.pop_front();
}
if (tv_verbose) verboseOutput()<<"PS "<<nr_PosSimp<<" P "<<nr_PosNSimp<<" NS "<<nr_NegSimp<<" N "<<nr_NegNSimp<<" ZS "<<nr_NeuSimp<<" Z "<<nr_NeuNSimp<<endl<<flush;
if (tv_verbose) verboseOutput()<<"transform_values: fill multimap with subfacets of NS"<<endl<<flush;
multimap < boost::dynamic_bitset<>, int> Neg_Subfacet_Multi;
boost::dynamic_bitset<> zero_i(nr_gen);
boost::dynamic_bitset<> subfacet(nr_gen);
for (i=0; i<nr_NegSimp;i++){
zero_i=Zero_PN & Neg_Simp[i]->GenInHyp;
nr_zero_i=zero_i.count();
if(nr_zero_i==subfacet_dim) // NEW This case treated separately
Neg_Subfacet_Multi.insert(pair <boost::dynamic_bitset<>, int> (zero_i,i));
else{
for (k =0; k<nr_gen; k++) { //TODO use BOOST ROUTINE
if(zero_i.test(k)) {
subfacet=zero_i;
subfacet.reset(k); // remove k-th element from facet to obtain subfacet
Neg_Subfacet_Multi.insert(pair <boost::dynamic_bitset<>, int> (subfacet,i));
}
}
}
}
if (tv_verbose) verboseOutput()<<"transform_values: go over multimap of size "<< Neg_Subfacet_Multi.size() <<endl<<flush;
multimap < boost::dynamic_bitset<>, int > ::iterator jj;
multimap < boost::dynamic_bitset<>, int > ::iterator del;
jj =Neg_Subfacet_Multi.begin(); // remove negative subfecets shared
while (jj!= Neg_Subfacet_Multi.end()) { // by two neg simpl facets
del=jj++;
if (jj!=Neg_Subfacet_Multi.end() && (*jj).first==(*del).first) { //delete since is the intersection of two negative simplicies
Neg_Subfacet_Multi.erase(del);
del=jj++;
Neg_Subfacet_Multi.erase(del);
}
}
if (tv_verbose) verboseOutput()<<"transform_values: singlemap size "<<Neg_Subfacet_Multi.size()<<endl<<flush;
size_t nr_NegSubfMult = Neg_Subfacet_Multi.size();
size_t nr_NegSubf;
map < boost::dynamic_bitset<>, int > Neg_Subfacet;
#pragma omp parallel private(jj)
{
size_t i,j,k,t,nr_zero_i;
boost::dynamic_bitset<> subfacet(dim-2);
jj = Neg_Subfacet_Multi.begin();
size_t jjpos=0;
map < boost::dynamic_bitset<>, int > ::iterator last_inserted=Neg_Subfacet.begin(); // used to speedup insertion into the new map
bool found;
#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;
for (i = 0; i <Neutral_Simp.size(); i++) {
found=subfacet.is_subset_of(Neutral_Simp[i]->GenInHyp);
if(found)
break;
}
if (!found) {
for (i = 0; i <Neutral_Non_Simp.size(); i++) {
found=subfacet.is_subset_of(Neutral_Non_Simp[i]->GenInHyp);
if(found)
break;
}
if(!found) {
for (i = 0; i <Neg_Non_Simp.size(); i++) {
found=subfacet.is_subset_of(Neg_Non_Simp[i]->GenInHyp);
if(found)
break;
}
}
}
if (!found) {
#pragma omp critical(NEGATIVE_SUBFACET)
{last_inserted=Neg_Subfacet.insert(last_inserted,*jj);}
}
}
#pragma omp single
{nr_NegSubf = Neg_Subfacet.size();}
#pragma omp single nowait
if (tv_verbose) {
verboseOutput()<<"transform_values: reduced map size "<<nr_NegSubf<<endl<<flush;
}
#pragma omp single nowait
{Neg_Subfacet_Multi.clear();}
#pragma omp single nowait
if (tv_verbose) {
verboseOutput()<<"transform_values: PS vs NS"<<endl<<flush;
}
boost::dynamic_bitset<> zero_i(nr_gen);
map <boost::dynamic_bitset<>, int> ::iterator jj_map;
#pragma omp for schedule(dynamic) nowait // Now matching positive and negative (sub)facets
for (i =0; i<nr_PosSimp; i++){ //Positive Simp vs.Negative Simp
zero_i=Pos_Simp[i]->GenInHyp & Zero_PN;
nr_zero_i=zero_i.count();
if (nr_zero_i==subfacet_dim) { // NEW slight change in logic. Positive simpl facet shared at most
jj_map=Neg_Subfacet.find(zero_i); // one subfacet with negative simpl facet
if (jj_map!=Neg_Subfacet.end()) {
add_hyperplane(ind_gen,*Pos_Simp[i],*Neg_Simp[(*jj_map).second]);
(*jj_map).second = -1; // block subfacet in further searches
}
}
if (nr_zero_i==facet_dim){ // now there could be more such subfacets. We make all and search them.
for (k =0; k<nr_gen; k++) { // BOOST ROUTINE
if(zero_i.test(k)) {
subfacet=zero_i;
subfacet.reset(k); // remove k-th element from facet to obtain subfacet
jj_map=Neg_Subfacet.find(subfacet);
if (jj_map!=Neg_Subfacet.end()) {
add_hyperplane(ind_gen,*Pos_Simp[i],*Neg_Simp[(*jj_map).second]);
(*jj_map).second = -1;
}
}
}
}
}
#pragma omp single nowait
if (tv_verbose) {
verboseOutput()<<"transform_values: NS vs P"<<endl<<flush;
}
// for (jj_map = Neg_Subfacet.begin(); jj_map != Neg_Subfacet.end(); ++jj_map) //Neg_simplex vs. Pos_Non_Simp
jj_map = Neg_Subfacet.begin();
jjpos=0;
#pragma omp for schedule(dynamic) nowait
for (size_t j=0; j<nr_NegSubf; ++j) {
for( ; j > jjpos; ++jjpos, ++jj_map) ;
for( ; j < jjpos; --jjpos, --jj_map) ;
if ( (*jj_map).second != -1 ) { // skip used subfacets
for (i = 0; i <Pos_Non_Simp.size(); i++) {
if(jj_map->first.is_subset_of(Pos_Non_Simp[i]->GenInHyp)){
add_hyperplane(ind_gen,*Pos_Non_Simp[i],*Neg_Simp[(*jj_map).second]);
break;
}
}
}
}
#pragma omp single nowait
if (tv_verbose) {
verboseOutput()<<"transform_values: PS vs N"<<endl<<flush;
}
vector<size_t> key(nr_gen);
size_t nr_missing;
bool common_subfacet;
#pragma omp for schedule(dynamic) nowait
for (size_t i =0; i<nr_PosSimp; i++){ //Positive Simp vs.Negative Non Simp
zero_i=Zero_PN & Pos_Simp[i]->GenInHyp;
nr_zero_i=0;
for(j=0;j<nr_gen && nr_zero_i<=facet_dim;j++)
if(zero_i.test(j)){
key[nr_zero_i]=j;
nr_zero_i++;
}
if(nr_zero_i>=subfacet_dim) {
for (j=0; j<Neg_Non_Simp.size(); j++){ // search negative facet with common subfacet
nr_missing=0;
common_subfacet=true;
for(k=0;k<nr_zero_i;k++) {
if(!Neg_Non_Simp[j]->GenInHyp.test(key[k])) {
nr_missing++;
if(nr_missing==2 || nr_zero_i==subfacet_dim) {
common_subfacet=false;
break;
}
}
}
if(common_subfacet){
add_hyperplane(ind_gen,*Pos_Simp[i],*Neg_Non_Simp[j]);
if(nr_zero_i==subfacet_dim) // only one subfacet can lie in negative hyperplane
break;
}
}
}
} // PS vs N
#pragma omp single nowait
if (tv_verbose) {
verboseOutput()<<"transform_values: P vs N"<<endl<<flush;
}
bool exactly_two;
FMDATA *hp_i, *hp_j, *hp_t; // pointers to current hyperplanes
size_t missing_bound, nr_common_zero;
boost::dynamic_bitset<> common_zero(nr_gen);
vector<size_t> common_key(nr_gen);
#pragma omp for schedule(dynamic) nowait
for (size_t i =0; i<nr_PosNSimp; i++){ //Positive Non Simp vs.Negative Non Simp
hp_i=Pos_Non_Simp[i];
zero_i=Zero_PN & hp_i->GenInHyp;
nr_zero_i=0;
for(j=0;j<nr_gen;j++)
if(zero_i.test(j)){
key[nr_zero_i]=j;
nr_zero_i++;
}
if (nr_zero_i>=subfacet_dim) {
missing_bound=nr_zero_i-subfacet_dim; // at most this number of generators can be missing
// to have a chance for common subfacet
for (j=0; j<nr_NegNSimp; j++){
hp_j=Neg_Non_Simp[j];
nr_missing=0;
nr_common_zero=0;
common_subfacet=true;
for(k=0;k<nr_zero_i;k++) {
if(!hp_j->GenInHyp.test(key[k])) {
nr_missing++;
if(nr_missing>missing_bound || nr_zero_i==subfacet_dim) {
common_subfacet=false;
break;
}
}
else {
common_key[nr_common_zero]=key[k];
nr_common_zero++;
}
}
if(common_subfacet){//intersection of *i and *j may be a subfacet
common_zero=zero_i & hp_j->GenInHyp;
exactly_two=true;
if (ranktest) {
Matrix<Integer> Test(nr_common_zero,dim);
for (k = 0; k < nr_common_zero; k++)
Test.write(k+1,Generators.read(common_key[k]+1));
if (Test.rank_destructiv()<subfacet_dim) {
exactly_two=false;
}
} // ranktest
else{ // now the comparison test
for (t=0;t<nr_PosNSimp;t++){
hp_t=Pos_Non_Simp[t];
if (t!=i && common_zero.is_subset_of(hp_t->GenInHyp)) {
exactly_two=false;
break;
}
}
if (exactly_two) {
for (t=0;t<Neg_Non_Simp.size();t++){
hp_t=Neg_Non_Simp[t];
if (t!=j && common_zero.is_subset_of(hp_t->GenInHyp)) {
exactly_two=false;
break;
}
}
}
if (exactly_two) {
for (t=0;t<nr_NeuNSimp;t++){
hp_t=Neutral_Non_Simp[t];
if(common_zero.is_subset_of(hp_t->GenInHyp)) {
exactly_two=false;
break;
}
}
}
} // else
if (exactly_two) { //intersection of i and j is a subfacet
add_hyperplane(ind_gen,*hp_i,*hp_j);
}
}
}
}
}
} //END parallel
//removing the negative hyperplanes
// now done in build_cone
if (tv_verbose) verboseOutput()<<"transform_values: done"<<endl;
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::add_simplex(const size_t& new_generator){
typename list<FMDATA>::const_iterator i=HypIndVal.begin();
typename list< pair< vector<size_t>, Integer> >::const_iterator j;
size_t nr_zero_i, nr_nonzero_i, not_in_i=0, l, k;
size_t s, Triangulation_size=Triangulation.size(); // the size we start with
vector<size_t> key(dim);
size_t ipos=0;
size_t listsize=HypIndVal.size();
#pragma omp parallel for private(j,nr_zero_i,nr_nonzero_i,l,k,s) firstprivate(ipos, i, key, not_in_i) schedule(dynamic)
for (size_t kk=0; kk<listsize; ++kk) {
for(;kk > ipos; ++ipos, ++i) ;
for(;kk < ipos; --ipos, --i) ;
if ((*i).ValNewGen<0) {
nr_zero_i=(*i).GenInHyp.count();
if (nr_zero_i==dim-1) { //simplicial
l=0;
for (k = 0; k <nr_gen; k++) {
if ((*i).GenInHyp[k]==1) {
key[l]=k+1;
l++;
}
}
key[dim-1]=new_generator+1;
store_key(key,i->ValNewGen);
if(!keep_triangulation){
Simplex<Integer> simp(key);
simp.evaluate(*this,i->ValNewGen);
}
}
else {
j =Triangulation.begin();
for (s=0; s<Triangulation_size; s++){
key=j->first;
nr_nonzero_i=0;
k=0;
do{
if ( !(*i).GenInHyp.test(key[k]-1)) {
nr_nonzero_i++;
not_in_i=k;
}
k++;
} while((k<dim)&&(nr_nonzero_i<2));
if (nr_nonzero_i<=1){
key[not_in_i]=new_generator+1;
store_key(key,i->ValNewGen);
if(!keep_triangulation){
Simplex<Integer> simp(key);
simp.evaluate(*this,i->ValNewGen);
}
}
j++;
} // s
} // else
} // if < 0
} // for kk
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::store_key(const vector<size_t>& key, const Integer& height){
pair<vector<size_t>,Integer> newsimplex;
newsimplex.first=key;
newsimplex.second=height;
#pragma omp critical(TRIANG)
Triangulation.push_back(newsimplex);
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::process_pyramids(const size_t ind_gen,const bool recursive){
typename list< FMDATA >::iterator l=HypIndVal.begin();
#ifdef _WIN32 //for 32 and 64 bit windows
size_t lpos=0, listsize=HypIndVal.size();
#pragma omp parallel for firstprivate(lpos,l) schedule(dynamic)
for (size_t k=0; k<listsize; k++) {
for(;k > lpos; lpos++, l++) ;
for(;k < lpos; lpos--, l--) ;
// only triangulation of Pyramids of height >=2 needeed
if(l->ValNewGen>=0 ||(!recursive && l->ValNewGen>=-1))
continue;
process_pyramid((*l), ind_gen, recursive);
} //end for
#else // all other systems
if (is_pyramid) { //do not create a new parallel region
for (; l != HypIndVal.end(); ++l) {
// only triangulation of Pyramids of height >=2 needeed
if(l->ValNewGen>=0 ||(!recursive && l->ValNewGen>=-1))
continue;
#pragma omp task firstprivate(l)
{
process_pyramid((*l), ind_gen, recursive);
}
} //end for
#pragma omp taskwait
} else {
#pragma omp parallel if(!is_pyramid)
{
#pragma omp single
{
for (; l != HypIndVal.end(); ++l) {
// only triangulation of Pyramids of height >=2 needeed
if(l->ValNewGen>=0 ||(!recursive && l->ValNewGen>=-1))
continue;
#pragma omp task firstprivate(l)
{
process_pyramid((*l), ind_gen, recursive);
}
} //end for
} //end single
#pragma omp taskwait
} //end parallel
}
#endif //else _WIN32
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::process_pyramid(FMDATA& l, const size_t ind_gen,const bool recursive){
vector<size_t> Pyramid_key;
Pyramid_key.reserve(nr_gen);
size_t i;
boost::dynamic_bitset<> in_Pyramid(nr_gen,false);
Pyramid_key.push_back(ind_gen+1);
in_Pyramid.set(ind_gen);
for(i=0;i<nr_gen;i++){
if(in_triang[i] && v_scalar_product(l.Hyp,Generators.read(i+1))==0){ // we cannot trust that HypIndVal is
Pyramid_key.push_back(i+1); // up-to-date
in_Pyramid.set(i);
}
}
Full_Cone<Integer> Pyramid(*this,Generators.submatrix(Pyramid_key));
Pyramid.do_triangulation= !recursive || do_triangulation;
if(Pyramid.do_triangulation)
Pyramid.do_partial_triangulation=false;
Pyramid.build_cone();
if(recursive && keep_triangulation){
typename list<pair<vector<size_t>,Integer> >::iterator pyr_simp=Pyramid.Triangulation.begin();
pair<vector<size_t>,Integer> newsimplex;
newsimplex.first=vector<size_t> (dim);
for(;pyr_simp!=Pyramid.Triangulation.end();pyr_simp++){
for(i=0;i<dim;i++)
newsimplex.first[i]=Pyramid_key[pyr_simp->first[i]-1];
newsimplex.second=pyr_simp->second;
#pragma omp critical(TRIANG)
Triangulation.push_back(newsimplex);
}
}
Pyramid.Triangulation.clear();
if(recursive){
typename list<vector<Integer> >::iterator pyr_hyp = Pyramid.Support_Hyperplanes.begin();
bool new_global_hyp;
FMDATA NewHypIndVal;
Integer test;
for(;pyr_hyp!=Pyramid.Support_Hyperplanes.end();pyr_hyp++){
if(v_scalar_product(Generators.read(ind_gen+1),*pyr_hyp)>0)
continue;
new_global_hyp=true;
for(i=0;i<nr_gen;i++){
if(in_Pyramid.test(i) || !in_triang[i])
continue;
test=v_scalar_product(Generators.read(i+1),*pyr_hyp);
if(test<=0){
new_global_hyp=false;
break;
}
}
if(new_global_hyp){
NewHypIndVal.Hyp=*pyr_hyp;
#pragma omp critical(HYPERPLANE)
HypIndVal.push_back(NewHypIndVal);
}
}
}
Pyramid.Support_Hyperplanes.clear();
if(do_h_vector) {
#pragma omp critical(HVECTOR)
H_Vector=v_add(H_Vector,Pyramid.H_Vector);
}
#pragma omp critical(MULTIPLICITY)
multiplicity += Pyramid.multiplicity;
#pragma omp critical(CANDIDATES)
Candidates.splice(Candidates.begin(),Pyramid.Candidates);
#pragma omp critical(HT1ELEMENTS)
Ht1_Elements.splice(Ht1_Elements.begin(),Pyramid.Ht1_Elements);
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::find_and_evaluate_start_simplex(){
size_t i,j;
Integer factor;
Simplex<Integer> S = find_start_simplex();
vector<size_t> key=S.read_key(); // generators indexed from 1
// vector<bool> in_triang(nr_gen,false);
for (i = 0; i < dim; i++) {
in_triang[key[i]-1]=true;
}
Matrix<Integer> H=S.read_support_hyperplanes();
for (i = 0; i <dim; i++) {
FMDATA NewHypIndVal; NewHypIndVal.Hyp.resize(dim); NewHypIndVal.GenInHyp.resize(nr_gen);
NewHypIndVal.Hyp=H.read(i+1);
for(j=0;j < dim;j++)
if(j!=i)
NewHypIndVal.GenInHyp.set(key[j]-1);
HypIndVal.push_back(NewHypIndVal);
}
if(!is_pyramid)
Order_Vector = vector<Integer>(dim,0);
if(!is_pyramid && do_h_vector){
Matrix<Integer> G=S.read_generators();
//srand(12345);
for(i=0;i<dim;i++){
factor=(unsigned long)(2*(rand()%(2*dim))+3);
for(j=0;j<dim;j++)
Order_Vector[j]+=factor*G.read(i+1,j+1);
}
}
//the volume is an upper bound for the height
if(do_triangulation)
store_key(key,-S.read_volume());
if(!keep_triangulation) {
Simplex<Integer> simp(key);
simp.evaluate(*this, -S.read_volume());
}
}
//int RekTiefe=-1;
//---------------------------------------------------------------------------
/* builds the cone successively by inserting generators, computes all essential data
except global reduction */
template<typename Integer>
void Full_Cone<Integer>::build_cone() {
if(dim>0){ //correction needed to include the 0 cone;
if (verbose && !is_pyramid) {
verboseOutput()<<"\n************************************************************\n";
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;
}
size_t i;
bool pyramid_recursion=false;
//#pragma omp critical(REKTIEFE)
//RekTiefe++;
//cout << RekTiefe;
// DECIDE WHETHER TO USE RECURSION
size_t RecBoundSuppHyp = dim*dim*dim;
RecBoundSuppHyp *= RecBoundSuppHyp * 10; //dim^6 * 10
size_t bound_div = nr_gen-dim+1;
if(bound_div > 3*dim) bound_div = 3*dim;
RecBoundSuppHyp /= bound_div;
size_t RecBoundTriang=RecBoundFactor; //dim*dim*dim*dim*RecBoundFactor;
//if(!is_pyramid) cout << "RecBoundSuppHyp = "<<RecBoundSuppHyp<<endl;
find_and_evaluate_start_simplex();
Integer scalar_product;
bool new_generator;
short round;
for (round = 0; round <= 1; round++) { //two times, first only KNOWN extreme rays are considered
for (i = 0; i < nr_gen; i++) {
if ((in_triang[i]==false)&&((round==1)||(Extreme_Rays[i]==true))) {
new_generator=false;
typename list< FMDATA >::iterator l=HypIndVal.begin();
size_t nr_pos=0; size_t nr_neg=0;
vector<Integer> L;
size_t old_nr_supp_hyps=HypIndVal.size();
size_t lpos=0;
size_t listsize=HypIndVal.size();
#pragma omp parallel for private(L,scalar_product) firstprivate(lpos,l) schedule(dynamic)
for (size_t k=0; k<listsize; k++) {
for(;k > lpos; lpos++, l++) ;
for(;k < lpos; lpos--, l--) ;
L=Generators.read(i+1);
scalar_product=v_scalar_product(L,(*l).Hyp);
if (test_arithmetic_overflow && !v_test_scalar_product(L,(*l).Hyp,scalar_product,overflow_test_modulus)) {
error_msg("error: Arithmetic failure in Full_cone::support_hyperplanes. Possible arithmetic overflow.\n");
throw ArithmeticException();
}
l->ValNewGen=scalar_product;
if (scalar_product<0) {
new_generator=true;
nr_neg++;
}
if (scalar_product>0)
nr_pos++;
} //end parallel for
if(!new_generator)
continue;
// if(pyramid_recursion || nr_neg*nr_pos>RecBoundSuppHyp){
if(pyramid_recursion || nr_neg*nr_pos>RecBoundSuppHyp || nr_neg*Triangulation.size()>RecBoundTriang){
if(!pyramid_recursion && !keep_triangulation)
Triangulation.clear();
pyramid_recursion=true;
process_pyramids(i,true); //recursive
}
else{
if(do_triangulation)
add_simplex(i);
if(do_partial_triangulation)
process_pyramids(i,false); // non-recursive
transform_values(i);
}
//removing the negative hyperplanes
l=HypIndVal.begin();
for (size_t j=0; j<old_nr_supp_hyps;j++){
if (l->ValNewGen<0)
l=HypIndVal.erase(l);
else
l++;
}
in_triang[i]=true;
if (verbose && !is_pyramid) {
verboseOutput() << "generator="<< i+1 <<" and "<<HypIndVal.size()<<" hyperplanes... ";
if(keep_triangulation)
verboseOutput() << Triangulation.size() << " simplices ";
verboseOutput()<<endl;
}
}
}
}
typename list<FMDATA>::const_iterator IHV=HypIndVal.begin();
for(;IHV!=HypIndVal.end();IHV++){
Support_Hyperplanes.push_back(IHV->Hyp);
}
} // end if (dim>0)
HypIndVal.clear();
//#pragma omp critical(REKTIEFE)
// RekTiefe--;
is_Computed.set(ConeProperty::SupportHyperplanes);
if(keep_triangulation) {
if(!is_pyramid) {
//sort the keys
typename list< pair<vector<size_t>, Integer> >::iterator it = Triangulation.begin();
while (it!=Triangulation.end()) {
sort(it->first.begin(),it->first.end());
++it;
}
}
is_Computed.set(ConeProperty::Triangulation);
}
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::extreme_rays_and_ht1_check() {
check_pointed();
if(!pointed) return;
compute_extreme_rays();
check_ht1_extreme_rays();
check_ht1_generated();
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::compute_support_hyperplanes(){
if(is_Computed.test(ConeProperty::SupportHyperplanes))
return;
bool save_tri=do_triangulation;
bool save_part_tri=do_partial_triangulation;
do_triangulation=false;
do_partial_triangulation=false;
build_cone();
do_triangulation=save_tri;
do_partial_triangulation=save_part_tri;
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::compute_support_hyperplanes_triangulation(){
keep_triangulation=true;
do_triangulation=true;
build_cone();
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::evaluate_triangulation(){
size_t listsize = Triangulation.size();
const long VERBOSE_STEPS = 50;
long step_x_size = listsize-VERBOSE_STEPS;
if (verbose) {
verboseOutput() << "evaluating "<<listsize<<" simplices" <<endl;
verboseOutput() << "---------+---------+---------+---------+---------+"
<< " (one | per 2%)" << endl;
}
#pragma omp parallel
{
typename list<pair<vector<size_t>,Integer> >::iterator s = Triangulation.begin();
size_t spos=0;
#pragma omp for schedule(dynamic)
for(size_t i=0; i<listsize; i++){
for(; i > spos; ++spos, ++s) ;
for(; i < spos; --spos, --s) ;
Simplex<Integer> simp(s->first);
simp.evaluate(*this,s->second);
s->second=simp.read_volume();
if (verbose) {
#pragma omp critical(VERBOSE)
while ((long)(i*VERBOSE_STEPS) >= step_x_size) {
step_x_size += listsize;
verboseOutput() << "|" <<flush;
}
}
}
}
if (verbose) {
verboseOutput() << endl << listsize<<" simplices evaluated." <<endl;
}
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::primal_algorithm_main(){
if (is_Computed.test(ConeProperty::IsHt1ExtremeRays) && !ht1_extreme_rays) {
if (do_ht1_elements)
return;
if (do_h_vector)
do_h_vector=false;
}
if (keep_triangulation) {
evaluate_triangulation();
} else {
Support_Hyperplanes.clear();
is_Computed.reset(ConeProperty::SupportHyperplanes);
for(size_t i=0;i<nr_gen;i++)
in_triang[i]=false;
// cout << "New build " << endl;
build_cone();
extreme_rays_and_ht1_check();
if(!pointed) return;
}
// cout << "Nr Invert " << NrInvert << endl;
if (ht1_extreme_rays && do_triangulation)
is_Computed.set(ConeProperty::Multiplicity,true);
if (do_Hilbert_basis) {
global_reduction();
is_Computed.set(ConeProperty::HilbertBasis,true);
check_integrally_closed();
}
if (ht1_extreme_rays && do_Hilbert_basis) {
select_ht1_elements();
check_ht1_hilbert_basis();
}
if (do_ht1_elements) {
for(size_t i=0;i<nr_gen;i++)
if(v_scalar_product(Linear_Form,Generators.read(i+1))==1)
Ht1_Elements.push_front(Generators.read(i+1));
Ht1_Elements.sort();
Ht1_Elements.unique();
is_Computed.set(ConeProperty::Ht1Elements,true);
}
if (do_h_vector) {
is_Computed.set(ConeProperty::HVector);
compute_polynomial();
}
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::primal_algorithm_keep_triang() {
compute_support_hyperplanes_triangulation();
extreme_rays_and_ht1_check();
if(!pointed) return;
if (ht1_extreme_rays && !ht1_generated) { //TODO ht1_triangulated einbauen und nutzen
if (verbose) {
cout << "not all generators have height 1, but extreme rays have"<<endl
<< "making a new triangulation with only extreme rays" <<endl;
}
Support_Hyperplanes.clear();
is_Computed.set(ConeProperty::SupportHyperplanes,false);
Triangulation.clear();
in_triang = vector<bool>(nr_gen,false);
is_Computed.set(ConeProperty::Triangulation,false);
compute_support_hyperplanes_triangulation();
}
primal_algorithm_main();
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::primal_algorithm_immediate_evaluation(){
if (do_triangulation || do_ht1_elements || do_h_vector) {
check_ht1_generated();
if(!ht1_generated) {
compute_support_hyperplanes();
extreme_rays_and_ht1_check();
if(!pointed) return;
}
}
primal_algorithm_main();
}
//---------------------------------------------------------------------------
// Normaliz modes (public)
//---------------------------------------------------------------------------
// pure dualization
template<typename Integer>
void Full_Cone<Integer>::dualize_cone() {
compute_support_hyperplanes();
reset_tasks();
}
// -s
template<typename Integer>
void Full_Cone<Integer>::support_hyperplanes() {
compute_support_hyperplanes();
extreme_rays_and_ht1_check();
reset_tasks();
}
// -v
template<typename Integer>
void Full_Cone<Integer>::support_hyperplanes_triangulation() {
primal_algorithm_keep_triang();
reset_tasks();
}
// -V
template<typename Integer>
void Full_Cone<Integer>::support_hyperplanes_triangulation_pyramid() {
do_triangulation=true;
primal_algorithm_immediate_evaluation();
reset_tasks();
}
//-n
template<typename Integer>
void Full_Cone<Integer>::triangulation_hilbert_basis() {
do_Hilbert_basis=true;
primal_algorithm_keep_triang();
reset_tasks();
}
// -N
template<typename Integer>
void Full_Cone<Integer>::hilbert_basis() {
do_Hilbert_basis=true;
do_partial_triangulation=true;
primal_algorithm_immediate_evaluation();
reset_tasks();
}
// -h
template<typename Integer>
void Full_Cone<Integer>::hilbert_basis_polynomial() {
do_Hilbert_basis=true;
do_h_vector=true;
primal_algorithm_keep_triang();
reset_tasks();
}
// -H
template<typename Integer>
void Full_Cone<Integer>::hilbert_basis_polynomial_pyramid() {
do_Hilbert_basis=true;
do_h_vector=true;
do_triangulation=true;
primal_algorithm_immediate_evaluation();
reset_tasks();
}
// -p
template<typename Integer>
void Full_Cone<Integer>::hilbert_polynomial() {
do_ht1_elements=true;
do_h_vector=true;
primal_algorithm_keep_triang();
reset_tasks();
}
// -P
template<typename Integer>
void Full_Cone<Integer>::hilbert_polynomial_pyramid() {
do_ht1_elements=true;
do_h_vector=true;
do_triangulation=true;
primal_algorithm_immediate_evaluation();
reset_tasks();
}
// -1
template<typename Integer>
void Full_Cone<Integer>::ht1_elements() {
do_ht1_elements=true;
do_partial_triangulation=true;
primal_algorithm_immediate_evaluation();
reset_tasks();
}
template<typename Integer>
void Full_Cone<Integer>::dual_mode() {
Support_Hyperplanes.sort();
Support_Hyperplanes.unique();
Support_Hyperplanes.remove(vector<Integer>(dim,0));
if(dim>0) { //correction needed to include the 0 cone;
Linear_Form = Generators.homogeneous(ht1_extreme_rays);
ht1_generated = ht1_extreme_rays;
is_Computed.set(ConeProperty::IsHt1ExtremeRays);
is_Computed.set(ConeProperty::IsHt1Generated);
if (ht1_extreme_rays) {
is_Computed.set(ConeProperty::LinearForm);
if (verbose) {
cout << "Find height 1 elements" << endl;
}
typename list < vector <Integer> >::const_iterator h;
for (h = Hilbert_Basis.begin(); h != Hilbert_Basis.end(); ++h) {
if (v_scalar_product((*h),Linear_Form)==1) {
Ht1_Elements.push_back((*h));
}
}
is_Computed.set(ConeProperty::Ht1Elements);
}
} else {
ht1_extreme_rays = ht1_generated = true;
Linear_Form=vector<Integer>(dim);
is_Computed.set(ConeProperty::IsHt1ExtremeRays);
is_Computed.set(ConeProperty::IsHt1ExtremeRays);
is_Computed.set(ConeProperty::LinearForm);
}
if (ht1_extreme_rays) check_ht1_hilbert_basis();
check_integrally_closed();
}
//---------------------------------------------------------------------------
// Checks and auxiliary algorithms
//---------------------------------------------------------------------------
template<typename Integer>
Simplex<Integer> Full_Cone<Integer>::find_start_simplex() const {
if (is_Computed.test(ConeProperty::ExtremeRays)) {
vector<size_t> marked_extreme_rays(0);
for (size_t i=0; i<nr_gen; i++) {
if (Extreme_Rays[i])
marked_extreme_rays.push_back(i+1);
}
vector<size_t> key_extreme = Generators.submatrix(Extreme_Rays).max_rank_submatrix_lex();
assert(key_extreme.size() == dim);
vector<size_t> key(dim);
for (size_t i=0; i<dim; i++) {
key[i] = marked_extreme_rays[key_extreme[i]-1];
}
return Simplex<Integer>(key, Generators);
}
else {
// assert(Generators.rank()>=dim);
return Simplex<Integer>(Generators);
}
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::compute_extreme_rays(){
size_t i,j,k,l,t;
Matrix<Integer> SH=getSupportHyperplanes().transpose();
Matrix<Integer> Val=Generators.multiplication(SH);
size_t nc=Val.nr_of_columns();
vector<size_t> Zero(nc);
vector<size_t> nr_zeroes(nr_gen);
for (i = 0; i <nr_gen; i++) {
k=0;
Extreme_Rays[i]=true;
for (j = 0; j <nc; j++) {
if (Val.get_elem(i+1,j+1)==0) {
k++;
}
}
nr_zeroes[i]=k;
if (k<dim-1||k==nc) // not contained in enough facets or in all (0 as generator)
Extreme_Rays[i]=false;
}
for (i = 0; i <nr_gen; i++) {
if(!Extreme_Rays[i]) // already known to be non-extreme
continue;
k=0;
for (j = 0; j <nc; j++) {
if (Val.get_elem(i+1,j+1)==0) {
Zero[k]=j;
k++;
}
}
for (j = 0; j <nr_gen; j++) {
if (i!=j && Extreme_Rays[j] // not compare with itself or a known nonextreme ray
&& nr_zeroes[i]<nr_zeroes[j]) { // or something whose zeroes cannot be a superset
l=0;
for (t = 0; t < nr_zeroes[i]; t++) {
if (Val.get_elem(j+1,Zero[t]+1)==0)
l++;
if (l>=nr_zeroes[i]) {
Extreme_Rays[i]=false;
break;
}
}
}
}
}
// cout << "Extr durch" << endl;
is_Computed.set(ConeProperty::ExtremeRays);
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::select_ht1_elements() {
typename list<vector<Integer> >::iterator h = Hilbert_Basis.begin();
for(;h!=Hilbert_Basis.end();h++)
if(v_scalar_product(Linear_Form,*h)==1)
Ht1_Elements.push_back(*h);
is_Computed.set(ConeProperty::Ht1Elements,true);
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::check_pointed() {
if (is_Computed.test(ConeProperty::IsPointed))
return;
Matrix<Integer> SH = getSupportHyperplanes();
pointed = (SH.rank_destructiv() == dim);
is_Computed.set(ConeProperty::IsPointed);
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::check_ht1_generated() {
if (is_Computed.test(ConeProperty::IsHt1Generated))
return;
if (is_Computed.test(ConeProperty::ExtremeRays)) {
check_ht1_extreme_rays();
if (ht1_extreme_rays) {
ht1_generated = true;
for (size_t i = 0; i < nr_gen; i++) {
if (!Extreme_Rays[i] && v_scalar_product(Generators[i], Linear_Form) != 1) {
ht1_generated = false;
break;
}
}
}
} else {
Linear_Form = Generators.homogeneous(ht1_generated);
if (ht1_generated) {
ht1_extreme_rays=true;
is_Computed.set(ConeProperty::IsHt1ExtremeRays);
is_Computed.set(ConeProperty::LinearForm);
}
}
is_Computed.set(ConeProperty::IsHt1Generated);
}
template<typename Integer>
void Full_Cone<Integer>::check_ht1_extreme_rays() {
if (is_Computed.test(ConeProperty::IsHt1ExtremeRays))
return;
if (ht1_generated) {
ht1_extreme_rays=true;
is_Computed.set(ConeProperty::IsHt1ExtremeRays);
return;
}
assert(is_Computed.test(ConeProperty::ExtremeRays));
vector<size_t> key;
for (size_t i = 0; i < nr_gen; i++) {
if (Extreme_Rays[i])
key.push_back(i+1);
}
Matrix<Integer> Extreme=Generators.submatrix(key);
Linear_Form = Extreme.homogeneous(ht1_extreme_rays);
is_Computed.set(ConeProperty::IsHt1ExtremeRays);
if (ht1_extreme_rays) {
is_Computed.set(ConeProperty::LinearForm);
}
}
template<typename Integer>
void Full_Cone<Integer>::check_ht1_hilbert_basis() {
if (is_Computed.test(ConeProperty::IsHt1HilbertBasis))
return;
if ( !is_Computed.test(ConeProperty::IsHt1ExtremeRays) || !is_Computed.test(ConeProperty::HilbertBasis)) {
errorOutput() << "Warning: unsatisfied preconditions in check_ht1_hilbert_basis()!" <<endl;
return;
}
if (is_Computed.test(ConeProperty::Ht1Elements)) {
ht1_hilbert_basis = (Ht1_Elements.size() == Hilbert_Basis.size());
} else {
ht1_hilbert_basis = true;
typename list< vector<Integer> >::iterator h;
for (h = Hilbert_Basis.begin(); h != Hilbert_Basis.end(); ++h) {
if (v_scalar_product((*h),Linear_Form)!=1) {
ht1_hilbert_basis = false;
break;
}
}
}
is_Computed.set(ConeProperty::IsHt1HilbertBasis);
}
template<typename Integer>
void Full_Cone<Integer>::check_integrally_closed() {
if (is_Computed.test(ConeProperty::IsIntegrallyClosed))
return;
if ( !is_Computed.test(ConeProperty::HilbertBasis)) {
errorOutput() << "Warning: unsatisfied preconditions in check_integrally_closed()!" <<endl;
return;
}
integrally_closed = false;
if (Hilbert_Basis.size() <= nr_gen) {
integrally_closed = true;
typename list< vector<Integer> >::iterator h;
for (h = Hilbert_Basis.begin(); h != Hilbert_Basis.end(); ++h) {
integrally_closed = false;
for (size_t i=1; i<= nr_gen; i++) {
if ((*h) == Generators.read(i)) {
integrally_closed = true;
break;
}
}
if (!integrally_closed) {
break;
}
}
}
is_Computed.set(ConeProperty::IsIntegrallyClosed);
}
//---------------------------------------------------------------------------
// Global reduction
//---------------------------------------------------------------------------
template<typename Integer>
bool Full_Cone<Integer>::is_reducible(list< vector<Integer>* >& Irred, const vector< Integer >& new_element){
register size_t i;
size_t s=Support_Hyperplanes.size();
vector <Integer> candidate=v_cut_front(new_element,dim);
vector <Integer> scalar_product=l_multiplication(Support_Hyperplanes,candidate);
typename list< vector<Integer>* >::iterator j;
vector<Integer> *reducer;
for (j =Irred.begin(); j != Irred.end(); j++) {
reducer=(*j);
for (i = 1; i <= s; i++) {
if ((*reducer)[i]>scalar_product[i-1]){
break;
}
}
if (i==s+1) {
//found a "reducer" and move it to the front
Irred.push_front(*j);
Irred.erase(j);
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::global_reduction() {
Integer norm;
list <vector<Integer> > Candidates_with_Scalar_Product;
list <vector<Integer> > HB;
typename list <vector<Integer> >::iterator c;
typename list <vector<Integer> >::const_iterator h;
typename list <vector<Integer> >::iterator cit;
for (size_t i = 0; i <nr_gen; i++) {
Candidates.push_front(Generators.read(i+1));
}
Candidates.sort();
Candidates.unique();
if (nr_gen == dim) { // cone is simplicial, therefore no global reduction is necessary
if (verbose) {
verboseOutput()<<"Cone is simplicial, no global reduction necessary."<<endl;
}
for (cit = Candidates.begin(); cit != Candidates.end(); ++cit) {
Hilbert_Basis.push_back(v_cut_front(*cit,dim));
}
Candidates.clear();
return;
}
vector<Integer> degree_function=compute_degree_function();
cit = Candidates.begin();
size_t cpos = 0;
size_t listsize=Candidates.size();
if(verbose) {
verboseOutput()<<"computing the degrees of the candidates... "<<flush;
}
//go over candidates: do single scalar product
//for (c = Candidates.begin(); c != Candidates.end(); c++) {
vector<Integer> scalar_product;
for (size_t j=0; j<listsize; ++j) {
for(;j > cpos; ++cpos, ++cit) ;
for(;j < cpos; --cpos, --cit) ;
norm=v_scalar_product(degree_function,(*cit));
vector <Integer> new_element(1);
new_element[0]=norm;
new_element=v_merge(new_element,(*cit));
Candidates_with_Scalar_Product.push_back(new_element);
}
Candidates.clear(); //delete old set
if(verbose) {
verboseOutput()<<"sorting the list... "<<endl<<flush;
}
Candidates_with_Scalar_Product.sort();
if (verbose) {
verboseOutput()<< Candidates_with_Scalar_Product.size() <<" candidate vectors sorted."<<endl;
}
// do global reduction
list< vector<Integer> > HBtmp(0);
Integer norm_crit;
while ( !Candidates_with_Scalar_Product.empty() ) {
//use norm criterion to find irreducible elements
c=Candidates_with_Scalar_Product.begin();
norm_crit=(*c)[0]*2; //candidates with smaller norm are irreducible
if ( Candidates_with_Scalar_Product.back()[0] < norm_crit) { //all candidates are irreducible
if (verbose) {
verboseOutput()<<Hilbert_Basis.size()+Candidates_with_Scalar_Product.size();
verboseOutput()<<" Hilbert Basis elements of degree <= "<<norm_crit-1<<"; done"<<endl;
}
while ( !Candidates_with_Scalar_Product.empty()) {
Hilbert_Basis.push_back(v_cut_front(*c,dim)); // already of the final type
c=Candidates_with_Scalar_Product.erase(c);
}
break;
}
while ( (*c)[0] < norm_crit ) { //can't go over the end because of the previous if
// push to HBtmp with scalar products
vector <Integer> candidate=v_cut_front(*c,dim);
vector <Integer> scalar_products=l_multiplication(Support_Hyperplanes,candidate);
vector <Integer> new_HB_element(1);
new_HB_element[0]=(*c)[0];
new_HB_element=v_merge(new_HB_element,scalar_products);
new_HB_element=v_merge(new_HB_element,candidate);
HBtmp.push_back(new_HB_element);
Hilbert_Basis.push_back(candidate); // already of the final type
c=Candidates_with_Scalar_Product.erase(c);
}
size_t csize=Candidates_with_Scalar_Product.size();
if (verbose) {
verboseOutput()<<Hilbert_Basis.size()<< " Hilbert Basis elements of degree <= "<<norm_crit-1<<"; "<<csize<<" candidates left"<<endl;
}
// reduce candidates against HBtmp
// fill pointer list
list < vector <Integer>* > HBpointers; // used to put "reducer" to the front
c=HBtmp.begin();
while (c!=HBtmp.end()) {
HBpointers.push_back(&(*(c++)));
}
long VERBOSE_STEPS = 50; //print | for 2%
if (verbose && csize>50000) { //print | for 1000 candidates
VERBOSE_STEPS=csize/1000;
}
long step_x_size = csize-VERBOSE_STEPS;
long counter = 0;
long steps_done = 0;
if (verbose) {
verboseOutput() << "---------+---------+---------+---------+---------+";
if (VERBOSE_STEPS == 50) {
verboseOutput() << " (one | per 2%)" << endl;
} else {
verboseOutput() << " (one | per 1000 candidates)" << endl;
}
}
#pragma omp parallel private(c,cpos) firstprivate(HBpointers)
{
// list< vector<Integer>* > HBcopy(HBpointers); //one copy for each thread
c=Candidates_with_Scalar_Product.begin();
cpos=0;
#pragma omp for schedule(dynamic)
for (size_t k=0; k<csize; ++k) {
for(;k > cpos; ++cpos, ++c) ;
for(;k < cpos; --cpos, --c) ;
if ( is_reducible(HBpointers, *c) ) {
(*c)[0]=-1; //mark as reducible
}
if (verbose) {
#pragma omp critical(VERBOSE)
{
counter++;
while (counter*VERBOSE_STEPS >= step_x_size) {
steps_done++;
step_x_size += csize;
verboseOutput() << "|" <<flush;
// cout<<counter<<" ";
if(VERBOSE_STEPS > 50 && steps_done%50 == 0) {
verboseOutput() << " " << (steps_done) << "000" << endl;
}
}
} //end critical(VERBOSE)
}
} //end for
} //end parallel
if (verbose) verboseOutput() << endl;
// delete reducible candidates
c=Candidates_with_Scalar_Product.begin();
while(c != Candidates_with_Scalar_Product.end()) {
if((*c)[0]==-1) {
c=Candidates_with_Scalar_Product.erase(c);
} else {
++c;
}
}
HBtmp.clear();
}
if (verbose) {
verboseOutput()<<Hilbert_Basis.size()<< " Hilbert Basis elements"<<endl;
}
}
//---------------------------------------------------------------------------
template<typename Integer>
vector<Integer> Full_Cone<Integer>::compute_degree_function() const {
if(verbose) {
verboseOutput()<<"computing degree function... ";
}
size_t i;
vector<Integer> degree_function(dim,0);
if(is_Computed.test(ConeProperty::LinearForm)){ //use Linear_From in homogeneous case
for (i=0; i<dim; i++) {
degree_function[i] = Linear_Form[i];
}
if(verbose) {
verboseOutput()<<"using homogenous linear form."<<endl<<flush;
}
} else { // add hyperplanes to get a degree function
typename list< vector<Integer> >::const_iterator h;
for (h=Support_Hyperplanes.begin(); h!=Support_Hyperplanes.end(); ++h) {
for (i=0; i<dim; i++) {
degree_function[i]+=(*h)[i];
}
} //TODO parallel addition in each thread and final addition at the end
//TODO make_prime()?
if(verbose) {
verboseOutput()<<"done."<<endl<<flush;
}
}
return degree_function;
}
//--------------------------------------------------------------------------
// Hilbert polynomial
//---------------------------------------------------------------------------
template<typename Integer>
vector<Integer> Full_Cone<Integer>::compute_e_vector(){
size_t i,j;
vector <Integer> E_Vector(dim,0);
vector <Integer> Q=H_Vector;
Q.push_back(0);
for (i = 0; i <dim; i++) {
for (j = 0; j <dim; j++) {
E_Vector[i]+=Q[j];
}
E_Vector[i]/=permutations<Integer>(1,i);
for (j = 1; j <=dim; j++) {
Q[j-1]=(unsigned long)j*Q[j];
}
}
return E_Vector;
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::compute_polynomial(){
size_t i,j;
Integer factorial=permutations<Integer>(1,dim);
if ((factorial-permutations_modulo<Integer>(1,dim,overflow_test_modulus))%overflow_test_modulus != 0) {
errorOutput() << "Hilbert polynom has too big coefficients. Its computation is omitted." <<endl;
return;
}
Integer mult_factor = factorial;
vector <Integer> E_Vector=compute_e_vector();
vector <Integer> C(dim,0);
C[0]=1;
for (i = 0; i <dim; i++) {
mult_factor=permutations<Integer>(i,dim);
if (((dim-1-i)%2)==0) {
for (j = 0; j <dim; j++) {
Hilbert_Polynomial[2*j]+=mult_factor*E_Vector[dim-1-i]*C[j];
}
}
else {
for (j = 0; j <dim; j++) {
Hilbert_Polynomial[2*j]-=mult_factor*E_Vector[dim-1-i]*C[j];
}
}
for (j = dim-1; 0 <j; j--) {
C[j]=(unsigned long)(i+1)*C[j]+C[j-1];
}
C[0]=permutations<Integer>(1,i+1);
}
for (i = 0; i <dim; i++) {
mult_factor=gcd<Integer>(Hilbert_Polynomial[2*i],factorial);
Hilbert_Polynomial[2*i]/= mult_factor;
Hilbert_Polynomial[2*i+1]= factorial/mult_factor;
}
is_Computed.set(ConeProperty::HilbertPolynomial);
}
//---------------------------------------------------------------------------
template<typename Integer>
Integer Full_Cone<Integer>::primary_multiplicity() const{
size_t i,j,k;
Integer primary_multiplicity=0;
vector <size_t> key,new_key(dim-1);
Matrix<Integer> Projection(nr_gen,dim-1);
for (i = 1; i <= nr_gen; i++) {
for (j = 1; j <= dim-1; j++) {
Projection.write(i,j,Generators.read(i,j));
}
}
typename list< vector<Integer> >::const_iterator h;
typename list<pair<vector<size_t>,Integer> >::const_iterator t;
for (h =Support_Hyperplanes.begin(); h != Support_Hyperplanes.end(); ++h){
if ((*h)[dim-1]!=0) {
for (t =Triangulation.begin(); t!=Triangulation.end(); ++t){
key=t->first;
for (i = 0; i <dim; i++) {
k=0;
for (j = 0; j < dim; j++) {
if (j!=i && Generators.read(key[j],dim)==1) {
if (v_scalar_product(Generators.read(key[j]),(*h))==0) {
k++;
}
}
if (k==dim-1) {
for (j = 0; j <i; j++) {
new_key[j]=key[j];
}
for (j = i; j <dim-1; j++) {
new_key[j]=key[j+1];
}
Simplex<Integer> S(new_key,Projection);
primary_multiplicity+=S.read_volume();
}
}
}
}
}
}
return primary_multiplicity;
}
//---------------------------------------------------------------------------
// Constructors
//---------------------------------------------------------------------------
template<typename Integer>
Full_Cone<Integer>::Full_Cone(){
dim=0;
nr_gen=0;
hyp_size=0;
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::reset_tasks(){
do_triangulation = false;
do_partial_triangulation = false;
do_Hilbert_basis = false;
do_ht1_elements = false;
keep_triangulation = false;
do_h_vector=false;
is_pyramid = false;
}
//---------------------------------------------------------------------------
template<typename Integer>
Full_Cone<Integer>::Full_Cone(Matrix<Integer> M){
dim=M.nr_of_columns();
if (dim!=M.rank()) {
error_msg("error: Matrix with rank = number of columns needed in the constructor of the object Full_Cone<Integer>.\nProbable reason: Cone not full dimensional (<=> dual cone not pointed)!");
throw NormalizException();
}
Generators = M;
nr_gen=Generators.nr_of_rows();
//make the generators coprime and remove 0 rows
vector<Integer> gcds = Generators.make_prime();
vector<size_t> key=v_non_zero_pos(gcds);
if (key.size() < nr_gen) {
Generators=Generators.submatrix(key);
nr_gen=Generators.nr_of_rows();
}
multiplicity = 0;
is_Computed = bitset<ConeProperty::EnumSize>(); //initialized to false
is_Computed.set(ConeProperty::Generators);
pointed = false;
ht1_extreme_rays = false;
ht1_generated = false;
ht1_hilbert_basis = false;
integrally_closed = false;
reset_tasks();
Extreme_Rays = vector<bool>(nr_gen,false);
Support_Hyperplanes = list< vector<Integer> >();
Triangulation = list<pair<vector<size_t>,Integer> >();
in_triang = vector<bool> (nr_gen,false);
HypIndVal = list<FMDATA>();
Hilbert_Basis = list< vector<Integer> >();
Candidates = list< vector<Integer> >();
Ht1_Elements = list< vector<Integer> >();
if(dim>0){ //correction needed to include the 0 cone;
H_Vector = vector<Integer>(dim);
Hilbert_Polynomial = vector<Integer>(2*dim);
} else {
multiplicity = 1;
H_Vector = vector<Integer>(1,1);
Hilbert_Polynomial = vector<Integer>(2,1);
Hilbert_Polynomial[0] = 0;
is_Computed.set(ConeProperty::HilbertPolynomial);
is_Computed.set(ConeProperty::HVector);
is_Computed.set(ConeProperty::Triangulation);
}
}
//---------------------------------------------------------------------------
template<typename Integer>
Full_Cone<Integer>::Full_Cone(const Cone_Dual_Mode<Integer> &C) {
dim = C.dim;
Generators = C.get_generators();
nr_gen = Generators.nr_of_rows();
multiplicity = 0;
is_Computed = bitset<ConeProperty::EnumSize>(); //initialized to false
is_Computed.set(ConeProperty::Generators);
pointed = true;
is_Computed.set(ConeProperty::IsPointed);
ht1_extreme_rays = false;
ht1_generated = false;
ht1_hilbert_basis = false;
integrally_closed = false;
reset_tasks();
Extreme_Rays = vector<bool>(nr_gen,true); //all generators are extreme rays
is_Computed.set(ConeProperty::ExtremeRays);
Matrix<Integer> SH = C.SupportHyperplanes;
Support_Hyperplanes = list< vector<Integer> >();
for (size_t i=1; i<= SH.nr_of_rows(); i++) {
Support_Hyperplanes.push_back(SH.read(i));
}
is_Computed.set(ConeProperty::SupportHyperplanes);
Triangulation = list<pair<vector<size_t>,Integer> >();
in_triang = vector<bool>(nr_gen,false);
HypIndVal = list<FMDATA>();
Hilbert_Basis = C.Hilbert_Basis;
is_Computed.set(ConeProperty::HilbertBasis);
Ht1_Elements = list< vector<Integer> >();
if(dim>0){ //correction needed to include the 0 cone;
H_Vector = vector<Integer>(dim);
Hilbert_Polynomial = vector<Integer>(2*dim);
} else {
multiplicity = 1;
H_Vector = vector<Integer>(1,1);
Hilbert_Polynomial = vector<Integer>(2,1);
Hilbert_Polynomial[0] = 0;
is_Computed.set(ConeProperty::HVector);
is_Computed.set(ConeProperty::HilbertPolynomial);
}
}
//---------------------------------------------------------------------------
/* constructor for pyramids */
template<typename Integer>
Full_Cone<Integer>::Full_Cone(const Full_Cone<Integer>& C, Matrix<Integer> M) {
dim = M.nr_of_columns();
Generators = M;
nr_gen = Generators.nr_of_rows();
multiplicity = 0;
is_Computed = bitset<ConeProperty::EnumSize>();
Extreme_Rays = vector<bool>(nr_gen,false);
Support_Hyperplanes = list< vector<Integer> >();
Triangulation = list< pair<vector<size_t>,Integer> >();
Hilbert_Basis = list< vector<Integer> >();
Ht1_Elements = list< vector<Integer> >();
Candidates = list< vector<Integer> >();
H_Vector = vector<Integer>(dim);
in_triang = vector<bool> (nr_gen,false);
HypIndVal = list<FMDATA>();
Linear_Form=C.Linear_Form;
Order_Vector=C.Order_Vector;
do_triangulation=C.do_triangulation;
do_partial_triangulation=C.do_partial_triangulation;
do_ht1_elements=C.do_ht1_elements;
do_h_vector=C.do_h_vector;
do_Hilbert_basis=C.do_Hilbert_basis;
keep_triangulation=C.keep_triangulation;
is_pyramid=true;
}
//---------------------------------------------------------------------------
template<typename Integer>
bool Full_Cone<Integer>::isComputed(ConeProperty::Enum prop) const{
return is_Computed.test(prop);
}
//---------------------------------------------------------------------------
// 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>::isHt1ExtremeRays() const{
return ht1_extreme_rays;
}
template<typename Integer>
bool Full_Cone<Integer>::isHt1HilbertBasis() const{
return ht1_hilbert_basis;
}
template<typename Integer>
bool Full_Cone<Integer>::isIntegrallyClosed() const{
return integrally_closed;
}
//---------------------------------------------------------------------------
template<typename Integer>
vector<Integer> Full_Cone<Integer>::getLinearForm() const{
return Linear_Form;
}
//---------------------------------------------------------------------------
template<typename Integer>
Integer Full_Cone<Integer>::getMultiplicity()const{
return multiplicity;
}
//---------------------------------------------------------------------------
template<typename Integer>
const Matrix<Integer>& Full_Cone<Integer>::getGenerators()const{
return Generators;
}
//---------------------------------------------------------------------------
template<typename Integer>
vector<bool> Full_Cone<Integer>::getExtremeRays()const{
return Extreme_Rays;
}
//---------------------------------------------------------------------------
template<typename Integer>
Matrix<Integer> Full_Cone<Integer>::getSupportHyperplanes()const{
size_t s= Support_Hyperplanes.size();
Matrix<Integer> M(s,dim);
size_t i=1;
typename list< vector<Integer> >::const_iterator l;
for (l =Support_Hyperplanes.begin(); l != Support_Hyperplanes.end(); l++) {
M.write(i,(*l));
i++;
}
return M;
}
//---------------------------------------------------------------------------
template<typename Integer>
void Full_Cone<Integer>::getTriangulation(list< vector<size_t> >& Triang, list<Integer>& TriangVol) const {
Triang.clear();
TriangVol.clear();
vector<size_t> key(dim);
typename list<pair<vector<size_t>,Integer> >::const_iterator l;
for (l =Triangulation.begin(); l != Triangulation.end(); l++) {
key=l->first;
sort(key.begin(),key.end());
Triang.push_back(key);
TriangVol.push_back(l->second);
}
}
//---------------------------------------------------------------------------
template<typename Integer>
Matrix<Integer> Full_Cone<Integer>::getHilbertBasis()const{
size_t s= Hilbert_Basis.size();
Matrix<Integer> M(s,dim);
size_t i=1;
typename list< vector<Integer> >::const_iterator l;
for (l =Hilbert_Basis.begin(); l != Hilbert_Basis.end(); l++) {
M.write(i,(*l));
i++;
}
return M;
}
//---------------------------------------------------------------------------
template<typename Integer>
Matrix<Integer> Full_Cone<Integer>::getHt1Elements()const{
size_t s= Ht1_Elements.size();
Matrix<Integer> M(s,dim);
size_t i=1;
typename list< vector<Integer> >::const_iterator l;
for (l =Ht1_Elements.begin(); l != Ht1_Elements.end(); l++) {
M.write(i,(*l));
i++;
}
return M;
}
//---------------------------------------------------------------------------
template<typename Integer>
vector<Integer> Full_Cone<Integer>::getHVector() const{
return H_Vector;
}
//---------------------------------------------------------------------------
template<typename Integer>
vector<Integer> Full_Cone<Integer>::getHilbertPolynomial() const{
return Hilbert_Polynomial;
}
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()<<"\nHomogeneous is "<<ht1_generated<<".\n";
verboseOutput()<<"\nLinear_Form is:\n";
v_read(Linear_Form);
verboseOutput()<<"\nMultiplicity is "<<multiplicity<<".\n";
verboseOutput()<<"\nGenerators are:\n";
Generators.read();
verboseOutput()<<"\nExtreme_rays are:\n";
v_read(Extreme_Rays);
verboseOutput()<<"\nSupport Hyperplanes are:\n";
l_read(Support_Hyperplanes);
verboseOutput()<<"\nTriangulation is:\n";
l_read(Triangulation);
verboseOutput()<<"\nHilbert basis is:\n";
l_read(Hilbert_Basis);
verboseOutput()<<"\nHt1 elements are:\n";
l_read(Ht1_Elements);
verboseOutput()<<"\nh-vector is:\n";
v_read(H_Vector);
verboseOutput()<<"\nHilbert polvnomial is:\n";
v_read(Hilbert_Polynomial);
}
} //end namespace
|