Skip to content

Commit

Permalink
chg: various changes, completed documentation
Browse files Browse the repository at this point in the history
removed makePolytope
an extra function to convert a cone into a polytope is unnecessary,
will write a cast for that in the future

removed scalePolytope
an extra function to scale a polytope is unnecessary,
since one can just write p*k, p polytope, k integer.

removed isComplete
this is not working as expected (gfanlib problems),
should user need such a functionality,
he/she needs to resort to the polymake interface.

changed insertCone/removeCone
input is checked for compatibility by default,
should the user wish to circumvent this check (which is slow)
the user needs to pass an extra int argument which is 0.

removed various chunks of code that were commented out
  • Loading branch information
Yue Ren committed Jul 4, 2012
1 parent 6c55a43 commit 46d943a
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 280 deletions.
4 changes: 2 additions & 2 deletions callgfanlib/bbcone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,7 @@ void bbcone_setup()
iiAddCproc("","coneViaInequalities",FALSE,coneViaNormals);
iiAddCproc("","coneViaPoints",FALSE,coneViaRays);
iiAddCproc("","canonicalizeCone",FALSE,canonicalizeCone);
iiAddCproc("","makePolytope",FALSE,coneToPolytope);
// iiAddCproc("","makePolytope",FALSE,coneToPolytope);

iiAddCproc("","inequalities",FALSE,inequalities);
iiAddCproc("","facets",FALSE,facets);
Expand All @@ -1527,7 +1527,7 @@ void bbcone_setup()
iiAddCproc("","setLinearForms",FALSE,setLinearForms);
iiAddCproc("","linearForms",FALSE,linearForms);

iiAddCproc("","dual",FALSE,dualCone);
iiAddCproc("","dualCone",FALSE,dualCone);
iiAddCproc("","negatedCone",FALSE,negatedCone);
iiAddCproc("","coneLink",FALSE,coneLink);
iiAddCproc("","convexIntersection",FALSE,intersectCones);
Expand Down
79 changes: 38 additions & 41 deletions callgfanlib/bbfan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -377,27 +377,6 @@ BOOLEAN isCompatible(leftv res, leftv args)
return TRUE;
}

BOOLEAN quickInsertCone(leftv res, leftv args)
{
leftv u=args;
if ((u != NULL) && (u->Typ() == fanID))
{
leftv v=u->next;
if ((v != NULL) && (v->Typ() == coneID))
{
gfan::ZFan* zf = (gfan::ZFan*)u->Data();
gfan::ZCone* zc = (gfan::ZCone*)v->Data();
zc->canonicalize();
zf->insert(*zc);
res->rtyp = NONE;
res->data = NULL;
return FALSE;
}
}
WerrorS("quickInsertCone: unexpected parameters");
return TRUE;
}

BOOLEAN insertCone(leftv res, leftv args)
{
leftv u=args;
Expand All @@ -409,19 +388,26 @@ BOOLEAN insertCone(leftv res, leftv args)
gfan::ZFan* zf = (gfan::ZFan*)u->Data();
gfan::ZCone* zc = (gfan::ZCone*)v->Data();
zc->canonicalize();
if (iscompatible(zf,zc))
{
zf->insert(*zc);
res->rtyp = NONE;
res->data = NULL;
IDDATA((idhdl)u->data)=(char *)zf;
return FALSE;
}
else
{

leftv w=v->next;
int n = 1;
if ((w != NULL) && (w->Typ() == INT_CMD))
int n = (int)(long) w;

if (n != 0)
{
if (!iscompatible(zf,zc))
{
WerrorS("insertCone: cone and fan not compatible");
return TRUE;
}
}

zf->insert(*zc);
res->rtyp = NONE;
res->data = NULL;
IDDATA((idhdl)u->data)=(char *)zf;
return FALSE;
}
}
else
Expand Down Expand Up @@ -510,13 +496,25 @@ BOOLEAN removeCone(leftv res, leftv args)
gfan::ZFan* zf = (gfan::ZFan*)u->Data();
gfan::ZCone* zc = (gfan::ZCone*)v->Data();
zc->canonicalize();
if(containsInCollection(zf,zc))

leftv w=v->next; int n = 1;
if ((w != NULL) && (w->Typ() == INT_CMD))
int n = (int)(long) w;

if (n != 0)
{
zf->remove(*zc);
res->rtyp = NONE;
res->data = NULL;
return FALSE;
if (!containsInCollection(zf,zc))
{
WerrorS("removeCone: cone not contained in fan");
return TRUE;
}
}

zf->remove(*zc);
res->rtyp = NONE;
res->data = NULL;
IDDATA((idhdl)u->data)=(char *)zf;
return FALSE;
}
}
WerrorS("removeCone: unexpected parameters");
Expand Down Expand Up @@ -641,7 +639,7 @@ BOOLEAN isComplete(leftv res, leftv args)
return TRUE;
}

BOOLEAN getFVector(leftv res, leftv args)
BOOLEAN fVector(leftv res, leftv args)
{
leftv u=args;
if ((u != NULL) && (u->Typ() == fanID))
Expand All @@ -652,7 +650,7 @@ BOOLEAN getFVector(leftv res, leftv args)
res->data = (void*) zVectorToBigintmat(zv);
return FALSE;
}
WerrorS("getFVector: unexpected parameters");
WerrorS("fVector: unexpected parameters");
return TRUE;
}

Expand Down Expand Up @@ -742,14 +740,13 @@ void bbfan_setup()
iiAddCproc("","numberOfConesOfDimension",FALSE,numberOfConesOfDimension);
iiAddCproc("","ncones",FALSE,ncones);
iiAddCproc("","nmaxcones",FALSE,nmaxcones);
iiAddCproc("","quickInsertCone",FALSE,quickInsertCone);
iiAddCproc("","insertCone",FALSE,insertCone);
iiAddCproc("","removeCone",FALSE,removeCone);
iiAddCproc("","getCone",FALSE,getCone);
iiAddCproc("","isSimplicial",FALSE,isSimplicial);
iiAddCproc("","isPure",FALSE,isPure);
iiAddCproc("","isComplete",FALSE,isComplete);
iiAddCproc("","getFVector",FALSE,getFVector);
// iiAddCproc("","isComplete",FALSE,isComplete); not working as expected, should leave this to polymake
iiAddCproc("","fVector",FALSE,fVector);
iiAddCproc("","containsInCollection",FALSE,containsInCollection);
// iiAddCproc("","grFan",FALSE,grFan);
fanID=setBlackboxStuff(b,"fan");
Expand Down
212 changes: 1 addition & 211 deletions callpolymake/polymake_wrapper.cc
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
#include <polymake_conversion.h>
#include <polymake_documentation.h>

// #include <polymake/Main.h>
// #include <polymake/Matrix.h>
// #include <polymake/Rational.h>
// #include <polymake/Integer.h>
// #include <polymake/common/lattice_tools.h>
// #include <polymake/perl/macros.h>
// #include <polymake/Set.h>
// #include <polymake/IncidenceMatrix.h>

// #include <gfanlib/gfanlib.h>
// #include <gfanlib/gfanlib_q.h>

// #include <gmpxx.h>

// #include <kernel/mod2.h>
// #include <kernel/structs.h>
// #include <kernel/febase.h>
// #include <kernel/intvec.h>

#include <callgfanlib/bbcone.h>
#include <callgfanlib/bbfan.h>
#include <callgfanlib/bbpolytope.h>

#include <Singular/blackbox.h>
#include <Singular/ipshell.h>
#include <Singular/subexpr.h>
// #include <Singular/tok.h>

using namespace polymake;

Expand Down Expand Up @@ -1636,185 +1616,6 @@ BOOLEAN normalFan(leftv res, leftv args)
return TRUE;
}


// BOOLEAN testingtypes(leftv res, leftv args)
// {
// leftv u = args;
// if (u != NULL)
// {
// leftv v = u->next;
// if (v != NULL)
// {
// leftv w = v->next;
// if (w != NULL)
// {
// Print("\n (u->Typ() ->) %d =?= %d (<-coneID) \n", u->Typ(),coneID);
// Print("\n (u->Typ() ->) %d =?= %d (<-fanID) \n", v->Typ(),fanID);
// Print("\n (u->Typ() ->) %d =?= %d (<-polytopeID) \n", w->Typ(),polytopeID);
// res->rtyp = NONE;
// res->data = NULL;
// return FALSE;
// }
// }
// }
// return TRUE;
// }


// BOOLEAN testingintvec(leftv res, leftv args)
// {
// leftv u = args;
// if ((u != NULL) && (u->Typ()==INTVEC_CMD))
// {
// intvec* iv = (intvec*)u->Data();
// polymake::Vector<polymake::Integer> pmvec = Intvec2PmVectorInteger(iv);
// res->rtyp = NONE;
// res->data = NULL;
// return FALSE;
// }
// return TRUE;
// }


// BOOLEAN testingfans(leftv res, leftv args) // for testing purposes
// { // creating a fan in polymake
// leftv u = args; // and handing it to Singular
// if ((u != NULL) && (u->Typ() == fanID))
// {
// gfan::ZFan* zf = (gfan::ZFan*) u->Data();
// perl::Object pf = ZFan2PmFan(zf);
// gfan::ZFan* zff = new gfan::ZFan(PmFan2ZFan(&pf));
// res->rtyp = fanID;
// res->data = (char *)zff;
// return FALSE;
// }
// return TRUE;
// }

// BOOLEAN testingmatrices(leftv res, leftv args)
// {
// leftv u = args;
// if ((u != NULL) && (u->Typ() == coneID))
// {
// gfan::ZCone* zc = (gfan::ZCone*) u->Data();
// gfan::ZMatrix zm = zc->getInequalities();
// polymake::Matrix<polymake::Integer> pm = GfZMatrix2PmMatrixInteger(&zm);
// gfan::ZMatrix zn = PmMatrixInteger2GfZMatrix(&pm);
// res->rtyp = NONE;
// res->data = NULL;
// return FALSE;
// }
// return TRUE;
// }

// BOOLEAN testingcones(leftv res, leftv args) // for testing purposes
// { // taking a cone from Singular,
// // handing it over to polymake
// // and back
// leftv u = args;
// if ((u != NULL) && (u->Typ() == coneID))
// {
// gfan::ZCone* zc = (gfan::ZCone*) u->Data();
// Print("converting gfan cone to polymake cone...\n");
// polymake::perl::Object pc = ZCone2PmCone(zc);
// Print("converting polymake cone to gfan cone...\n");
// gfan::ZCone* zd = new gfan::ZCone(PmCone2ZCone(&pc));
// // res->rtyp = coneID;
// // res->data = (char *) zd;
// res->rtyp = NONE;
// res->data = NULL;
// return FALSE;
// }
// return TRUE;
// }

// BOOLEAN testingpolytopes(leftv res, leftv args) // for testing purposes
// { // taking a cone from Singular,
// // handing it over to polymake
// // and back
// leftv u = args;
// if ((u != NULL) && (u->Typ() == polytopeID))
// {
// gfan::ZCone* zp = (gfan::ZCone*) u->Data();
// polymake::perl::Object pp = ZPolytope2PmPolytope(zp);
// gfan::ZCone* zq = new gfan::ZCone(PmPolytope2ZPolytope(&pp));
// res->rtyp = polytopeID;
// res->data = (char *) zq;
// return FALSE;
// }
// return TRUE;
// }

// BOOLEAN testingvisuals(leftv res, leftv args) // for testing purposes
// { // testing visualization of fans
// try{ // exactly same as smalltest
// // perl::Object p("Polytope<Rational>");
// // p = CallPolymakeFunction("cube",3);
// perl::Object p("PolyhedralFan");
// Matrix<Integer> zm=(unit_matrix<Integer>(3));
// p.take("INPUT_RAYS") << zm;
// Set<int> s;
// s = s+0;
// s = s+1;
// s = s+2;
// Array<Set<int> > ar(1);
// ar[0]=s;
// p.take("INPUT_CONES") << ar;
// VoidCallPolymakeFunction("jreality",p.CallPolymakeMethod("VISUAL"));
// res->rtyp = NONE;
// res->data = NULL;
// return FALSE;
// }
// catch (const std::exception& ex)
// {
// WerrorS("ERROR: "); WerrorS(ex.what()); WerrorS("\n");
// return TRUE;
// }
// }


// BOOLEAN testingstrings(leftv res, leftv args)
// {
// leftv u = args;
// gfan::ZFan* zf = (gfan::ZFan*) u->Data();
// std::string zs = zf->toString();
// std::istringstream s(zs);
// gfan::ZFan* zg = new gfan::ZFan(s);
// res->rtyp = fanID;
// res->data = (char*) zg;
// return FALSE;
// }


// BOOLEAN callpolymakefunction(leftv res, leftv args)
// {
// leftv u = args;
// if (u != NULL)
// {
// leftv v = u->next;
// if ((v != NULL) && (v->typ() == STRING_CMD))
// {
// /* checks for type of input,
// stores it into a polymake::perl::Object */
// if (u->typ() == coneID)
// {
// gfan::ZCone* zc = (gfan::ZCone*) u->data();
// polymake::perl::Object in = ZCone2PmCone(zc);
// }
// if (u->typ() == fanID)
// {
// gfan::ZFan* zf = (gfan::ZFan*) u->data();
// polymake::perl::Object in = ZFan2PmFan(zf);
// }
// /* calls the functions in polymake */
// string cmd = v->data();
// polymake::perl::Object out;
// CallPolymakeFunction(cmd, in) >> out;
// }
// }
// }


BOOLEAN PMconeViaRays(leftv res, leftv args)
{
leftv u = args;
Expand Down Expand Up @@ -1881,25 +1682,14 @@ BOOLEAN PMpolytopeViaVertices(leftv res, leftv args)
return TRUE;
}


// BOOLEAN loadPolymakeDocumentation(leftv res, leftv args)
// {
// init_polymake_help();

// res->rtyp = NONE;
// res->data = NULL;
// return FALSE;
// }


extern "C" int mod_init(void* polymakesingular)
{
if (init_polymake==NULL)
{init_polymake = new polymake::Main();}
init_polymake->set_application("fan");
// iiAddCproc("","cube",FALSE,cube);
// iiAddCproc("","cross",FALSE,cross);
iiAddCproc("","coneViaRays",FALSE,PMconeViaRays);
iiAddCproc("","coneViaPoints",FALSE,PMconeViaRays);
iiAddCproc("","polytopeViaVertices",FALSE,PMpolytopeViaVertices);
iiAddCproc("","isLatticePolytope",FALSE,PMisLatticePolytope);
iiAddCproc("","isBounded",FALSE,PMisBounded);
Expand Down
Loading

0 comments on commit 46d943a

Please sign in to comment.