1 | #include <polymake_conversion.h> |
---|
2 | #include <polymake_documentation.h> |
---|
3 | #include <polymake/Graph.h> |
---|
4 | |
---|
5 | #include <dyn_modules/callgfanlib/bbcone.h> |
---|
6 | #include <dyn_modules/callgfanlib/bbfan.h> |
---|
7 | #include <dyn_modules/callgfanlib/bbpolytope.h> |
---|
8 | |
---|
9 | #include <Singular/blackbox.h> |
---|
10 | #include <Singular/ipshell.h> |
---|
11 | #include <Singular/subexpr.h> |
---|
12 | |
---|
13 | polymake::Main* init_polymake=NULL; |
---|
14 | |
---|
15 | static BOOLEAN bbpolytope_Op2(int op, leftv res, leftv i1, leftv i2) |
---|
16 | { |
---|
17 | gfan::ZCone* zp = (gfan::ZCone*) i1->Data(); |
---|
18 | switch(op) |
---|
19 | { |
---|
20 | case '+': |
---|
21 | { |
---|
22 | if (i2->Typ()==polytopeID || i2->Typ()==coneID) |
---|
23 | { |
---|
24 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
25 | gfan::ZCone* ms; |
---|
26 | try |
---|
27 | { |
---|
28 | polymake::perl::Object* pp = ZPolytope2PmPolytope(zp); |
---|
29 | polymake::perl::Object* pq = ZPolytope2PmPolytope(zq); |
---|
30 | polymake::perl::Object pms; |
---|
31 | CallPolymakeFunction("minkowski_sum", *pp, *pq) >> pms; |
---|
32 | ms = PmPolytope2ZPolytope(&pms); |
---|
33 | delete pp; |
---|
34 | delete pq; |
---|
35 | } |
---|
36 | catch (const std::exception& ex) |
---|
37 | { |
---|
38 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
39 | return TRUE; |
---|
40 | } |
---|
41 | res->rtyp = polytopeID; |
---|
42 | res->data = (void*) ms; |
---|
43 | return FALSE; |
---|
44 | } |
---|
45 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
46 | } |
---|
47 | case '*': |
---|
48 | { |
---|
49 | if (i2->Typ()==INT_CMD) |
---|
50 | { |
---|
51 | int s = (int)(long) i2->Data(); |
---|
52 | gfan::ZMatrix zm = zp->extremeRays(); |
---|
53 | for (int i=0; i<zm.getHeight(); i++) |
---|
54 | for (int j=1; j<zm.getWidth(); j++) |
---|
55 | zm[i][j] *= s; |
---|
56 | gfan::ZCone* zs = new gfan::ZCone(); |
---|
57 | *zs = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth())); |
---|
58 | res->rtyp = polytopeID; |
---|
59 | res->data = (void*) zs; |
---|
60 | return FALSE; |
---|
61 | } |
---|
62 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
63 | } |
---|
64 | case '&': |
---|
65 | { |
---|
66 | if (i2->Typ()==polytopeID) |
---|
67 | { |
---|
68 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
69 | int d1 = zp->ambientDimension(); |
---|
70 | int d2 = zq->ambientDimension(); |
---|
71 | if (d1 != d2) |
---|
72 | { |
---|
73 | Werror("mismatching ambient dimensions"); |
---|
74 | return TRUE; |
---|
75 | } |
---|
76 | gfan::ZCone* zs = new gfan::ZCone(); |
---|
77 | *zs = gfan::intersection(*zp, *zq); |
---|
78 | zs->canonicalize(); |
---|
79 | res->rtyp = polytopeID; |
---|
80 | res->data = (void*) zs; |
---|
81 | return FALSE; |
---|
82 | } |
---|
83 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
84 | } |
---|
85 | case '|': |
---|
86 | { |
---|
87 | if(i2->Typ()==polytopeID) |
---|
88 | { |
---|
89 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
90 | int d1 = zp->ambientDimension(); |
---|
91 | int d2 = zq->ambientDimension(); |
---|
92 | if (d1 != d2) |
---|
93 | { |
---|
94 | Werror("mismatching ambient dimensions"); |
---|
95 | return TRUE; |
---|
96 | } |
---|
97 | gfan::ZMatrix rays = zp->extremeRays(); |
---|
98 | rays.append(zq->extremeRays()); |
---|
99 | gfan::ZMatrix lineality = zp->generatorsOfLinealitySpace(); |
---|
100 | lineality.append(zq->generatorsOfLinealitySpace()); |
---|
101 | gfan::ZCone* zs = new gfan::ZCone(); |
---|
102 | *zs = gfan::ZCone::givenByRays(rays,lineality); |
---|
103 | zs->canonicalize(); |
---|
104 | res->rtyp = polytopeID; |
---|
105 | res->data = (void*) zs; |
---|
106 | return FALSE; |
---|
107 | } |
---|
108 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
109 | } |
---|
110 | case EQUAL_EQUAL: |
---|
111 | { |
---|
112 | if(i2->Typ()==polytopeID) |
---|
113 | { |
---|
114 | gfan::ZCone* zq = (gfan::ZCone*) i2->Data(); |
---|
115 | zp->canonicalize(); |
---|
116 | zq->canonicalize(); |
---|
117 | bool b = !((*zp)!=(*zq)); |
---|
118 | res->rtyp = INT_CMD; |
---|
119 | res->data = (char*) (long) b; |
---|
120 | return FALSE; |
---|
121 | } |
---|
122 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
123 | } |
---|
124 | default: |
---|
125 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
126 | } |
---|
127 | return blackboxDefaultOp2(op,res,i1,i2); |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | /* Functions for using Polymake in Singular */ |
---|
132 | |
---|
133 | // BOOLEAN cube(leftv res, leftv args) |
---|
134 | // { |
---|
135 | // leftv u = args; |
---|
136 | // if ((u !=NULL) && (u->Typ() == INT_CMD)) |
---|
137 | // { |
---|
138 | // int ambientDim = (int)(long)u->Data(); |
---|
139 | // if (ambientDim < 0) |
---|
140 | // { |
---|
141 | // Werror("expected non-negative ambient dim but got %d", ambientDim); |
---|
142 | // return TRUE; |
---|
143 | // } |
---|
144 | // gfan::ZMatrix zm(ambientDim*2,ambientDim+1); |
---|
145 | // int j=1; |
---|
146 | // for (int i=0; i<ambientDim*2; i=i+2) |
---|
147 | // { |
---|
148 | // zm[i][0] = 1; |
---|
149 | // zm[i][j] = 1; |
---|
150 | // zm[i+1][0] = 1; |
---|
151 | // zm[i+1][j] = -1; |
---|
152 | // j = j+1; |
---|
153 | // } |
---|
154 | // gfan::ZCone* zc = new gfan::ZCone(zm, gfan::ZMatrix(0, zm.getWidth())); |
---|
155 | // res->rtyp = coneID; |
---|
156 | // res->data = (char *)zc; |
---|
157 | // return FALSE; |
---|
158 | // } |
---|
159 | // WerrorS("cube: unexpected parameters"); |
---|
160 | // return TRUE; |
---|
161 | // } |
---|
162 | |
---|
163 | // BOOLEAN cross(leftv res, leftv args) |
---|
164 | // { |
---|
165 | // leftv u = args; |
---|
166 | // if ((u !=NULL) && (u->Typ() == INT_CMD)) |
---|
167 | // { |
---|
168 | // int ambientDim = (int)(long)u->Data(); |
---|
169 | // if (ambientDim < 0) |
---|
170 | // { |
---|
171 | // Werror("expected non-negative ambient dim but got %d", ambientDim); |
---|
172 | // return TRUE; |
---|
173 | // } |
---|
174 | // gfan::ZMatrix zm(ambientDim*2,ambientDim+1); |
---|
175 | // int j=1; |
---|
176 | // for (int i=0; i<ambientDim*2; i=i+2) |
---|
177 | // { |
---|
178 | // zm[i][0] = 1; |
---|
179 | // zm[i][j] = 1; |
---|
180 | // zm[i+1][0] = 1; |
---|
181 | // zm[i+1][j] = -1; |
---|
182 | // j = j+1; |
---|
183 | // } |
---|
184 | // gfan::ZCone* zc = new gfan::ZCone(); |
---|
185 | // *zc = gfan::ZCone::givenByRays(zm, gfan::ZMatrix(0, zm.getWidth())); |
---|
186 | // res->rtyp = coneID; |
---|
187 | // res->data = (char *)zc; |
---|
188 | // return FALSE; |
---|
189 | // } |
---|
190 | // WerrorS("cross: unexpected parameters"); |
---|
191 | // return TRUE; |
---|
192 | // } |
---|
193 | |
---|
194 | |
---|
195 | BOOLEAN PMisLatticePolytope(leftv res, leftv args) |
---|
196 | { |
---|
197 | leftv u = args; |
---|
198 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
199 | { |
---|
200 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
201 | bool b; |
---|
202 | try |
---|
203 | { |
---|
204 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
205 | b = p->give("Lattice"); |
---|
206 | delete p; |
---|
207 | } |
---|
208 | catch (const std::exception& ex) |
---|
209 | { |
---|
210 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
211 | return TRUE; |
---|
212 | } |
---|
213 | res->rtyp = INT_CMD; |
---|
214 | res->data = (char*) (long) b; |
---|
215 | return FALSE; |
---|
216 | } |
---|
217 | WerrorS("isLatticePolytope: unexpected parameters"); |
---|
218 | return TRUE; |
---|
219 | } |
---|
220 | |
---|
221 | |
---|
222 | BOOLEAN PMisBounded(leftv res, leftv args) |
---|
223 | { |
---|
224 | leftv u = args; |
---|
225 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
226 | { |
---|
227 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
228 | bool b; |
---|
229 | try |
---|
230 | { |
---|
231 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
232 | b = p->give("BOUNDED"); |
---|
233 | delete p; |
---|
234 | } |
---|
235 | catch (const std::exception& ex) |
---|
236 | { |
---|
237 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
238 | return TRUE; |
---|
239 | } |
---|
240 | res->rtyp = INT_CMD; |
---|
241 | res->data = (char*) (long) b; |
---|
242 | return FALSE; |
---|
243 | } |
---|
244 | WerrorS("isBounded: unexpected parameters"); |
---|
245 | return TRUE; |
---|
246 | } |
---|
247 | |
---|
248 | |
---|
249 | BOOLEAN PMisReflexive(leftv res, leftv args) |
---|
250 | { |
---|
251 | leftv u = args; |
---|
252 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
253 | { |
---|
254 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
255 | bool b; |
---|
256 | try |
---|
257 | { |
---|
258 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
259 | b = p->give("REFLEXIVE"); |
---|
260 | delete p; |
---|
261 | } |
---|
262 | catch (const std::exception& ex) |
---|
263 | { |
---|
264 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
265 | return TRUE; |
---|
266 | } |
---|
267 | res->rtyp = INT_CMD; |
---|
268 | res->data = (char*) (long) b; |
---|
269 | return FALSE; |
---|
270 | } |
---|
271 | WerrorS("isReflexive: unexpected parameters"); |
---|
272 | return TRUE; |
---|
273 | } |
---|
274 | |
---|
275 | |
---|
276 | BOOLEAN PMisGorenstein(leftv res, leftv args) |
---|
277 | { |
---|
278 | leftv u = args; |
---|
279 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
280 | { |
---|
281 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
282 | bool b; |
---|
283 | try |
---|
284 | { |
---|
285 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
286 | b = p->give("GORENSTEIN"); |
---|
287 | delete p; |
---|
288 | } |
---|
289 | catch (const std::exception& ex) |
---|
290 | { |
---|
291 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
292 | return TRUE; |
---|
293 | } |
---|
294 | res->rtyp = INT_CMD; |
---|
295 | res->data = (char*) (long) b; |
---|
296 | return FALSE; |
---|
297 | } |
---|
298 | WerrorS("isGorenstein: unexpected parameters"); |
---|
299 | return TRUE; |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | BOOLEAN PMgorensteinIndex(leftv res, leftv args) |
---|
304 | { |
---|
305 | leftv u = args; |
---|
306 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
307 | { |
---|
308 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
309 | int gi; |
---|
310 | bool ok = true; |
---|
311 | try |
---|
312 | { |
---|
313 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
314 | bool b = p->give("GORENSTEIN"); |
---|
315 | if (b) |
---|
316 | { |
---|
317 | polymake::Integer pgi = p->give("GORENSTEIN_INDEX"); |
---|
318 | gi = PmInteger2Int(pgi,ok); |
---|
319 | delete p; |
---|
320 | } |
---|
321 | else |
---|
322 | { |
---|
323 | delete p; |
---|
324 | WerrorS("gorensteinIndex: input polytope not gorenstein"); |
---|
325 | return TRUE; |
---|
326 | } |
---|
327 | } |
---|
328 | catch (const std::exception& ex) |
---|
329 | { |
---|
330 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
331 | return TRUE; |
---|
332 | } |
---|
333 | if (!ok) |
---|
334 | { |
---|
335 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
336 | return TRUE; |
---|
337 | } |
---|
338 | res->rtyp = INT_CMD; |
---|
339 | res->data = (char*) (long) gi; |
---|
340 | return FALSE; |
---|
341 | } |
---|
342 | WerrorS("gorensteinIndex: unexpected parameters"); |
---|
343 | return TRUE; |
---|
344 | } |
---|
345 | |
---|
346 | |
---|
347 | BOOLEAN PMgorensteinVector(leftv res, leftv args) |
---|
348 | { |
---|
349 | leftv u = args; |
---|
350 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
351 | { |
---|
352 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
353 | intvec* gv; |
---|
354 | bool ok = true; |
---|
355 | try |
---|
356 | { |
---|
357 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
358 | bool b = p->give("GORENSTEIN"); |
---|
359 | if (b) |
---|
360 | { |
---|
361 | polymake::Vector<polymake::Integer> pgv = p->give("GORENSTEIN_VECTOR"); |
---|
362 | gv = PmVectorInteger2Intvec(&pgv,ok); |
---|
363 | delete p; |
---|
364 | } |
---|
365 | else |
---|
366 | { |
---|
367 | delete p; |
---|
368 | WerrorS("gorensteinVector: input polytope not gorenstein"); |
---|
369 | return TRUE; |
---|
370 | } |
---|
371 | } |
---|
372 | catch (const std::exception& ex) |
---|
373 | { |
---|
374 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
375 | return TRUE; |
---|
376 | } |
---|
377 | if (!ok) |
---|
378 | { |
---|
379 | WerrorS("gorensteinVector: overflow in PmVectorInteger2Intvec"); |
---|
380 | return TRUE; |
---|
381 | } |
---|
382 | res->rtyp = INTVEC_CMD; |
---|
383 | res->data = (char*) gv; |
---|
384 | return FALSE; |
---|
385 | } |
---|
386 | WerrorS("gorensteinVector: unexpected parameters"); |
---|
387 | return TRUE; |
---|
388 | } |
---|
389 | |
---|
390 | |
---|
391 | BOOLEAN PMisCanonical(leftv res, leftv args) |
---|
392 | { |
---|
393 | leftv u = args; |
---|
394 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
395 | { |
---|
396 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
397 | bool b; |
---|
398 | try |
---|
399 | { |
---|
400 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
401 | b = p->give("CANONICAL"); |
---|
402 | delete p; |
---|
403 | } |
---|
404 | catch (const std::exception& ex) |
---|
405 | { |
---|
406 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
407 | return TRUE; |
---|
408 | } |
---|
409 | res->rtyp = INT_CMD; |
---|
410 | res->data = (char*) (long) b; |
---|
411 | return FALSE; |
---|
412 | } |
---|
413 | WerrorS("isCanonical: unexpected parameters"); |
---|
414 | return TRUE; |
---|
415 | } |
---|
416 | |
---|
417 | |
---|
418 | BOOLEAN PMisTerminal(leftv res, leftv args) |
---|
419 | { |
---|
420 | leftv u = args; |
---|
421 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
422 | { |
---|
423 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
424 | bool b; |
---|
425 | try |
---|
426 | { |
---|
427 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
428 | b = p->give("TERMINAL"); |
---|
429 | delete p; |
---|
430 | } |
---|
431 | catch (const std::exception& ex) |
---|
432 | { |
---|
433 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
434 | return TRUE; |
---|
435 | } |
---|
436 | res->rtyp = INT_CMD; |
---|
437 | res->data = (char*) (long) b; |
---|
438 | return FALSE; |
---|
439 | } |
---|
440 | WerrorS("isTerminal: unexpected parameters"); |
---|
441 | return TRUE; |
---|
442 | } |
---|
443 | |
---|
444 | |
---|
445 | BOOLEAN PMisLatticeEmpty(leftv res, leftv args) |
---|
446 | { |
---|
447 | leftv u = args; |
---|
448 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
449 | { |
---|
450 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
451 | bool b; |
---|
452 | try |
---|
453 | { |
---|
454 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
455 | b = p->give("LATTICE_EMPTY"); |
---|
456 | delete p; |
---|
457 | } |
---|
458 | catch (const std::exception& ex) |
---|
459 | { |
---|
460 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
461 | return TRUE; |
---|
462 | } |
---|
463 | res->rtyp = INT_CMD; |
---|
464 | res->data = (char*) (long) b; |
---|
465 | return FALSE; |
---|
466 | } |
---|
467 | WerrorS("isLatticeEmpty: unexpected parameters"); |
---|
468 | return TRUE; |
---|
469 | } |
---|
470 | |
---|
471 | |
---|
472 | BOOLEAN PMlatticeVolume(leftv res, leftv args) |
---|
473 | { |
---|
474 | leftv u = args; |
---|
475 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
476 | { |
---|
477 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
478 | int lv; |
---|
479 | bool ok = true; |
---|
480 | try |
---|
481 | { |
---|
482 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
483 | polymake::Integer plv = p->give("LATTICE_VOLUME"); |
---|
484 | delete p; |
---|
485 | lv = PmInteger2Int(plv,ok); |
---|
486 | } |
---|
487 | catch (const std::exception& ex) |
---|
488 | { |
---|
489 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
490 | return TRUE; |
---|
491 | } |
---|
492 | if (!ok) |
---|
493 | { |
---|
494 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
495 | return TRUE; |
---|
496 | } |
---|
497 | res->rtyp = INT_CMD; |
---|
498 | res->data = (char*) (long) lv; |
---|
499 | return FALSE; |
---|
500 | } |
---|
501 | WerrorS("latticeVolume: unexpected parameters"); |
---|
502 | return TRUE; |
---|
503 | } |
---|
504 | |
---|
505 | |
---|
506 | BOOLEAN PMlatticeDegree(leftv res, leftv args) |
---|
507 | { |
---|
508 | leftv u = args; |
---|
509 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
510 | { |
---|
511 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
512 | int ld; |
---|
513 | bool ok = true; |
---|
514 | try |
---|
515 | { |
---|
516 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
517 | polymake::Integer pld = p->give("LATTICE_DEGREE"); |
---|
518 | delete p; |
---|
519 | ld = PmInteger2Int(pld,ok); |
---|
520 | } |
---|
521 | catch (const std::exception& ex) |
---|
522 | { |
---|
523 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
524 | return TRUE; |
---|
525 | } |
---|
526 | if (!ok) |
---|
527 | { |
---|
528 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
529 | return TRUE; |
---|
530 | } |
---|
531 | res->rtyp = INT_CMD; |
---|
532 | res->data = (char*) (long) ld; |
---|
533 | return FALSE; |
---|
534 | } |
---|
535 | WerrorS("latticeDegree: unexpected parameters"); |
---|
536 | return TRUE; |
---|
537 | } |
---|
538 | |
---|
539 | |
---|
540 | BOOLEAN PMlatticeCodegree(leftv res, leftv args) |
---|
541 | { |
---|
542 | leftv u = args; |
---|
543 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
544 | { |
---|
545 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
546 | int lc; |
---|
547 | bool ok = true; |
---|
548 | try |
---|
549 | { |
---|
550 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
551 | polymake::Integer plc = p->give("LATTICE_CODEGREE"); |
---|
552 | delete p; |
---|
553 | lc = PmInteger2Int(plc,ok); |
---|
554 | } |
---|
555 | catch (const std::exception& ex) |
---|
556 | { |
---|
557 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
558 | return TRUE; |
---|
559 | } |
---|
560 | if (!ok) |
---|
561 | { |
---|
562 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
563 | return TRUE; |
---|
564 | } |
---|
565 | res->rtyp = INT_CMD; |
---|
566 | res->data = (char*) (long) lc; |
---|
567 | return FALSE; |
---|
568 | } |
---|
569 | WerrorS("latticeCodegree: unexpected parameters"); |
---|
570 | return TRUE; |
---|
571 | } |
---|
572 | |
---|
573 | |
---|
574 | BOOLEAN PMehrhartPolynomialCoeff(leftv res, leftv args) |
---|
575 | { |
---|
576 | leftv u = args; |
---|
577 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
578 | { |
---|
579 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
580 | intvec* ec; |
---|
581 | bool ok = true; |
---|
582 | try |
---|
583 | { |
---|
584 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
585 | polymake::Vector<polymake::Integer> pec = p->give("EHRHART_POLYNOMIAL_COEFF"); |
---|
586 | delete p; |
---|
587 | ec = PmVectorInteger2Intvec(&pec,ok); |
---|
588 | } |
---|
589 | catch (const std::exception& ex) |
---|
590 | { |
---|
591 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
592 | return TRUE; |
---|
593 | } |
---|
594 | if (!ok) |
---|
595 | { |
---|
596 | WerrorS("ehrhartPolynomialCoeff: overflow in PmVectorInteger2Intvec"); |
---|
597 | return TRUE; |
---|
598 | } |
---|
599 | res->rtyp = INTVEC_CMD; |
---|
600 | res->data = (char*) ec; |
---|
601 | return FALSE; |
---|
602 | } |
---|
603 | WerrorS("ehrhartPolynomialCoeff: unexpected parameters"); |
---|
604 | return TRUE; |
---|
605 | } |
---|
606 | |
---|
607 | |
---|
608 | BOOLEAN PMfVector(leftv res, leftv args) |
---|
609 | { |
---|
610 | leftv u = args; |
---|
611 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
612 | { |
---|
613 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
614 | intvec* hv; |
---|
615 | bool ok = true; |
---|
616 | try |
---|
617 | { |
---|
618 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
619 | polymake::Vector<polymake::Integer> phv = p->give("F_VECTOR"); |
---|
620 | delete p; |
---|
621 | hv = PmVectorInteger2Intvec(&phv,ok); |
---|
622 | } |
---|
623 | catch (const std::exception& ex) |
---|
624 | { |
---|
625 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
626 | return TRUE; |
---|
627 | } |
---|
628 | if (!ok) |
---|
629 | { |
---|
630 | WerrorS("fVector: overflow in PmVectorInteger2Intvec"); |
---|
631 | return TRUE; |
---|
632 | } |
---|
633 | res->rtyp = INTVEC_CMD; |
---|
634 | res->data = (char*) hv; |
---|
635 | return FALSE; |
---|
636 | } |
---|
637 | WerrorS("fVector: unexpected parameters"); |
---|
638 | return TRUE; |
---|
639 | } |
---|
640 | |
---|
641 | |
---|
642 | BOOLEAN PMhVector(leftv res, leftv args) |
---|
643 | { |
---|
644 | leftv u = args; |
---|
645 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
646 | { |
---|
647 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
648 | intvec* hv; |
---|
649 | bool ok = true; |
---|
650 | try |
---|
651 | { |
---|
652 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
653 | polymake::Vector<polymake::Integer> phv = p->give("H_VECTOR"); |
---|
654 | delete p; |
---|
655 | hv = PmVectorInteger2Intvec(&phv,ok); |
---|
656 | } |
---|
657 | catch (const std::exception& ex) |
---|
658 | { |
---|
659 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
660 | return TRUE; |
---|
661 | } |
---|
662 | if (!ok) |
---|
663 | { |
---|
664 | WerrorS("hVector: overflow in PmVectorInteger2Intvec"); |
---|
665 | return TRUE; |
---|
666 | } |
---|
667 | res->rtyp = INTVEC_CMD; |
---|
668 | res->data = (char*) hv; |
---|
669 | return FALSE; |
---|
670 | } |
---|
671 | WerrorS("hVector: unexpected parameters"); |
---|
672 | return TRUE; |
---|
673 | } |
---|
674 | |
---|
675 | |
---|
676 | BOOLEAN PMhStarVector(leftv res, leftv args) |
---|
677 | { |
---|
678 | leftv u = args; |
---|
679 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
680 | { |
---|
681 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
682 | intvec* hv; |
---|
683 | bool ok = true; |
---|
684 | try |
---|
685 | { |
---|
686 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
687 | polymake::Vector<polymake::Integer> phv = p->give("H_STAR_VECTOR"); |
---|
688 | delete p; |
---|
689 | hv = PmVectorInteger2Intvec(&phv,ok); |
---|
690 | } |
---|
691 | catch (const std::exception& ex) |
---|
692 | { |
---|
693 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
694 | return TRUE; |
---|
695 | } |
---|
696 | if (!ok) |
---|
697 | { |
---|
698 | WerrorS("hStarVector: overflow in PmVectorInteger2Intvec"); |
---|
699 | return TRUE; |
---|
700 | } |
---|
701 | res->rtyp = INTVEC_CMD; |
---|
702 | res->data = (char*) hv; |
---|
703 | return FALSE; |
---|
704 | } |
---|
705 | WerrorS("hStarVector: unexpected parameters"); |
---|
706 | return TRUE; |
---|
707 | } |
---|
708 | |
---|
709 | |
---|
710 | BOOLEAN PMisNormal(leftv res, leftv args) |
---|
711 | { |
---|
712 | leftv u = args; |
---|
713 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
714 | { |
---|
715 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
716 | bool b; |
---|
717 | try |
---|
718 | { |
---|
719 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
720 | b = p->give("NORMAL"); |
---|
721 | delete p; |
---|
722 | } |
---|
723 | catch (const std::exception& ex) |
---|
724 | { |
---|
725 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
726 | return TRUE; |
---|
727 | } |
---|
728 | res->rtyp = INT_CMD; |
---|
729 | res->data = (char*) (long) b; |
---|
730 | return FALSE; |
---|
731 | } |
---|
732 | WerrorS("isNormal: unexpected parameters"); |
---|
733 | return TRUE; |
---|
734 | } |
---|
735 | |
---|
736 | |
---|
737 | BOOLEAN PMfacetWidths(leftv res, leftv args) |
---|
738 | { |
---|
739 | leftv u = args; |
---|
740 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
741 | { |
---|
742 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
743 | intvec* fw; |
---|
744 | bool ok = true; |
---|
745 | try |
---|
746 | { |
---|
747 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
748 | polymake::Vector<polymake::Integer> pfw = p->give("FACET_WIDTHS"); |
---|
749 | delete p; |
---|
750 | fw = PmVectorInteger2Intvec(&pfw,ok); |
---|
751 | } |
---|
752 | catch (const std::exception& ex) |
---|
753 | { |
---|
754 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
755 | return TRUE; |
---|
756 | } |
---|
757 | if (!ok) |
---|
758 | { |
---|
759 | WerrorS("facetWidths: overflow in PmVectorInteger2Intvec"); |
---|
760 | return TRUE; |
---|
761 | } |
---|
762 | res->rtyp = INTVEC_CMD; |
---|
763 | res->data = (char*) fw; |
---|
764 | return FALSE; |
---|
765 | } |
---|
766 | WerrorS("facetWidths: unexpected parameters"); |
---|
767 | return TRUE; |
---|
768 | } |
---|
769 | |
---|
770 | |
---|
771 | BOOLEAN PMfacetWidth(leftv res, leftv args) |
---|
772 | { |
---|
773 | leftv u = args; |
---|
774 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
775 | { |
---|
776 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
777 | int fw; |
---|
778 | bool ok = true; |
---|
779 | try |
---|
780 | { |
---|
781 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
782 | polymake::Integer pfw = p->give("FACET_WIDTH"); |
---|
783 | delete p; |
---|
784 | fw = PmInteger2Int(pfw,ok); |
---|
785 | } |
---|
786 | catch (const std::exception& ex) |
---|
787 | { |
---|
788 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
789 | return TRUE; |
---|
790 | } |
---|
791 | if (!ok) |
---|
792 | { |
---|
793 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
794 | return TRUE; |
---|
795 | } |
---|
796 | res->rtyp = INT_CMD; |
---|
797 | res->data = (char*) (long) fw; |
---|
798 | return FALSE; |
---|
799 | } |
---|
800 | WerrorS("facetWidth: unexpected parameters"); |
---|
801 | return TRUE; |
---|
802 | } |
---|
803 | |
---|
804 | |
---|
805 | BOOLEAN PMfacetVertexLatticeDistances(leftv res, leftv args) |
---|
806 | { |
---|
807 | leftv u = args; |
---|
808 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
809 | { |
---|
810 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
811 | intvec* ld; |
---|
812 | bool ok=true; |
---|
813 | try |
---|
814 | { |
---|
815 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
816 | polymake::Matrix<polymake::Integer> pld = p->give("FACET_VERTEX_LATTICE_DISTANCES"); |
---|
817 | delete p; |
---|
818 | ld = PmMatrixInteger2Intvec(&pld,ok); |
---|
819 | } |
---|
820 | catch (const std::exception& ex) |
---|
821 | { |
---|
822 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
823 | return TRUE; |
---|
824 | } |
---|
825 | if (!ok) |
---|
826 | { |
---|
827 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
828 | return TRUE; |
---|
829 | } |
---|
830 | res->rtyp = INTMAT_CMD; |
---|
831 | res->data = (char*) ld; |
---|
832 | return FALSE; |
---|
833 | } |
---|
834 | WerrorS("facetVertexLatticeDistances: unexpected parameters"); |
---|
835 | return TRUE; |
---|
836 | } |
---|
837 | |
---|
838 | |
---|
839 | BOOLEAN PMisCompressed(leftv res, leftv args) |
---|
840 | { |
---|
841 | leftv u = args; |
---|
842 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
843 | { |
---|
844 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
845 | bool b; |
---|
846 | try |
---|
847 | { |
---|
848 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
849 | b = p->give("COMPRESSED"); |
---|
850 | delete p; |
---|
851 | } |
---|
852 | catch (const std::exception& ex) |
---|
853 | { |
---|
854 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
855 | return TRUE; |
---|
856 | } |
---|
857 | res->rtyp = INT_CMD; |
---|
858 | res->data = (char*) (long) b; |
---|
859 | return FALSE; |
---|
860 | } |
---|
861 | WerrorS("isCompressed: unexpected parameters"); |
---|
862 | return TRUE; |
---|
863 | } |
---|
864 | |
---|
865 | |
---|
866 | BOOLEAN PMisSmooth(leftv res, leftv args) |
---|
867 | { |
---|
868 | leftv u = args; |
---|
869 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
870 | { |
---|
871 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
872 | bool b; |
---|
873 | try |
---|
874 | { |
---|
875 | polymake::perl::Object* p = ZCone2PmCone(zc); |
---|
876 | b = p->give("SMOOTH_CONE"); |
---|
877 | delete p; |
---|
878 | } |
---|
879 | catch (const std::exception& ex) |
---|
880 | { |
---|
881 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
882 | return TRUE; |
---|
883 | } |
---|
884 | res->rtyp = INT_CMD; |
---|
885 | res->data = (char*) (long) b; |
---|
886 | return FALSE; |
---|
887 | } |
---|
888 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
889 | { |
---|
890 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
891 | bool b; |
---|
892 | try |
---|
893 | { |
---|
894 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
895 | b = p->give("SMOOTH"); |
---|
896 | delete p; |
---|
897 | } |
---|
898 | catch (const std::exception& ex) |
---|
899 | { |
---|
900 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
901 | return TRUE; |
---|
902 | } |
---|
903 | res->rtyp = INT_CMD; |
---|
904 | res->data = (char*) (long) b; |
---|
905 | return FALSE; |
---|
906 | } |
---|
907 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
908 | { |
---|
909 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
910 | bool b; |
---|
911 | try |
---|
912 | { |
---|
913 | polymake::perl::Object* p = ZFan2PmFan(zf); |
---|
914 | b = p->give("SMOOTH_FAN"); |
---|
915 | delete p; |
---|
916 | } |
---|
917 | catch (const std::exception& ex) |
---|
918 | { |
---|
919 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
920 | return TRUE; |
---|
921 | } |
---|
922 | res->rtyp = INT_CMD; |
---|
923 | res->data = (char*) (long) b; |
---|
924 | return FALSE; |
---|
925 | } |
---|
926 | WerrorS("isSmooth: unexpected parameters"); |
---|
927 | return TRUE; |
---|
928 | } |
---|
929 | |
---|
930 | |
---|
931 | BOOLEAN PMisVeryAmple(leftv res, leftv args) |
---|
932 | { |
---|
933 | leftv u = args; |
---|
934 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
935 | { |
---|
936 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
937 | bool b; |
---|
938 | try |
---|
939 | { |
---|
940 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
941 | b = p->give("VERY_AMPLE"); |
---|
942 | delete p; |
---|
943 | } |
---|
944 | catch (const std::exception& ex) |
---|
945 | { |
---|
946 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
947 | return TRUE; |
---|
948 | } |
---|
949 | res->rtyp = INT_CMD; |
---|
950 | res->data = (char*) (long) b; |
---|
951 | return FALSE; |
---|
952 | } |
---|
953 | WerrorS("isVeryAmple: unexpected parameters"); |
---|
954 | return TRUE; |
---|
955 | } |
---|
956 | |
---|
957 | |
---|
958 | BOOLEAN PMlatticePoints(leftv res, leftv args) |
---|
959 | { |
---|
960 | leftv u = args; |
---|
961 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
962 | { |
---|
963 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
964 | intvec* iv; |
---|
965 | bool ok = true; |
---|
966 | try |
---|
967 | { |
---|
968 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
969 | polymake::Matrix<polymake::Integer> lp = p->give("LATTICE_POINTS"); |
---|
970 | delete p; |
---|
971 | iv = PmMatrixInteger2Intvec(&lp,ok); |
---|
972 | } |
---|
973 | catch (const std::exception& ex) |
---|
974 | { |
---|
975 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
976 | return TRUE; |
---|
977 | } |
---|
978 | if (!ok) |
---|
979 | { |
---|
980 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
981 | return TRUE; |
---|
982 | } |
---|
983 | res->rtyp = INTMAT_CMD; |
---|
984 | res->data = (char*) iv; |
---|
985 | return FALSE; |
---|
986 | } |
---|
987 | WerrorS("LatticePoints: unexpected parameters"); |
---|
988 | return TRUE; |
---|
989 | } |
---|
990 | |
---|
991 | |
---|
992 | BOOLEAN PMnLatticePoints(leftv res, leftv args) |
---|
993 | { |
---|
994 | leftv u = args; |
---|
995 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
996 | { |
---|
997 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
998 | int n; |
---|
999 | bool ok = true; |
---|
1000 | try |
---|
1001 | { |
---|
1002 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1003 | polymake::Integer nlp = p->give("N_LATTICE_POINTS"); |
---|
1004 | delete p; |
---|
1005 | n = PmInteger2Int(nlp,ok); |
---|
1006 | } |
---|
1007 | catch (const std::exception& ex) |
---|
1008 | { |
---|
1009 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1010 | return TRUE; |
---|
1011 | } |
---|
1012 | if (!ok) |
---|
1013 | { |
---|
1014 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1015 | return TRUE; |
---|
1016 | } |
---|
1017 | res->rtyp = INT_CMD; |
---|
1018 | res->data = (char*) (long) n; |
---|
1019 | return FALSE; |
---|
1020 | } |
---|
1021 | WerrorS("nLatticePoints: unexpected parameters"); |
---|
1022 | return TRUE; |
---|
1023 | } |
---|
1024 | |
---|
1025 | |
---|
1026 | BOOLEAN PMinteriorLatticePoints(leftv res, leftv args) |
---|
1027 | { |
---|
1028 | leftv u = args; |
---|
1029 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1030 | { |
---|
1031 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1032 | intvec* iv; |
---|
1033 | bool ok = true; |
---|
1034 | try |
---|
1035 | { |
---|
1036 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1037 | polymake::Matrix<polymake::Integer> lp = p->give("INTERIOR_LATTICE_POINTS"); |
---|
1038 | delete p; |
---|
1039 | iv = PmMatrixInteger2Intvec(&lp,ok); |
---|
1040 | } |
---|
1041 | catch (const std::exception& ex) |
---|
1042 | { |
---|
1043 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1044 | return TRUE; |
---|
1045 | } |
---|
1046 | if (!ok) |
---|
1047 | { |
---|
1048 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1049 | return TRUE; |
---|
1050 | } |
---|
1051 | res->rtyp = INTMAT_CMD; |
---|
1052 | res->data = (char*) iv; |
---|
1053 | return FALSE; |
---|
1054 | } |
---|
1055 | WerrorS("interiorLatticePoints: unexpected parameters"); |
---|
1056 | return TRUE; |
---|
1057 | } |
---|
1058 | |
---|
1059 | |
---|
1060 | BOOLEAN PMnInteriorLatticePoints(leftv res, leftv args) |
---|
1061 | { |
---|
1062 | leftv u = args; |
---|
1063 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1064 | { |
---|
1065 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1066 | int n; |
---|
1067 | bool ok = true; |
---|
1068 | try |
---|
1069 | { |
---|
1070 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1071 | polymake::Integer nlp = p->give("N_INTERIOR_LATTICE_POINTS"); |
---|
1072 | delete p; |
---|
1073 | n = PmInteger2Int(nlp,ok); |
---|
1074 | } |
---|
1075 | catch (const std::exception& ex) |
---|
1076 | { |
---|
1077 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1078 | return TRUE; |
---|
1079 | } |
---|
1080 | if (!ok) |
---|
1081 | { |
---|
1082 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1083 | return TRUE; |
---|
1084 | } |
---|
1085 | res->rtyp = INT_CMD; |
---|
1086 | res->data = (char*) (long) n; |
---|
1087 | return FALSE; |
---|
1088 | } |
---|
1089 | WerrorS("nInteriorLatticePoints: unexpected parameters"); |
---|
1090 | return TRUE; |
---|
1091 | } |
---|
1092 | |
---|
1093 | |
---|
1094 | BOOLEAN PMboundaryLatticePoints(leftv res, leftv args) |
---|
1095 | { |
---|
1096 | leftv u = args; |
---|
1097 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1098 | { |
---|
1099 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1100 | intvec* iv; |
---|
1101 | bool ok = true; |
---|
1102 | try |
---|
1103 | { |
---|
1104 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1105 | polymake::Matrix<polymake::Integer> lp = p->give("BOUNDARY_LATTICE_POINTS"); |
---|
1106 | delete p; |
---|
1107 | iv = PmMatrixInteger2Intvec(&lp,ok); |
---|
1108 | } |
---|
1109 | catch (const std::exception& ex) |
---|
1110 | { |
---|
1111 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1112 | return TRUE; |
---|
1113 | } |
---|
1114 | if (!ok) |
---|
1115 | { |
---|
1116 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1117 | return TRUE; |
---|
1118 | } |
---|
1119 | res->rtyp = INTMAT_CMD; |
---|
1120 | res->data = (char*) iv; |
---|
1121 | return FALSE; |
---|
1122 | } |
---|
1123 | WerrorS("boundaryLatticePoints: unexpected parameters"); |
---|
1124 | return TRUE; |
---|
1125 | } |
---|
1126 | |
---|
1127 | |
---|
1128 | BOOLEAN PMnBoundaryLatticePoints(leftv res, leftv args) |
---|
1129 | { |
---|
1130 | leftv u = args; |
---|
1131 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1132 | { |
---|
1133 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1134 | int n; |
---|
1135 | bool ok = true; |
---|
1136 | try |
---|
1137 | { |
---|
1138 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1139 | polymake::Integer nlp = p->give("N_BOUNDARY_LATTICE_POINTS"); |
---|
1140 | delete p; |
---|
1141 | n = PmInteger2Int(nlp,ok); |
---|
1142 | } |
---|
1143 | catch (const std::exception& ex) |
---|
1144 | { |
---|
1145 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1146 | return TRUE; |
---|
1147 | } |
---|
1148 | if (!ok) |
---|
1149 | { |
---|
1150 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1151 | return TRUE; |
---|
1152 | } |
---|
1153 | res->rtyp = INT_CMD; |
---|
1154 | res->data = (char*) (long) n; |
---|
1155 | return FALSE; |
---|
1156 | } |
---|
1157 | WerrorS("nBoundaryLatticePoints: unexpected parameters"); |
---|
1158 | return TRUE; |
---|
1159 | } |
---|
1160 | |
---|
1161 | |
---|
1162 | BOOLEAN PMhilbertBasis(leftv res, leftv args) |
---|
1163 | { |
---|
1164 | leftv u = args; |
---|
1165 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1166 | { |
---|
1167 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1168 | intvec* iv; |
---|
1169 | bool ok = true; |
---|
1170 | try |
---|
1171 | { |
---|
1172 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1173 | polymake::Matrix<polymake::Integer> lp = p->give("HILBERT_BASIS"); |
---|
1174 | delete p; |
---|
1175 | iv = PmMatrixInteger2Intvec(&lp,ok); |
---|
1176 | } |
---|
1177 | catch (const std::exception& ex) |
---|
1178 | { |
---|
1179 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1180 | return TRUE; |
---|
1181 | } |
---|
1182 | if (!ok) |
---|
1183 | { |
---|
1184 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1185 | return TRUE; |
---|
1186 | } |
---|
1187 | res->rtyp = INTMAT_CMD; |
---|
1188 | res->data = (char*) iv; |
---|
1189 | return FALSE; |
---|
1190 | } |
---|
1191 | WerrorS("hilbertBasis: unexpected parameters"); |
---|
1192 | return TRUE; |
---|
1193 | } |
---|
1194 | |
---|
1195 | |
---|
1196 | BOOLEAN PMnHilbertBasis(leftv res, leftv args) |
---|
1197 | { |
---|
1198 | leftv u = args; |
---|
1199 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1200 | { |
---|
1201 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1202 | int n; |
---|
1203 | bool ok = true; |
---|
1204 | try |
---|
1205 | { |
---|
1206 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1207 | polymake::Integer nlp = p->give("N_HILBERT_BASIS"); |
---|
1208 | delete p; |
---|
1209 | n = PmInteger2Int(nlp,ok); |
---|
1210 | } |
---|
1211 | catch (const std::exception& ex) |
---|
1212 | { |
---|
1213 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1214 | return TRUE; |
---|
1215 | } |
---|
1216 | if (!ok) |
---|
1217 | { |
---|
1218 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1219 | return TRUE; |
---|
1220 | } |
---|
1221 | res->rtyp = INT_CMD; |
---|
1222 | res->data = (char*) (long) n; |
---|
1223 | return FALSE; |
---|
1224 | } |
---|
1225 | WerrorS("nHilbertBasis: unexpected parameters"); |
---|
1226 | return TRUE; |
---|
1227 | } |
---|
1228 | |
---|
1229 | |
---|
1230 | BOOLEAN PMminkowskiSum(leftv res, leftv args) |
---|
1231 | { |
---|
1232 | leftv u = args; |
---|
1233 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1234 | { |
---|
1235 | leftv v = u->next; |
---|
1236 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1237 | { |
---|
1238 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1239 | gfan::ZCone* zq = (gfan::ZCone*)v->Data(); |
---|
1240 | gfan::ZCone* ms; |
---|
1241 | try |
---|
1242 | { |
---|
1243 | polymake::perl::Object* pp = ZPolytope2PmPolytope(zp); |
---|
1244 | polymake::perl::Object* pq = ZPolytope2PmPolytope(zq); |
---|
1245 | polymake::perl::Object pms; |
---|
1246 | CallPolymakeFunction("minkowski_sum", *pp, *pq) >> pms; |
---|
1247 | delete pp; |
---|
1248 | delete pq; |
---|
1249 | ms = PmPolytope2ZPolytope(&pms); |
---|
1250 | } |
---|
1251 | catch (const std::exception& ex) |
---|
1252 | { |
---|
1253 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1254 | return TRUE; |
---|
1255 | } |
---|
1256 | res->rtyp = polytopeID; |
---|
1257 | res->data = (char*) ms; |
---|
1258 | return FALSE; |
---|
1259 | } |
---|
1260 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1261 | { |
---|
1262 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1263 | gfan::ZCone* zc = (gfan::ZCone*)v->Data(); |
---|
1264 | gfan::ZCone* zq = new gfan::ZCone(liftUp(*zc)); |
---|
1265 | gfan::ZCone* ms; |
---|
1266 | try |
---|
1267 | { |
---|
1268 | polymake::perl::Object* pp = ZPolytope2PmPolytope(zp); |
---|
1269 | polymake::perl::Object* pq = ZPolytope2PmPolytope(zq); |
---|
1270 | polymake::perl::Object pms; |
---|
1271 | CallPolymakeFunction("minkowski_sum", *pp, *pq) >> pms; |
---|
1272 | delete pp; |
---|
1273 | delete pq; |
---|
1274 | ms = PmPolytope2ZPolytope(&pms); |
---|
1275 | } |
---|
1276 | catch (const std::exception& ex) |
---|
1277 | { |
---|
1278 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1279 | delete zq; |
---|
1280 | return TRUE; |
---|
1281 | } |
---|
1282 | res->rtyp = polytopeID; |
---|
1283 | res->data = (char*) ms; |
---|
1284 | delete zq; |
---|
1285 | return FALSE; |
---|
1286 | } |
---|
1287 | } |
---|
1288 | if ((u != NULL) && (u->Typ() == coneID)) |
---|
1289 | { |
---|
1290 | leftv v = u->next; |
---|
1291 | if ((v != NULL) && (v->Typ() == polytopeID)) |
---|
1292 | { |
---|
1293 | gfan::ZCone* zc = (gfan::ZCone*)u->Data(); |
---|
1294 | gfan::ZCone* zp = new gfan::ZCone(liftUp(*zc)); |
---|
1295 | gfan::ZCone* zq = (gfan::ZCone*)v->Data(); |
---|
1296 | gfan::ZCone* ms; |
---|
1297 | try |
---|
1298 | { |
---|
1299 | polymake::perl::Object* pp = ZPolytope2PmPolytope(zp); |
---|
1300 | polymake::perl::Object* pq = ZPolytope2PmPolytope(zq); |
---|
1301 | polymake::perl::Object pms; |
---|
1302 | CallPolymakeFunction("minkowski_sum", *pp, *pq) >> pms; |
---|
1303 | delete pp; |
---|
1304 | delete pq; |
---|
1305 | ms = PmPolytope2ZPolytope(&pms); |
---|
1306 | } |
---|
1307 | catch (const std::exception& ex) |
---|
1308 | { |
---|
1309 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1310 | delete zp; |
---|
1311 | return TRUE; |
---|
1312 | } |
---|
1313 | res->rtyp = polytopeID; |
---|
1314 | res->data = (char*) ms; |
---|
1315 | delete zp; |
---|
1316 | return FALSE; |
---|
1317 | } |
---|
1318 | if ((v != NULL) && (v->Typ() == coneID)) |
---|
1319 | { |
---|
1320 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1321 | gfan::ZCone* zq = (gfan::ZCone*)v->Data(); |
---|
1322 | gfan::ZCone* ms; |
---|
1323 | try |
---|
1324 | { |
---|
1325 | polymake::perl::Object* pp = ZPolytope2PmPolytope(zp); |
---|
1326 | polymake::perl::Object* pq = ZPolytope2PmPolytope(zq); |
---|
1327 | polymake::perl::Object pms; |
---|
1328 | CallPolymakeFunction("minkowski_sum", *pp, *pq) >> pms; |
---|
1329 | delete pp; |
---|
1330 | delete pq; |
---|
1331 | ms = PmPolytope2ZPolytope(&pms); |
---|
1332 | } |
---|
1333 | catch (const std::exception& ex) |
---|
1334 | { |
---|
1335 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1336 | return TRUE; |
---|
1337 | } |
---|
1338 | res->rtyp = coneID; |
---|
1339 | res->data = (char*) ms; |
---|
1340 | return FALSE; |
---|
1341 | } |
---|
1342 | } |
---|
1343 | WerrorS("minkowskiSum: unexpected parameters"); |
---|
1344 | return TRUE; |
---|
1345 | } |
---|
1346 | |
---|
1347 | |
---|
1348 | polymake::Matrix<polymake::Integer> verticesOf(const polymake::perl::Object* p, |
---|
1349 | const polymake::Set<polymake::Integer>* s) |
---|
1350 | { |
---|
1351 | polymake::Matrix<polymake::Integer> allrays = p->give("VERTICES"); |
---|
1352 | polymake::Matrix<polymake::Integer> wantedrays; |
---|
1353 | bool ok = true; |
---|
1354 | for(polymake::Entire<polymake::Set<polymake::Integer> >::const_iterator i=polymake::entire(*s); !i.at_end(); i++) |
---|
1355 | { |
---|
1356 | wantedrays = wantedrays / allrays.row(PmInteger2Int(*i,ok)); |
---|
1357 | } |
---|
1358 | if (!ok) |
---|
1359 | { |
---|
1360 | WerrorS("overflow while converting polymake::Integer to int in raysOf"); |
---|
1361 | } |
---|
1362 | return wantedrays; |
---|
1363 | } |
---|
1364 | |
---|
1365 | |
---|
1366 | BOOLEAN PMmaximalFace(leftv res, leftv args) |
---|
1367 | { |
---|
1368 | leftv u = args; |
---|
1369 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1370 | { |
---|
1371 | leftv v = u->next; |
---|
1372 | if ((v != NULL) && (v->Typ() == INTVEC_CMD)) |
---|
1373 | { |
---|
1374 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1375 | intvec* iv = (intvec*) v->Data(); |
---|
1376 | intvec* maxface; |
---|
1377 | bool ok = true; |
---|
1378 | try |
---|
1379 | { |
---|
1380 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1381 | polymake::perl::Object o("LinearProgram<Rational>"); |
---|
1382 | o.take("LINEAR_OBJECTIVE") << Intvec2PmVectorInteger(iv); |
---|
1383 | p->take("LP") << o; |
---|
1384 | polymake::Set<polymake::Integer> mf = p->give("LP.MAXIMAL_FACE"); |
---|
1385 | polymake::Matrix<polymake::Integer> vertices = verticesOf(p,&mf); |
---|
1386 | delete p; |
---|
1387 | maxface = new intvec(PmMatrixInteger2Intvec(&vertices,ok)); |
---|
1388 | } |
---|
1389 | catch (const std::exception& ex) |
---|
1390 | { |
---|
1391 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1392 | return TRUE; |
---|
1393 | } |
---|
1394 | if (!ok) |
---|
1395 | { |
---|
1396 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1397 | return TRUE; |
---|
1398 | } |
---|
1399 | res->rtyp = INTVEC_CMD; |
---|
1400 | res->data = (char*) maxface; |
---|
1401 | return FALSE; |
---|
1402 | } |
---|
1403 | } |
---|
1404 | WerrorS("maximalFace: unexpected parameters"); |
---|
1405 | return TRUE; |
---|
1406 | } |
---|
1407 | |
---|
1408 | |
---|
1409 | BOOLEAN PMminimalFace(leftv res, leftv args) |
---|
1410 | { |
---|
1411 | leftv u = args; |
---|
1412 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1413 | { |
---|
1414 | leftv v = u->next; |
---|
1415 | if ((v != NULL) && (v->Typ() == INTVEC_CMD)) |
---|
1416 | { |
---|
1417 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1418 | intvec* iv = (intvec*) v->Data(); |
---|
1419 | intvec* minface; |
---|
1420 | bool ok = true; |
---|
1421 | try |
---|
1422 | { |
---|
1423 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1424 | polymake::perl::Object o("LinearProgram<Rational>"); |
---|
1425 | o.take("LINEAR_OBJECTIVE") << Intvec2PmVectorInteger(iv); |
---|
1426 | p->take("LP") << o; |
---|
1427 | polymake::Set<polymake::Integer> mf = p->give("LP.MINIMAL_FACE"); |
---|
1428 | polymake::Matrix<polymake::Integer> vertices = verticesOf(p,&mf); |
---|
1429 | delete p; |
---|
1430 | minface = new intvec(PmMatrixInteger2Intvec(&vertices,ok)); |
---|
1431 | } |
---|
1432 | catch (const std::exception& ex) |
---|
1433 | { |
---|
1434 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1435 | return TRUE; |
---|
1436 | } |
---|
1437 | if (!ok) |
---|
1438 | { |
---|
1439 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1440 | return TRUE; |
---|
1441 | } |
---|
1442 | res->rtyp = INTVEC_CMD; |
---|
1443 | res->data = (char*) minface; |
---|
1444 | return FALSE; |
---|
1445 | } |
---|
1446 | } |
---|
1447 | WerrorS("minimalFace: unexpected parameters"); |
---|
1448 | return TRUE; |
---|
1449 | } |
---|
1450 | |
---|
1451 | |
---|
1452 | BOOLEAN PMmaximalValue(leftv res, leftv args) |
---|
1453 | { |
---|
1454 | leftv u = args; |
---|
1455 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1456 | { |
---|
1457 | leftv v = u->next; |
---|
1458 | if ((v != NULL) && (v->Typ() == INTVEC_CMD)) |
---|
1459 | { |
---|
1460 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1461 | intvec* iv = (intvec*) v->Data(); |
---|
1462 | if (iv->rows()==zp->ambientDimension()) |
---|
1463 | { |
---|
1464 | int m; |
---|
1465 | bool ok = true; |
---|
1466 | try |
---|
1467 | { |
---|
1468 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1469 | polymake::Vector<polymake::Integer> lo = Intvec2PmVectorInteger(iv); |
---|
1470 | polymake::perl::Object o("LinearProgram<Rational>"); |
---|
1471 | o.take("LINEAR_OBJECTIVE") << lo; |
---|
1472 | p->take("LP") << o; |
---|
1473 | polymake::Integer mv = p->give("LP.MAXIMAL_VALUE"); |
---|
1474 | delete p; |
---|
1475 | m = PmInteger2Int(mv,ok); |
---|
1476 | } |
---|
1477 | catch (const std::exception& ex) |
---|
1478 | { |
---|
1479 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1480 | return TRUE; |
---|
1481 | } |
---|
1482 | if (!ok) |
---|
1483 | { |
---|
1484 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1485 | return TRUE; |
---|
1486 | } |
---|
1487 | res->rtyp = INT_CMD; |
---|
1488 | res->data = (char*) (long) m; |
---|
1489 | return FALSE; |
---|
1490 | } |
---|
1491 | } |
---|
1492 | WerrorS("maximalValue: vector is of wrong size"); |
---|
1493 | return TRUE; |
---|
1494 | } |
---|
1495 | WerrorS("maximalValue: unexpected parameters"); |
---|
1496 | return TRUE; |
---|
1497 | } |
---|
1498 | |
---|
1499 | BOOLEAN PMminimalValue(leftv res, leftv args) |
---|
1500 | { |
---|
1501 | leftv u = args; |
---|
1502 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1503 | { |
---|
1504 | leftv v = u->next; |
---|
1505 | if ((v != NULL) && (v->Typ() == INTVEC_CMD)) |
---|
1506 | { |
---|
1507 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1508 | intvec* iv = (intvec*) v->Data(); |
---|
1509 | if (iv->rows()==zp->ambientDimension()) |
---|
1510 | { |
---|
1511 | int m; |
---|
1512 | bool ok = true; |
---|
1513 | try |
---|
1514 | { |
---|
1515 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1516 | polymake::Vector<polymake::Integer> lo = Intvec2PmVectorInteger(iv); |
---|
1517 | polymake::perl::Object o("LinearProgram<Rational>"); |
---|
1518 | o.take("LINEAR_OBJECTIVE") << lo; |
---|
1519 | p->take("LP") << o; |
---|
1520 | polymake::Integer mv = p->give("LP.MINIMAL_VALUE"); |
---|
1521 | delete p; |
---|
1522 | m = PmInteger2Int(mv,ok); |
---|
1523 | } |
---|
1524 | catch (const std::exception& ex) |
---|
1525 | { |
---|
1526 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1527 | return TRUE; |
---|
1528 | } |
---|
1529 | if (!ok) |
---|
1530 | { |
---|
1531 | WerrorS("overflow while converting polymake::Integer to int"); |
---|
1532 | return TRUE; |
---|
1533 | } |
---|
1534 | res->rtyp = INT_CMD; |
---|
1535 | res->data = (char*) (long) m; |
---|
1536 | return FALSE; |
---|
1537 | } |
---|
1538 | } |
---|
1539 | WerrorS("minimalValue: vector is of wrong size"); |
---|
1540 | return TRUE; |
---|
1541 | } |
---|
1542 | WerrorS("minimalValue: unexpected parameters"); |
---|
1543 | return TRUE; |
---|
1544 | } |
---|
1545 | |
---|
1546 | |
---|
1547 | BOOLEAN visual(leftv res, leftv args) |
---|
1548 | { |
---|
1549 | leftv u = args; |
---|
1550 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1551 | { |
---|
1552 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1553 | try |
---|
1554 | { |
---|
1555 | polymake::perl::Object* pp = ZPolytope2PmPolytope(zp); |
---|
1556 | VoidCallPolymakeFunction("jreality",pp->CallPolymakeMethod("VISUAL")); |
---|
1557 | delete pp; |
---|
1558 | } |
---|
1559 | catch (const std::exception& ex) |
---|
1560 | { |
---|
1561 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1562 | return TRUE; |
---|
1563 | } |
---|
1564 | res->rtyp = NONE; |
---|
1565 | res->data = NULL; |
---|
1566 | return FALSE; |
---|
1567 | } |
---|
1568 | if ((u != NULL) && (u->Typ() == fanID)) |
---|
1569 | { |
---|
1570 | gfan::ZFan* zf = (gfan::ZFan*)u->Data(); |
---|
1571 | try |
---|
1572 | { |
---|
1573 | polymake::perl::Object* pf=ZFan2PmFan(zf); |
---|
1574 | VoidCallPolymakeFunction("jreality",pf->CallPolymakeMethod("VISUAL")); |
---|
1575 | } |
---|
1576 | catch (const std::exception& ex) |
---|
1577 | { |
---|
1578 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1579 | return TRUE; |
---|
1580 | } |
---|
1581 | res->rtyp = NONE; |
---|
1582 | res->data = NULL; |
---|
1583 | return FALSE; |
---|
1584 | } |
---|
1585 | WerrorS("visual: unexpected parameters"); |
---|
1586 | return TRUE; |
---|
1587 | } |
---|
1588 | |
---|
1589 | BOOLEAN normalFan(leftv res, leftv args) |
---|
1590 | { |
---|
1591 | leftv u = args; |
---|
1592 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1593 | { |
---|
1594 | gfan::ZCone* zp = (gfan::ZCone*)u->Data(); |
---|
1595 | gfan::ZFan* zf = new gfan::ZFan(0); |
---|
1596 | try |
---|
1597 | { |
---|
1598 | polymake::perl::Object* p=ZPolytope2PmPolytope(zp); |
---|
1599 | polymake::perl::Object pf; |
---|
1600 | CallPolymakeFunction("normal_fan", *p) >> pf; |
---|
1601 | delete p; |
---|
1602 | zf = PmFan2ZFan(&pf); |
---|
1603 | } |
---|
1604 | catch (const std::exception& ex) |
---|
1605 | { |
---|
1606 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1607 | return TRUE; |
---|
1608 | } |
---|
1609 | res->rtyp = fanID; |
---|
1610 | res->data = (char*) zf; |
---|
1611 | return FALSE; |
---|
1612 | } |
---|
1613 | WerrorS("normalFan: unexpected parameters"); |
---|
1614 | return TRUE; |
---|
1615 | } |
---|
1616 | |
---|
1617 | BOOLEAN PMconeViaRays(leftv res, leftv args) |
---|
1618 | { |
---|
1619 | leftv u = args; |
---|
1620 | if ((u != NULL) && (u->Typ() == INTMAT_CMD)) |
---|
1621 | { |
---|
1622 | polymake::perl::Object pc("Cone<Rational>"); |
---|
1623 | intvec* hlines = (intvec*) u->Data(); // these will are half lines in the cone |
---|
1624 | polymake::Matrix<polymake::Integer> pmhlines = Intvec2PmMatrixInteger(hlines); |
---|
1625 | pc.take("INPUT_RAYS") << pmhlines; |
---|
1626 | |
---|
1627 | leftv v = u->next; |
---|
1628 | if ((v != NULL) && (v->Typ() == INTMAT_CMD)) |
---|
1629 | { |
---|
1630 | intvec* lines = (intvec*) v->Data(); // these will be lines in the cone |
---|
1631 | polymake::Matrix<polymake::Integer> pmlines = Intvec2PmMatrixInteger(lines); |
---|
1632 | pc.take("INPUT_LINEALITY") << pmlines; |
---|
1633 | |
---|
1634 | // leftv w = v->next; |
---|
1635 | // if ((w != NULL) && (w->Typ() == INT_CMD)) |
---|
1636 | // { |
---|
1637 | // int flag = (int) (long) w->Data(); // TODO: this will indicate whether the |
---|
1638 | // // information provided are exact |
---|
1639 | // } |
---|
1640 | } |
---|
1641 | gfan::ZCone* zc = PmCone2ZCone(&pc); |
---|
1642 | res->rtyp = coneID; |
---|
1643 | res->data = (char*) zc; |
---|
1644 | return FALSE; |
---|
1645 | } |
---|
1646 | WerrorS("coneViaRays: unexpected parameters"); |
---|
1647 | return TRUE; |
---|
1648 | } |
---|
1649 | |
---|
1650 | |
---|
1651 | BOOLEAN PMpolytopeViaVertices(leftv res, leftv args) |
---|
1652 | { |
---|
1653 | leftv u = args; |
---|
1654 | if ((u != NULL) && (u->Typ() == INTMAT_CMD)) |
---|
1655 | { |
---|
1656 | polymake::perl::Object pp("Polytope<Rational>"); |
---|
1657 | intvec* points = (intvec*) u->Data(); // these will be vertices of or points in the polytope |
---|
1658 | polymake::Matrix<polymake::Integer> pmpoints = Intvec2PmMatrixInteger(points); |
---|
1659 | |
---|
1660 | leftv v = u->next; |
---|
1661 | if ((v != NULL) && (v->Typ() == INT_CMD)) |
---|
1662 | { |
---|
1663 | int flag = (int) (long) v->Data(); |
---|
1664 | switch(flag) |
---|
1665 | { |
---|
1666 | case 0: pp.take("POINTS") << pmpoints; // case means the matrix may contain points inside the polytope |
---|
1667 | case 1: pp.take("VERTICES") << pmpoints; // case means the matrix only contains vertices of the polytope |
---|
1668 | default: WerrorS("polytopeViaVertices: invalid flag"); |
---|
1669 | } |
---|
1670 | } |
---|
1671 | else |
---|
1672 | pp.take("POINTS") << pmpoints; // by default, we assume that matrix may contain non-vertices |
---|
1673 | |
---|
1674 | gfan::ZCone* zp = PmPolytope2ZPolytope(&pp); |
---|
1675 | res->rtyp = polytopeID; |
---|
1676 | res->data = (char*) zp; |
---|
1677 | return FALSE; |
---|
1678 | } |
---|
1679 | WerrorS("polytopeViaVertices: unexpected parameters"); |
---|
1680 | return TRUE; |
---|
1681 | } |
---|
1682 | |
---|
1683 | |
---|
1684 | BOOLEAN PMvertexAdjacencyGraph(leftv res, leftv args) |
---|
1685 | { |
---|
1686 | leftv u = args; |
---|
1687 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1688 | { |
---|
1689 | gfan::ZCone* zp = (gfan::ZCone*) u->Data(); |
---|
1690 | lists output=(lists)omAllocBin(slists_bin); output->Init(2); |
---|
1691 | try |
---|
1692 | { |
---|
1693 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1694 | polymake::Matrix<polymake::Integer> vert0 = p->give("VERTICES"); |
---|
1695 | bigintmat* vert1 = PmMatrixInteger2Bigintmat(&vert0); |
---|
1696 | output->m[0].rtyp = BIGINTMAT_CMD; |
---|
1697 | output->m[0].data = (void*) vert1; |
---|
1698 | |
---|
1699 | polymake::Graph<> gr=p->give("GRAPH.ADJACENCY"); |
---|
1700 | polymake::IncidenceMatrix<polymake::NonSymmetric> adj = adjacency_matrix(gr); |
---|
1701 | lists listOfEdges = PmIncidenceMatrix2ListOfIntvecs(&adj); |
---|
1702 | output->m[1].rtyp = LIST_CMD; |
---|
1703 | output->m[1].data = (void*) listOfEdges; |
---|
1704 | delete p; |
---|
1705 | } |
---|
1706 | catch (const std::exception& ex) |
---|
1707 | { |
---|
1708 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1709 | return TRUE; |
---|
1710 | } |
---|
1711 | res->rtyp = LIST_CMD; |
---|
1712 | res->data = (void*) output; |
---|
1713 | return FALSE; |
---|
1714 | } |
---|
1715 | WerrorS("vertexEdgeGraph: unexpected parameters"); |
---|
1716 | return TRUE; |
---|
1717 | } |
---|
1718 | |
---|
1719 | |
---|
1720 | BOOLEAN PMvertexEdgeGraph(leftv res, leftv args) |
---|
1721 | { |
---|
1722 | leftv u = args; |
---|
1723 | if ((u != NULL) && (u->Typ() == polytopeID)) |
---|
1724 | { |
---|
1725 | gfan::ZCone* zp = (gfan::ZCone*) u->Data(); |
---|
1726 | lists output=(lists)omAllocBin(slists_bin); output->Init(2); |
---|
1727 | try |
---|
1728 | { |
---|
1729 | polymake::perl::Object* p = ZPolytope2PmPolytope(zp); |
---|
1730 | polymake::Matrix<polymake::Integer> vert0 = p->give("VERTICES"); |
---|
1731 | bigintmat* vert1 = PmMatrixInteger2Bigintmat(&vert0); |
---|
1732 | output->m[0].rtyp = BIGINTMAT_CMD; |
---|
1733 | output->m[0].data = (void*) vert1; |
---|
1734 | |
---|
1735 | polymake::Graph<> gr=p->give("GRAPH.ADJACENCY"); |
---|
1736 | polymake::IncidenceMatrix<polymake::NonSymmetric> adj = adjacency_matrix(gr); |
---|
1737 | lists listOfEdges = PmAdjacencyMatrix2ListOfEdges(&adj); |
---|
1738 | output->m[1].rtyp = LIST_CMD; |
---|
1739 | output->m[1].data = (void*) listOfEdges; |
---|
1740 | delete p; |
---|
1741 | } |
---|
1742 | catch (const std::exception& ex) |
---|
1743 | { |
---|
1744 | WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n"); |
---|
1745 | return TRUE; |
---|
1746 | } |
---|
1747 | res->rtyp = LIST_CMD; |
---|
1748 | res->data = (void*) output; |
---|
1749 | return FALSE; |
---|
1750 | } |
---|
1751 | WerrorS("vertexEdgeGraph: unexpected parameters"); |
---|
1752 | return TRUE; |
---|
1753 | } |
---|
1754 | |
---|
1755 | |
---|
1756 | extern "C" int mod_init(SModulFunctions* p) |
---|
1757 | { |
---|
1758 | if (init_polymake==NULL) |
---|
1759 | {init_polymake = new polymake::Main();} |
---|
1760 | init_polymake->set_application("fan"); |
---|
1761 | // p->iiAddCproc("polymake.so","coneViaPoints",FALSE,PMconeViaRays); |
---|
1762 | // p->iiAddCproc("polymake.so","polytopeViaPoints",FALSE,PMpolytopeViaVertices); |
---|
1763 | p->iiAddCproc("polymake.so","isLatticePolytope",FALSE,PMisLatticePolytope); |
---|
1764 | p->iiAddCproc("polymake.so","isBounded",FALSE,PMisBounded); |
---|
1765 | p->iiAddCproc("polymake.so","isReflexive",FALSE,PMisReflexive); |
---|
1766 | p->iiAddCproc("polymake.so","isGorenstein",FALSE,PMisGorenstein); |
---|
1767 | p->iiAddCproc("polymake.so","gorensteinIndex",FALSE,PMgorensteinIndex); |
---|
1768 | p->iiAddCproc("polymake.so","gorensteinVector",FALSE,PMgorensteinVector); |
---|
1769 | p->iiAddCproc("polymake.so","isCanonical",FALSE,PMisCanonical); |
---|
1770 | p->iiAddCproc("polymake.so","isTerminal",FALSE,PMisTerminal); |
---|
1771 | p->iiAddCproc("polymake.so","isLatticeEmpty",FALSE,PMisLatticeEmpty); |
---|
1772 | p->iiAddCproc("polymake.so","latticeVolume",FALSE,PMlatticeVolume); |
---|
1773 | p->iiAddCproc("polymake.so","latticeDegree",FALSE,PMlatticeDegree); |
---|
1774 | p->iiAddCproc("polymake.so","latticeCodegree",FALSE,PMlatticeCodegree); |
---|
1775 | p->iiAddCproc("polymake.so","ehrhartPolynomialCoeff",FALSE,PMehrhartPolynomialCoeff); |
---|
1776 | p->iiAddCproc("polymake.so","fVector",FALSE,PMfVector); |
---|
1777 | p->iiAddCproc("polymake.so","hVector",FALSE,PMhVector); |
---|
1778 | p->iiAddCproc("polymake.so","hStarVector",FALSE,PMhStarVector); |
---|
1779 | p->iiAddCproc("polymake.so","isNormal",FALSE,PMisNormal); |
---|
1780 | p->iiAddCproc("polymake.so","facetWidths",FALSE,PMfacetWidths); |
---|
1781 | p->iiAddCproc("polymake.so","facetWidth",FALSE,PMfacetWidth); |
---|
1782 | p->iiAddCproc("polymake.so","facetVertexLatticeDistances",FALSE,PMfacetVertexLatticeDistances); |
---|
1783 | p->iiAddCproc("polymake.so","isCompressed",FALSE,PMisCompressed); |
---|
1784 | p->iiAddCproc("polymake.so","isSmooth",FALSE,PMisSmooth); |
---|
1785 | p->iiAddCproc("polymake.so","isVeryAmple",FALSE,PMisVeryAmple); |
---|
1786 | p->iiAddCproc("polymake.so","latticePoints",FALSE,PMlatticePoints); |
---|
1787 | p->iiAddCproc("polymake.so","nLatticePoints",FALSE,PMnLatticePoints); |
---|
1788 | p->iiAddCproc("polymake.so","interiorLatticePoints",FALSE,PMinteriorLatticePoints); |
---|
1789 | p->iiAddCproc("polymake.so","nInteriorLatticePoints",FALSE,PMnInteriorLatticePoints); |
---|
1790 | p->iiAddCproc("polymake.so","boundaryLatticePoints",FALSE,PMboundaryLatticePoints); |
---|
1791 | p->iiAddCproc("polymake.so","nBoundaryLatticePoints",FALSE,PMnBoundaryLatticePoints); |
---|
1792 | p->iiAddCproc("polymake.so","hilbertBasis",FALSE,PMhilbertBasis); |
---|
1793 | p->iiAddCproc("polymake.so","nHilbertBasis",FALSE,PMnHilbertBasis); |
---|
1794 | p->iiAddCproc("polymake.so","minkowskiSum",FALSE,PMminkowskiSum); |
---|
1795 | p->iiAddCproc("polymake.so","maximalFace",FALSE,PMmaximalFace); |
---|
1796 | p->iiAddCproc("polymake.so","minimalFace",FALSE,PMminimalFace); |
---|
1797 | p->iiAddCproc("polymake.so","maximalValue",FALSE,PMmaximalValue); |
---|
1798 | p->iiAddCproc("polymake.so","minimalValue",FALSE,PMminimalValue); |
---|
1799 | p->iiAddCproc("polymake.so","visual",FALSE,visual); |
---|
1800 | p->iiAddCproc("polymake.so","normalFan",FALSE,normalFan); |
---|
1801 | p->iiAddCproc("polymake.so","vertexAdjacencyGraph",FALSE,PMvertexAdjacencyGraph); |
---|
1802 | p->iiAddCproc("polymake.so","vertexEdgeGraph",FALSE,PMvertexEdgeGraph); |
---|
1803 | |
---|
1804 | blackbox* b=getBlackboxStuff(polytopeID); |
---|
1805 | b->blackbox_Op2=bbpolytope_Op2; |
---|
1806 | |
---|
1807 | init_polymake_help(); |
---|
1808 | return 0; |
---|
1809 | } |
---|