1 | #include <utility> |
---|
2 | |
---|
3 | #include <kernel/GBEngine/kstd1.h> |
---|
4 | #include <kernel/ideals.h> |
---|
5 | #include <Singular/ipid.h> |
---|
6 | |
---|
7 | #include <polys/monomials/p_polys.h> |
---|
8 | #include <polys/monomials/ring.h> |
---|
9 | #include <polys/prCopy.h> |
---|
10 | |
---|
11 | #include <gfanlib/gfanlib.h> |
---|
12 | #include <gfanlib/gfanlib_matrix.h> |
---|
13 | |
---|
14 | #include <initial.h> |
---|
15 | #include <tropicalStrategy.h> |
---|
16 | #include <groebnerCone.h> |
---|
17 | #include <callgfanlib_conversion.h> |
---|
18 | #include <containsMonomial.h> |
---|
19 | #include <initial.h> |
---|
20 | // #include <flip.h> |
---|
21 | #include <tropicalCurves.h> |
---|
22 | #include <bbcone.h> |
---|
23 | |
---|
24 | #ifndef NDEBUG |
---|
25 | static bool checkPolynomialInput(const ideal I, const ring r) |
---|
26 | { |
---|
27 | if (r) rTest(r); |
---|
28 | if (I && r) id_Test(I,r); |
---|
29 | return ((!I) || (I && r)); |
---|
30 | } |
---|
31 | |
---|
32 | static bool checkOrderingAndCone(const ring r, const gfan::ZCone zc) |
---|
33 | { |
---|
34 | return true; |
---|
35 | if (r) |
---|
36 | { |
---|
37 | int n = rVar(r); int* w = r->wvhdl[0]; |
---|
38 | gfan::ZVector v = wvhdlEntryToZVector(n,w); |
---|
39 | if (r->order[0]==ringorder_ws) |
---|
40 | v = gfan::Integer((long)-1)*v; |
---|
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; |
---|
48 | return false; |
---|
49 | } |
---|
50 | return true; |
---|
51 | } |
---|
52 | return (zc.dimension()==0); |
---|
53 | } |
---|
54 | |
---|
55 | static bool checkPolyhedralInput(const gfan::ZCone zc, const gfan::ZVector p) |
---|
56 | { |
---|
57 | return zc.containsRelatively(p); |
---|
58 | } |
---|
59 | |
---|
60 | #if 0 /*unused*/ |
---|
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 | } |
---|
67 | #endif |
---|
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(); |
---|
102 | if(dual.containsRelatively(facetNormal)) |
---|
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 | |
---|
115 | groebnerCone::groebnerCone(): |
---|
116 | polynomialIdeal(NULL), |
---|
117 | polynomialRing(NULL), |
---|
118 | polyhedralCone(gfan::ZCone(0)), |
---|
119 | interiorPoint(gfan::ZVector(0)), |
---|
120 | currentStrategy(NULL) |
---|
121 | { |
---|
122 | } |
---|
123 | |
---|
124 | groebnerCone::groebnerCone(const ideal I, const ring r, const tropicalStrategy& currentCase): |
---|
125 | polynomialIdeal(NULL), |
---|
126 | polynomialRing(NULL), |
---|
127 | currentStrategy(¤tCase) |
---|
128 | { |
---|
129 | assume(checkPolynomialInput(I,r)); |
---|
130 | if (r) polynomialRing = rCopy(r); |
---|
131 | if (I) |
---|
132 | { |
---|
133 | polynomialIdeal = id_Copy(I,r); |
---|
134 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
135 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
136 | } |
---|
137 | |
---|
138 | int n = rVar(polynomialRing); |
---|
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); |
---|
145 | for (int i=0; i<idSize(polynomialIdeal); i++) |
---|
146 | { |
---|
147 | g = polynomialIdeal->m[i]; |
---|
148 | if (g) |
---|
149 | { |
---|
150 | p_GetExpV(g,leadexpv,r); |
---|
151 | leadexpw = expvToZVector(n, leadexpv); |
---|
152 | pIter(g); |
---|
153 | while (g) |
---|
154 | { |
---|
155 | p_GetExpV(g,tailexpv,r); |
---|
156 | tailexpw = expvToZVector(n, tailexpv); |
---|
157 | inequalities.appendRow(leadexpw-tailexpw); |
---|
158 | pIter(g); |
---|
159 | } |
---|
160 | } |
---|
161 | } |
---|
162 | omFreeSize(leadexpv,(n+1)*sizeof(int)); |
---|
163 | omFreeSize(tailexpv,(n+1)*sizeof(int)); |
---|
164 | // if (currentStrategy->restrictToLowerHalfSpace()) |
---|
165 | // { |
---|
166 | // gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
167 | // lowerHalfSpaceCondition[0] = -1; |
---|
168 | // inequalities.appendRow(lowerHalfSpaceCondition); |
---|
169 | // } |
---|
170 | |
---|
171 | polyhedralCone = gfan::ZCone(inequalities,gfan::ZMatrix(0, inequalities.getWidth())); |
---|
172 | polyhedralCone.canonicalize(); |
---|
173 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
174 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
175 | } |
---|
176 | |
---|
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) |
---|
181 | { |
---|
182 | assume(checkPolynomialInput(I,r)); |
---|
183 | if (r) polynomialRing = rCopy(r); |
---|
184 | if (I) |
---|
185 | { |
---|
186 | polynomialIdeal = id_Copy(I,r); |
---|
187 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
188 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
189 | } |
---|
190 | |
---|
191 | int n = rVar(polynomialRing); |
---|
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)); |
---|
195 | for (int i=0; i<idSize(polynomialIdeal); i++) |
---|
196 | { |
---|
197 | poly g = polynomialIdeal->m[i]; |
---|
198 | if (g) |
---|
199 | { |
---|
200 | p_GetExpV(g,expv,polynomialRing); |
---|
201 | gfan::ZVector leadexpv = intStar2ZVector(n,expv); |
---|
202 | long d = wDeg(g,polynomialRing,w); |
---|
203 | for (pIter(g); g; pIter(g)) |
---|
204 | { |
---|
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 | } |
---|
214 | } |
---|
215 | } |
---|
216 | } |
---|
217 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
218 | // if (currentStrategy->restrictToLowerHalfSpace()) |
---|
219 | // { |
---|
220 | // gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
221 | // lowerHalfSpaceCondition[0] = -1; |
---|
222 | // inequalities.appendRow(lowerHalfSpaceCondition); |
---|
223 | // } |
---|
224 | |
---|
225 | polyhedralCone = gfan::ZCone(inequalities,equations); |
---|
226 | polyhedralCone.canonicalize(); |
---|
227 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
228 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
229 | } |
---|
230 | |
---|
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); |
---|
242 | if (I) |
---|
243 | { |
---|
244 | polynomialIdeal = id_Copy(I,r); |
---|
245 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
246 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
247 | } |
---|
248 | |
---|
249 | int n = rVar(polynomialRing); |
---|
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)); |
---|
253 | for (int i=0; i<idSize(polynomialIdeal); i++) |
---|
254 | { |
---|
255 | poly g = polynomialIdeal->m[i]; |
---|
256 | if (g) |
---|
257 | { |
---|
258 | p_GetExpV(g,expv,polynomialRing); |
---|
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)) |
---|
263 | { |
---|
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 | } |
---|
273 | } |
---|
274 | } |
---|
275 | } |
---|
276 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
277 | // if (currentStrategy->restrictToLowerHalfSpace()) |
---|
278 | // { |
---|
279 | // gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
280 | // lowerHalfSpaceCondition[0] = -1; |
---|
281 | // inequalities.appendRow(lowerHalfSpaceCondition); |
---|
282 | // } |
---|
283 | |
---|
284 | polyhedralCone = gfan::ZCone(inequalities,equations); |
---|
285 | polyhedralCone.canonicalize(); |
---|
286 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
287 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
288 | } |
---|
289 | |
---|
290 | |
---|
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)); |
---|
298 | |
---|
299 | currentCase.pReduce(polynomialIdeal,polynomialRing); |
---|
300 | currentCase.reduce(polynomialIdeal,polynomialRing); |
---|
301 | |
---|
302 | int n = rVar(r); |
---|
303 | gfan::ZMatrix equations = gfan::ZMatrix(0,n); |
---|
304 | int* expv = (int*) omAlloc((n+1)*sizeof(int)); |
---|
305 | for (int i=0; i<idSize(inI); i++) |
---|
306 | { |
---|
307 | poly g = inI->m[i]; |
---|
308 | if (g) |
---|
309 | { |
---|
310 | p_GetExpV(g,expv,r); |
---|
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 | } |
---|
318 | } |
---|
319 | } |
---|
320 | gfan::ZMatrix inequalities = gfan::ZMatrix(0,n); |
---|
321 | for (int i=0; i<idSize(polynomialIdeal); i++) |
---|
322 | { |
---|
323 | poly g = polynomialIdeal->m[i]; |
---|
324 | if (g) |
---|
325 | { |
---|
326 | p_GetExpV(g,expv,r); |
---|
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 | } |
---|
334 | } |
---|
335 | } |
---|
336 | omFreeSize(expv,(n+1)*sizeof(int)); |
---|
337 | if (currentStrategy->restrictToLowerHalfSpace()) |
---|
338 | { |
---|
339 | gfan::ZVector lowerHalfSpaceCondition = gfan::ZVector(n); |
---|
340 | lowerHalfSpaceCondition[0] = -1; |
---|
341 | inequalities.appendRow(lowerHalfSpaceCondition); |
---|
342 | } |
---|
343 | |
---|
344 | polyhedralCone = gfan::ZCone(inequalities,equations); |
---|
345 | polyhedralCone.canonicalize(); |
---|
346 | interiorPoint = polyhedralCone.getRelativeInteriorPoint(); |
---|
347 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
348 | } |
---|
349 | |
---|
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()) |
---|
356 | { |
---|
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()); |
---|
362 | } |
---|
363 | |
---|
364 | groebnerCone::~groebnerCone() |
---|
365 | { |
---|
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; |
---|
384 | } |
---|
385 | |
---|
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 | |
---|
394 | |
---|
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 |
---|
400 | { |
---|
401 | assume(checkOrderingAndCone(polynomialRing,polyhedralCone)); |
---|
402 | ideal I = polynomialIdeal; |
---|
403 | ring r = polynomialRing; |
---|
404 | |
---|
405 | gfan::ZCone coneToCheck = polyhedralCone; |
---|
406 | gfan::ZMatrix R = coneToCheck.extremeRays(); |
---|
407 | for (int i=0; i<R.getHeight(); i++) |
---|
408 | { |
---|
409 | assume(!currentStrategy->restrictToLowerHalfSpace() || R[i][0].sign()<=0); |
---|
410 | if (currentStrategy->restrictToLowerHalfSpace() && R[i][0].sign()==0) |
---|
411 | continue; |
---|
412 | std::pair<poly,int> s = currentStrategy->checkInitialIdealForMonomial(I,r,R[i]); |
---|
413 | if (s.first==NULL) |
---|
414 | { |
---|
415 | if (s.second<0) |
---|
416 | // if monomial was initialized, delete it |
---|
417 | p_Delete(&s.first,r); |
---|
418 | return R[i]; |
---|
419 | } |
---|
420 | } |
---|
421 | return gfan::ZVector(); |
---|
422 | } |
---|
423 | |
---|
424 | /** |
---|
425 | * Given an interior point on the facet and the outer normal factor on the facet, |
---|
426 | * returns the adjacent groebnerCone sharing that facet |
---|
427 | */ |
---|
428 | groebnerCone groebnerCone::flipCone(const gfan::ZVector &interiorPoint, const gfan::ZVector &facetNormal) const |
---|
429 | { |
---|
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 */ |
---|
436 | std::pair<ideal,ring> flipped = currentStrategy->computeFlip(polynomialIdeal,polynomialRing,interiorPoint,facetNormal); |
---|
437 | assume(checkPolynomialInput(flipped.first,flipped.second)); |
---|
438 | groebnerCone flippedCone(flipped.first, flipped.second, interiorPoint, facetNormal, *currentStrategy); |
---|
439 | id_Delete(&flipped.first,flipped.second); |
---|
440 | rDelete(flipped.second); |
---|
441 | return flippedCone; |
---|
442 | } |
---|
443 | |
---|
444 | |
---|
445 | /*** |
---|
446 | * Returns a complete list of neighboring Groebner cones. |
---|
447 | **/ |
---|
448 | groebnerCones groebnerCone::groebnerNeighbours() const |
---|
449 | { |
---|
450 | std::pair<gfan::ZMatrix, gfan::ZMatrix> facetsData = interiorPointsAndNormalsOfFacets(polyhedralCone); |
---|
451 | |
---|
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++) |
---|
457 | { |
---|
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 | } |
---|
466 | neighbours.insert(flipCone(interiorPoints[i],facetNormals[i])); |
---|
467 | } |
---|
468 | return neighbours; |
---|
469 | } |
---|
470 | |
---|
471 | |
---|
472 | bool groebnerCone::pointsOutwards(const gfan::ZVector w) const |
---|
473 | { |
---|
474 | gfan::ZCone dual = polyhedralCone.dualCone(); |
---|
475 | return (!dual.contains(w)); |
---|
476 | } |
---|
477 | |
---|
478 | |
---|
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 | { |
---|
488 | if (!(currentStrategy->restrictToLowerHalfSpace() && interiorPoints[i][0].sign()==0)) |
---|
489 | { |
---|
490 | ideal initialIdeal = initial(polynomialIdeal,polynomialRing,interiorPoints[i]); |
---|
491 | gfan::ZMatrix ray = raysOfTropicalStar(initialIdeal,polynomialRing,interiorPoints[i],currentStrategy); |
---|
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 | } |
---|
498 | id_Delete(&initialIdeal,polynomialRing); |
---|
499 | } |
---|
500 | } |
---|
501 | return neighbours; |
---|
502 | } |
---|
503 | |
---|
504 | |
---|
505 | gfan::ZFan* toFanStar(groebnerCones setOfCones) |
---|
506 | { |
---|
507 | if (setOfCones.size() > 0) |
---|
508 | { |
---|
509 | groebnerCones::iterator sigma = setOfCones.begin(); |
---|
510 | gfan::ZFan* zf = new gfan::ZFan(sigma->getPolyhedralCone().ambientDimension()); |
---|
511 | for (; sigma!=setOfCones.end(); sigma++) |
---|
512 | { |
---|
513 | gfan::ZCone zc = sigma->getPolyhedralCone(); |
---|
514 | // assume(isCompatible(zf,&zc)); |
---|
515 | zf->insert(zc); |
---|
516 | } |
---|
517 | return zf; |
---|
518 | } |
---|
519 | else |
---|
520 | return new gfan::ZFan(gfan::ZFan::fullFan(currRing->N)); |
---|
521 | } |
---|
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 |
---|