1 | #include "kernel/mod2.h" |
---|
2 | |
---|
3 | #if HAVE_GFANLIB |
---|
4 | |
---|
5 | #include "misc/intvec.h" |
---|
6 | #include "misc/sirandom.h" |
---|
7 | |
---|
8 | #include "coeffs/bigintmat.h" |
---|
9 | #include "coeffs/longrat.h" |
---|
10 | |
---|
11 | #include "Singular/ipid.h" |
---|
12 | #include "Singular/ipshell.h" |
---|
13 | #include "Singular/blackbox.h" |
---|
14 | |
---|
15 | #include "Singular/links/ssiLink.h" |
---|
16 | |
---|
17 | #include "callgfanlib_conversion.h" |
---|
18 | |
---|
19 | #include "gfanlib/gfanlib.h" |
---|
20 | #include "gfanlib/gfanlib_q.h" |
---|
21 | |
---|
22 | #include "bbfan.h" |
---|
23 | #include "bbpolytope.h" |
---|
24 | |
---|
25 | int coneID; |
---|
26 | |
---|
27 | std::string toString(const gfan::ZCone* const c) |
---|
28 | { |
---|
29 | std::stringstream s; |
---|
30 | s<<"AMBIENT_DIM"<<std::endl; |
---|
31 | s<<c->ambientDimension()<<std::endl; |
---|
32 | |
---|
33 | gfan::ZMatrix i=c->getInequalities(); |
---|
34 | char* ineqs = toString(i); |
---|
35 | if (c->areFacetsKnown()) |
---|
36 | s<<"FACETS"<<std::endl; |
---|
37 | else |
---|
38 | s<<"INEQUALITIES"<<std::endl; |
---|
39 | if (ineqs!=NULL) |
---|
40 | { |
---|
41 | s<<ineqs<<std::endl; |
---|
42 | omFree(ineqs); |
---|
43 | } |
---|
44 | |
---|
45 | gfan::ZMatrix e=c->getEquations(); |
---|
46 | char* eqs = toString(e); |
---|
47 | if (c->areImpliedEquationsKnown()) |
---|
48 | s<<"LINEAR_SPAN"<<std::endl; |
---|
49 | else |
---|
50 | s<<"EQUATIONS"<<std::endl; |
---|
51 | if (eqs!=NULL) |
---|
52 | { |
---|
53 | s<<eqs<<std::endl; |
---|
54 | omFree(eqs); |
---|
55 | } |
---|
56 | |
---|
57 | if (c->areExtremeRaysKnown()) |
---|
58 | { |
---|
59 | gfan::ZMatrix r=c->extremeRays(); |
---|
60 | char* rs = toString(r); |
---|
61 | s<<"RAYS"<<std::endl; |
---|
62 | if (rs!=NULL) |
---|
63 | { |
---|
64 | s<<rs<<std::endl; |
---|
65 | omFree(rs); |
---|
66 | } |
---|
67 | gfan::ZMatrix l=c->generatorsOfLinealitySpace(); |
---|
68 | char* ls = toString(l); |
---|
69 | s<<"LINEALITY_SPACE"<<std::endl; |
---|
70 | if (ls!=NULL) |
---|
71 | { |
---|
72 | s<<ls<<std::endl; |
---|
73 | omFree(ls); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | return s.str(); |
---|
78 | } |
---|
79 | |
---|
80 | void* bbcone_Init(blackbox* /*b*/) |
---|
81 | { |
---|
82 | return (void*)(new gfan::ZCone()); |
---|
83 | } |
---|
84 | |
---|
85 | BOOLEAN bbcone_Assign(leftv l, leftv r) |
---|
86 | { |
---|
87 | gfan::ZCone* newZc; |
---|
88 | if (r==NULL) |
---|
89 | { |
---|
90 | if (l->Data()!=NULL) |
---|
91 | { |
---|
92 | gfan::ZCone* zd = (gfan::ZCone*)l->Data(); |
---|
93 | delete zd; |
---|
94 | } |
---|
95 | newZc = new gfan::ZCone(); |
---|
96 | } |
---|
97 | else if (r->Typ()==l->Typ()) |
---|
98 | { |
---|
99 | if (l->Data()!=NULL) |
---|
100 | { |
---|
101 | gfan::ZCone* zd = (gfan::ZCone*)l->Data(); |
---|
102 | delete zd; |
---|
103 | } |
---|
104 | newZc = (gfan::ZCone*)r->CopyD(); |
---|
105 | } |
---|
106 | else if (r->Typ()==INT_CMD) |
---|
107 | { |
---|
108 | int ambientDim = (int)(long)r->Data(); |
---|
109 | if (ambientDim < 0) |
---|
110 | { |
---|
111 | Werror("expected an int >= 0, but got %d", ambientDim); |
---|
112 | return TRUE; |
---|
113 | } |
---|
114 | if (l->Data()!=NULL) |
---|
115 | { |
---|
116 | gfan::ZCone* zd = (gfan::ZCone*)l->Data(); |
---|
117 | delete zd; |
---|
118 | } |
---|
119 | newZc = new gfan::ZCone(ambientDim); |
---|
120 | } |
---|
121 | else |
---|
122 | { |
---|
123 | Werror("assign Type(%d) = Type(%d) not implemented",l->Typ(),r->Typ()); |
---|
124 | return TRUE; |
---|
125 | } |
---|
126 | |
---|
127 | if (l->rtyp==IDHDL) |
---|
128 | { |
---|
129 | IDDATA((idhdl)l->data)=(char*) newZc; |
---|
130 | } |
---|
131 | else |
---|
132 | { |
---|
133 | l->data=(void *)newZc; |
---|
134 | } |
---|
135 | return FALSE; |
---|
136 | } |
---|
137 | |
---|
138 | char* bbcone_String(blackbox* /*b*/, void *d) |
---|
139 | { |
---|
140 | if (d==NULL) return omStrDup("invalid object"); |
---|
141 | else |
---|
142 | { |
---|
143 | std::string s=toString((gfan::ZCone*) d); |
---|
144 | return omStrDup(s.c_str()); |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | void bbcone_destroy(blackbox* /*b*/, void *d) |
---|
149 | { |
---|
150 | if (d!=NULL) |
---|
151 | { |
---|
152 | gfan::ZCone* zc = (gfan::ZCone*) d; |
---|
153 | delete zc; |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | void* bbcone_Copy(blackbox* /*b*/, void *d) |
---|
158 | { |
---|
159 | gfan::ZCone* zc = (gfan::ZCone*)d; |
---|
160 | gfan::ZCone* newZc = new gfan::ZCone(*zc); |
---|
161 | return newZc; |
---|
162 | } |
---|
163 | |
---|
164 | static BOOLEAN bbcone_Op2(int op, leftv res, leftv i1, leftv i2) |
---|
165 | { |
---|
166 | gfan::ZCone* zp = (gfan::ZCone*) i1->Data(); |
---|
167 | switch(op) |
---|
168 | { |
---|
169 | case '&': |
---|
170 | { |
---|
171 | if (i2->Typ()==coneID) |
---|
172 | { |
---|
173 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
174 | int d1 = zp->ambientDimension(); |
---|
175 | int d2 = zq->ambientDimension(); |
---|
176 | if (d1 != d2) |
---|
177 | { |
---|
178 | WerrorS("mismatching ambient dimensions"); |
---|
179 | return TRUE; |
---|
180 | } |
---|
181 | gfan::ZCone* zs = new gfan::ZCone(); |
---|
182 | *zs = gfan::intersection(*zp, *zq); |
---|
183 | zs->canonicalize(); |
---|
184 | res->rtyp = coneID; |
---|
185 | res->data = (void*) zs; |
---|
186 | return FALSE; |
---|
187 | } |
---|
188 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
189 | } |
---|
190 | case '|': |
---|
191 | { |
---|
192 | if(i2->Typ()==coneID) |
---|
193 | { |
---|
194 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
195 | int d1 = zp->ambientDimension(); |
---|
196 | int d2 = zq->ambientDimension(); |
---|
197 | if (d1 != d2) |
---|
198 | { |
---|
199 | WerrorS("mismatching ambient dimensions"); |
---|
200 | return TRUE; |
---|
201 | } |
---|
202 | gfan::ZMatrix rays = zp->extremeRays(); |
---|
203 | rays.append(zq->extremeRays()); |
---|
204 | gfan::ZMatrix lineality = zp->generatorsOfLinealitySpace(); |
---|
205 | lineality.append(zq->generatorsOfLinealitySpace()); |
---|
206 | gfan::ZCone* zs = new gfan::ZCone(); |
---|
207 | *zs = gfan::ZCone::givenByRays(rays,lineality); |
---|
208 | zs->canonicalize(); |
---|
209 | res->rtyp = coneID; |
---|
210 | res->data = (void*) zs; |
---|
211 | return FALSE; |
---|
212 | } |
---|
213 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
214 | } |
---|
215 | case EQUAL_EQUAL: |
---|
216 | { |
---|
217 | if(i2->Typ()==coneID) |
---|
218 | { |
---|
219 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
220 | zp->canonicalize(); |
---|
221 | zq->canonicalize(); |
---|
222 | bool b = !((*zp)!=(*zq)); |
---|
223 | res->rtyp = INT_CMD; |
---|
224 | res->data = (void*) b; |
---|
225 | return FALSE; |
---|
226 | } |
---|
227 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
228 | } |
---|
229 | default: |
---|
230 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
231 | } |
---|
232 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | /* singular wrapper for gfanlib functions */ |
---|
237 | static BOOLEAN jjCONENORMALS1(leftv res, leftv v) |
---|
238 | { |
---|
239 | /* method for generating a cone object from inequalities; |
---|
240 | valid parametrizations: (intmat) */ |
---|
241 | bigintmat* ineq = NULL; |
---|
242 | if (v->Typ() == INTMAT_CMD) |
---|
243 | { |
---|
244 | intvec* ineq0 = (intvec*) v->Data(); |
---|
245 | ineq = iv2bim(ineq0,coeffs_BIGINT); |
---|
246 | } |
---|
247 | else |
---|
248 | ineq = (bigintmat*) v->Data(); |
---|
249 | gfan::ZMatrix* zm = bigintmatToZMatrix(ineq); |
---|
250 | gfan::ZCone* zc = new gfan::ZCone(*zm, gfan::ZMatrix(0, zm->getWidth())); |
---|
251 | delete zm; |
---|
252 | if (v->Typ() == INTMAT_CMD) |
---|
253 | delete ineq; |
---|
254 | res->rtyp = coneID; |
---|
255 | res->data = (void*) zc; |
---|
256 | return FALSE; |
---|
257 | } |
---|
258 | |
---|
259 | static BOOLEAN jjCONENORMALS2(leftv res, leftv u, leftv v) |
---|
260 | { |
---|
261 | /* method for generating a cone object from iequalities, |
---|
262 | and equations (...) |
---|
263 | valid parametrizations: (intmat, intmat) |
---|
264 | Errors will be invoked in the following cases: |
---|
265 | - u and v have different numbers of columns */ |
---|
266 | bigintmat* ineq = NULL; bigintmat* eq = NULL; |
---|
267 | if (u->Typ() == INTMAT_CMD) |
---|
268 | { |
---|
269 | intvec* ineq0 = (intvec*) u->Data(); |
---|
270 | ineq = iv2bim(ineq0,coeffs_BIGINT); |
---|
271 | } |
---|
272 | else |
---|
273 | ineq = (bigintmat*) u->Data(); |
---|
274 | if (v->Typ() == INTMAT_CMD) |
---|
275 | { |
---|
276 | intvec* eq0 = (intvec*) v->Data(); |
---|
277 | eq = iv2bim(eq0,coeffs_BIGINT); |
---|
278 | } |
---|
279 | else |
---|
280 | eq = (bigintmat*) v->Data(); |
---|
281 | |
---|
282 | if (ineq->cols() != eq->cols()) |
---|
283 | { |
---|
284 | Werror("expected same number of columns but got %d vs. %d", |
---|
285 | ineq->cols(), eq->cols()); |
---|
286 | return TRUE; |
---|
287 | } |
---|
288 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(ineq); |
---|
289 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(eq); |
---|
290 | gfan::ZCone* zc = new gfan::ZCone(*zm1, *zm2); |
---|
291 | delete zm1; |
---|
292 | delete zm2; |
---|
293 | if (u->Typ() == INTMAT_CMD) |
---|
294 | delete ineq; |
---|
295 | if (v->Typ() == INTMAT_CMD) |
---|
296 | delete eq; |
---|
297 | res->rtyp = coneID; |
---|
298 | res->data = (void*) zc; |
---|
299 | return FALSE; |
---|
300 | } |
---|
301 | |
---|
302 | static BOOLEAN jjCONENORMALS3(leftv res, leftv u, leftv v, leftv w) |
---|
303 | { |
---|
304 | /* method for generating a cone object from inequalities, equations, |
---|
305 | and an integer k; |
---|
306 | valid parametrizations: (intmat, intmat, int); |
---|
307 | Errors will be invoked in the following cases: |
---|
308 | - u and v have different numbers of columns, |
---|
309 | - k not in [0..3]; |
---|
310 | if the 2^0-bit of k is set, then ... */ |
---|
311 | bigintmat* ineq = NULL; bigintmat* eq = NULL; |
---|
312 | if (u->Typ() == INTMAT_CMD) |
---|
313 | { |
---|
314 | intvec* ineq0 = (intvec*) u->Data(); |
---|
315 | ineq = iv2bim(ineq0,coeffs_BIGINT); |
---|
316 | } |
---|
317 | else |
---|
318 | ineq = (bigintmat*) u->Data(); |
---|
319 | if (v->Typ() == INTMAT_CMD) |
---|
320 | { |
---|
321 | intvec* eq0 = (intvec*) v->Data(); |
---|
322 | eq = iv2bim(eq0,coeffs_BIGINT); |
---|
323 | } |
---|
324 | else |
---|
325 | eq = (bigintmat*) v->Data(); |
---|
326 | if (ineq->cols() != eq->cols()) |
---|
327 | { |
---|
328 | Werror("expected same number of columns but got %d vs. %d", |
---|
329 | ineq->cols(), eq->cols()); |
---|
330 | return TRUE; |
---|
331 | } |
---|
332 | int k = (int)(long)w->Data(); |
---|
333 | if ((k < 0) || (k > 3)) |
---|
334 | { |
---|
335 | WerrorS("expected int argument in [0..3]"); |
---|
336 | return TRUE; |
---|
337 | } |
---|
338 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(ineq); |
---|
339 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(eq); |
---|
340 | gfan::ZCone* zc = new gfan::ZCone(*zm1, *zm2, k); |
---|
341 | delete zm1; |
---|
342 | delete zm2; |
---|
343 | if (u->Typ() == INTMAT_CMD) |
---|
344 | delete ineq; |
---|
345 | if (v->Typ() == INTMAT_CMD) |
---|
346 | delete eq; |
---|
347 | res->rtyp = coneID; |
---|
348 | res->data = (void*) zc; |
---|
349 | return FALSE; |
---|
350 | } |
---|
351 | |
---|
352 | BOOLEAN coneViaNormals(leftv res, leftv args) |
---|
353 | { |
---|
354 | gfan::initializeCddlibIfRequired(); |
---|
355 | leftv u = args; |
---|
356 | if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) |
---|
357 | { |
---|
358 | if (u->next == NULL) |
---|
359 | { |
---|
360 | BOOLEAN bo = jjCONENORMALS1(res, u); |
---|
361 | gfan::deinitializeCddlibIfRequired(); |
---|
362 | return bo; |
---|
363 | } |
---|
364 | } |
---|
365 | leftv v = u->next; |
---|
366 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTMAT_CMD))) |
---|
367 | { |
---|
368 | if (v->next == NULL) |
---|
369 | { |
---|
370 | BOOLEAN bo = jjCONENORMALS2(res, u, v); |
---|
371 | gfan::deinitializeCddlibIfRequired(); |
---|
372 | return bo; |
---|
373 | } |
---|
374 | } |
---|
375 | leftv w = v->next; |
---|
376 | if ((w != NULL) && (w->Typ() == INT_CMD)) |
---|
377 | { |
---|
378 | if (w->next == NULL) |
---|
379 | { |
---|
380 | BOOLEAN bo = jjCONENORMALS3(res, u, v, w); |
---|
381 | gfan::deinitializeCddlibIfRequired(); |
---|
382 | return bo; |
---|
383 | } |
---|
384 | } |
---|
385 | WerrorS("coneViaInequalities: unexpected parameters"); |
---|
386 | return TRUE; |
---|
387 | } |
---|
388 | |
---|
389 | static BOOLEAN jjCONERAYS1(leftv res, leftv v) |
---|
390 | { |
---|
391 | /* method for generating a cone object from half-lines |
---|
392 | (cone = convex hull of the half-lines; note: there may be |
---|
393 | entire lines in the cone); |
---|
394 | valid parametrizations: (intmat) */ |
---|
395 | bigintmat* rays = NULL; |
---|
396 | if (v->Typ() == INTMAT_CMD) |
---|
397 | { |
---|
398 | intvec* rays0 = (intvec*) v->Data(); |
---|
399 | rays = iv2bim(rays0,coeffs_BIGINT); |
---|
400 | } |
---|
401 | else |
---|
402 | rays = (bigintmat*) v->Data(); |
---|
403 | |
---|
404 | gfan::ZMatrix* zm = bigintmatToZMatrix(rays); |
---|
405 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
406 | *zc = gfan::ZCone::givenByRays(*zm, gfan::ZMatrix(0, zm->getWidth())); |
---|
407 | res->rtyp = coneID; |
---|
408 | res->data = (void*) zc; |
---|
409 | |
---|
410 | delete zm; |
---|
411 | if (v->Typ() == INTMAT_CMD) |
---|
412 | delete rays; |
---|
413 | return FALSE; |
---|
414 | } |
---|
415 | |
---|
416 | static BOOLEAN jjCONERAYS2(leftv res, leftv u, leftv v) |
---|
417 | { |
---|
418 | /* method for generating a cone object from half-lines, |
---|
419 | and lines (any point in the cone being the sum of a point |
---|
420 | in the convex hull of the half-lines and a point in the span |
---|
421 | of the lines; the second argument may contain or entirely consist |
---|
422 | of zero rows); |
---|
423 | valid parametrizations: (intmat, intmat) |
---|
424 | Errors will be invoked in the following cases: |
---|
425 | - u and v have different numbers of columns */ |
---|
426 | bigintmat* rays = NULL; bigintmat* linSpace = NULL; |
---|
427 | if (u->Typ() == INTMAT_CMD) |
---|
428 | { |
---|
429 | intvec* rays0 = (intvec*) u->Data(); |
---|
430 | rays = iv2bim(rays0,coeffs_BIGINT); |
---|
431 | } |
---|
432 | else |
---|
433 | rays = (bigintmat*) u->Data(); |
---|
434 | if (v->Typ() == INTMAT_CMD) |
---|
435 | { |
---|
436 | intvec* linSpace0 = (intvec*) v->Data(); |
---|
437 | linSpace = iv2bim(linSpace0,coeffs_BIGINT); |
---|
438 | } |
---|
439 | else |
---|
440 | linSpace = (bigintmat*) v->Data(); |
---|
441 | |
---|
442 | if (rays->cols() != linSpace->cols()) |
---|
443 | { |
---|
444 | Werror("expected same number of columns but got %d vs. %d", |
---|
445 | rays->cols(), linSpace->cols()); |
---|
446 | return TRUE; |
---|
447 | } |
---|
448 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(rays); |
---|
449 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(linSpace); |
---|
450 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
451 | *zc = gfan::ZCone::givenByRays(*zm1, *zm2); |
---|
452 | res->rtyp = coneID; |
---|
453 | res->data = (void*) zc; |
---|
454 | |
---|
455 | delete zm1; |
---|
456 | delete zm2; |
---|
457 | if (u->Typ() == INTMAT_CMD) |
---|
458 | delete rays; |
---|
459 | if (v->Typ() == INTMAT_CMD) |
---|
460 | delete linSpace; |
---|
461 | return FALSE; |
---|
462 | } |
---|
463 | |
---|
464 | static BOOLEAN jjCONERAYS3(leftv res, leftv u, leftv v, leftv w) |
---|
465 | { |
---|
466 | /* method for generating a cone object from half-lines, |
---|
467 | and lines (any point in the cone being the sum of a point |
---|
468 | in the convex hull of the half-lines and a point in the span |
---|
469 | of the lines), and an integer k; |
---|
470 | valid parametrizations: (intmat, intmat, int); |
---|
471 | Errors will be invoked in the following cases: |
---|
472 | - u and v have different numbers of columns, |
---|
473 | - k not in [0..3]; |
---|
474 | if the 2^0-bit of k is set, then the lineality space is known |
---|
475 | to be the span of the provided lines; |
---|
476 | if the 2^1-bit of k is set, then the extreme rays are known: |
---|
477 | each half-line spans a (different) extreme ray */ |
---|
478 | bigintmat* rays = NULL; bigintmat* linSpace = NULL; |
---|
479 | if (u->Typ() == INTMAT_CMD) |
---|
480 | { |
---|
481 | intvec* rays0 = (intvec*) u->Data(); |
---|
482 | rays = iv2bim(rays0,coeffs_BIGINT); |
---|
483 | } |
---|
484 | else |
---|
485 | rays = (bigintmat*) u->Data(); |
---|
486 | if (v->Typ() == INTMAT_CMD) |
---|
487 | { |
---|
488 | intvec* linSpace0 = (intvec*) v->Data(); |
---|
489 | linSpace = iv2bim(linSpace0,coeffs_BIGINT); |
---|
490 | } |
---|
491 | else |
---|
492 | linSpace = (bigintmat*) v->Data(); |
---|
493 | |
---|
494 | if (rays->cols() != linSpace->cols()) |
---|
495 | { |
---|
496 | Werror("expected same number of columns but got %d vs. %d", |
---|
497 | rays->cols(), linSpace->cols()); |
---|
498 | return TRUE; |
---|
499 | } |
---|
500 | int k = (int)(long)w->Data(); |
---|
501 | if ((k < 0) || (k > 3)) |
---|
502 | { |
---|
503 | WerrorS("expected int argument in [0..3]"); |
---|
504 | return TRUE; |
---|
505 | } |
---|
506 | gfan::ZMatrix* zm1 = bigintmatToZMatrix(rays); |
---|
507 | gfan::ZMatrix* zm2 = bigintmatToZMatrix(linSpace); |
---|
508 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
509 | *zc = gfan::ZCone::givenByRays(*zm1, *zm2); |
---|
510 | //k should be passed on to zc; not available yet |
---|
511 | res->rtyp = coneID; |
---|
512 | res->data = (void*) zc; |
---|
513 | |
---|
514 | delete zm1; |
---|
515 | delete zm2; |
---|
516 | if (u->Typ() == INTMAT_CMD) |
---|
517 | delete rays; |
---|
518 | if (v->Typ() == INTMAT_CMD) |
---|
519 | delete linSpace; |
---|
520 | return FALSE; |
---|
521 | } |
---|
522 | |
---|
523 | BOOLEAN coneViaRays(leftv res, leftv args) |
---|
524 | { |
---|
525 | gfan::initializeCddlibIfRequired(); |
---|
526 | leftv u = args; |
---|
527 | if ((u != NULL) && ((u->Typ() == BIGINTMAT_CMD) || (u->Typ() == INTMAT_CMD))) |
---|
528 | { |
---|
529 | if (u->next == NULL) |
---|
530 | { |
---|
531 | BOOLEAN bo = jjCONERAYS1(res, u); |
---|
532 | gfan::deinitializeCddlibIfRequired(); |
---|
533 | return bo; |
---|
534 | } |
---|
535 | leftv v = u->next; |
---|
536 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTMAT_CMD))) |
---|
537 | { |
---|
538 | if (v->next == NULL) |
---|
539 | { |
---|
540 | BOOLEAN bo = jjCONERAYS2(res, u, v); |
---|
541 | gfan::deinitializeCddlibIfRequired(); |
---|
542 | return bo; |
---|
543 | } |
---|
544 | leftv w = v->next; |
---|
545 | if ((w != NULL) && (w->Typ() == INT_CMD)) |
---|
546 | { |
---|
547 | if (w->next == NULL) |
---|
548 | { |
---|
549 | BOOLEAN bo = jjCONERAYS3(res, u, v, w); |
---|
550 | gfan::deinitializeCddlibIfRequired(); |
---|
551 | return bo; |
---|
552 | } |
---|
553 | } |
---|
554 | } |
---|
555 | } |
---|
556 | WerrorS("coneViaPoints: unexpected parameters"); |
---|
557 | return TRUE; |
---|
558 | } |
---|
559 | |
---|
560 | BOOLEAN inequalities(leftv res, leftv args) |
---|
561 | { |
---|
562 | leftv u = args; |
---|
563 | if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) |
---|
564 | { |
---|
565 | gfan::initializeCddlibIfRequired(); |
---|
566 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
567 | gfan::ZMatrix zmat = zc->getInequalities(); |
---|
568 | res->rtyp = BIGINTMAT_CMD; |
---|
569 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
570 | gfan::deinitializeCddlibIfRequired(); |
---|
571 | return FALSE; |
---|
572 | } |
---|
573 | WerrorS("inequalities: unexpected parameters"); |
---|
574 | return TRUE; |
---|
575 | } |
---|
576 | |
---|
577 | BOOLEAN equations(leftv res, leftv args) |
---|
578 | { |
---|
579 | leftv u = args; |
---|
580 | if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) |
---|
581 | { |
---|
582 | gfan::initializeCddlibIfRequired(); |
---|
583 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
584 | gfan::ZMatrix zmat = zc->getEquations(); |
---|
585 | res->rtyp = BIGINTMAT_CMD; |
---|
586 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
587 | gfan::deinitializeCddlibIfRequired(); |
---|
588 | return FALSE; |
---|
589 | } |
---|
590 | WerrorS("equations: unexpected parameters"); |
---|
591 | return TRUE; |
---|
592 | } |
---|
593 | |
---|
594 | BOOLEAN facets(leftv res, leftv args) |
---|
595 | { |
---|
596 | leftv u = args; |
---|
597 | if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) |
---|
598 | { |
---|
599 | gfan::initializeCddlibIfRequired(); |
---|
600 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
601 | gfan::ZMatrix zm = zc->getFacets(); |
---|
602 | res->rtyp = BIGINTMAT_CMD; |
---|
603 | res->data = (void*) zMatrixToBigintmat(zm); |
---|
604 | gfan::deinitializeCddlibIfRequired(); |
---|
605 | return FALSE; |
---|
606 | } |
---|
607 | WerrorS("facets: unexpected parameters"); |
---|
608 | return TRUE; |
---|
609 | } |
---|
610 | |
---|
611 | BOOLEAN impliedEquations(leftv res, leftv args) |
---|
612 | { |
---|
613 | leftv u = args; |
---|
614 | if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) |
---|
615 | { |
---|
616 | gfan::initializeCddlibIfRequired(); |
---|
617 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
618 | gfan::ZMatrix zmat = zc->getImpliedEquations(); |
---|
619 | res->rtyp = BIGINTMAT_CMD; |
---|
620 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
621 | gfan::deinitializeCddlibIfRequired(); |
---|
622 | return FALSE; |
---|
623 | } |
---|
624 | WerrorS("span: unexpected parameters"); |
---|
625 | return TRUE; |
---|
626 | } |
---|
627 | |
---|
628 | BOOLEAN generatorsOfSpan(leftv res, leftv args) |
---|
629 | { |
---|
630 | leftv u = args; |
---|
631 | if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) |
---|
632 | { |
---|
633 | gfan::initializeCddlibIfRequired(); |
---|
634 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
635 | gfan::ZMatrix zmat = zc->generatorsOfSpan(); |
---|
636 | res->rtyp = BIGINTMAT_CMD; |
---|
637 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
638 | gfan::deinitializeCddlibIfRequired(); |
---|
639 | return FALSE; |
---|
640 | } |
---|
641 | WerrorS("generatorsOfSpan: unexpected parameters"); |
---|
642 | return TRUE; |
---|
643 | } |
---|
644 | |
---|
645 | BOOLEAN generatorsOfLinealitySpace(leftv res, leftv args) |
---|
646 | { |
---|
647 | leftv u = args; |
---|
648 | if ((u != NULL) && (u->Typ() == coneID || u->Typ() == polytopeID)) |
---|
649 | { |
---|
650 | gfan::initializeCddlibIfRequired(); |
---|
651 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
652 | gfan::ZMatrix zmat = zc->generatorsOfLinealitySpace(); |
---|
653 | res->rtyp = BIGINTMAT_CMD; |
---|
654 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
655 | gfan::deinitializeCddlibIfRequired(); |
---|
656 | return FALSE; |
---|
657 | } |
---|
658 | WerrorS("generatorsOfLinealitySpace: unexpected parameters"); |
---|
659 | return TRUE; |
---|
660 | } |
---|
661 | |
---|
662 | BOOLEAN rays(leftv res, leftv args) |
---|
663 | { |
---|
664 | leftv u = args; |
---|
665 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
666 | { |
---|
667 | gfan::initializeCddlibIfRequired(); |
---|
668 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
669 | gfan::ZMatrix zm = zc->extremeRays(); |
---|
670 | res->rtyp = BIGINTMAT_CMD; |
---|
671 | res->data = (void*)zMatrixToBigintmat(zm); |
---|
672 | gfan::deinitializeCddlibIfRequired(); |
---|
673 | return FALSE; |
---|
674 | } |
---|
675 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
676 | { |
---|
677 | gfan::initializeCddlibIfRequired(); |
---|
678 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
679 | gfan::ZMatrix zmat = rays(zf); |
---|
680 | res->rtyp = BIGINTMAT_CMD; |
---|
681 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
682 | gfan::deinitializeCddlibIfRequired(); |
---|
683 | return FALSE; |
---|
684 | } |
---|
685 | WerrorS("rays: unexpected parameters"); |
---|
686 | return TRUE; |
---|
687 | } |
---|
688 | |
---|
689 | BOOLEAN quotientLatticeBasis(leftv res, leftv args) |
---|
690 | { |
---|
691 | leftv u = args; |
---|
692 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
693 | { |
---|
694 | gfan::initializeCddlibIfRequired(); |
---|
695 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
696 | gfan::ZMatrix zmat = zc->quotientLatticeBasis(); |
---|
697 | res->rtyp = BIGINTMAT_CMD; |
---|
698 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
699 | gfan::deinitializeCddlibIfRequired(); |
---|
700 | return FALSE; |
---|
701 | } |
---|
702 | WerrorS("quotientLatticeBasis: unexpected parameters"); |
---|
703 | return TRUE; |
---|
704 | } |
---|
705 | |
---|
706 | BOOLEAN getLinearForms(leftv res, leftv args) |
---|
707 | { |
---|
708 | leftv u = args; |
---|
709 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
710 | { |
---|
711 | gfan::initializeCddlibIfRequired(); |
---|
712 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
713 | gfan::ZMatrix zmat = zc->getLinearForms(); |
---|
714 | res->rtyp = BIGINTMAT_CMD; |
---|
715 | res->data = (void*) zMatrixToBigintmat(zmat); |
---|
716 | gfan::deinitializeCddlibIfRequired(); |
---|
717 | return FALSE; |
---|
718 | } |
---|
719 | WerrorS("getLinearForms: unexpected parameters"); |
---|
720 | return TRUE; |
---|
721 | } |
---|
722 | |
---|
723 | BOOLEAN ambientDimension(leftv res, leftv args) |
---|
724 | { |
---|
725 | leftv u=args; |
---|
726 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
727 | { |
---|
728 | gfan::initializeCddlibIfRequired(); |
---|
729 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
730 | res->rtyp = INT_CMD; |
---|
731 | res->data = (void*) (long) zc->ambientDimension(); |
---|
732 | gfan::deinitializeCddlibIfRequired(); |
---|
733 | return FALSE; |
---|
734 | } |
---|
735 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
736 | { |
---|
737 | gfan::initializeCddlibIfRequired(); |
---|
738 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
739 | res->rtyp = INT_CMD; |
---|
740 | res->data = (void*) (long) getAmbientDimension(zf); |
---|
741 | gfan::deinitializeCddlibIfRequired(); |
---|
742 | return FALSE; |
---|
743 | } |
---|
744 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
745 | { |
---|
746 | gfan::initializeCddlibIfRequired(); |
---|
747 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
748 | res->rtyp = INT_CMD; |
---|
749 | res->data = (void*) (long) getAmbientDimension(zc); |
---|
750 | gfan::deinitializeCddlibIfRequired(); |
---|
751 | return FALSE; |
---|
752 | } |
---|
753 | WerrorS("ambientDimension: unexpected parameters"); |
---|
754 | return TRUE; |
---|
755 | } |
---|
756 | |
---|
757 | BOOLEAN dimension(leftv res, leftv args) |
---|
758 | { |
---|
759 | leftv u=args; |
---|
760 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
761 | { |
---|
762 | gfan::initializeCddlibIfRequired(); |
---|
763 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
764 | res->rtyp = INT_CMD; |
---|
765 | res->data = (void*) (long) zc->dimension(); |
---|
766 | gfan::deinitializeCddlibIfRequired(); |
---|
767 | return FALSE; |
---|
768 | } |
---|
769 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
770 | { |
---|
771 | gfan::initializeCddlibIfRequired(); |
---|
772 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
773 | res->rtyp = INT_CMD; |
---|
774 | res->data = (void*) (long) getDimension(zf); |
---|
775 | gfan::deinitializeCddlibIfRequired(); |
---|
776 | return FALSE; |
---|
777 | } |
---|
778 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
779 | { |
---|
780 | gfan::initializeCddlibIfRequired(); |
---|
781 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
782 | res->rtyp = INT_CMD; |
---|
783 | res->data = (void*) (long) getDimension(zc); |
---|
784 | gfan::deinitializeCddlibIfRequired(); |
---|
785 | return FALSE; |
---|
786 | } |
---|
787 | WerrorS("dimension: unexpected parameters"); |
---|
788 | return TRUE; |
---|
789 | } |
---|
790 | |
---|
791 | BOOLEAN codimension(leftv res, leftv args) |
---|
792 | { |
---|
793 | leftv u=args; |
---|
794 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
795 | { |
---|
796 | gfan::initializeCddlibIfRequired(); |
---|
797 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
798 | res->rtyp = INT_CMD; |
---|
799 | res->data = (void*) (long) zc->codimension(); |
---|
800 | gfan::deinitializeCddlibIfRequired(); |
---|
801 | return FALSE; |
---|
802 | } |
---|
803 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
804 | { |
---|
805 | gfan::initializeCddlibIfRequired(); |
---|
806 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
807 | res->rtyp = INT_CMD; |
---|
808 | res->data = (void*) (long) getCodimension(zf); |
---|
809 | gfan::deinitializeCddlibIfRequired(); |
---|
810 | return FALSE; |
---|
811 | } |
---|
812 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
813 | { |
---|
814 | gfan::initializeCddlibIfRequired(); |
---|
815 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
816 | res->rtyp = INT_CMD; |
---|
817 | res->data = (void*) (long) getCodimension(zc); |
---|
818 | gfan::deinitializeCddlibIfRequired(); |
---|
819 | return FALSE; |
---|
820 | } |
---|
821 | WerrorS("getCodimension: unexpected parameters"); |
---|
822 | return TRUE; |
---|
823 | } |
---|
824 | |
---|
825 | BOOLEAN linealityDimension(leftv res, leftv args) |
---|
826 | { |
---|
827 | leftv u=args; |
---|
828 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
829 | { |
---|
830 | gfan::initializeCddlibIfRequired(); |
---|
831 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
832 | res->rtyp = INT_CMD; |
---|
833 | res->data = (void*) (long) zc->dimensionOfLinealitySpace(); |
---|
834 | gfan::deinitializeCddlibIfRequired(); |
---|
835 | return FALSE; |
---|
836 | } |
---|
837 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
838 | { |
---|
839 | gfan::initializeCddlibIfRequired(); |
---|
840 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
841 | res->rtyp = INT_CMD; |
---|
842 | res->data = (void*) (long) getLinealityDimension(zf); |
---|
843 | gfan::deinitializeCddlibIfRequired(); |
---|
844 | return FALSE; |
---|
845 | } |
---|
846 | WerrorS("linealityDimension: unexpected parameters"); |
---|
847 | return TRUE; |
---|
848 | } |
---|
849 | |
---|
850 | BOOLEAN getMultiplicity(leftv res, leftv args) |
---|
851 | { |
---|
852 | leftv u = args; |
---|
853 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
854 | { |
---|
855 | gfan::initializeCddlibIfRequired(); |
---|
856 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
857 | number i = integerToNumber(zc->getMultiplicity()); |
---|
858 | res->rtyp = BIGINT_CMD; |
---|
859 | res->data = (void*) i; |
---|
860 | gfan::deinitializeCddlibIfRequired(); |
---|
861 | return FALSE; |
---|
862 | } |
---|
863 | WerrorS("getMultiplicity: unexpected parameters"); |
---|
864 | return TRUE; |
---|
865 | } |
---|
866 | |
---|
867 | BOOLEAN isOrigin(leftv res, leftv args) |
---|
868 | { |
---|
869 | leftv u = args; |
---|
870 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
871 | { |
---|
872 | gfan::initializeCddlibIfRequired(); |
---|
873 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
874 | int i = zc->isOrigin(); |
---|
875 | res->rtyp = INT_CMD; |
---|
876 | res->data = (void*) (long) i; |
---|
877 | gfan::deinitializeCddlibIfRequired(); |
---|
878 | return FALSE; |
---|
879 | } |
---|
880 | WerrorS("isOrigin: unexpected parameters"); |
---|
881 | return TRUE; |
---|
882 | } |
---|
883 | |
---|
884 | BOOLEAN isFullSpace(leftv res, leftv args) |
---|
885 | { |
---|
886 | leftv u = args; |
---|
887 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
888 | { |
---|
889 | gfan::initializeCddlibIfRequired(); |
---|
890 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
891 | int i = zc->isFullSpace(); |
---|
892 | res->rtyp = INT_CMD; |
---|
893 | res->data = (void*) (long) i; |
---|
894 | gfan::deinitializeCddlibIfRequired(); |
---|
895 | return FALSE; |
---|
896 | } |
---|
897 | WerrorS("isFullSpace: unexpected parameters"); |
---|
898 | return TRUE; |
---|
899 | } |
---|
900 | |
---|
901 | BOOLEAN isSimplicial(leftv res, leftv args) |
---|
902 | { |
---|
903 | leftv u=args; |
---|
904 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
905 | { |
---|
906 | gfan::initializeCddlibIfRequired(); |
---|
907 | gfan::ZCone* zc = (gfan::ZCone*) u->Data(); |
---|
908 | int b = zc->isSimplicial(); |
---|
909 | res->rtyp = INT_CMD; |
---|
910 | res->data = (void*) (long) b; |
---|
911 | gfan::deinitializeCddlibIfRequired(); |
---|
912 | return FALSE; |
---|
913 | } |
---|
914 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
915 | { |
---|
916 | gfan::initializeCddlibIfRequired(); |
---|
917 | gfan::ZFan* zf = (gfan::ZFan*) u->Data(); |
---|
918 | bool b = isSimplicial(zf); |
---|
919 | res->rtyp = INT_CMD; |
---|
920 | res->data = (void*) (long) b; |
---|
921 | gfan::deinitializeCddlibIfRequired(); |
---|
922 | return FALSE; |
---|
923 | } |
---|
924 | WerrorS("isSimplicial: unexpected parameters"); |
---|
925 | return TRUE; |
---|
926 | } |
---|
927 | |
---|
928 | BOOLEAN containsPositiveVector(leftv res, leftv args) |
---|
929 | { |
---|
930 | leftv u = args; |
---|
931 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
932 | { |
---|
933 | gfan::initializeCddlibIfRequired(); |
---|
934 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
935 | int i = zc->containsPositiveVector(); |
---|
936 | res->rtyp = INT_CMD; |
---|
937 | res->data = (void*) (long) i; |
---|
938 | gfan::deinitializeCddlibIfRequired(); |
---|
939 | return FALSE; |
---|
940 | } |
---|
941 | WerrorS("containsPositiveVector: unexpected parameters"); |
---|
942 | return TRUE; |
---|
943 | } |
---|
944 | |
---|
945 | BOOLEAN linealitySpace(leftv res, leftv args) |
---|
946 | { |
---|
947 | leftv u = args; |
---|
948 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
949 | { |
---|
950 | gfan::initializeCddlibIfRequired(); |
---|
951 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
952 | gfan::ZCone* zd = new gfan::ZCone(zc->linealitySpace()); |
---|
953 | res->rtyp = coneID; |
---|
954 | res->data = (void*) zd; |
---|
955 | gfan::deinitializeCddlibIfRequired(); |
---|
956 | return FALSE; |
---|
957 | } |
---|
958 | WerrorS("linealitySpace: unexpected parameters"); |
---|
959 | return TRUE; |
---|
960 | } |
---|
961 | |
---|
962 | BOOLEAN dualCone(leftv res, leftv args) |
---|
963 | { |
---|
964 | leftv u = args; |
---|
965 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
966 | { |
---|
967 | gfan::initializeCddlibIfRequired(); |
---|
968 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
969 | gfan::ZCone* zd = new gfan::ZCone(zc->dualCone()); |
---|
970 | res->rtyp = coneID; |
---|
971 | res->data = (void*) zd; |
---|
972 | gfan::deinitializeCddlibIfRequired(); |
---|
973 | return FALSE; |
---|
974 | } |
---|
975 | WerrorS("dual: unexpected parameters"); |
---|
976 | return TRUE; |
---|
977 | } |
---|
978 | |
---|
979 | BOOLEAN negatedCone(leftv res, leftv args) |
---|
980 | { |
---|
981 | leftv u = args; |
---|
982 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
983 | { |
---|
984 | gfan::initializeCddlibIfRequired(); |
---|
985 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
986 | gfan::ZCone* zd = new gfan::ZCone(zc->negated()); |
---|
987 | res->rtyp = coneID; |
---|
988 | res->data = (void*) zd; |
---|
989 | gfan::deinitializeCddlibIfRequired(); |
---|
990 | return FALSE; |
---|
991 | } |
---|
992 | WerrorS("negatedCone: unexpected parameters"); |
---|
993 | return TRUE; |
---|
994 | } |
---|
995 | |
---|
996 | BOOLEAN semigroupGenerator(leftv res, leftv args) |
---|
997 | { |
---|
998 | leftv u = args; |
---|
999 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1000 | { |
---|
1001 | gfan::initializeCddlibIfRequired(); |
---|
1002 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1003 | int d = zc->dimension(); |
---|
1004 | int dLS = zc->dimensionOfLinealitySpace(); |
---|
1005 | if (d == dLS + 1) |
---|
1006 | { |
---|
1007 | gfan::ZVector zv = zc->semiGroupGeneratorOfRay(); |
---|
1008 | res->rtyp = BIGINTMAT_CMD; |
---|
1009 | res->data = (void*) zVectorToBigintmat(zv); |
---|
1010 | gfan::deinitializeCddlibIfRequired(); |
---|
1011 | return FALSE; |
---|
1012 | } |
---|
1013 | gfan::deinitializeCddlibIfRequired(); |
---|
1014 | Werror("expected dim of cone one larger than dim of lin space\n" |
---|
1015 | "but got dimensions %d and %d", d, dLS); |
---|
1016 | } |
---|
1017 | WerrorS("semigroupGenerator: unexpected parameters"); |
---|
1018 | return TRUE; |
---|
1019 | } |
---|
1020 | |
---|
1021 | BOOLEAN relativeInteriorPoint(leftv res, leftv args) |
---|
1022 | { |
---|
1023 | leftv u = args; |
---|
1024 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1025 | { |
---|
1026 | gfan::initializeCddlibIfRequired(); |
---|
1027 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1028 | gfan::ZVector zv = zc->getRelativeInteriorPoint(); |
---|
1029 | res->rtyp = BIGINTMAT_CMD; |
---|
1030 | res->data = (void*) zVectorToBigintmat(zv); |
---|
1031 | gfan::deinitializeCddlibIfRequired(); |
---|
1032 | return FALSE; |
---|
1033 | } |
---|
1034 | WerrorS("relativeInteriorPoint: unexpected parameters"); |
---|
1035 | return TRUE; |
---|
1036 | } |
---|
1037 | |
---|
1038 | BOOLEAN uniquePoint(leftv res, leftv args) |
---|
1039 | { |
---|
1040 | leftv u = args; |
---|
1041 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1042 | { |
---|
1043 | gfan::initializeCddlibIfRequired(); |
---|
1044 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1045 | gfan::ZVector zv = zc->getUniquePoint(); |
---|
1046 | res->rtyp = BIGINTMAT_CMD; |
---|
1047 | res->data = (void*) zVectorToBigintmat(zv); |
---|
1048 | gfan::deinitializeCddlibIfRequired(); |
---|
1049 | return FALSE; |
---|
1050 | } |
---|
1051 | WerrorS("uniquePoint: unexpected parameters"); |
---|
1052 | return TRUE; |
---|
1053 | } |
---|
1054 | |
---|
1055 | gfan::ZVector randomPoint(const gfan::ZCone* zc) |
---|
1056 | { |
---|
1057 | gfan::ZVector rp = gfan::ZVector(zc->ambientDimension()); |
---|
1058 | |
---|
1059 | gfan::ZMatrix rays = zc->extremeRays(); |
---|
1060 | for (int i=0; i<rays.getHeight(); i++) |
---|
1061 | { |
---|
1062 | int n = siRand(); |
---|
1063 | rp = rp + n * rays[i].toVector(); |
---|
1064 | } |
---|
1065 | |
---|
1066 | gfan::ZMatrix lins = zc->generatorsOfLinealitySpace(); |
---|
1067 | for (int i=0; i<lins.getHeight(); i++) |
---|
1068 | { |
---|
1069 | int n = siRand(); |
---|
1070 | rp = rp + n * lins[i].toVector(); |
---|
1071 | } |
---|
1072 | |
---|
1073 | return rp; |
---|
1074 | } |
---|
1075 | |
---|
1076 | BOOLEAN randomPoint(leftv res, leftv args) |
---|
1077 | { |
---|
1078 | leftv u = args; |
---|
1079 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1080 | { |
---|
1081 | gfan::initializeCddlibIfRequired(); |
---|
1082 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1083 | gfan::ZVector zv = randomPoint(zc); |
---|
1084 | res->rtyp = BIGINTMAT_CMD; |
---|
1085 | res->data = (void*) zVectorToBigintmat(zv); |
---|
1086 | gfan::deinitializeCddlibIfRequired(); |
---|
1087 | return FALSE; |
---|
1088 | } |
---|
1089 | WerrorS("randomPoint: unexpected parameters"); |
---|
1090 | return TRUE; |
---|
1091 | } |
---|
1092 | |
---|
1093 | BOOLEAN setMultiplicity(leftv res, leftv args) |
---|
1094 | { |
---|
1095 | leftv u = args; |
---|
1096 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1097 | { |
---|
1098 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1099 | leftv v = u->next; |
---|
1100 | if ((v != NULL) && (v->Typ() == INT_CMD)) |
---|
1101 | { |
---|
1102 | gfan::initializeCddlibIfRequired(); |
---|
1103 | int val = (int)(long)v->Data(); |
---|
1104 | zc->setMultiplicity(gfan::Integer(val)); |
---|
1105 | res->rtyp = NONE; |
---|
1106 | res->data = NULL; |
---|
1107 | gfan::deinitializeCddlibIfRequired(); |
---|
1108 | return FALSE; |
---|
1109 | } |
---|
1110 | } |
---|
1111 | WerrorS("setMultiplicity: unexpected parameters"); |
---|
1112 | return TRUE; |
---|
1113 | } |
---|
1114 | |
---|
1115 | BOOLEAN setLinearForms(leftv res, leftv args) |
---|
1116 | { |
---|
1117 | leftv u = args; |
---|
1118 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1119 | { |
---|
1120 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1121 | leftv v = u->next; |
---|
1122 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
1123 | { |
---|
1124 | gfan::initializeCddlibIfRequired(); |
---|
1125 | bigintmat* mat=NULL; |
---|
1126 | if (v->Typ() == INTVEC_CMD) |
---|
1127 | { |
---|
1128 | intvec* mat0 = (intvec*) v->Data(); |
---|
1129 | mat = iv2bim(mat0,coeffs_BIGINT)->transpose(); |
---|
1130 | } |
---|
1131 | else |
---|
1132 | mat = (bigintmat*) v->Data(); |
---|
1133 | gfan::ZMatrix* zm = bigintmatToZMatrix(mat); |
---|
1134 | zc->setLinearForms(*zm); |
---|
1135 | res->rtyp = NONE; |
---|
1136 | res->data = NULL; |
---|
1137 | |
---|
1138 | delete zm; |
---|
1139 | if (v->Typ() == INTVEC_CMD) |
---|
1140 | delete mat; |
---|
1141 | gfan::deinitializeCddlibIfRequired(); |
---|
1142 | return FALSE; |
---|
1143 | } |
---|
1144 | } |
---|
1145 | WerrorS("setLinearForms: unexpected parameters"); |
---|
1146 | return TRUE; |
---|
1147 | } |
---|
1148 | |
---|
1149 | gfan::ZMatrix liftUp(const gfan::ZMatrix &zm) |
---|
1150 | { |
---|
1151 | int r=zm.getHeight(); |
---|
1152 | int c=zm.getWidth(); |
---|
1153 | gfan::ZMatrix zn(r+1,c+1); |
---|
1154 | zn[1][1]=1; |
---|
1155 | for (int i=0; i<r; i++) |
---|
1156 | for (int j=0; j<c; j++) |
---|
1157 | zn[i+1][j+1]=zm[i][j]; |
---|
1158 | return zn; |
---|
1159 | } |
---|
1160 | |
---|
1161 | gfan::ZCone liftUp(const gfan::ZCone &zc) |
---|
1162 | { |
---|
1163 | gfan::ZMatrix ineq=zc.getInequalities(); |
---|
1164 | gfan::ZMatrix eq=zc.getEquations(); |
---|
1165 | gfan::ZCone zd(liftUp(ineq),liftUp(eq)); |
---|
1166 | return zd; |
---|
1167 | } |
---|
1168 | |
---|
1169 | BOOLEAN coneToPolytope(leftv res, leftv args) |
---|
1170 | { |
---|
1171 | leftv u = args; |
---|
1172 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1173 | { |
---|
1174 | gfan::initializeCddlibIfRequired(); |
---|
1175 | gfan::ZCone* zc = (gfan::ZCone*) u->Data(); |
---|
1176 | gfan::ZMatrix ineq=zc->getInequalities(); |
---|
1177 | gfan::ZMatrix eq=zc->getEquations(); |
---|
1178 | gfan::ZCone* zd = new gfan::ZCone(liftUp(ineq),liftUp(eq)); |
---|
1179 | res->rtyp = polytopeID; |
---|
1180 | res->data = (void*) zd; |
---|
1181 | gfan::deinitializeCddlibIfRequired(); |
---|
1182 | return FALSE; |
---|
1183 | } |
---|
1184 | WerrorS("makePolytope: unexpected parameters"); |
---|
1185 | return TRUE; |
---|
1186 | } |
---|
1187 | |
---|
1188 | BOOLEAN intersectCones(leftv res, leftv args) |
---|
1189 | { |
---|
1190 | leftv u = args; |
---|
1191 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1192 | { |
---|
1193 | leftv v = u->next; |
---|
1194 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1195 | { |
---|
1196 | gfan::initializeCddlibIfRequired(); |
---|
1197 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1198 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1199 | int d1 = zc1->ambientDimension(); |
---|
1200 | int d2 = zc2->ambientDimension(); |
---|
1201 | if (d1 != d2) |
---|
1202 | { |
---|
1203 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1204 | "but got %d and %d", d1, d2); |
---|
1205 | gfan::deinitializeCddlibIfRequired(); |
---|
1206 | return TRUE; |
---|
1207 | } |
---|
1208 | gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2); |
---|
1209 | zc3.canonicalize(); |
---|
1210 | res->rtyp = coneID; |
---|
1211 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1212 | gfan::deinitializeCddlibIfRequired(); |
---|
1213 | return FALSE; |
---|
1214 | } |
---|
1215 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1216 | { |
---|
1217 | gfan::initializeCddlibIfRequired(); |
---|
1218 | gfan::ZCone* zc11 = (gfan::ZCone*)u->Data(); |
---|
1219 | gfan::ZCone zc1 = liftUp(*zc11); |
---|
1220 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1221 | int d1 = zc1.ambientDimension(); |
---|
1222 | int d2 = zc2->ambientDimension(); |
---|
1223 | if (d1 != d2) |
---|
1224 | { |
---|
1225 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1226 | "but got %d and %d", d1, d2); |
---|
1227 | gfan::deinitializeCddlibIfRequired(); |
---|
1228 | return TRUE; |
---|
1229 | } |
---|
1230 | gfan::ZCone zc3 = gfan::intersection(zc1, *zc2); |
---|
1231 | zc3.canonicalize(); |
---|
1232 | res->rtyp = polytopeID; |
---|
1233 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1234 | gfan::deinitializeCddlibIfRequired(); |
---|
1235 | return FALSE; |
---|
1236 | } |
---|
1237 | } |
---|
1238 | if ((u != NULL) && (u->Typ() == LIST_CMD)) |
---|
1239 | { |
---|
1240 | if (u->next == NULL) |
---|
1241 | { |
---|
1242 | lists l = (lists) u->Data(); |
---|
1243 | |
---|
1244 | // find the total number of inequalities and equations |
---|
1245 | int r1=0; // total number of inequalities |
---|
1246 | int r2=0; // total number of equations |
---|
1247 | int c=0; // ambient dimension |
---|
1248 | for (int i=0; i<=lSize(l); i++) |
---|
1249 | { |
---|
1250 | if (l->m[i].Typ() != coneID) |
---|
1251 | { |
---|
1252 | WerrorS("convexIntersection: entries of wrong type in list"); |
---|
1253 | return TRUE; |
---|
1254 | } |
---|
1255 | gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data(); |
---|
1256 | r1 = r1 + ll->getInequalities().getHeight(); |
---|
1257 | r2 = r2 + ll->getEquations().getHeight(); |
---|
1258 | } |
---|
1259 | if (lSize(l)>=0) |
---|
1260 | { |
---|
1261 | gfan::ZCone* ll = (gfan::ZCone*) l->m[0].Data(); |
---|
1262 | c = ll->getInequalities().getWidth(); |
---|
1263 | } |
---|
1264 | gfan::ZMatrix totalIneqs(r1,c); |
---|
1265 | gfan::ZMatrix totalEqs(r2,c); |
---|
1266 | |
---|
1267 | // concat all inequalities and equations |
---|
1268 | r1=0; // counter for inequalities |
---|
1269 | r2=0; // counter for equations |
---|
1270 | for (int i=0; i<=lSize(l); i++) |
---|
1271 | { |
---|
1272 | gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data(); |
---|
1273 | gfan::ZMatrix ineqs = ll->getInequalities(); |
---|
1274 | for (int j=0; j<ineqs.getHeight(); j++) |
---|
1275 | { |
---|
1276 | totalIneqs[r1]=ineqs[j]; |
---|
1277 | r1 = r1+1; |
---|
1278 | } |
---|
1279 | gfan::ZMatrix eqs = ll->getEquations(); |
---|
1280 | for (int j=0; j<eqs.getHeight(); j++) |
---|
1281 | { |
---|
1282 | totalEqs[r2]=eqs[j]; |
---|
1283 | r2 = r2+1; |
---|
1284 | } |
---|
1285 | } |
---|
1286 | |
---|
1287 | gfan::ZCone* zc = new gfan::ZCone(totalIneqs,totalEqs); |
---|
1288 | zc->canonicalize(); |
---|
1289 | res->rtyp = coneID; |
---|
1290 | res->data = (void *) zc; |
---|
1291 | return FALSE; |
---|
1292 | } |
---|
1293 | } |
---|
1294 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1295 | { |
---|
1296 | leftv v = u->next; |
---|
1297 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1298 | { |
---|
1299 | gfan::initializeCddlibIfRequired(); |
---|
1300 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1301 | gfan::ZCone* zc22 = (gfan::ZCone*)v->Data(); |
---|
1302 | gfan::ZCone zc2 = liftUp(*zc22); |
---|
1303 | int d1 = zc1->ambientDimension(); |
---|
1304 | int d2 = zc2.ambientDimension(); |
---|
1305 | if (d1 != d2) |
---|
1306 | { |
---|
1307 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1308 | "but got %d and %d", d1, d2); |
---|
1309 | gfan::deinitializeCddlibIfRequired(); |
---|
1310 | return TRUE; |
---|
1311 | } |
---|
1312 | gfan::ZCone zc3 = gfan::intersection(*zc1, zc2); |
---|
1313 | zc3.canonicalize(); |
---|
1314 | res->rtyp = polytopeID; |
---|
1315 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1316 | gfan::deinitializeCddlibIfRequired(); |
---|
1317 | return FALSE; |
---|
1318 | } |
---|
1319 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1320 | { |
---|
1321 | gfan::initializeCddlibIfRequired(); |
---|
1322 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1323 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1324 | int d1 = zc1->ambientDimension(); |
---|
1325 | int d2 = zc2->ambientDimension(); |
---|
1326 | if (d1 != d2) |
---|
1327 | { |
---|
1328 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1329 | "but got %d and %d", d1, d2); |
---|
1330 | gfan::deinitializeCddlibIfRequired(); |
---|
1331 | return TRUE; |
---|
1332 | } |
---|
1333 | gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2); |
---|
1334 | zc3.canonicalize(); |
---|
1335 | res->rtyp = polytopeID; |
---|
1336 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1337 | gfan::deinitializeCddlibIfRequired(); |
---|
1338 | return FALSE; |
---|
1339 | } |
---|
1340 | } |
---|
1341 | WerrorS("convexIntersection: unexpected parameters"); |
---|
1342 | return TRUE; |
---|
1343 | } |
---|
1344 | |
---|
1345 | BOOLEAN convexHull(leftv res, leftv args) |
---|
1346 | { |
---|
1347 | leftv u = args; |
---|
1348 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1349 | { |
---|
1350 | leftv v = u->next; |
---|
1351 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1352 | { |
---|
1353 | gfan::initializeCddlibIfRequired(); |
---|
1354 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1355 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1356 | int d1 = zc1->ambientDimension(); |
---|
1357 | int d2 = zc2->ambientDimension(); |
---|
1358 | if (d1 != d2) |
---|
1359 | { |
---|
1360 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1361 | "but got %d and %d", d1, d2); |
---|
1362 | gfan::deinitializeCddlibIfRequired(); |
---|
1363 | return TRUE; |
---|
1364 | } |
---|
1365 | gfan::ZMatrix zm1 = zc1->extremeRays(); |
---|
1366 | gfan::ZMatrix zm2 = zc2->extremeRays(); |
---|
1367 | gfan::ZMatrix zn1 = zc1->generatorsOfLinealitySpace(); |
---|
1368 | gfan::ZMatrix zn2 = zc2->generatorsOfLinealitySpace(); |
---|
1369 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
1370 | gfan::ZMatrix zn = combineOnTop(zn1,zn2); |
---|
1371 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
1372 | *zc = gfan::ZCone::givenByRays(zm, zn); |
---|
1373 | res->rtyp = coneID; |
---|
1374 | res->data = (void*) zc; |
---|
1375 | gfan::deinitializeCddlibIfRequired(); |
---|
1376 | return FALSE; |
---|
1377 | } |
---|
1378 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1379 | { |
---|
1380 | gfan::initializeCddlibIfRequired(); |
---|
1381 | gfan::ZCone* zc11 = (gfan::ZCone*)u->Data(); |
---|
1382 | gfan::ZCone zc1 = liftUp(*zc11); |
---|
1383 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1384 | int d1 = zc1.ambientDimension()-1; |
---|
1385 | int d2 = zc2->ambientDimension()-1; |
---|
1386 | if (d1 != d2) |
---|
1387 | { |
---|
1388 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1389 | "but got %d and %d", d1, d2); |
---|
1390 | gfan::deinitializeCddlibIfRequired(); |
---|
1391 | return TRUE; |
---|
1392 | } |
---|
1393 | gfan::ZMatrix zm1 = zc1.extremeRays(); |
---|
1394 | gfan::ZMatrix zm2 = zc2->extremeRays(); |
---|
1395 | gfan::ZMatrix zn = zc1.generatorsOfLinealitySpace(); |
---|
1396 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
1397 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
1398 | *zc = gfan::ZCone::givenByRays(zm, zn); |
---|
1399 | res->rtyp = polytopeID; |
---|
1400 | res->data = (void*) zc; |
---|
1401 | gfan::deinitializeCddlibIfRequired(); |
---|
1402 | return FALSE; |
---|
1403 | } |
---|
1404 | } |
---|
1405 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1406 | { |
---|
1407 | leftv v = u->next; |
---|
1408 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1409 | { |
---|
1410 | gfan::initializeCddlibIfRequired(); |
---|
1411 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1412 | gfan::ZCone* zc22 = (gfan::ZCone*)v->Data(); |
---|
1413 | gfan::ZCone zc2 = liftUp(*zc22); |
---|
1414 | int d1 = zc1->ambientDimension()-1; |
---|
1415 | int d2 = zc2.ambientDimension()-1; |
---|
1416 | if (d1 != d2) |
---|
1417 | { |
---|
1418 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1419 | "but got %d and %d", d1, d2); |
---|
1420 | gfan::deinitializeCddlibIfRequired(); |
---|
1421 | return TRUE; |
---|
1422 | } |
---|
1423 | gfan::ZMatrix zm1 = zc1->extremeRays(); |
---|
1424 | gfan::ZMatrix zm2 = zc2.extremeRays(); |
---|
1425 | gfan::ZMatrix zn = zc2.generatorsOfLinealitySpace(); |
---|
1426 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
1427 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
1428 | *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth())); |
---|
1429 | res->rtyp = polytopeID; |
---|
1430 | res->data = (void*) zc; |
---|
1431 | gfan::deinitializeCddlibIfRequired(); |
---|
1432 | return FALSE; |
---|
1433 | } |
---|
1434 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1435 | { |
---|
1436 | gfan::initializeCddlibIfRequired(); |
---|
1437 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1438 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1439 | int d1 = zc1->ambientDimension()-1; |
---|
1440 | int d2 = zc2->ambientDimension()-1; |
---|
1441 | if (d1 != d2) |
---|
1442 | { |
---|
1443 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1444 | "but got %d and %d", d1, d2); |
---|
1445 | gfan::deinitializeCddlibIfRequired(); |
---|
1446 | return TRUE; |
---|
1447 | } |
---|
1448 | gfan::ZMatrix zm1 = zc1->extremeRays(); |
---|
1449 | gfan::ZMatrix zm2 = zc2->extremeRays(); |
---|
1450 | gfan::ZMatrix zm = combineOnTop(zm1,zm2); |
---|
1451 | gfan::ZCone* zc = new gfan::ZCone(); |
---|
1452 | *zc = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth())); |
---|
1453 | res->rtyp = polytopeID; |
---|
1454 | res->data = (void*) zc; |
---|
1455 | gfan::deinitializeCddlibIfRequired(); |
---|
1456 | return FALSE; |
---|
1457 | } |
---|
1458 | } |
---|
1459 | WerrorS("convexHull: unexpected parameters"); |
---|
1460 | return TRUE; |
---|
1461 | } |
---|
1462 | |
---|
1463 | BOOLEAN coneLink(leftv res, leftv args) |
---|
1464 | { |
---|
1465 | leftv u = args; |
---|
1466 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1467 | { |
---|
1468 | leftv v = u->next; |
---|
1469 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
1470 | { |
---|
1471 | gfan::initializeCddlibIfRequired(); |
---|
1472 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1473 | bigintmat* iv = NULL; |
---|
1474 | if (v->Typ() == INTVEC_CMD) |
---|
1475 | { |
---|
1476 | intvec* iv0 = (intvec*) v->Data(); |
---|
1477 | iv = iv2bim(iv0,coeffs_BIGINT)->transpose(); |
---|
1478 | } |
---|
1479 | else |
---|
1480 | iv = (bigintmat*)v->Data(); |
---|
1481 | gfan::ZVector* zv = bigintmatToZVector(iv); |
---|
1482 | int d1 = zc->ambientDimension(); |
---|
1483 | int d2 = zv->size(); |
---|
1484 | if (d1 != d2) |
---|
1485 | { |
---|
1486 | Werror("expected ambient dim of cone and size of vector\n" |
---|
1487 | " to be equal but got %d and %d", d1, d2); |
---|
1488 | gfan::deinitializeCddlibIfRequired(); |
---|
1489 | return TRUE; |
---|
1490 | } |
---|
1491 | if(!zc->contains(*zv)) |
---|
1492 | { |
---|
1493 | WerrorS("the provided intvec does not lie in the cone"); |
---|
1494 | gfan::deinitializeCddlibIfRequired(); |
---|
1495 | return TRUE; |
---|
1496 | } |
---|
1497 | gfan::ZCone* zd = new gfan::ZCone(zc->link(*zv)); |
---|
1498 | res->rtyp = coneID; |
---|
1499 | res->data = (void *) zd; |
---|
1500 | |
---|
1501 | delete zv; |
---|
1502 | if (v->Typ() == INTVEC_CMD) |
---|
1503 | delete iv; |
---|
1504 | gfan::deinitializeCddlibIfRequired(); |
---|
1505 | return FALSE; |
---|
1506 | } |
---|
1507 | } |
---|
1508 | WerrorS("coneLink: unexpected parameters"); |
---|
1509 | return TRUE; |
---|
1510 | } |
---|
1511 | |
---|
1512 | BOOLEAN containsInSupport(leftv res, leftv args) |
---|
1513 | { |
---|
1514 | leftv u=args; |
---|
1515 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1516 | { |
---|
1517 | leftv v=u->next; |
---|
1518 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1519 | { |
---|
1520 | gfan::initializeCddlibIfRequired(); |
---|
1521 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1522 | gfan::ZCone* zd = (gfan::ZCone*)v->Data(); |
---|
1523 | int d1 = zc->ambientDimension(); |
---|
1524 | int d2 = zd->ambientDimension(); |
---|
1525 | if (d1 != d2) |
---|
1526 | { |
---|
1527 | Werror("expected cones with same ambient dimensions\n but got" |
---|
1528 | " dimensions %d and %d", d1, d2); |
---|
1529 | gfan::deinitializeCddlibIfRequired(); |
---|
1530 | return TRUE; |
---|
1531 | } |
---|
1532 | bool b = (zc->contains(*zd) ? 1 : 0); |
---|
1533 | res->rtyp = INT_CMD; |
---|
1534 | res->data = (void*) (long) b; |
---|
1535 | gfan::deinitializeCddlibIfRequired(); |
---|
1536 | return FALSE; |
---|
1537 | } |
---|
1538 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
1539 | { |
---|
1540 | gfan::initializeCddlibIfRequired(); |
---|
1541 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1542 | bigintmat* iv = NULL; |
---|
1543 | if (v->Typ() == INTVEC_CMD) |
---|
1544 | { |
---|
1545 | intvec* iv0 = (intvec*) v->Data(); |
---|
1546 | iv = iv2bim(iv0,coeffs_BIGINT)->transpose(); |
---|
1547 | } |
---|
1548 | else |
---|
1549 | iv = (bigintmat*)v->Data(); |
---|
1550 | |
---|
1551 | gfan::ZVector* zv = bigintmatToZVector(iv); |
---|
1552 | int d1 = zc->ambientDimension(); |
---|
1553 | int d2 = zv->size(); |
---|
1554 | if (d1 != d2) |
---|
1555 | { |
---|
1556 | Werror("expected cones with same ambient dimensions\n but got" |
---|
1557 | " dimensions %d and %d", d1, d2); |
---|
1558 | gfan::deinitializeCddlibIfRequired(); |
---|
1559 | return TRUE; |
---|
1560 | } |
---|
1561 | int b = zc->contains(*zv); |
---|
1562 | res->rtyp = INT_CMD; |
---|
1563 | res->data = (void*) (long) b; |
---|
1564 | |
---|
1565 | delete zv; |
---|
1566 | if (v->Typ() == INTVEC_CMD) |
---|
1567 | delete iv; |
---|
1568 | gfan::deinitializeCddlibIfRequired(); |
---|
1569 | return FALSE; |
---|
1570 | } |
---|
1571 | } |
---|
1572 | WerrorS("containsInSupport: unexpected parameters"); |
---|
1573 | return TRUE; |
---|
1574 | } |
---|
1575 | |
---|
1576 | BOOLEAN containsInSupportOld(leftv res, leftv args) |
---|
1577 | { |
---|
1578 | gfan::initializeCddlibIfRequired(); |
---|
1579 | leftv u=args; |
---|
1580 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1581 | { |
---|
1582 | leftv v=u->next; |
---|
1583 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1584 | { |
---|
1585 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1586 | gfan::ZCone* zd = (gfan::ZCone*)v->Data(); |
---|
1587 | int d1 = zc->ambientDimension(); |
---|
1588 | int d2 = zd->ambientDimension(); |
---|
1589 | if (d1 != d2) |
---|
1590 | { |
---|
1591 | Werror("expected cones with same ambient dimensions\n but got" |
---|
1592 | " dimensions %d and %d", d1, d2); |
---|
1593 | return TRUE; |
---|
1594 | } |
---|
1595 | bool b = (zc->contains(*zd) ? 1 : 0); |
---|
1596 | res->rtyp = INT_CMD; |
---|
1597 | res->data = (void*) (long) b; |
---|
1598 | return FALSE; |
---|
1599 | } |
---|
1600 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
1601 | { |
---|
1602 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1603 | bigintmat* iv = NULL; |
---|
1604 | if (v->Typ() == INTVEC_CMD) |
---|
1605 | { |
---|
1606 | intvec* iv0 = (intvec*) v->Data(); |
---|
1607 | iv = iv2bim(iv0,coeffs_BIGINT)->transpose(); |
---|
1608 | } |
---|
1609 | else |
---|
1610 | iv = (bigintmat*)v->Data(); |
---|
1611 | |
---|
1612 | gfan::ZVector* zv = bigintmatToZVector(iv); |
---|
1613 | int d1 = zc->ambientDimension(); |
---|
1614 | int d2 = zv->size(); |
---|
1615 | if (d1 != d2) |
---|
1616 | { |
---|
1617 | Werror("expected cones with same ambient dimensions\n but got" |
---|
1618 | " dimensions %d and %d", d1, d2); |
---|
1619 | return TRUE; |
---|
1620 | } |
---|
1621 | int b = zc->contains(*zv); |
---|
1622 | res->rtyp = INT_CMD; |
---|
1623 | res->data = (void*) (long) b; |
---|
1624 | |
---|
1625 | delete zv; |
---|
1626 | if (v->Typ() == INTMAT_CMD) |
---|
1627 | delete iv; |
---|
1628 | return FALSE; |
---|
1629 | } |
---|
1630 | } |
---|
1631 | WerrorS("containsInSupportOld: unexpected parameters"); |
---|
1632 | return TRUE; |
---|
1633 | } |
---|
1634 | |
---|
1635 | BOOLEAN convexIntersectionOld(leftv res, leftv args) |
---|
1636 | { |
---|
1637 | gfan::initializeCddlibIfRequired(); |
---|
1638 | leftv u = args; |
---|
1639 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1640 | { |
---|
1641 | leftv v = u->next; |
---|
1642 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1643 | { |
---|
1644 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1645 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1646 | int d1 = zc1->ambientDimension(); |
---|
1647 | int d2 = zc2->ambientDimension(); |
---|
1648 | if (d1 != d2) |
---|
1649 | { |
---|
1650 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1651 | "but got %d and %d", d1, d2); |
---|
1652 | return TRUE; |
---|
1653 | } |
---|
1654 | gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2); |
---|
1655 | zc3.canonicalize(); |
---|
1656 | res->rtyp = coneID; |
---|
1657 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1658 | return FALSE; |
---|
1659 | } |
---|
1660 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1661 | { |
---|
1662 | gfan::ZCone* zc11 = (gfan::ZCone*)u->Data(); |
---|
1663 | gfan::ZCone zc1 = liftUp(*zc11); |
---|
1664 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1665 | int d1 = zc1.ambientDimension(); |
---|
1666 | int d2 = zc2->ambientDimension(); |
---|
1667 | if (d1 != d2) |
---|
1668 | { |
---|
1669 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1670 | "but got %d and %d", d1, d2); |
---|
1671 | return TRUE; |
---|
1672 | } |
---|
1673 | gfan::ZCone zc3 = gfan::intersection(zc1, *zc2); |
---|
1674 | zc3.canonicalize(); |
---|
1675 | res->rtyp = polytopeID; |
---|
1676 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1677 | return FALSE; |
---|
1678 | } |
---|
1679 | } |
---|
1680 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1681 | { |
---|
1682 | leftv v = u->next; |
---|
1683 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1684 | { |
---|
1685 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1686 | gfan::ZCone* zc22 = (gfan::ZCone*)v->Data(); |
---|
1687 | gfan::ZCone zc2 = liftUp(*zc22); |
---|
1688 | int d1 = zc1->ambientDimension(); |
---|
1689 | int d2 = zc2.ambientDimension(); |
---|
1690 | if (d1 != d2) |
---|
1691 | { |
---|
1692 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1693 | "but got %d and %d", d1, d2); |
---|
1694 | return TRUE; |
---|
1695 | } |
---|
1696 | gfan::ZCone zc3 = gfan::intersection(*zc1, zc2); |
---|
1697 | zc3.canonicalize(); |
---|
1698 | res->rtyp = polytopeID; |
---|
1699 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1700 | return FALSE; |
---|
1701 | } |
---|
1702 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1703 | { |
---|
1704 | gfan::ZCone* zc1 = (gfan::ZCone*)u->Data(); |
---|
1705 | gfan::ZCone* zc2 = (gfan::ZCone*)v->Data(); |
---|
1706 | int d1 = zc1->ambientDimension(); |
---|
1707 | int d2 = zc2->ambientDimension(); |
---|
1708 | if (d1 != d2) |
---|
1709 | { |
---|
1710 | Werror("expected ambient dims of both cones to coincide\n" |
---|
1711 | "but got %d and %d", d1, d2); |
---|
1712 | return TRUE; |
---|
1713 | } |
---|
1714 | gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2); |
---|
1715 | zc3.canonicalize(); |
---|
1716 | res->rtyp = polytopeID; |
---|
1717 | res->data = (void *)new gfan::ZCone(zc3); |
---|
1718 | return FALSE; |
---|
1719 | } |
---|
1720 | } |
---|
1721 | WerrorS("convexIntersectionOld: unexpected parameters"); |
---|
1722 | return TRUE; |
---|
1723 | } |
---|
1724 | |
---|
1725 | BOOLEAN containsRelatively(leftv res, leftv args) |
---|
1726 | { |
---|
1727 | leftv u = args; |
---|
1728 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1729 | { |
---|
1730 | leftv v = u->next; |
---|
1731 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
1732 | { |
---|
1733 | gfan::initializeCddlibIfRequired(); |
---|
1734 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1735 | bigintmat* iv = NULL; |
---|
1736 | if (v->Typ() == INTVEC_CMD) |
---|
1737 | { |
---|
1738 | intvec* iv0 = (intvec*) v->Data(); |
---|
1739 | iv = iv2bim(iv0,coeffs_BIGINT)->transpose(); |
---|
1740 | } |
---|
1741 | else |
---|
1742 | iv = (bigintmat*)v->Data(); |
---|
1743 | gfan::ZVector* zv = bigintmatToZVector(iv); |
---|
1744 | int d1 = zc->ambientDimension(); |
---|
1745 | int d2 = zv->size(); |
---|
1746 | if (d1 == d2) |
---|
1747 | { |
---|
1748 | bool b = (zc->containsRelatively(*zv) ? 1 : 0); |
---|
1749 | res->rtyp = INT_CMD; |
---|
1750 | res->data = (void *) b; |
---|
1751 | delete zv; |
---|
1752 | if (v->Typ() == INTVEC_CMD) |
---|
1753 | delete iv; |
---|
1754 | gfan::deinitializeCddlibIfRequired(); |
---|
1755 | return FALSE; |
---|
1756 | } |
---|
1757 | delete zv; |
---|
1758 | if (v->Typ() == INTVEC_CMD) |
---|
1759 | delete iv; |
---|
1760 | gfan::deinitializeCddlibIfRequired(); |
---|
1761 | Werror("expected ambient dim of cone and size of vector\n" |
---|
1762 | "to be equal but got %d and %d", d1, d2); |
---|
1763 | } |
---|
1764 | } |
---|
1765 | WerrorS("containsRelatively: unexpected parameters"); |
---|
1766 | return TRUE; |
---|
1767 | } |
---|
1768 | |
---|
1769 | BOOLEAN hasFace(leftv res, leftv args) |
---|
1770 | { |
---|
1771 | leftv u=args; |
---|
1772 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1773 | { |
---|
1774 | leftv v=u->next; |
---|
1775 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1776 | { |
---|
1777 | gfan::initializeCddlibIfRequired(); |
---|
1778 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1779 | gfan::ZCone* zd = (gfan::ZCone*)v->Data(); |
---|
1780 | bool b = zc->hasFace(*zd); |
---|
1781 | res->rtyp = INT_CMD; |
---|
1782 | res->data = (void*) (long) b; |
---|
1783 | gfan::deinitializeCddlibIfRequired(); |
---|
1784 | return FALSE; |
---|
1785 | } |
---|
1786 | } |
---|
1787 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1788 | { |
---|
1789 | leftv v=u->next; |
---|
1790 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1791 | { |
---|
1792 | gfan::initializeCddlibIfRequired(); |
---|
1793 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1794 | gfan::ZCone* zd = (gfan::ZCone*)v->Data(); |
---|
1795 | bool b = zc->hasFace(*zd); |
---|
1796 | res->rtyp = INT_CMD; |
---|
1797 | res->data = (void*) (long) b; |
---|
1798 | gfan::deinitializeCddlibIfRequired(); |
---|
1799 | return FALSE; |
---|
1800 | } |
---|
1801 | } |
---|
1802 | WerrorS("containsAsFace: unexpected parameters"); |
---|
1803 | return TRUE; |
---|
1804 | } |
---|
1805 | |
---|
1806 | BOOLEAN canonicalizeCone(leftv res, leftv args) |
---|
1807 | { |
---|
1808 | leftv u=args; |
---|
1809 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1810 | { |
---|
1811 | gfan::initializeCddlibIfRequired(); |
---|
1812 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1813 | gfan::ZCone* zd = new gfan::ZCone(*zc); |
---|
1814 | zd->canonicalize(); |
---|
1815 | res->rtyp = coneID; |
---|
1816 | res->data = (void*) zd; |
---|
1817 | gfan::deinitializeCddlibIfRequired(); |
---|
1818 | return FALSE; |
---|
1819 | } |
---|
1820 | WerrorS("canonicalizeCone: unexpected parameters"); |
---|
1821 | return TRUE; |
---|
1822 | } |
---|
1823 | |
---|
1824 | BOOLEAN containsCone(leftv res, leftv args) |
---|
1825 | { |
---|
1826 | leftv u=args; |
---|
1827 | if ((u != NULL) && (u->Typ() == LIST_CMD)) |
---|
1828 | { |
---|
1829 | leftv v=u->next; |
---|
1830 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1831 | { |
---|
1832 | gfan::initializeCddlibIfRequired(); |
---|
1833 | lists l = (lists) u->Data(); |
---|
1834 | gfan::ZCone* zc = (gfan::ZCone*) v->Data(); |
---|
1835 | zc->canonicalize(); |
---|
1836 | int b = 0; |
---|
1837 | for (int i=0; i<=lSize(l); i++) |
---|
1838 | { |
---|
1839 | if (l->m[i].Typ() != coneID) |
---|
1840 | { |
---|
1841 | WerrorS("containsCone: entries of wrong type in list"); |
---|
1842 | gfan::deinitializeCddlibIfRequired(); |
---|
1843 | return TRUE; |
---|
1844 | } |
---|
1845 | gfan::ZCone* ll = (gfan::ZCone*) l->m[i].Data(); |
---|
1846 | ll->canonicalize(); |
---|
1847 | if (!((*ll) != (*zc))) |
---|
1848 | { |
---|
1849 | b = 1; |
---|
1850 | break; |
---|
1851 | } |
---|
1852 | } |
---|
1853 | res->rtyp = INT_CMD; |
---|
1854 | res->data = (char*) (long) b; |
---|
1855 | gfan::deinitializeCddlibIfRequired(); |
---|
1856 | return FALSE; |
---|
1857 | } |
---|
1858 | } |
---|
1859 | WerrorS("containsCone: unexpected parameters"); |
---|
1860 | return TRUE; |
---|
1861 | } |
---|
1862 | |
---|
1863 | BOOLEAN faceContaining(leftv res, leftv args) |
---|
1864 | { |
---|
1865 | leftv u = args; |
---|
1866 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1867 | { |
---|
1868 | leftv v = u->next; |
---|
1869 | if ((v != NULL) && ((v->Typ() == BIGINTMAT_CMD) || (v->Typ() == INTVEC_CMD))) |
---|
1870 | { |
---|
1871 | gfan::initializeCddlibIfRequired(); |
---|
1872 | gfan::ZCone* zc = (gfan::ZCone*) u->Data(); |
---|
1873 | |
---|
1874 | bigintmat* point1; |
---|
1875 | if (v->Typ() == INTVEC_CMD) |
---|
1876 | { |
---|
1877 | intvec* point0 = (intvec*) v->Data(); |
---|
1878 | point1 = iv2bim(point0,coeffs_BIGINT)->transpose(); |
---|
1879 | } |
---|
1880 | else |
---|
1881 | point1 = (bigintmat*) v->Data(); |
---|
1882 | gfan::ZVector* point = bigintmatToZVector(*point1); |
---|
1883 | |
---|
1884 | if (!zc->contains(*point)) |
---|
1885 | { |
---|
1886 | WerrorS("faceContaining: point not in cone"); |
---|
1887 | return TRUE; |
---|
1888 | } |
---|
1889 | res->rtyp = coneID; |
---|
1890 | res->data = (void*) new gfan::ZCone(zc->faceContaining(*point)); |
---|
1891 | |
---|
1892 | delete point; |
---|
1893 | if (v->Typ() == INTVEC_CMD) |
---|
1894 | delete point1; |
---|
1895 | gfan::deinitializeCddlibIfRequired(); |
---|
1896 | return FALSE; |
---|
1897 | } |
---|
1898 | } |
---|
1899 | WerrorS("faceContaining: unexpected parameters"); |
---|
1900 | return TRUE; |
---|
1901 | } |
---|
1902 | |
---|
1903 | |
---|
1904 | /*** |
---|
1905 | * Computes a relative interior point for each facet of zc |
---|
1906 | **/ |
---|
1907 | gfan::ZMatrix interiorPointsOfFacets(const gfan::ZCone &zc, const std::set<gfan::ZVector> &exceptThese) |
---|
1908 | { |
---|
1909 | gfan::ZMatrix inequalities = zc.getFacets(); |
---|
1910 | gfan::ZMatrix equations = zc.getImpliedEquations(); |
---|
1911 | int r = inequalities.getHeight(); |
---|
1912 | int c = inequalities.getWidth(); |
---|
1913 | |
---|
1914 | /* our cone has r facets, if r==0 return empty matrices */ |
---|
1915 | gfan::ZMatrix relativeInteriorPoints = gfan::ZMatrix(0,c); |
---|
1916 | if (r==0) return relativeInteriorPoints; |
---|
1917 | |
---|
1918 | /* next we iterate over each of the r facets, |
---|
1919 | * build the respective cone and add it to the list |
---|
1920 | * this is the i=0 case */ |
---|
1921 | gfan::ZMatrix newInequalities = inequalities.submatrix(1,0,r,c); |
---|
1922 | gfan::ZMatrix newEquations = equations; |
---|
1923 | newEquations.appendRow(inequalities[0]); |
---|
1924 | gfan::ZCone facet = gfan::ZCone(newInequalities,newEquations); |
---|
1925 | facet.canonicalize(); |
---|
1926 | gfan::ZVector interiorPoint = facet.getRelativeInteriorPoint(); |
---|
1927 | if (exceptThese.count(interiorPoint)==0) |
---|
1928 | relativeInteriorPoints.appendRow(interiorPoint); |
---|
1929 | |
---|
1930 | /* these are the cases i=1,...,r-2 */ |
---|
1931 | for (int i=1; i<r-1; i++) |
---|
1932 | { |
---|
1933 | newInequalities = inequalities.submatrix(0,0,i,c); |
---|
1934 | newInequalities.append(inequalities.submatrix(i+1,0,r,c)); |
---|
1935 | newEquations = equations; |
---|
1936 | newEquations.appendRow(inequalities[i]); |
---|
1937 | facet = gfan::ZCone(newInequalities,newEquations); |
---|
1938 | facet.canonicalize(); |
---|
1939 | interiorPoint = facet.getRelativeInteriorPoint(); |
---|
1940 | if (exceptThese.count(interiorPoint)==0) |
---|
1941 | relativeInteriorPoints.appendRow(interiorPoint); |
---|
1942 | } |
---|
1943 | |
---|
1944 | /* this is the i=r-1 case */ |
---|
1945 | newInequalities = inequalities.submatrix(0,0,r-1,c); |
---|
1946 | newEquations = equations; |
---|
1947 | newEquations.appendRow(inequalities[r-1]); |
---|
1948 | facet = gfan::ZCone(newInequalities,newEquations); |
---|
1949 | facet.canonicalize(); |
---|
1950 | interiorPoint = facet.getRelativeInteriorPoint(); |
---|
1951 | if (exceptThese.count(interiorPoint)==0) |
---|
1952 | relativeInteriorPoints.appendRow(interiorPoint); |
---|
1953 | |
---|
1954 | return relativeInteriorPoints; |
---|
1955 | } |
---|
1956 | |
---|
1957 | |
---|
1958 | /*** |
---|
1959 | * Computes a relative interior point and an outer normal vector for each facet of zc |
---|
1960 | **/ |
---|
1961 | std::pair<gfan::ZMatrix,gfan::ZMatrix> interiorPointsAndNormalsOfFacets(const gfan::ZCone zc, const std::set<gfan::ZVector> &exceptThesePoints, const bool onlyLowerHalfSpace) |
---|
1962 | { |
---|
1963 | gfan::ZMatrix inequalities = zc.getFacets(); |
---|
1964 | gfan::ZMatrix equations = zc.getImpliedEquations(); |
---|
1965 | int r = inequalities.getHeight(); |
---|
1966 | int c = inequalities.getWidth(); |
---|
1967 | |
---|
1968 | /* our cone has r facets, if r==0 return empty matrices */ |
---|
1969 | gfan::ZMatrix relativeInteriorPoints = gfan::ZMatrix(0,c); |
---|
1970 | gfan::ZMatrix outerFacetNormals = gfan::ZMatrix(0,c); |
---|
1971 | if (r==0) |
---|
1972 | return std::make_pair(relativeInteriorPoints,outerFacetNormals); |
---|
1973 | |
---|
1974 | /* next we iterate over each of the r facets, |
---|
1975 | * build the respective cone and add it to the list |
---|
1976 | * this is the i=0 case */ |
---|
1977 | gfan::ZMatrix newInequalities = inequalities.submatrix(1,0,r,c); |
---|
1978 | gfan::ZMatrix newEquations = equations; |
---|
1979 | newEquations.appendRow(inequalities[0]); |
---|
1980 | gfan::ZCone facet = gfan::ZCone(newInequalities,newEquations); |
---|
1981 | gfan::ZVector interiorPoint = facet.getRelativeInteriorPoint(); |
---|
1982 | if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0) |
---|
1983 | { |
---|
1984 | if (exceptThesePoints.count(interiorPoint)==0) |
---|
1985 | { |
---|
1986 | relativeInteriorPoints.appendRow(interiorPoint); |
---|
1987 | outerFacetNormals.appendRow(-inequalities[0].toVector()); |
---|
1988 | } |
---|
1989 | } |
---|
1990 | |
---|
1991 | /* these are the cases i=1,...,r-2 */ |
---|
1992 | for (int i=1; i<r-1; i++) |
---|
1993 | { |
---|
1994 | newInequalities = inequalities.submatrix(0,0,i,c); |
---|
1995 | newInequalities.append(inequalities.submatrix(i+1,0,r,c)); |
---|
1996 | newEquations = equations; |
---|
1997 | newEquations.appendRow(inequalities[i]); |
---|
1998 | facet = gfan::ZCone(newInequalities,newEquations); |
---|
1999 | interiorPoint = facet.getRelativeInteriorPoint(); |
---|
2000 | if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0) |
---|
2001 | { |
---|
2002 | if (exceptThesePoints.count(interiorPoint)==0) |
---|
2003 | { |
---|
2004 | relativeInteriorPoints.appendRow(interiorPoint); |
---|
2005 | outerFacetNormals.appendRow(-inequalities[i].toVector()); |
---|
2006 | } |
---|
2007 | } |
---|
2008 | } |
---|
2009 | |
---|
2010 | /* this is the i=r-1 case */ |
---|
2011 | newInequalities = inequalities.submatrix(0,0,r-1,c); |
---|
2012 | newEquations = equations; |
---|
2013 | newEquations.appendRow(inequalities[r-1]); |
---|
2014 | facet = gfan::ZCone(newInequalities,newEquations); |
---|
2015 | interiorPoint = facet.getRelativeInteriorPoint(); |
---|
2016 | if (onlyLowerHalfSpace==false || interiorPoint[0].sign()<0) |
---|
2017 | { |
---|
2018 | if (exceptThesePoints.count(interiorPoint)==0) |
---|
2019 | { |
---|
2020 | relativeInteriorPoints.appendRow(interiorPoint); |
---|
2021 | outerFacetNormals.appendRow(-inequalities[r-1].toVector()); |
---|
2022 | } |
---|
2023 | } |
---|
2024 | |
---|
2025 | return std::make_pair(relativeInteriorPoints,outerFacetNormals); |
---|
2026 | } |
---|
2027 | |
---|
2028 | |
---|
2029 | static void gfanIntegerWriteFd(gfan::Integer n, ssiInfo* dd) |
---|
2030 | { |
---|
2031 | mpz_t tmp; |
---|
2032 | mpz_init(tmp); |
---|
2033 | n.setGmp(tmp); |
---|
2034 | mpz_out_str (dd->f_write,SSI_BASE, tmp); |
---|
2035 | mpz_clear(tmp); |
---|
2036 | fputc(' ',dd->f_write); |
---|
2037 | } |
---|
2038 | |
---|
2039 | static void gfanZMatrixWriteFd(gfan::ZMatrix M, ssiInfo* dd) |
---|
2040 | { |
---|
2041 | fprintf(dd->f_write,"%d %d ",M.getHeight(),M.getWidth()); |
---|
2042 | |
---|
2043 | for (int i=0; i<M.getHeight(); i++) |
---|
2044 | { |
---|
2045 | for (int j=0; j<M.getWidth(); j++) |
---|
2046 | { |
---|
2047 | gfanIntegerWriteFd(M[i][j],dd); |
---|
2048 | } |
---|
2049 | } |
---|
2050 | } |
---|
2051 | |
---|
2052 | BOOLEAN bbcone_serialize(blackbox *b, void *d, si_link f) |
---|
2053 | { |
---|
2054 | ssiInfo *dd = (ssiInfo *)f->data; |
---|
2055 | |
---|
2056 | sleftv l; |
---|
2057 | memset(&l,0,sizeof(l)); |
---|
2058 | l.rtyp=STRING_CMD; |
---|
2059 | l.data=(void*)"cone"; |
---|
2060 | f->m->Write(f, &l); |
---|
2061 | |
---|
2062 | gfan::ZCone *Z = (gfan::ZCone*) d; |
---|
2063 | fprintf(dd->f_write,"%d ",Z->areImpliedEquationsKnown()+Z->areFacetsKnown()*2); |
---|
2064 | |
---|
2065 | gfan::ZMatrix i=Z->getInequalities(); |
---|
2066 | gfanZMatrixWriteFd(i,dd); |
---|
2067 | |
---|
2068 | gfan::ZMatrix e=Z->getEquations(); |
---|
2069 | gfanZMatrixWriteFd(e,dd); |
---|
2070 | |
---|
2071 | // assert(i.getWidth() == e.getWidth()); |
---|
2072 | return FALSE; |
---|
2073 | } |
---|
2074 | |
---|
2075 | static gfan::Integer gfanIntegerReadFd(ssiInfo* dd) |
---|
2076 | { |
---|
2077 | mpz_t tmp; |
---|
2078 | mpz_init(tmp); |
---|
2079 | s_readmpz_base(dd->f_read,tmp,SSI_BASE); |
---|
2080 | gfan::Integer n(tmp); |
---|
2081 | mpz_clear(tmp); |
---|
2082 | return n; |
---|
2083 | } |
---|
2084 | |
---|
2085 | static gfan::ZMatrix gfanZMatrixReadFd(ssiInfo* dd) |
---|
2086 | { |
---|
2087 | int r=s_readint(dd->f_read); |
---|
2088 | int c=s_readint(dd->f_read); |
---|
2089 | |
---|
2090 | gfan::ZMatrix M(r,c); |
---|
2091 | for (int i=0; i<r; i++) |
---|
2092 | { |
---|
2093 | for (int j=0; j<c; j++) |
---|
2094 | { |
---|
2095 | M[i][j] = gfanIntegerReadFd(dd); |
---|
2096 | } |
---|
2097 | } |
---|
2098 | return M; |
---|
2099 | } |
---|
2100 | |
---|
2101 | BOOLEAN bbcone_deserialize(blackbox **b, void **d, si_link f) |
---|
2102 | { |
---|
2103 | ssiInfo *dd = (ssiInfo *)f->data; |
---|
2104 | int preassumptions = s_readint(dd->f_read); |
---|
2105 | |
---|
2106 | gfan::ZMatrix i = gfanZMatrixReadFd(dd); |
---|
2107 | gfan::ZMatrix e = gfanZMatrixReadFd(dd); |
---|
2108 | |
---|
2109 | // if (e.getHeight()==0) // why is e sometimes 0x0 and sometimex 0xn??? |
---|
2110 | // e = gfan::ZMatrix(0,i.getWidth()); |
---|
2111 | |
---|
2112 | gfan::ZCone* Z = new gfan::ZCone(i,e,preassumptions); |
---|
2113 | |
---|
2114 | *d=Z; |
---|
2115 | return FALSE; |
---|
2116 | } |
---|
2117 | |
---|
2118 | void bbcone_setup(SModulFunctions* p) |
---|
2119 | { |
---|
2120 | blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox)); |
---|
2121 | // all undefined entries will be set to default in setBlackboxStuff |
---|
2122 | // the default Print is quite usefull, |
---|
2123 | // all other are simply error messages |
---|
2124 | b->blackbox_destroy=bbcone_destroy; |
---|
2125 | b->blackbox_String=bbcone_String; |
---|
2126 | // b->blackbox_Print=blackbox_default_Print; |
---|
2127 | b->blackbox_Init=bbcone_Init; |
---|
2128 | b->blackbox_Copy=bbcone_Copy; |
---|
2129 | b->blackbox_Assign=bbcone_Assign; |
---|
2130 | b->blackbox_Op2=bbcone_Op2; |
---|
2131 | b->blackbox_serialize=bbcone_serialize; |
---|
2132 | b->blackbox_deserialize=bbcone_deserialize; |
---|
2133 | p->iiAddCproc("gfan.lib","coneViaInequalities",FALSE,coneViaNormals); |
---|
2134 | p->iiAddCproc("gfan.lib","coneViaPoints",FALSE,coneViaRays); |
---|
2135 | p->iiAddCproc("","listContainsCone",FALSE,containsCone); |
---|
2136 | // iiAddCproc("gfan.lib","makePolytope",FALSE,coneToPolytope); |
---|
2137 | p->iiAddCproc("gfan.lib","ambientDimension",FALSE,ambientDimension); |
---|
2138 | p->iiAddCproc("gfan.lib","canonicalizeCone",FALSE,canonicalizeCone); |
---|
2139 | p->iiAddCproc("gfan.lib","codimension",FALSE,codimension); |
---|
2140 | p->iiAddCproc("gfan.lib","coneLink",FALSE,coneLink); |
---|
2141 | p->iiAddCproc("gfan.lib","containsAsFace",FALSE,hasFace); |
---|
2142 | p->iiAddCproc("gfan.lib","containsInSupport",FALSE,containsInSupport); |
---|
2143 | p->iiAddCproc("gfan.lib","containsInSupportOld",FALSE,containsInSupportOld); |
---|
2144 | p->iiAddCproc("gfan.lib","containsPositiveVector",FALSE,containsPositiveVector); |
---|
2145 | p->iiAddCproc("gfan.lib","containsRelatively",FALSE,containsRelatively); |
---|
2146 | p->iiAddCproc("gfan.lib","convexHull",FALSE,convexHull); |
---|
2147 | p->iiAddCproc("gfan.lib","convexIntersection",FALSE,intersectCones); |
---|
2148 | p->iiAddCproc("gfan.lib","convexIntersectionOld",FALSE,convexIntersectionOld); |
---|
2149 | p->iiAddCproc("gfan.lib","dimension",FALSE,dimension); |
---|
2150 | p->iiAddCproc("gfan.lib","dualCone",FALSE,dualCone); |
---|
2151 | p->iiAddCproc("gfan.lib","equations",FALSE,equations); |
---|
2152 | p->iiAddCproc("gfan.lib","facets",FALSE,facets); |
---|
2153 | p->iiAddCproc("gfan.lib","generatorsOfLinealitySpace",FALSE,generatorsOfLinealitySpace); |
---|
2154 | p->iiAddCproc("gfan.lib","generatorsOfSpan",FALSE,generatorsOfSpan); |
---|
2155 | p->iiAddCproc("gfan.lib","getLinearForms",FALSE,getLinearForms); |
---|
2156 | p->iiAddCproc("gfan.lib","getMultiplicity",FALSE,getMultiplicity); |
---|
2157 | p->iiAddCproc("gfan.lib","inequalities",FALSE,inequalities); |
---|
2158 | p->iiAddCproc("gfan.lib","isFullSpace",FALSE,isFullSpace); |
---|
2159 | p->iiAddCproc("gfan.lib","isOrigin",FALSE,isOrigin); |
---|
2160 | p->iiAddCproc("gfan.lib","isSimplicial",FALSE,isSimplicial); |
---|
2161 | p->iiAddCproc("gfan.lib","linealityDimension",FALSE,linealityDimension); |
---|
2162 | p->iiAddCproc("gfan.lib","linealitySpace",FALSE,linealitySpace); |
---|
2163 | p->iiAddCproc("gfan.lib","negatedCone",FALSE,negatedCone); |
---|
2164 | p->iiAddCproc("gfan.lib","quotientLatticeBasis",FALSE,quotientLatticeBasis); |
---|
2165 | p->iiAddCproc("gfan.lib","randomPoint",FALSE,randomPoint); |
---|
2166 | p->iiAddCproc("gfan.lib","rays",FALSE,rays); |
---|
2167 | p->iiAddCproc("gfan.lib","relativeInteriorPoint",FALSE,relativeInteriorPoint); |
---|
2168 | p->iiAddCproc("gfan.lib","semigroupGenerator",FALSE,semigroupGenerator); |
---|
2169 | p->iiAddCproc("gfan.lib","setLinearForms",FALSE,setLinearForms); |
---|
2170 | p->iiAddCproc("gfan.lib","setMultiplicity",FALSE,setMultiplicity); |
---|
2171 | p->iiAddCproc("gfan.lib","span",FALSE,impliedEquations); |
---|
2172 | p->iiAddCproc("gfan.lib","uniquePoint",FALSE,uniquePoint); |
---|
2173 | p->iiAddCproc("gfan.lib","faceContaining",FALSE,faceContaining); |
---|
2174 | coneID=setBlackboxStuff(b,"cone"); |
---|
2175 | } |
---|
2176 | |
---|
2177 | #endif |
---|