4#ifndef POLYMAKE_VERSION
5#define POLYMAKE_VERSION POLYMAKEVERSION
10#include <polymake/Main.h>
11#include <polymake/Matrix.h>
12#include <polymake/Rational.h>
13#include <polymake/Integer.h>
14#include <polymake/Set.h>
15#include <polymake/common/lattice_tools.h>
16#include <polymake/IncidenceMatrix.h>
18#include "gfanlib/gfanlib.h"
19#include "gfanlib/gfanlib_q.h"
35 mpz_t cache; mpz_init(cache);
37 polymake::Integer
pi(cache);
43 mpq_t cache; mpq_init(cache);
45 polymake::Rational pr(cache);
51 polymake::Vector<polymake::Integer> vi(iv->
length());
61 int rows=zm->getHeight();
62 int cols=zm->getWidth();
63 polymake::Matrix<polymake::Integer> mi(rows,cols);
64 for(
int r=1; r<=rows; r++)
65 for(
int c=1; c<=cols; c++)
72 int rows=qm->getHeight();
73 int cols=qm->getWidth();
74 polymake::Matrix<polymake::Rational> mr(rows,cols);
75 for(
int r=1; r<=rows; r++)
76 for(
int c=1; c<=cols; c++)
85 mpz_class cache(
pi.get_rep());
86 gfan::Integer gi(cache.get_mpz_t());
92 mpq_class cache(pr.get_rep());
93 gfan::Rational gr(cache.get_mpq_t());
101 gfan::ZMatrix zm(rows,cols);
102 for(
int r=1; r<=rows; r++)
103 for(
int c=1; c<=cols; c++)
112 gfan::QMatrix qm(rows,cols);
113 for(
int r=1; r<=rows; r++)
114 for(
int c=1; c<=cols; c++)
126#if POLYMAKE_VERSION >= 301
132 catch (
const std::exception& ex)
142 mpz_class cache(
pi.get_rep());
144 if(mpz_cmp_si(cache.get_mpz_t(),
m))
146 int temp = (int) mpz_get_si(cache.get_mpz_t());
156 for(
int i=1;
i<=vi->size();
i++)
165 int rows = mi->
rows();
166 int cols = mi->cols();
168#if POLYMAKE_VERSION >= 301
169 pm::array_traits<pm::Integer>::iterator
pi = concat_rows(*mi).begin();
171 const polymake::Integer*
pi = concat_rows(*mi).begin();
173 for (
int r = 1; r <= rows; r++)
174 for (
int c = 1; c <= cols; c++)
184 int rows = mi->
rows();
185 int cols = mi->cols();
187#if POLYMAKE_VERSION >= 301
188 pm::array_traits<pm::Integer>::iterator
pi = concat_rows(*mi).begin();
190 const polymake::Integer*
pi = concat_rows(*mi).begin();
192 for (
int r = 1; r <= rows; r++)
193 for (
int c = 1; c <= cols; c++)
205 int rows = icmat->rows();
206 int cols = icmat->cols();
210 for (
int r = 0; r < rows; r++)
213 for (
int c = 0; c < cols; c++)
215 if ((*icmat).row(r).exists(c))
220 L->
m[r].
data = (
void*) iv;
228 int rows = icmat->rows();
229 int cols = icmat->cols();
233 for (r=0; r<rows; r++)
235 for (c=0; c<cols; c++)
237 if ((*icmat).row(r).exists(c) && r<c)
246 for (r=0; r<rows; r++)
248 for (c=0; c<cols; c++)
250 if ((*icmat).row(r).exists(c) && r<c)
253 (*iv)[0]=r; (*iv)[1]=c;
255 L->
m[
i].
data = (
void*) iv;
266 polymake::Vector<polymake::Integer> vi(*si);
276 polymake::Matrix<polymake::Integer> mi(rows,cols);
277 for(
int r=0; r<rows; r++)
278 for(
int c=0; c<cols; c++)
279 mi(r,c) = polymake::Integer(
IMATELEM(*im, r+1, c+1));
290 polymake::Integer ambientdim1 = pc->give(
"CONE_AMBIENT_DIM");
291 bool ok=
true;
int ambientdim2 =
PmInteger2Int(ambientdim1, ok);
294 WerrorS(
"PmCone2ZCone: overflow while converting polymake::Integer to int");
296 polymake::Matrix<polymake::Rational> ineqrational = pc->give(
"FACETS");
297 polymake::Matrix<polymake::Rational> eqrational = pc->give(
"LINEAR_SPAN");
301 gfan::ZMatrix zv, zw, zx, zy, zz;
304 if (ineqrational.cols()!=0)
306 polymake::Matrix<polymake::Integer> ineqinteger = polymake::common::primitive(ineqrational);
310 zv = gfan::ZMatrix(0, ambientdim2);
311 if (eqrational.cols()!=0)
313 polymake::Matrix<polymake::Integer> eqinteger = polymake::common::primitive(eqrational);
317 zw = gfan::ZMatrix(0, ambientdim2);
334 gfan::ZCone* zc =
new gfan::ZCone(zv,zw,3);
337 WerrorS(
"PmCone2ZCone: unexpected parameters");
343 if (
pp->isa(
"Polytope<Rational>"))
345 polymake::Integer ambientdim1 =
pp->give(
"CONE_AMBIENT_DIM");
346 bool ok=
true;
int ambientdim2 =
PmInteger2Int(ambientdim1, ok);
349 WerrorS(
"overflow while converting polymake::Integer to int");
351 polymake::Matrix<polymake::Rational> ineqrational =
pp->give(
"FACETS");
352 polymake::Matrix<polymake::Rational> eqrational =
pp->give(
"AFFINE_HULL");
356 gfan::ZMatrix zv, zw;
359 if (ineqrational.cols()!=0)
361 polymake::Matrix<polymake::Integer> ineqinteger = polymake::common::primitive(ineqrational);
365 zv = gfan::ZMatrix(0, ambientdim2);
367 if (eqrational.cols()!=0)
369 polymake::Matrix<polymake::Integer> eqinteger = polymake::common::primitive(eqrational);
373 zw = gfan::ZMatrix(0, ambientdim2);
391 gfan::ZCone* zp =
new gfan::ZCone(zv,zw,3);
395 WerrorS(
"PmPolytope2ZPolytope: unexpected parameters");
401 if (pf->isa(
"PolyhedralFan"))
403 int d = (int) pf->give(
"FAN_AMBIENT_DIM");
404 gfan::ZFan* zf =
new gfan::ZFan(d);
406 int n = pf->give(
"N_MAXIMAL_CONES");
407 for (
int i=0;
i<n;
i++)
409 #if (POLYMAKE_VERSION >= 305)
410 polymake::perl::Object pmcone=pf->call_method(
"cone",
i);
412 polymake::perl::Object pmcone=pf->CallPolymakeMethod(
"cone",
i);
419 WerrorS(
"PmFan2ZFan: unexpected parameters");
425 polymake::perl::Object* gc =
new polymake::perl::Object(
"Cone<Rational>");
430 gfan::ZMatrix
equations = zc->getEquations();
450 polymake::perl::Object*
pp =
new polymake::perl::Object(
"Polytope<Rational>");
455 gfan::ZMatrix
equations = zc->getEquations();
467polymake::Matrix<polymake::Integer>
raysOf(gfan::ZFan* zf)
469 int d = zf->getAmbientDimension();
470 int n = zf->numberOfConesOfDimension(1,0,0);
471 gfan::ZMatrix zm(n,d);
473 for (
int i=0;
i<n;
i++)
475 gfan::ZCone zc = zf->getCone(1,
i,0,0);
476 gfan::ZMatrix ray = zc.extremeRays();
477 for (
int j=0;
j<d;
j++)
488 int n = zf->numberOfConesOfDimension(1,0,0);
494 int d = zf->getAmbientDimension();
497 for (
int i=0;
i<=d;
i++)
499 n = n + zf->numberOfConesOfDimension(
i,0,1);
505polymake::Array<polymake::Set<int> >
conesOf(gfan::ZFan* zf)
509 polymake::Matrix<polymake::Integer> pm=
raysOf(zf);
510 polymake::Array<polymake::Set<int> > L(r);
513 for (
int d=1; d<=zf->getAmbientDimension(); d++)
515 for (
int i=0;
i<zf->numberOfConesOfDimension(d,0,1);
i++)
517 gfan::IntVector
v = zf->getConeIndices(d,
i,0,1);
518 polymake::Set<int>
s;
519 for (
int j=0;
j<(int)
v.size();
j++)
532 polymake::perl::Object* pf =
new polymake::perl::Object(
"PolyhedralFan");
534 polymake::Matrix<polymake::Integer> zm =
raysOf(zf);
535 pf->take(
"RAYS") << zm;
537 polymake::Array<polymake::Set<int> > ar =
conesOf(zf);
538 pf->take(
"MAXIMAL_CONES") << ar;
BOOLEAN equations(leftv res, leftv args)
BOOLEAN inequalities(leftv res, leftv args)
void set(int i, int j, number n, const coeffs C=NULL)
replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]
void resize(int new_length)
INLINE_THIS void Init(int l=0)
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE number n_InitMPZ(mpz_t n, const coeffs r)
conversion of a GMP integer to number
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
const CanonicalForm int s
const Variable & v
< [in] a sqrfree bivariate poly
void WerrorS(const char *s)
#define IMATELEM(M, I, J)
int PmInteger2Int(const polymake::Integer &pi, bool &ok)
intvec * PmSetInteger2Intvec(polymake::Set< polymake::Integer > *si, bool &b)
gfan::ZCone * PmPolytope2ZPolytope(polymake::perl::Object *pp)
polymake::Integer GfInteger2PmInteger(const gfan::Integer &gi)
gfan::Rational PmRational2GfRational(const polymake::Rational &pr)
polymake::Matrix< polymake::Integer > GfZMatrix2PmMatrixInteger(const gfan::ZMatrix *zm)
number PmInteger2Number(const polymake::Integer &pi)
polymake::Vector< polymake::Integer > Intvec2PmVectorInteger(const intvec *iv)
polymake::Matrix< polymake::Rational > GfQMatrix2PmMatrixRational(const gfan::QMatrix *qm)
polymake::Matrix< polymake::Integer > raysOf(gfan::ZFan *zf)
int numberOfMaximalConesOf(gfan::ZFan *zf)
polymake::perl::Object * ZFan2PmFan(gfan::ZFan *zf)
gfan::ZCone * PmCone2ZCone(polymake::perl::Object *pc)
gfan::ZFan * PmFan2ZFan(polymake::perl::Object *pf)
lists PmIncidenceMatrix2ListOfIntvecs(polymake::IncidenceMatrix< polymake::NonSymmetric > *icmat)
intvec * PmMatrixInteger2Intvec(polymake::Matrix< polymake::Integer > *mi, bool &ok)
polymake::Matrix< polymake::Integer > Intvec2PmMatrixInteger(const intvec *im)
lists PmAdjacencyMatrix2ListOfEdges(polymake::IncidenceMatrix< polymake::NonSymmetric > *icmat)
polymake::perl::Object * ZCone2PmCone(gfan::ZCone *zc)
gfan::ZMatrix PmMatrixInteger2GfZMatrix(const polymake::Matrix< polymake::Integer > *mi)
polymake::perl::Object * ZPolytope2PmPolytope(gfan::ZCone *zc)
polymake::Rational GfRational2PmRational(const gfan::Rational &gr)
bigintmat * PmMatrixInteger2Bigintmat(polymake::Matrix< polymake::Integer > *mi)
polymake::Array< polymake::Set< int > > conesOf(gfan::ZFan *zf)
intvec * PmVectorInteger2Intvec(const polymake::Vector< polymake::Integer > *vi, bool &ok)
int numberOfRaysOf(gfan::ZFan *zf)
gfan::Integer PmInteger2GfInteger(const polymake::Integer &pi)
gfan::QMatrix PmMatrixRational2GfQMatrix(const polymake::Matrix< polymake::Rational > *mr)