[3c0aa5] | 1 | #include <utility> |
---|
| 2 | |
---|
[06d5774] | 3 | #include <kernel/GBEngine/kstd1.h> |
---|
[9abcc6] | 4 | #include <kernel/ideals.h> |
---|
[ebb19d] | 5 | #include <Singular/ipid.h> |
---|
| 6 | |
---|
[3f58b8d] | 7 | #include <polys/monomials/p_polys.h> |
---|
| 8 | #include <polys/monomials/ring.h> |
---|
| 9 | #include <polys/prCopy.h> |
---|
[9abcc6] | 10 | |
---|
[c89014] | 11 | #include <gfanlib/gfanlib.h> |
---|
[3c0aa5] | 12 | #include <gfanlib/gfanlib_matrix.h> |
---|
[ebb19d] | 13 | |
---|
[9c0326] | 14 | #include <initial.h> |
---|
[3c0aa5] | 15 | #include <tropicalStrategy.h> |
---|
[ebb19d] | 16 | #include <groebnerCone.h> |
---|
[3c0aa5] | 17 | #include <callgfanlib_conversion.h> |
---|
| 18 | #include <containsMonomial.h> |
---|
[ebb19d] | 19 | #include <initial.h> |
---|
[5d0cbd] | 20 | // #include <flip.h> |
---|
[3c0aa5] | 21 | #include <tropicalCurves.h> |
---|
| 22 | #include <bbcone.h> |
---|
[ebb19d] | 23 | |
---|
[551009] | 24 | #ifndef NDEBUG |
---|
[3c0aa5] | 25 | static bool checkPolynomialInput(const ideal I, const ring r) |
---|
[ebb19d] | 26 | { |
---|
[3c0aa5] | 27 | if (r) rTest(r); |
---|
| 28 | if (I && r) id_Test(I,r); |
---|
| 29 | return ((!I) || (I && r)); |
---|
| 30 | } |
---|
[ebb19d] | 31 | |
---|
[3c0aa5] | 32 | static bool checkOrderingAndCone(const ring r, const gfan::ZCone zc) |
---|
| 33 | { |
---|
[dffd154] | 34 | return true; |
---|
[3c0aa5] | 35 | if (r) |
---|
[ebb19d] | 36 | { |
---|
[3c0aa5] | 37 | int n = rVar(r); int* w = r->wvhdl[0]; |
---|
| 38 | gfan::ZVector v = wvhdlEntryToZVector(n,w); |
---|
[78abc7] | 39 | if (r->order[0]==ringorder_ws) |
---|
| 40 | v = gfan::Integer((long)-1)*v; |
---|
[3c0aa5] | 41 | if (!zc.contains(v)) |
---|
| 42 | { |
---|
| 43 | std::cout << "ERROR: weight of ordering not inside Groebner cone!" << std::endl |
---|
| 44 | << "cone: " << std::endl |
---|
| 45 | << toString(&zc) |
---|
| 46 | << "weight: " << std::endl |
---|
| 47 | << v << std::endl; |
---|
[eb836c] | 48 | return false; |
---|
[3c0aa5] | 49 | } |
---|
[eb836c] | 50 | return true; |
---|
[ebb19d] | 51 | } |
---|
[3c0aa5] | 52 | return (zc.dimension()==0); |
---|
[ebb19d] | 53 | } |
---|
| 54 | |
---|
[3c0aa5] | 55 | static bool checkPolyhedralInput(const gfan::ZCone zc, const gfan::ZVector p) |
---|
[ebb19d] | 56 | { |
---|
[3c0aa5] | 57 | return zc.containsRelatively(p); |
---|
[ebb19d] | 58 | } |
---|
| 59 | |
---|
[598793] | 60 | #if 0 /*unused*/ |
---|
[551009] | 61 | static bool checkOrderingAndWeight(const ideal I, const ring r, const gfan::ZVector w, const tropicalStrategy& currentCase) |
---|
| 62 | { |
---|
| 63 | groebnerCone sigma(I,r,currentCase); |
---|
| 64 | gfan::ZCone zc = sigma.getPolyhedralCone(); |
---|
| 65 | return zc.contains(w); |
---|
| 66 | } |
---|
[598793] | 67 | #endif |
---|
[551009] | 68 | |
---|
| 69 | bool groebnerCone::checkFlipConeInput(const gfan::ZVector interiorPoint, const gfan::ZVector facetNormal) const |
---|
| 70 | { |
---|
| 71 | /* check first whether interiorPoint lies on the boundary of the cone */ |
---|
| 72 | if (!polyhedralCone.contains(interiorPoint)) |
---|
| 73 | { |
---|
| 74 | std::cout << "ERROR: interiorPoint is not contained in the Groebner cone!" << std::endl |
---|
| 75 | << "cone: " << std::endl |
---|
| 76 | << toString(&polyhedralCone) |
---|
| 77 | << "interiorPoint:" << std::endl |
---|
| 78 | << interiorPoint << std::endl; |
---|
| 79 | return false; |
---|
| 80 | } |
---|
| 81 | if (polyhedralCone.containsRelatively(interiorPoint)) |
---|
| 82 | { |
---|
| 83 | std::cout << "ERROR: interiorPoint is contained in the interior of the maximal Groebner cone!" << std::endl |
---|
| 84 | << "cone: " << std::endl |
---|
| 85 | << toString(&polyhedralCone) |
---|
| 86 | << "interiorPoint:" << std::endl |
---|
| 87 | << interiorPoint << std::endl; |
---|
| 88 | return false; |
---|
| 89 | } |
---|
| 90 | gfan::ZCone hopefullyAFacet = polyhedralCone.faceContaining(interiorPoint); |
---|
| 91 | if (hopefullyAFacet.dimension()!=(polyhedralCone.dimension()-1)) |
---|
| 92 | { |
---|
| 93 | std::cout << "ERROR: interiorPoint is not contained in the interior of a facet!" << std::endl |
---|
| 94 | << "cone: " << std::endl |
---|
| 95 | << toString(&polyhedralCone) |
---|
| 96 | << "interiorPoint:" << std::endl |
---|
| 97 | << interiorPoint << std::endl; |
---|
| 98 | return false; |
---|
| 99 | } |
---|
| 100 | /* check whether facet normal points outwards */ |
---|
| 101 | gfan::ZCone dual = polyhedralCone.dualCone(); |
---|
[7723d00] | 102 | if(dual.containsRelatively(facetNormal)) |
---|
[551009] | 103 | { |
---|
| 104 | std::cout << "ERROR: facetNormal is not pointing outwards!" << std::endl |
---|
| 105 | << "cone: " << std::endl |
---|
| 106 | << toString(&polyhedralCone) |
---|
| 107 | << "facetNormal:" << std::endl |
---|
| 108 | << facetNormal << std::endl; |
---|
| 109 | return false; |
---|
| 110 | } |
---|
| 111 | return true; |
---|
| 112 | } |
---|
| 113 | #endif //NDEBUG |
---|
| 114 | |
---|
[3c0aa5] | 115 | groebnerCone::groebnerCone(): |
---|
| 116 | polynomialIdeal(NULL), |
---|
| 117 | polynomialRing(NULL), |
---|
| 118 | polyhedralCone(gfan::ZCone(0)), |
---|
| 119 | interiorPoint(gfan::ZVector(0)), |
---|
| 120 | currentStrategy(NULL) |
---|
[ebb19d] | 121 | { |
---|
| 122 | } |
---|
| 123 | |
---|
[3c0aa5] | 124 | groebnerCone::groebnerCone(const ideal I, const ring r, const tropicalStrategy& currentCase): |
---|
| 125 | polynomialIdeal(NULL), |
---|
| 126 | polynomialRing(NULL), |
---|
| 127 | currentStrategy(¤tCase) |
---|
[ebb19d] | 128 | { |
---|
[3c0aa5] | 129 | assume(checkPolynomialInput(I,r)); |
---|
| 130 | if (r) polynomialRing = rCopy(r); |
---|
[7723d00] | 131 | if (I) |
---|
| 132 | { |
---|
| 133 | polynomialIdeal = id_Copy(I,r); |
---|
| 134 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
| 135 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
| 136 | } |
---|
[ebb19d] | 137 | |
---|
[3c0aa5] | 138 | int n = rVar(polynomialRing); |
---|
[9abcc6] | 139 | poly g = NULL; |
---|
| 140 | int* leadexpv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
| 141 | int* tailexpv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
| 142 | gfan::ZVector leadexpw = gfan::ZVector(n); |
---|
| 143 | gfan::ZVector tailexpw = gfan::ZVector(n); |
---|
| 144 | gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); |
---|
[34183a] | 145 | for (int i=0; i<IDELEMS(polynomialIdeal); i++) |
---|
[9abcc6] | 146 | { |
---|
[7723d00] | 147 | g = polynomialIdeal->m[i]; |
---|
[eacb781] | 148 | if (g) |
---|
[9abcc6] | 149 | { |
---|
[eacb781] | 150 | p_GetExpV(g,leadexpv,r); |
---|
[b71400a] | 151 | leadexpw = expvToZVector(n, leadexpv); |
---|
[9abcc6] | 152 | pIter(g); |
---|
[eacb781] | 153 | while (g) |
---|
| 154 | { |
---|
| 155 | p_GetExpV(g,tailexpv,r); |
---|
[b71400a] | 156 | tailexpw = expvToZVector(n, tailexpv); |
---|
[eacb781] | 157 | inequalities.appendRow(leadexpw-tailexpw); |
---|
| 158 | pIter(g); |
---|
| 159 | } |
---|
[9abcc6] | 160 | } |
---|
| 161 | } |
---|
| 162 | omFreeSize(leadexpv,(n+1)*sizeof(int)); |
---|
| 163 | omFreeSize(tailexpv,(n+1)*sizeof(int)); |
---|
[b71400a] | 164 | // if (currentStrategy->restrictToLowerHalfSpace()) |
---|
| 165 | // { |
---|
| 166 | // gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
| 167 | // lowerHalfSpaceCondition[0] = -1; |
---|
| 168 | // inequalities.appendRow(lowerHalfSpaceCondition); |
---|
| 169 | // } |
---|
[eacb781] | 170 | |
---|
[3c0aa5] | 171 | polyhedralCone = gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth())); |
---|
[eacb781] | 172 | polyhedralCone.canonicalize(); |
---|
[3c0aa5] | 173 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
| 174 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
[9abcc6] | 175 | } |
---|
| 176 | |
---|
[3c0aa5] | 177 | groebnerCone::groebnerCone(const ideal I, const ring r, const gfan::ZVector& w, const tropicalStrategy& currentCase): |
---|
| 178 | polynomialIdeal(NULL), |
---|
| 179 | polynomialRing(NULL), |
---|
| 180 | currentStrategy(¤tCase) |
---|
[ebb19d] | 181 | { |
---|
[3c0aa5] | 182 | assume(checkPolynomialInput(I,r)); |
---|
| 183 | if (r) polynomialRing = rCopy(r); |
---|
[7723d00] | 184 | if (I) |
---|
| 185 | { |
---|
| 186 | polynomialIdeal = id_Copy(I,r); |
---|
| 187 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
| 188 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
| 189 | } |
---|
[3c0aa5] | 190 | |
---|
[9c0326] | 191 | int n = rVar(polynomialRing); |
---|
[3c0aa5] | 192 | gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); |
---|
| 193 | gfan::ZMatrix equations = gfan::ZMatrix(0,n); |
---|
| 194 | int* expv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
[34183a] | 195 | for (int i=0; i<IDELEMS(polynomialIdeal); i++) |
---|
[3c0aa5] | 196 | { |
---|
[7723d00] | 197 | poly g = polynomialIdeal->m[i]; |
---|
[eacb781] | 198 | if (g) |
---|
[3c0aa5] | 199 | { |
---|
[e744d9] | 200 | p_GetExpV(g,expv,polynomialRing); |
---|
[eacb781] | 201 | gfan::ZVector leadexpv = intStar2ZVector(n,expv); |
---|
| 202 | long d = wDeg(g,polynomialRing,w); |
---|
| 203 | for (pIter(g); g; pIter(g)) |
---|
[3c0aa5] | 204 | { |
---|
[eacb781] | 205 | p_GetExpV(g,expv,polynomialRing); |
---|
| 206 | gfan::ZVector tailexpv = intStar2ZVector(n,expv); |
---|
| 207 | if (wDeg(g,polynomialRing,w)==d) |
---|
| 208 | equations.appendRow(leadexpv-tailexpv); |
---|
| 209 | else |
---|
| 210 | { |
---|
| 211 | assume(wDeg(g,polynomialRing,w)<d); |
---|
| 212 | inequalities.appendRow(leadexpv-tailexpv); |
---|
| 213 | } |
---|
[3c0aa5] | 214 | } |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
[dffd154] | 218 | // if (currentStrategy->restrictToLowerHalfSpace()) |
---|
| 219 | // { |
---|
| 220 | // gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
| 221 | // lowerHalfSpaceCondition[0] = -1; |
---|
| 222 | // inequalities.appendRow(lowerHalfSpaceCondition); |
---|
| 223 | // } |
---|
[3c0aa5] | 224 | |
---|
| 225 | polyhedralCone = gfan::ZCone(inequalities,equations); |
---|
[eacb781] | 226 | polyhedralCone.canonicalize(); |
---|
[3c0aa5] | 227 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
| 228 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
[ebb19d] | 229 | } |
---|
| 230 | |
---|
[eb836c] | 231 | /*** |
---|
| 232 | * Computes the groebner cone of I around u+e*w for e>0 sufficiently small. |
---|
| 233 | * Assumes that this cone is a face of the maximal Groenbner cone given by the ordering of r. |
---|
| 234 | **/ |
---|
| 235 | groebnerCone::groebnerCone(const ideal I, const ring r, const gfan::ZVector& u, const gfan::ZVector& w, const tropicalStrategy& currentCase): |
---|
| 236 | polynomialIdeal(NULL), |
---|
| 237 | polynomialRing(NULL), |
---|
| 238 | currentStrategy(¤tCase) |
---|
| 239 | { |
---|
| 240 | assume(checkPolynomialInput(I,r)); |
---|
| 241 | if (r) polynomialRing = rCopy(r); |
---|
[7723d00] | 242 | if (I) |
---|
| 243 | { |
---|
| 244 | polynomialIdeal = id_Copy(I,r); |
---|
| 245 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
| 246 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
| 247 | } |
---|
[eb836c] | 248 | |
---|
[9c0326] | 249 | int n = rVar(polynomialRing); |
---|
[eb836c] | 250 | gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); |
---|
| 251 | gfan::ZMatrix equations = gfan::ZMatrix(0,n); |
---|
| 252 | int* expv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
[34183a] | 253 | for (int i=0; i<IDELEMS(polynomialIdeal); i++) |
---|
[eb836c] | 254 | { |
---|
[7723d00] | 255 | poly g = polynomialIdeal->m[i]; |
---|
[eacb781] | 256 | if (g) |
---|
[eb836c] | 257 | { |
---|
| 258 | p_GetExpV(g,expv,polynomialRing); |
---|
[eacb781] | 259 | gfan::ZVector leadexpv = intStar2ZVector(n,expv); |
---|
| 260 | long d1 = wDeg(g,polynomialRing,u); |
---|
| 261 | long d2 = wDeg(g,polynomialRing,w); |
---|
| 262 | for (pIter(g); g; pIter(g)) |
---|
[eb836c] | 263 | { |
---|
[eacb781] | 264 | p_GetExpV(g,expv,polynomialRing); |
---|
| 265 | gfan::ZVector tailexpv = intStar2ZVector(n,expv); |
---|
| 266 | if (wDeg(g,polynomialRing,u)==d1 && wDeg(g,polynomialRing,w)==d2) |
---|
| 267 | equations.appendRow(leadexpv-tailexpv); |
---|
| 268 | else |
---|
| 269 | { |
---|
| 270 | assume(wDeg(g,polynomialRing,u)<d1 || wDeg(g,polynomialRing,w)<d2); |
---|
| 271 | inequalities.appendRow(leadexpv-tailexpv); |
---|
| 272 | } |
---|
[eb836c] | 273 | } |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
[dffd154] | 277 | // if (currentStrategy->restrictToLowerHalfSpace()) |
---|
| 278 | // { |
---|
| 279 | // gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
| 280 | // lowerHalfSpaceCondition[0] = -1; |
---|
| 281 | // inequalities.appendRow(lowerHalfSpaceCondition); |
---|
| 282 | // } |
---|
[eb836c] | 283 | |
---|
| 284 | polyhedralCone = gfan::ZCone(inequalities,equations); |
---|
[eacb781] | 285 | polyhedralCone.canonicalize(); |
---|
[eb836c] | 286 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
| 287 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
[e744d9] | 291 | groebnerCone::groebnerCone(const ideal I, const ideal inI, const ring r, const tropicalStrategy& currentCase): |
---|
| 292 | polynomialIdeal(id_Copy(I,r)), |
---|
| 293 | polynomialRing(rCopy(r)), |
---|
| 294 | currentStrategy(¤tCase) |
---|
| 295 | { |
---|
| 296 | assume(checkPolynomialInput(I,r)); |
---|
| 297 | assume(checkPolynomialInput(inI,r)); |
---|
[ff48aa] | 298 | |
---|
[7723d00] | 299 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
| 300 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
[9c0326] | 301 | |
---|
[e744d9] | 302 | int n = rVar(r); |
---|
| 303 | gfan::ZMatrix equations = gfan::ZMatrix(0,n); |
---|
| 304 | int* expv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
[34183a] | 305 | for (int i=0; i<IDELEMS(inI); i++) |
---|
[e744d9] | 306 | { |
---|
[ff48aa] | 307 | poly g = inI->m[i]; |
---|
[eacb781] | 308 | if (g) |
---|
[e744d9] | 309 | { |
---|
| 310 | p_GetExpV(g,expv,r); |
---|
[eacb781] | 311 | gfan::ZVector leadexpv = intStar2ZVector(n,expv); |
---|
| 312 | for (pIter(g); g; pIter(g)) |
---|
| 313 | { |
---|
| 314 | p_GetExpV(g,expv,r); |
---|
| 315 | gfan::ZVector tailexpv = intStar2ZVector(n,expv); |
---|
| 316 | equations.appendRow(leadexpv-tailexpv); |
---|
| 317 | } |
---|
[e744d9] | 318 | } |
---|
| 319 | } |
---|
| 320 | gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); |
---|
[34183a] | 321 | for (int i=0; i<IDELEMS(polynomialIdeal); i++) |
---|
[e744d9] | 322 | { |
---|
[7723d00] | 323 | poly g = polynomialIdeal->m[i]; |
---|
[eacb781] | 324 | if (g) |
---|
[e744d9] | 325 | { |
---|
| 326 | p_GetExpV(g,expv,r); |
---|
[eacb781] | 327 | gfan::ZVector leadexpv = intStar2ZVector(n,expv); |
---|
| 328 | for (pIter(g); g; pIter(g)) |
---|
| 329 | { |
---|
| 330 | p_GetExpV(g,expv,r); |
---|
| 331 | gfan::ZVector tailexpv = intStar2ZVector(n,expv); |
---|
| 332 | inequalities.appendRow(leadexpv-tailexpv); |
---|
| 333 | } |
---|
[e744d9] | 334 | } |
---|
| 335 | } |
---|
| 336 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
[eacb781] | 337 | if (currentStrategy->restrictToLowerHalfSpace()) |
---|
| 338 | { |
---|
| 339 | gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
| 340 | lowerHalfSpaceCondition[0] = -1; |
---|
| 341 | inequalities.appendRow(lowerHalfSpaceCondition); |
---|
| 342 | } |
---|
[e744d9] | 343 | |
---|
| 344 | polyhedralCone = gfan::ZCone(inequalities,equations); |
---|
[eacb781] | 345 | polyhedralCone.canonicalize(); |
---|
[e744d9] | 346 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
| 347 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
| 348 | } |
---|
| 349 | |
---|
[3c0aa5] | 350 | groebnerCone::groebnerCone(const groebnerCone &sigma): |
---|
| 351 | polynomialIdeal(NULL), |
---|
| 352 | polynomialRing(NULL), |
---|
| 353 | polyhedralCone(gfan::ZCone(sigma.getPolyhedralCone())), |
---|
| 354 | interiorPoint(gfan::ZVector(sigma.getInteriorPoint())), |
---|
| 355 | currentStrategy(sigma.getTropicalStrategy()) |
---|
[ebb19d] | 356 | { |
---|
[3c0aa5] | 357 | assume(checkPolynomialInput(sigma.getPolynomialIdeal(),sigma.getPolynomialRing())); |
---|
| 358 | assume(checkOrderingAndCone(sigma.getPolynomialRing(),sigma.getPolyhedralCone())); |
---|
| 359 | assume(checkPolyhedralInput(sigma.getPolyhedralCone(),sigma.getInteriorPoint())); |
---|
| 360 | if (sigma.getPolynomialIdeal()) polynomialIdeal = id_Copy(sigma.getPolynomialIdeal(),sigma.getPolynomialRing()); |
---|
| 361 | if (sigma.getPolynomialRing()) polynomialRing = rCopy(sigma.getPolynomialRing()); |
---|
[ebb19d] | 362 | } |
---|
| 363 | |
---|
[7aa26b2] | 364 | groebnerCone::~groebnerCone() |
---|
[ebb19d] | 365 | { |
---|
[3c0aa5] | 366 | assume(checkPolynomialInput(polynomialIdeal,polynomialRing)); |
---|
| 367 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
| 368 | assume(checkPolyhedralInput(polyhedralCone,interiorPoint)); |
---|
| 369 | if (polynomialIdeal) id_Delete(&polynomialIdeal,polynomialRing); |
---|
| 370 | if (polynomialRing) rDelete(polynomialRing); |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | groebnerCone& groebnerCone::operator=(const groebnerCone& sigma) |
---|
| 374 | { |
---|
| 375 | assume(checkPolynomialInput(sigma.getPolynomialIdeal(),sigma.getPolynomialRing())); |
---|
| 376 | assume(checkOrderingAndCone(sigma.getPolynomialRing(),sigma.getPolyhedralCone())); |
---|
| 377 | assume(checkPolyhedralInput(sigma.getPolyhedralCone(),sigma.getInteriorPoint())); |
---|
| 378 | if (sigma.getPolynomialIdeal()) polynomialIdeal = id_Copy(sigma.getPolynomialIdeal(),sigma.getPolynomialRing()); |
---|
| 379 | if (sigma.getPolynomialRing()) polynomialRing = rCopy(sigma.getPolynomialRing()); |
---|
| 380 | polyhedralCone = sigma.getPolyhedralCone(); |
---|
| 381 | interiorPoint = sigma.getInteriorPoint(); |
---|
| 382 | currentStrategy = sigma.getTropicalStrategy(); |
---|
| 383 | return *this; |
---|
[ebb19d] | 384 | } |
---|
[c89014] | 385 | |
---|
[551009] | 386 | /** |
---|
| 387 | * Returns true if Groebner cone contains w, false otherwise |
---|
| 388 | */ |
---|
| 389 | bool groebnerCone::contains(const gfan::ZVector &w) const |
---|
| 390 | { |
---|
| 391 | return polyhedralCone.contains(w); |
---|
| 392 | } |
---|
| 393 | |
---|
[c89014] | 394 | |
---|
[3c0aa5] | 395 | /*** |
---|
| 396 | * Returns a point in the tropical variety, if the groebnerCone contains one. |
---|
| 397 | * Returns an empty vector otherwise. |
---|
| 398 | **/ |
---|
| 399 | gfan::ZVector groebnerCone::tropicalPoint() const |
---|
[c89014] | 400 | { |
---|
[eacb781] | 401 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
[3c0aa5] | 402 | ideal I = polynomialIdeal; |
---|
| 403 | ring r = polynomialRing; |
---|
[eacb781] | 404 | |
---|
| 405 | gfan::ZCone coneToCheck = polyhedralCone; |
---|
| 406 | gfan::ZMatrix R = coneToCheck.extremeRays(); |
---|
[3c0aa5] | 407 | for (int i=0; i<R.getHeight(); i++) |
---|
[c89014] | 408 | { |
---|
[eacb781] | 409 | assume(!currentStrategy->restrictToLowerHalfSpace() || R[i][0].sign()<=0); |
---|
[9c0326] | 410 | if (currentStrategy->restrictToLowerHalfSpace() && R[i][0].sign()==0) |
---|
| 411 | continue; |
---|
[08b7c2a] | 412 | std::pair<poly,int> s = currentStrategy->checkInitialIdealForMonomial(I,r,R[i]); |
---|
| 413 | if (s.first==NULL) |
---|
[c89014] | 414 | { |
---|
[08b7c2a] | 415 | if (s.second<0) |
---|
| 416 | // if monomial was initialized, delete it |
---|
| 417 | p_Delete(&s.first,r); |
---|
[3c0aa5] | 418 | return R[i]; |
---|
[c89014] | 419 | } |
---|
| 420 | } |
---|
[3c0aa5] | 421 | return gfan::ZVector(); |
---|
| 422 | } |
---|
| 423 | |
---|
[9c0326] | 424 | /** |
---|
[3c0aa5] | 425 | * Given an interior point on the facet and the outer normal factor on the facet, |
---|
| 426 | * returns the adjacent groebnerCone sharing that facet |
---|
[9c0326] | 427 | */ |
---|
[551009] | 428 | groebnerCone groebnerCone::flipCone(const gfan::ZVector &interiorPoint, const gfan::ZVector &facetNormal) const |
---|
[9abcc6] | 429 | { |
---|
[3c0aa5] | 430 | assume(this->checkFlipConeInput(interiorPoint,facetNormal)); |
---|
| 431 | /* Note: the polynomial ring created will have a weighted ordering with respect to interiorPoint |
---|
| 432 | * and with a weighted ordering with respect to facetNormal as tiebreaker. |
---|
| 433 | * Hence it is sufficient to compute the initial form with respect to facetNormal, |
---|
| 434 | * to obtain an initial form with respect to interiorPoint+e*facetNormal, |
---|
| 435 | * for e>0 sufficiently small */ |
---|
[ff48aa] | 436 | std::pair<ideal,ring> flipped = currentStrategy->computeFlip(polynomialIdeal,polynomialRing,interiorPoint,facetNormal); |
---|
[3c0aa5] | 437 | assume(checkPolynomialInput(flipped.first,flipped.second)); |
---|
[eb836c] | 438 | groebnerCone flippedCone(flipped.first, flipped.second, interiorPoint, facetNormal, *currentStrategy); |
---|
[bf83d3] | 439 | id_Delete(&flipped.first,flipped.second); |
---|
| 440 | rDelete(flipped.second); |
---|
[3c0aa5] | 441 | return flippedCone; |
---|
[9abcc6] | 442 | } |
---|
| 443 | |
---|
[3c0aa5] | 444 | |
---|
| 445 | /*** |
---|
| 446 | * Returns a complete list of neighboring Groebner cones. |
---|
| 447 | **/ |
---|
| 448 | groebnerCones groebnerCone::groebnerNeighbours() const |
---|
[9abcc6] | 449 | { |
---|
[3c0aa5] | 450 | std::pair<gfan::ZMatrix, gfan::ZMatrix> facetsData = interiorPointsAndNormalsOfFacets(polyhedralCone); |
---|
[bf83d3] | 451 | |
---|
[3c0aa5] | 452 | gfan::ZMatrix interiorPoints = facetsData.first; |
---|
| 453 | gfan::ZMatrix facetNormals = facetsData.second; |
---|
| 454 | |
---|
| 455 | groebnerCones neighbours; |
---|
| 456 | for (int i=0; i<interiorPoints.getHeight(); i++) |
---|
[eacb781] | 457 | { |
---|
[9c0326] | 458 | gfan::ZVector w = interiorPoints[i]; |
---|
| 459 | gfan::ZVector v = facetNormals[i]; |
---|
| 460 | if (currentStrategy->restrictToLowerHalfSpace()) |
---|
| 461 | { |
---|
| 462 | assume(w[0].sign()<=0); |
---|
| 463 | if (w[0].sign()==0 && v[0].sign()>0) |
---|
| 464 | continue; |
---|
| 465 | } |
---|
[bf83d3] | 466 | neighbours.insert(flipCone(interiorPoints[i],facetNormals[i])); |
---|
[eacb781] | 467 | } |
---|
[3c0aa5] | 468 | return neighbours; |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | |
---|
[b71400a] | 472 | bool groebnerCone::pointsOutwards(const gfan::ZVector w) const |
---|
| 473 | { |
---|
| 474 | gfan::ZCone dual = polyhedralCone.dualCone(); |
---|
| 475 | return (!dual.contains(w)); |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | |
---|
[3c0aa5] | 479 | /*** |
---|
| 480 | * Returns a complete list of neighboring Groebner cones in the tropical variety. |
---|
| 481 | **/ |
---|
| 482 | groebnerCones groebnerCone::tropicalNeighbours() const |
---|
| 483 | { |
---|
| 484 | gfan::ZMatrix interiorPoints = interiorPointsOfFacets(polyhedralCone); |
---|
| 485 | groebnerCones neighbours; |
---|
| 486 | for (int i=0; i<interiorPoints.getHeight(); i++) |
---|
| 487 | { |
---|
[eacb781] | 488 | if (!(currentStrategy->restrictToLowerHalfSpace() && interiorPoints[i][0].sign()==0)) |
---|
| 489 | { |
---|
| 490 | ideal initialIdeal = initial(polynomialIdeal,polynomialRing,interiorPoints[i]); |
---|
[551009] | 491 | gfan::ZMatrix ray = raysOfTropicalStar(initialIdeal,polynomialRing,interiorPoints[i],currentStrategy); |
---|
[b71400a] | 492 | for (int j=0; j<ray.getHeight(); j++) |
---|
| 493 | if (pointsOutwards(ray[j])) |
---|
| 494 | { |
---|
| 495 | groebnerCone neighbour = flipCone(interiorPoints[i],ray[j]); |
---|
| 496 | neighbours.insert(neighbour); |
---|
| 497 | } |
---|
[bf83d3] | 498 | id_Delete(&initialIdeal,polynomialRing); |
---|
[eacb781] | 499 | } |
---|
[3c0aa5] | 500 | } |
---|
| 501 | return neighbours; |
---|
[9abcc6] | 502 | } |
---|
| 503 | |
---|
| 504 | |
---|
[7aa26b2] | 505 | gfan::ZFan* toFanStar(groebnerCones setOfCones) |
---|
[9abcc6] | 506 | { |
---|
| 507 | if (setOfCones.size() > 0) |
---|
| 508 | { |
---|
[3c0aa5] | 509 | groebnerCones::iterator sigma = setOfCones.begin(); |
---|
| 510 | gfan::ZFan* zf = new gfan::ZFan(sigma->getPolyhedralCone().ambientDimension()); |
---|
| 511 | for (; sigma!=setOfCones.end(); sigma++) |
---|
[7723d00] | 512 | { |
---|
| 513 | gfan::ZCone zc = sigma->getPolyhedralCone(); |
---|
[1d85871] | 514 | // assume(isCompatible(zf,&zc)); |
---|
[7723d00] | 515 | zf->insert(zc); |
---|
| 516 | } |
---|
[9abcc6] | 517 | return zf; |
---|
| 518 | } |
---|
| 519 | else |
---|
[24d30d] | 520 | return new gfan::ZFan(gfan::ZFan(currRing->N)); |
---|
[9abcc6] | 521 | } |
---|
[bf83d3] | 522 | |
---|
| 523 | |
---|
| 524 | #ifndef NDEBUG |
---|
| 525 | |
---|
| 526 | BOOLEAN flipConeDebug(leftv res, leftv args) |
---|
| 527 | { |
---|
| 528 | leftv u = args; |
---|
| 529 | if ((u!=NULL) && (u->Typ()==IDEAL_CMD)) |
---|
| 530 | { |
---|
| 531 | leftv v = u->next; |
---|
| 532 | if ((v!=NULL) && (v->Typ()==NUMBER_CMD)) |
---|
| 533 | { |
---|
| 534 | leftv w = v->next; |
---|
| 535 | if ((w!=NULL) && (w->Typ()==BIGINTMAT_CMD)) |
---|
| 536 | { |
---|
| 537 | leftv x = w->next; |
---|
| 538 | if ((x!=NULL) && (x->Typ()==BIGINTMAT_CMD)) |
---|
| 539 | { |
---|
| 540 | omUpdateInfo(); |
---|
| 541 | Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); |
---|
| 542 | |
---|
| 543 | ideal I = (ideal) u->CopyD(); |
---|
| 544 | number p = (number) v->CopyD(); |
---|
| 545 | bigintmat* interiorPoint0 = (bigintmat*) w->CopyD(); |
---|
| 546 | bigintmat* facetNormal0 = (bigintmat*) x->CopyD(); |
---|
| 547 | tropicalStrategy debug = tropicalStrategy::debugStrategy(I,p,currRing); |
---|
| 548 | |
---|
| 549 | gfan::ZVector* interiorPoint = bigintmatToZVector(interiorPoint0); |
---|
| 550 | gfan::ZVector* facetNormal = bigintmatToZVector(facetNormal0); |
---|
| 551 | |
---|
| 552 | groebnerCone sigma(I,currRing,debug); |
---|
| 553 | groebnerCone theta = sigma.flipCone(*interiorPoint,*facetNormal); |
---|
| 554 | |
---|
| 555 | id_Delete(&I,currRing); |
---|
| 556 | n_Delete(&p,currRing->cf); |
---|
| 557 | delete interiorPoint0; |
---|
| 558 | delete facetNormal0; |
---|
| 559 | delete interiorPoint; |
---|
| 560 | delete facetNormal; |
---|
| 561 | |
---|
| 562 | res->rtyp = NONE; |
---|
| 563 | res->data = NULL; |
---|
| 564 | return FALSE; |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | } |
---|
| 568 | } |
---|
| 569 | WerrorS("computeFlipDebug: unexpected parameters"); |
---|
| 570 | return TRUE; |
---|
| 571 | } |
---|
| 572 | |
---|
| 573 | BOOLEAN groebnerNeighboursDebug(leftv res, leftv args) |
---|
| 574 | { |
---|
| 575 | leftv u = args; |
---|
| 576 | if ((u!=NULL) && (u->Typ()==IDEAL_CMD)) |
---|
| 577 | { |
---|
| 578 | leftv v = u->next; |
---|
| 579 | if ((v!=NULL) && (v->Typ()==NUMBER_CMD)) |
---|
| 580 | { |
---|
| 581 | omUpdateInfo(); |
---|
| 582 | Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); |
---|
| 583 | |
---|
| 584 | ideal I = (ideal) u->CopyD(); |
---|
| 585 | number p = (number) v->CopyD(); |
---|
| 586 | |
---|
| 587 | tropicalStrategy debug = tropicalStrategy::debugStrategy(I,p,currRing); |
---|
| 588 | groebnerCone sigma(I,currRing,debug); |
---|
| 589 | groebnerCones neighbours = sigma.groebnerNeighbours(); |
---|
| 590 | |
---|
| 591 | id_Delete(&I,currRing); |
---|
| 592 | n_Delete(&p,currRing->cf); |
---|
| 593 | res->rtyp = NONE; |
---|
| 594 | res->data = NULL; |
---|
| 595 | return FALSE; |
---|
| 596 | } |
---|
| 597 | } |
---|
| 598 | WerrorS("computeFlipDebug: unexpected parameters"); |
---|
| 599 | return TRUE; |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | BOOLEAN tropicalNeighboursDebug(leftv res, leftv args) |
---|
| 603 | { |
---|
| 604 | leftv u = args; |
---|
| 605 | if ((u!=NULL) && (u->Typ()==IDEAL_CMD)) |
---|
| 606 | { |
---|
| 607 | leftv v = u->next; |
---|
| 608 | if ((v!=NULL) && (v->Typ()==NUMBER_CMD)) |
---|
| 609 | { |
---|
| 610 | omUpdateInfo(); |
---|
| 611 | Print("usedBytesBefore=%ld\n",om_Info.UsedBytes); |
---|
| 612 | |
---|
| 613 | ideal I = (ideal) u->CopyD(); |
---|
| 614 | number p = (number) v->CopyD(); |
---|
| 615 | |
---|
| 616 | tropicalStrategy debug = tropicalStrategy::debugStrategy(I,p,currRing); |
---|
| 617 | groebnerCone sigma(I,currRing,debug); |
---|
| 618 | groebnerCones neighbours = sigma.groebnerNeighbours(); |
---|
| 619 | |
---|
| 620 | id_Delete(&I,currRing); |
---|
| 621 | n_Delete(&p,currRing->cf); |
---|
| 622 | res->rtyp = NONE; |
---|
| 623 | res->data = NULL; |
---|
| 624 | return FALSE; |
---|
| 625 | } |
---|
| 626 | } |
---|
| 627 | WerrorS("computeFlipDebug: unexpected parameters"); |
---|
| 628 | return TRUE; |
---|
| 629 | } |
---|
| 630 | #endif |
---|