7 #include <polymake/Main.h>
8 #include <polymake/Matrix.h>
9 #include <polymake/Rational.h>
10 #include <polymake/Integer.h>
11 #include <polymake/Set.h>
12 #include <polymake/common/lattice_tools.h>
13 #include <polymake/IncidenceMatrix.h>
15 #include "gfanlib/gfanlib.h"
16 #include "gfanlib/gfanlib_q.h"
32 mpz_t cache; mpz_init(cache);
34 polymake::Integer
pi(cache);
40 mpq_t cache; mpq_init(cache);
42 polymake::Rational pr(cache);
48 polymake::Vector<polymake::Integer> vi(iv->
length());
58 int rows=zm->getHeight();
59 int cols=zm->getWidth();
60 polymake::Matrix<polymake::Integer> mi(rows,cols);
61 for(
int r=1; r<=rows; r++)
62 for(
int c=1; c<=cols; c++)
69 int rows=qm->getHeight();
70 int cols=qm->getWidth();
71 polymake::Matrix<polymake::Rational> mr(rows,cols);
72 for(
int r=1; r<=rows; r++)
73 for(
int c=1; c<=cols; c++)
82 mpz_class cache(
pi.get_rep());
83 gfan::Integer gi(cache.get_mpz_t());
89 mpq_class cache(pr.get_rep());
90 gfan::Rational gr(cache.get_mpq_t());
96 int rows=
static_cast<int>(mi->rows());
97 int cols=
static_cast<int>(mi->cols());
98 gfan::ZMatrix zm(rows,cols);
99 for(
int r=1; r<=rows; r++)
100 for(
int c=1; c<=cols; c++)
107 int rows=
static_cast<int>(mr->rows());
108 int cols=
static_cast<int>(mr->cols());
109 gfan::QMatrix qm(rows,cols);
110 for(
int r=1; r<=rows; r++)
111 for(
int c=1; c<=cols; c++)
123 #if POLYMAKE_VERSION >= 301
129 catch (
const std::exception& ex)
139 mpz_class cache(
pi.get_rep());
141 if(mpz_cmp_si(cache.get_mpz_t(),
m))
143 int temp = (int) mpz_get_si(cache.get_mpz_t());
153 for(
int i=1; i<=static_cast<int>(vi->size());
i++)
162 int rows =
static_cast<int>(mi->rows());
163 int cols =
static_cast<int>(mi->cols());
165 #if POLYMAKE_VERSION >= 301
166 pm::array_traits<pm::Integer>::iterator
pi = concat_rows(*mi).begin();
168 const polymake::Integer*
pi = concat_rows(*mi).begin();
170 for (
int r = 1; r <= rows; r++)
171 for (
int c = 1; c <= cols; c++)
181 int rows =
static_cast<int>(mi->rows());
182 int cols =
static_cast<int>(mi->cols());
184 #if POLYMAKE_VERSION >= 301
185 pm::array_traits<pm::Integer>::iterator
pi = concat_rows(*mi).begin();
187 const polymake::Integer*
pi = concat_rows(*mi).begin();
189 for (
int r = 1; r <= rows; r++)
190 for (
int c = 1; c <= cols; c++)
202 int rows =
static_cast<int>(icmat->rows());
203 int cols =
static_cast<int>(icmat->cols());
207 for (
int r = 0; r < rows; r++)
210 for (
int c = 0; c < cols; c++)
212 if ((*icmat).row(r).exists(c))
217 L->
m[r].
data = (
void*) iv;
225 int rows =
static_cast<int>(icmat->rows());
226 int cols =
static_cast<int>(icmat->cols());
230 for (r=0; r<rows; r++)
232 for (c=0; c<cols; c++)
234 if ((*icmat).row(r).exists(c) && r<c)
243 for (r=0; r<rows; r++)
245 for (c=0; c<cols; c++)
247 if ((*icmat).row(r).exists(c) && r<c)
250 (*iv)[0]=r; (*iv)[1]=c;
252 L->
m[
i].
data = (
void*) iv;
263 polymake::Vector<polymake::Integer> vi(*si);
273 polymake::Matrix<polymake::Integer> mi(rows,cols);
274 for(
int r=0; r<rows; r++)
275 for(
int c=0; c<cols; c++)
276 mi(r,c) = polymake::Integer(
IMATELEM(*im, r+1, c+1));
287 polymake::Integer ambientdim1 = pc->give(
"CONE_AMBIENT_DIM");
288 bool ok=
true;
int ambientdim2 =
PmInteger2Int(ambientdim1, ok);
291 WerrorS(
"PmCone2ZCone: overflow while converting polymake::Integer to int");
293 polymake::Matrix<polymake::Rational> ineqrational = pc->give(
"FACETS");
294 polymake::Matrix<polymake::Rational> eqrational = pc->give(
"LINEAR_SPAN");
298 gfan::ZMatrix zv, zw, zx, zy, zz;
301 if (ineqrational.cols()!=0)
303 polymake::Matrix<polymake::Integer> ineqinteger = polymake::common::primitive(ineqrational);
307 zv = gfan::ZMatrix(0, ambientdim2);
308 if (eqrational.cols()!=0)
310 polymake::Matrix<polymake::Integer> eqinteger = polymake::common::primitive(eqrational);
314 zw = gfan::ZMatrix(0, ambientdim2);
331 gfan::ZCone* zc =
new gfan::ZCone(zv,zw,3);
334 WerrorS(
"PmCone2ZCone: unexpected parameters");
340 if (
pp->isa(
"Polytope<Rational>"))
342 polymake::Integer ambientdim1 =
pp->give(
"CONE_AMBIENT_DIM");
343 bool ok=
true;
int ambientdim2 =
PmInteger2Int(ambientdim1, ok);
346 WerrorS(
"overflow while converting polymake::Integer to int");
348 polymake::Matrix<polymake::Rational> ineqrational =
pp->give(
"FACETS");
349 polymake::Matrix<polymake::Rational> eqrational =
pp->give(
"AFFINE_HULL");
353 gfan::ZMatrix zv, zw;
356 if (ineqrational.cols()!=0)
358 polymake::Matrix<polymake::Integer> ineqinteger = polymake::common::primitive(ineqrational);
362 zv = gfan::ZMatrix(0, ambientdim2);
364 if (eqrational.cols()!=0)
366 polymake::Matrix<polymake::Integer> eqinteger = polymake::common::primitive(eqrational);
370 zw = gfan::ZMatrix(0, ambientdim2);
388 gfan::ZCone* zp =
new gfan::ZCone(zv,zw,3);
392 WerrorS(
"PmPolytope2ZPolytope: unexpected parameters");
398 if (pf->isa(
"PolyhedralFan"))
400 int d = (int) pf->give(
"FAN_AMBIENT_DIM");
401 gfan::ZFan* zf =
new gfan::ZFan(d);
403 int n = pf->give(
"N_MAXIMAL_CONES");
404 for (
int i=0;
i<n;
i++)
406 pm::perl::BigObject pmcone=pf->call_method(
"cone",
i);
412 WerrorS(
"PmFan2ZFan: unexpected parameters");
418 pm::perl::BigObject* gc =
new pm::perl::BigObject(
"Cone<Rational>");
423 gfan::ZMatrix
equations = zc->getEquations();
443 pm::perl::BigObject*
pp =
new pm::perl::BigObject(
"Polytope<Rational>");
448 gfan::ZMatrix
equations = zc->getEquations();
460 polymake::Matrix<polymake::Integer>
raysOf(gfan::ZFan* zf)
462 int d = zf->getAmbientDimension();
463 int n = zf->numberOfConesOfDimension(1,0,0);
464 gfan::ZMatrix zm(n,d);
466 for (
int i=0;
i<n;
i++)
468 gfan::ZCone zc = zf->getCone(1,
i,0,0);
469 gfan::ZMatrix ray = zc.extremeRays();
470 for (
int j=0;
j<d;
j++)
481 int n = zf->numberOfConesOfDimension(1,0,0);
487 int d = zf->getAmbientDimension();
490 for (
int i=0;
i<=d;
i++)
492 n = n + zf->numberOfConesOfDimension(
i,0,1);
498 polymake::Array<polymake::Set<polymake::Int> >
conesOf(gfan::ZFan* zf)
502 polymake::Matrix<polymake::Integer> pm=
raysOf(zf);
503 polymake::Array<polymake::Set<polymake::Int> > L(r);
506 for (
int d=1; d<=zf->getAmbientDimension(); d++)
508 for (
int i=0;
i<zf->numberOfConesOfDimension(d,0,1);
i++)
510 gfan::IntVector
v = zf->getConeIndices(d,
i,0,1);
511 polymake::Set<polymake::Int>
s;
512 for (
int j=0;
j<(int)
v.size();
j++)
525 pm::perl::BigObject* pf =
new pm::perl::BigObject(
"PolyhedralFan");
527 polymake::Matrix<polymake::Integer> zm =
raysOf(zf);
528 pf->take(
"RAYS") << zm;
530 polymake::Array<polymake::Set<polymake::Int> > ar =
conesOf(zf);
531 pf->take(
"MAXIMAL_CONES") << ar;