[SCM] an open source computer algebra system branch, cleanedupstream, updated. 6125e540ca6d66c307958938a9d53b245507c323
Bernhard R. Link
brlink at debian.org
Tue Apr 24 15:54:18 UTC 2012
The following commit has been merged in the cleanedupstream branch:
commit ace03f7b3245fbbba1ad7e6453fb04a03ac3eeca
Author: Janko Boehm <janko at lubuntu>
Date: Tue Mar 6 17:46:26 2012 +0100
chg: revised version of divisor.lib
fix: transferring cones/polytopes between singular and polymake
new: more caching of results in gfan::ZCones
diff --git a/Singular/LIB/divisors.lib b/Singular/LIB/divisors.lib
index 1557a0b..e320fc3 100755
--- a/Singular/LIB/divisors.lib
+++ b/Singular/LIB/divisors.lib
@@ -68,7 +68,7 @@ LIB "primdec.lib";
proc mod_init()
{
-//if (!defined(Gfanlib::coneViaRays)) {
+//if (!defined(coneViaRays)) {
// LIB("gfanlib.so");
// export(Gfanlib);
//}
@@ -304,41 +304,54 @@ return(E);}
proc makePDivisor(list L){
pdivisor P;
-P.summands = L;
-cone C = tailCone(L[1][1]);
-P.tail = C;
+list CP = decomposePolyhedron(L[1][1]);
+P.tail = CP[1];
+list LP;
+LP[1]=list(CP[2],L[1][2]);
+int i;
+for (i=2; i<=size(L);i++){
+ CP = decomposePolyhedron(L[i][1]);
+ if (!(CP[1]==P.tail)) {ERROR("All P-coefficients should have the same tail cone");}
+ LP[i]=list(CP[2],L[i][2]);
+}
+P.summands = LP;
return(P);
}
-proc tailCone(polytope P){
-intmat rays = Gfanlib::getVertices(P);
+proc decomposePolyhedron(polytope P){
+intmat rays = getVertices(P);
+intmat rays2 = rays;
int i,j;
for (i=1; i<=nrows(rays);i++){
if (rays[i,1]==1) {
for (j=1; j<=ncols(rays);j++){
rays[i,j]=0;
}
+ } else {
+ for (j=1; j<=ncols(rays);j++){
+ rays2[i,j]=0;
+ }
}
}
-cone C = Gfanlib::coneViaRays(rays);
-return(C);
+cone C = coneViaRays(rays);
+polytope C2 = polytopeViaVertices(rays2);
+return(list(C,C2));
}
proc evaluatePDivisor(pdivisor D,intvec v){
formaldivisor vD;
-//
list L = D.summands;
+cone C = D.tail;
+cone dC = getDualCone(C);
list vL;
int i;
-intvec vv = 0;
-for (i=1; i<=size(v);i++){
- vv[i+1]=v[i];
-}
+intvec vv = 0,v;
+if (!(containsInSupport(dC,vv))) {ERROR("the linear form given should be in the dual tail cone");}
for (i=1; i<=size(L);i++){
vL[i]=list();
vL[i][2]=L[i][2];
- vL[i][1]=Polymake::minimalValue(L[i][1],vv);
+ vL[i][1]=Polymake::minimalValue(L[i][1],vv);
}
vD.summands = vL;
return(vD);}
diff --git a/callgfanlib/bbcone.cc b/callgfanlib/bbcone.cc
index e364465..7d1a336 100644
--- a/callgfanlib/bbcone.cc
+++ b/callgfanlib/bbcone.cc
@@ -1295,6 +1295,38 @@ BOOLEAN canonicalizeCone(leftv res, leftv args)
}
}
+BOOLEAN areExtremeRaysKnown(leftv res, leftv args)
+{
+ leftv u=args;
+ if ((u != NULL) && (u->Typ() == coneID))
+ {
+ gfan::ZCone* zc = (gfan::ZCone*)u->Data();
+ bool b = zc->areExtremeRaysKnown();
+ int bb = (int) b;
+ res->rtyp = INT_CMD;
+ res->data = (char*) bb;
+ return FALSE;
+ }
+ WerrorS("haveExtremeRaysBeenCached: unexpected parameters");
+ return TRUE;
+}
+
+BOOLEAN areGeneratorsOfLinealitySpaceKnown(leftv res, leftv args)
+{
+ leftv u=args;
+ if ((u != NULL) && (u->Typ() == coneID))
+ {
+ gfan::ZCone* zc = (gfan::ZCone*)u->Data();
+ bool b = zc->areGeneratorsOfLinealitySpaceKnown();
+ int bb = (int) b;
+ res->rtyp = INT_CMD;
+ res->data = (char*) bb;
+ return FALSE;
+ }
+ WerrorS("haveExtremeRaysBeenCached: unexpected parameters");
+ return TRUE;
+}
+
void bbcone_setup()
{
blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
@@ -1345,6 +1377,8 @@ void bbcone_setup()
iiAddCproc("","getUniquePoint",FALSE,getUniquePoint);
// iiAddCproc("","faceContaining",FALSE,faceContaining);
iiAddCproc("","hasFace",FALSE,hasFace);
+ iiAddCproc("","areExtremeRaysKnown",FALSE,areExtremeRaysKnown);
+ iiAddCproc("","areGeneratorsOfLinealitySpaceKnown",FALSE,areGeneratorsOfLinealitySpaceKnown);
coneID=setBlackboxStuff(b,"cone");
//Print("created type %d (cone)\n",coneID);
}
diff --git a/callpolymake/polymake.cc b/callpolymake/polymake.cc
index 5acd7cb..73ac7f0 100755
--- a/callpolymake/polymake.cc
+++ b/callpolymake/polymake.cc
@@ -211,8 +211,9 @@ gfan::ZCone PmCone2ZCone (polymake::perl::Object* pc)
polymake::Matrix<polymake::Rational> ineqrational = pc->give("FACETS");
polymake::Matrix<polymake::Rational> eqrational = pc->give("LINEAR_SPAN");
polymake::Matrix<polymake::Rational> exraysrational = pc->give("RAYS");
+ polymake::Matrix<polymake::Rational> linrational = pc->give("LINEALITY_SPACE");
- gfan::ZMatrix zv, zw, zx;
+ gfan::ZMatrix zv, zw, zx, zy;
if (ineqrational.cols()!=0)
{
polymake::Matrix<polymake::Integer> ineqinteger = polymake::polytope::multiply_by_common_denominator(ineqrational);
@@ -229,13 +230,24 @@ gfan::ZCone PmCone2ZCone (polymake::perl::Object* pc)
zw = gfan::ZMatrix(0, ambientdim2);
if (exraysrational.cols()!=0)
{
- polymake::Matrix<polymake::Integer> exraysinteger = polymake::polytope::multiply_by_common_denominator(exraysrational);
+ polymake::Matrix<polymake::Integer> exraysinteger = polymake::polytope::multiply_by_common_denominator(exraysrational);
zx = PmMatrixInteger2GfZMatrix(&exraysinteger);
}
else
zx = gfan::ZMatrix(0, ambientdim2);
- gfan::ZCone zc = gfan::ZCone(zv,zw,zx,2);
+ gfan::ZCone zc = gfan::ZCone(zv,zw,zx,3);
+
+ if (linrational.cols()!=0)
+ {
+ polymake::Matrix<polymake::Integer> lininteger = polymake::polytope::multiply_by_common_denominator(linrational);
+ zy = PmMatrixInteger2GfZMatrix(&lininteger);
+ }
+ else
+ zy = gfan::ZMatrix(0, ambientdim2);
+
+ zc.setGeneratorsOfLinealitySpace(zy);
+
return zc;
}
WerrorS("PmCone2ZCone: unexpected parameters");
@@ -281,7 +293,7 @@ gfan::ZCone PmPolytope2ZPolytope (polymake::perl::Object* pp)
else
zx = gfan::ZMatrix(0, ambientdim2);
- gfan::ZCone zp = gfan::ZCone(zv,zw,zx,2);
+ gfan::ZCone zp = gfan::ZCone(zv,zw,zx,3);
return zp;
}
WerrorS("PmPolytope2ZPolytope: unexpected parameters");
@@ -311,21 +323,21 @@ polymake::perl::Object ZCone2PmCone (gfan::ZCone* zc)
polymake::perl::Object gc("Cone<Rational>");
gfan::ZMatrix inequalities = zc->getInequalities();
- gc.take("INEQUALITIES") << GfZMatrix2PmMatrixInteger(&inequalities);
+ gc.take("FACETS") << GfZMatrix2PmMatrixInteger(&inequalities);
gfan::ZMatrix equations = zc->getEquations();
- gc.take("EQUATIONS") << GfZMatrix2PmMatrixInteger(&equations);
+ gc.take("LINEAR_SPAN") << GfZMatrix2PmMatrixInteger(&equations);
if(zc->areExtremeRaysKnown())
{
gfan::ZMatrix extremeRays = zc->extremeRays();
- gc.take("INPUT_RAYS") << GfZMatrix2PmMatrixInteger(&extremeRays);
+ gc.take("RAYS") << GfZMatrix2PmMatrixInteger(&extremeRays);
}
if(zc->areGeneratorsOfLinealitySpaceKnown())
{
gfan::ZMatrix lineality = zc->generatorsOfLinealitySpace();
- gc.take("INPUT_LINEALITY") << GfZMatrix2PmMatrixInteger(&lineality);
+ gc.take("LINEALITY_SPACE") << GfZMatrix2PmMatrixInteger(&lineality);
}
return gc;
@@ -336,15 +348,15 @@ polymake::perl::Object ZPolytope2PmPolytope (gfan::ZCone* zc)
polymake::perl::Object pp("Polytope<Rational>");
gfan::ZMatrix inequalities = zc->getInequalities();
- gc.take("INEQUALITIES") << GfZMatrix2PmMatrixInteger(&inequalities);
+ pp.take("FACETS") << GfZMatrix2PmMatrixInteger(&inequalities);
gfan::ZMatrix equations = zc->getEquations();
- gc.take("EQUATIONS") << GfZMatrix2PmMatrixInteger(&equations);
+ pp.take("LINEAR_SPAN") << GfZMatrix2PmMatrixInteger(&equations);
- if(zc->areExtremeRays())
+ if(zc->areExtremeRaysKnown())
{
gfan::ZMatrix vertices = zc->extremeRays();
- pp.take("VERTICES") << GfZMatrix2PmMatrixInteger(&zm);
+ pp.take("VERTICES") << GfZMatrix2PmMatrixInteger(&vertices);
}
return pp;
@@ -1782,6 +1794,22 @@ BOOLEAN normalFan(leftv res, leftv args)
// 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
@@ -1888,16 +1916,6 @@ BOOLEAN testingstrings(leftv res, leftv args)
// }
-BOOLEAN testingmatrices(leftv res, leftv args)
-{
- intvec* im = (intvec*) args->Data();
- polymake::Matrix<polymake::Integer> pm = Intvec2PmMatrixInteger(im);
- res->rtyp = NONE;
- res->data = NULL;
- return FALSE;
-}
-
-
BOOLEAN PMconeViaRays(leftv res, leftv args)
{
leftv u = args;
@@ -1913,7 +1931,7 @@ BOOLEAN PMconeViaRays(leftv res, leftv args)
{
intvec* lines = (intvec*) v->Data(); // these will be lines in the cone
polymake::Matrix<polymake::Integer> pmlines = Intvec2PmMatrixInteger(lines);
- pc.take("INPUT_LINEALITY") << pmlines;
+ pc.take("INPUT_LINEALITY_SPACE") << pmlines;
leftv w = v->next;
if ((w != NULL) && (w->Typ() == INT_CMD))
diff --git a/gfanlib/gfanlib_polyhedralfan.cpp b/gfanlib/gfanlib_polyhedralfan.cpp
index 8f60a4e..c6536fc 100644
--- a/gfanlib/gfanlib_polyhedralfan.cpp
+++ b/gfanlib/gfanlib_polyhedralfan.cpp
@@ -8,6 +8,7 @@
#include <sstream>
#include "gfanlib_polyhedralfan.h"
#include "gfanlib_polymakefile.h"
+#include "gfanlib_zcone.h"
using namespace std;
namespace gfan{
diff --git a/gfanlib/gfanlib_zcone.cpp b/gfanlib/gfanlib_zcone.cpp
index e77e7f8..4b36902 100644
--- a/gfanlib/gfanlib_zcone.cpp
+++ b/gfanlib/gfanlib_zcone.cpp
@@ -1045,8 +1045,18 @@ ZCone ZCone::dualCone()const
// assert(state>=1);
ZMatrix dualInequalities,dualEquations;
- lpSolver.dual(inequalities,equations,dualInequalities,dualEquations);
- ZCone ret(dualInequalities,dualEquations);
+ if(this->areExtremeRaysKnown())
+ dualInequalities=cachedExtremeRays;
+ else
+ dualInequalities=this->extremeRays();
+
+ if(this->areGeneratorsOfLinealitySpaceKnown())
+ dualEquations=cachedGeneratorsOfLinealitySpace;
+ else
+ dualEquations=this->generatorsOfLinealitySpace();
+
+ // lpSolver.dual(inequalities,equations,dualInequalities,dualEquations);
+ ZCone ret(dualInequalities,dualEquations,3);
ret.ensureStateAsMinimum(state);
return ret;
--
an open source computer algebra system
More information about the debian-science-commits
mailing list