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