Skip to content

Commit

Permalink
NEW: scalingPolytope, overloaded '*'
Browse files Browse the repository at this point in the history
scalingPolytope scales a polytope by an integer factor,
can be used through overloaded '*' if polymake is loaded.
  • Loading branch information
Yue Ren committed Feb 24, 2012
1 parent ba53ff2 commit 0e07c1f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
28 changes: 28 additions & 0 deletions callgfanlib/bbpolytope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,33 @@ BOOLEAN newtonPolytope(leftv res, leftv args)
return TRUE;
}

BOOLEAN scalePolytope(leftv res, leftv args)
{
leftv u = args;
if ((u != NULL) && (u->Typ() == INT_CMD))
{
leftv v = u->next;
if ((v != NULL) && (v->Typ() == polytopeID))
{

int* n = (int*) u->Data();
gfan::ZCone* zp = (gfan::ZCone*) v->Data();
gfan::ZMatrix zm = zp->extremeRays();
for (int i=1; i<zm.getHeight(); i++)
for (int j=1; j<zm.getWidth(); j++)
zm[i][j]+=1;
gfan::ZCone* zq = new gfan::ZCone();
*zq = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth()));
res->rtyp = polytopeID;
res->data = (char*) zq;
return FALSE;
}
}
WerrorS("scalePolytope: unexpected parameters");
return TRUE;

}

void bbpolytope_setup()
{
blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
Expand All @@ -511,6 +538,7 @@ void bbpolytope_setup()
iiAddCproc("","quickPolytopeViaNormals",FALSE,quickPolytopeViaNormals);
iiAddCproc("","getVertices",FALSE,getVertices);
iiAddCproc("","newtonPolytope",FALSE,newtonPolytope);
iiAddCproc("","scalePolytope",FALSE,scalePolytope);
/********************************************************/
/* the following functions are implemented in bbcone.cc */
// iiAddCproc("","getAmbientDimension",FALSE,getAmbientDimension);
Expand Down
29 changes: 23 additions & 6 deletions callpolymake/polymake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,16 @@ polymake::perl::Object ZFan2PmFan (gfan::ZFan* zf)
/*******************************************************/


static BOOLEAN bbpolytope_Op2(int op, leftv res, leftv p, leftv q)
static BOOLEAN bbpolytope_Op2(int op, leftv res, leftv i1, leftv i2)
{
gfan::ZCone* zp = (gfan::ZCone*) p->Data();
gfan::ZCone* zp = (gfan::ZCone*) i1->Data();
switch(op)
{
case '+':
{
if (q->Typ()==polytopeID)
if (i2->Typ()==polytopeID)
{
gfan::ZCone* zq = (gfan::ZCone*) q->Data();
gfan::ZCone* zq = (gfan::ZCone*) i2->Data();
gfan::ZCone* ms;
try
{
Expand All @@ -347,10 +347,27 @@ static BOOLEAN bbpolytope_Op2(int op, leftv res, leftv p, leftv q)
}
return TRUE;
}
case '*':
{
if (i2->Typ()==INT_CMD)
{
int* s = (int*) i2->Data();
gfan::ZMatrix zm = zp->extremeRays();
for (int i=1; i<zm.getHeight(); i++)
for (int j=1; j<zm.getWidth(); j++)
zm[i][j]+=1;
gfan::ZCone* zs = new gfan::ZCone();
*zs = gfan::ZCone::givenByRays(zm,gfan::ZMatrix(0, zm.getWidth()));
res->rtyp = polytopeID;
res->data = (void*) zs;
return FALSE;
}
return TRUE;
}
default:
return blackboxDefaultOp2(op,res,p,q);
return blackboxDefaultOp2(op,res,i1,i2);
}
return blackboxDefaultOp2(op,res,p,q);
return blackboxDefaultOp2(op,res,i1,i2);
}


Expand Down

0 comments on commit 0e07c1f

Please sign in to comment.