[SCM] an open source computer algebra system branch, cleanedupstream, updated. 6125e540ca6d66c307958938a9d53b245507c323
Bernhard R. Link
brlink at debian.org
Tue Apr 24 15:54:20 UTC 2012
The following commit has been merged in the cleanedupstream branch:
commit 6856068b89624d016fbcacc621fbe0aafc4803cd
Author: Yue Ren <ren at mathematik.uni-kl.de>
Date: Mon Mar 12 14:41:21 2012 +0100
chg: changed how cached data is handled in gfanlib because of Anders
diff --git a/callpolymake/polymake.cc b/callpolymake/polymake.cc
index 55a061b..b28c7ed 100755
--- a/callpolymake/polymake.cc
+++ b/callpolymake/polymake.cc
@@ -213,8 +213,10 @@ gfan::ZCone PmCone2ZCone (polymake::perl::Object* pc)
polymake::Matrix<polymake::Rational> exraysrational = pc->give("RAYS");
polymake::Matrix<polymake::Rational> linrational = pc->give("LINEALITY_SPACE");
- gfan::ZMatrix zv, zw, zx, zy;
- if (ineqrational.cols()!=0)
+ gfan::ZMatrix zv, zw, zx, zy, zz;
+ // the following branching statements are to cover cases in which polymake returns empty matrices
+ // by convention, gfanlib ignores empty matrices, hence zero matrices of right dimensions have to be supplied
+ if (ineqrational.cols()!=0)
{
polymake::Matrix<polymake::Integer> ineqinteger = polymake::polytope::multiply_by_common_denominator(ineqrational);
zv = PmMatrixInteger2GfZMatrix(&ineqinteger);
@@ -235,9 +237,6 @@ gfan::ZCone PmCone2ZCone (polymake::perl::Object* pc)
}
else
zx = gfan::ZMatrix(0, ambientdim2);
-
- 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);
@@ -246,7 +245,7 @@ gfan::ZCone PmCone2ZCone (polymake::perl::Object* pc)
else
zy = gfan::ZMatrix(0, ambientdim2);
- zc.setGeneratorsOfLinealitySpace(zy);
+ gfan::ZCone zc = gfan::ZCone(zv,zw,zx,zy,zz,3);
return zc;
}
@@ -267,10 +266,13 @@ gfan::ZCone PmPolytope2ZPolytope (polymake::perl::Object* pp)
polymake::Matrix<polymake::Rational> ineqrational = pp->give("FACETS");
polymake::Matrix<polymake::Rational> eqrational = pp->give("AFFINE_HULL");
polymake::Matrix<polymake::Rational> vertrational = pp->give("VERTICES");
+ polymake::Matrix<polymake::Rational> linrational = pp->give("LINEALITY_SPACE");
- gfan::ZMatrix zv, zw, zx;
- if (ineqrational.cols()!=0) // the following branching statements are to cover the cases
- { // when polymake returns an empty matrix
+ gfan::ZMatrix zv, zw, zx, zy, zz;
+ // the following branching statements are to cover the cases when polymake returns empty matrices
+ // by convention, gfanlib ignores empty matrices, hence zero matrices of right dimensions have to be supplied
+ if (ineqrational.cols()!=0)
+ {
polymake::Matrix<polymake::Integer> ineqinteger = polymake::polytope::multiply_by_common_denominator(ineqrational);
zv = PmMatrixInteger2GfZMatrix(&ineqinteger);
}
@@ -292,8 +294,15 @@ gfan::ZCone PmPolytope2ZPolytope (polymake::perl::Object* pp)
}
else
zx = gfan::ZMatrix(0, ambientdim2);
+ 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);
- gfan::ZCone zp = gfan::ZCone(zv,zw,zx,3);
+ gfan::ZCone zp = gfan::ZCone(zv,zw,zx,zy,zz,3);
return zp;
}
WerrorS("PmPolytope2ZPolytope: unexpected parameters");
@@ -1802,99 +1811,99 @@ 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 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 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 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 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)
@@ -2040,12 +2049,12 @@ extern "C" int mod_init(void* polymakesingular)
iiAddCproc("","normalFan",FALSE,normalFan);
// iiAddCproc("","testingtypes",FALSE,testingtypes);
// iiAddCproc("","testingintvec",FALSE,testingintvec);
- iiAddCproc("","testingcones",FALSE,testingcones);
- iiAddCproc("","testingpolytopes",FALSE,testingpolytopes);
+ // iiAddCproc("","testingcones",FALSE,testingcones);
+ // iiAddCproc("","testingpolytopes",FALSE,testingpolytopes);
// iiAddCproc("","testingfans",FALSE,testingfans);
- iiAddCproc("","testingvisuals",FALSE,testingvisuals);
- iiAddCproc("","testingstrings",FALSE,testingstrings);
- iiAddCproc("","testingmatrices",FALSE,testingmatrices);
+ // iiAddCproc("","testingvisuals",FALSE,testingvisuals);
+ // iiAddCproc("","testingstrings",FALSE,testingstrings);
+ // iiAddCproc("","testingmatrices",FALSE,testingmatrices);
blackbox* b=getBlackboxStuff(polytopeID);
b->blackbox_Op2=bbpolytope_Op2;
diff --git a/gfanlib/gfanlib_zcone.cpp b/gfanlib/gfanlib_zcone.cpp
index 4b36902..cf195e4 100644
--- a/gfanlib/gfanlib_zcone.cpp
+++ b/gfanlib/gfanlib_zcone.cpp
@@ -737,9 +737,8 @@ ZCone::ZCone(int ambientDimension):
preassumptions(PCP_impliedEquationsKnown|PCP_facetsKnown),
multiplicity(1),
haveExtremeRaysBeenCached(false),
- haveGeneratorsOfSpanBeenCached(false),
haveGeneratorsOfLinealitySpaceBeenCached(false),
- hasQuotientLatticeBasisBeenCached(false),
+ haveGeneratorsOfSpanBeenCached(false),
linearForms(ZMatrix(0,ambientDimension))
{
}
@@ -752,9 +751,8 @@ ZCone::ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, int preass
preassumptions(preassumptions_),
multiplicity(1),
haveExtremeRaysBeenCached(false),
- haveGeneratorsOfSpanBeenCached(false),
haveGeneratorsOfLinealitySpaceBeenCached(false),
- hasQuotientLatticeBasisBeenCached(false),
+ haveGeneratorsOfSpanBeenCached(false),
n(inequalities_.getWidth()),
linearForms(ZMatrix(0,inequalities_.getWidth()))
{
@@ -763,20 +761,27 @@ ZCone::ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, int preass
ensureStateAsMinimum(1);
}
-ZCone::ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, ZMatrix const &cachedExtremeRays_, int preassumptions_):
+ZCone::ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, ZMatrix const &cachedExtremeRays_, ZMatrix const &cachedGeneratorsOfLinealitySpace_, ZMatrix const &cachedGeneratorsOfSpan_, int preassumptions_):
inequalities(inequalities_),
equations(equations_),
cachedExtremeRays(cachedExtremeRays_),
+ cachedGeneratorsOfLinealitySpace(cachedExtremeRays_),
+ cachedGeneratorsOfSpan(cachedGeneratorsOfSpan_),
state(0),
preassumptions(preassumptions_),
multiplicity(1),
- haveExtremeRaysBeenCached(true),
- haveGeneratorsOfSpanBeenCached(false),
+ haveExtremeRaysBeenCached(false),
haveGeneratorsOfLinealitySpaceBeenCached(false),
- hasQuotientLatticeBasisBeenCached(false),
+ haveGeneratorsOfSpanBeenCached(false),
n(inequalities_.getWidth()),
linearForms(ZMatrix(0,inequalities_.getWidth()))
{
+ if (cachedExtremeRays_.getWidth()!=0)
+ haveExtremeRaysBeenCached=true;
+ if (cachedGeneratorsOfLinealitySpace_.getWidth()!=0)
+ haveGeneratorsOfLinealitySpaceBeenCached=true;
+ if (cachedGeneratorsOfSpan_.getWidth()!=0)
+ haveGeneratorsOfSpanBeenCached=true;
assert(preassumptions_<4);//OTHERWISE WE ARE DOING SOMETHING STUPID LIKE SPECIFYING AMBIENT DIMENSION
assert(equations_.getWidth()==n);
ensureStateAsMinimum(1);
@@ -858,6 +863,8 @@ int ZCone::dimension()const
int ZCone::dimensionOfLinealitySpace()const
{
+ if(haveGeneratorsOfLinealitySpaceBeenCached)
+ return cachedGeneratorsOfLinealitySpace.getHeight();
ZMatrix temp=inequalities;
temp.append(equations);
ZCone temp2(ZMatrix(0,n),temp);
@@ -1190,34 +1197,6 @@ void ZCone::setLinearForms(ZMatrix const &linearForms_)
}
-void ZCone::setExtremeRays(ZMatrix const &extremeRays_)
-{
- cachedExtremeRays=extremeRays_;
- haveExtremeRaysBeenCached=true;
-}
-
-
-void ZCone::setGeneratorsOfSpan(ZMatrix const &generatorsOfSpan_)
-{
- cachedGeneratorsOfSpan=generatorsOfSpan_;
- haveGeneratorsOfSpanBeenCached=true;
-}
-
-
-void ZCone::setGeneratorsOfLinealitySpace(ZMatrix const &generatorsOfLinealitySpace_)
-{
- cachedGeneratorsOfLinealitySpace=generatorsOfLinealitySpace_;
- haveGeneratorsOfLinealitySpaceBeenCached=true;
-}
-
-
-void ZCone::setQuotientLatticeBasis(ZMatrix const "ientLatticeBasis_)
-{
- cachedQuotientLatticeBasis=quotientLatticeBasis_;
- hasQuotientLatticeBasisBeenCached=true;
-}
-
-
ZMatrix ZCone::quotientLatticeBasis()const
{
// assert(isInStateMinimum(1));// Implied equations must have been computed in order to know the span of the cone
@@ -1373,16 +1352,26 @@ ZMatrix ZCone::getEquations()const
ZMatrix ZCone::generatorsOfSpan()const
{
+ if(haveGeneratorsOfSpanBeenCached)
+ return cachedGeneratorsOfSpan;
+
ensureStateAsMinimum(1);
QMatrix l=ZToQMatrix(equations);
- return QToZMatrixPrimitive(l.reduceAndComputeKernel());
+ cachedGeneratorsOfSpan=QToZMatrixPrimitive(l.reduceAndComputeKernel());
+ haveGeneratorsOfSpanBeenCached=true;
+ return cachedGeneratorsOfSpan;
}
ZMatrix ZCone::generatorsOfLinealitySpace()const
{
+ if(haveGeneratorsOfLinealitySpaceBeenCached)
+ return cachedGeneratorsOfLinealitySpace;
+
QMatrix l=ZToQMatrix(combineOnTop(inequalities,equations));
- return QToZMatrixPrimitive(l.reduceAndComputeKernel());
+ cachedGeneratorsOfLinealitySpace=QToZMatrixPrimitive(l.reduceAndComputeKernel());
+ haveGeneratorsOfLinealitySpaceBeenCached=true;
+ return cachedGeneratorsOfLinealitySpace;
}
};
diff --git a/gfanlib/gfanlib_zcone.h b/gfanlib/gfanlib_zcone.h
index eeca97c..386ceb4 100644
--- a/gfanlib/gfanlib_zcone.h
+++ b/gfanlib/gfanlib_zcone.h
@@ -107,13 +107,6 @@ class ZCone
*/
mutable bool haveExtremeRaysBeenCached;
- mutable ZMatrix cachedGeneratorsOfSpan;
-/**
- * If this true it means that cachedGeneratorsOfSpan contains
- * the generators of the span as found by generatorsOfSpan().
- */
- mutable bool haveGeneratorsOfSpanBeenCached;
-
mutable ZMatrix cachedGeneratorsOfLinealitySpace;
/**
* If true it means that cachedGeneratorsOfLinealitySpace contains
@@ -121,12 +114,12 @@ class ZCone
*/
mutable bool haveGeneratorsOfLinealitySpaceBeenCached;
- mutable ZMatrix cachedQuotientLatticeBasis;
+ mutable ZMatrix cachedGeneratorsOfSpan;
/**
- * If true it means that cachedQuotientLatticeBasis contains
- * the basis of the quotient lattice as found by quotientLatticeBasis().
+ * If this true it means that cachedGeneratorsOfSpan contains
+ * the generators of the span as found by generatorsOfSpan().
*/
- mutable bool hasQuotientLatticeBasisBeenCached;
+ mutable bool haveGeneratorsOfSpanBeenCached;
void ensureStateAsMinimum(int s)const;
@@ -140,9 +133,10 @@ public:
*/
ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, int preassumptions_=PCP_none);
/**
- * Same as above except that cachedExtremeRays may be set. Those are always believed to be right!
+ * Same as above except that additional data may be set. Those are always believed to be right!
+ * No checks for validality will be done!
*/
- ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, ZMatrix const &cachedExtremeRays_, int preassumptions_=PCP_none);
+ ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, ZMatrix const &cachedExtremeRays_, ZMatrix const &cachedGeneratorsOfLinealitySpace_, ZMatrix const &cachedGeneratorsOfSpan_, int preassumptions_=PCP_none);
/**
* Get the multiplicity of the cone.
*/
@@ -159,7 +153,6 @@ public:
* Store a matrix of linear forms in the cone object.
*/
void setLinearForms(ZMatrix const &linearForms_);
-
/**
* Get the inequalities in the description of the cone.
*/
@@ -185,21 +178,11 @@ public:
*/
bool areImpliedEquationsKnown()const{return (state>=1)||(preassumptions&PCP_impliedEquationsKnown);}
/**
- * The following functions return true iff the respective data is cashed.
+ * The following functions return true iff the respective data is cached.
*/
bool areExtremeRaysKnown()const{return haveExtremeRaysBeenCached;}
bool areGeneratorsOfSpanKnown()const{return haveGeneratorsOfSpanBeenCached;}
bool areGeneratorsOfLinealitySpaceKnown()const{return haveGeneratorsOfLinealitySpaceBeenCached;}
- bool isQuotientLatticeBasisKnown()const{return hasQuotientLatticeBasisBeenCached;}
- /**
- * The following functions set the respective data to be the given input.
- * The input will always assumed to be correct, there are no checks.
- * Should it not be correct, future calculations relying on it might break.
- */
- void setExtremeRays(ZMatrix const &extremeRays_);
- void setGeneratorsOfSpan(ZMatrix const &generatorsOfSpan_);
- void setGeneratorsOfLinealitySpace(ZMatrix const &generatorsOfLinealitySpace_);
- void setQuotientLatticeBasis(ZMatrix const "ientLatticeBasis_);
/**
* Takes the cone to a canonical form. After taking cones to canonical form, two cones are the same
* if and only if their matrices of equations and inequalities are the same.
@@ -226,7 +209,7 @@ public:
void findImpliedEquations();
/**
- * Constructor for polyhedral cone with no inequalities or equations. Tthat is, the full space of some dimension.
+ * Constructor for polyhedral cone with no inequalities or equations. That is, the full space of some dimension.
*/
ZCone(int ambientDimension=0);
@@ -234,15 +217,15 @@ public:
* Computes are relative interior point of the cone.
*/
ZVector getRelativeInteriorPoint()const;
- /**
- Assuming that this cone C is in state at least 3 (why not 2?), this routine returns a relative interior point v(C) of C with the following properties:
- 1) v is a function, that is v(C) is found deterministically
- 2) for any angle preserving, lattice preserving and lineality space preserving transformation T of R^n we have that v(T(C))=T(v(C)). This makes it easy to check if two cones in the same fan are equal up to symmetry. Here preserving the lineality space L just means T(L)=L.
- */
+ /**
+ Assuming that this cone C is in state at least 3 (why not 2?), this routine returns a relative interior point v(C) of C with the following properties:
+ 1) v is a function, that is v(C) is found deterministically
+ 2) for any angle preserving, lattice preserving and lineality space preserving transformation T of R^n we have that v(T(C))=T(v(C)). This makes it easy to check if two cones in the same fan are equal up to symmetry. Here preserving the lineality space L just means T(L)=L.
+ */
ZVector getUniquePoint()const;
- /**
- * Takes a list of possible extreme rays and add up those actually contained in the cone.
- */
+ /**
+ * Takes a list of possible extreme rays and add up those actually contained in the cone.
+ */
ZVector getUniquePointFromExtremeRays(ZMatrix const &extremeRays)const;
/**
* Returns the dimension of the ambient space.
@@ -316,7 +299,7 @@ public:
* Returns true iff the PolyhedralCone contains v in its relative interior. False otherwise. The cone must be in state at least 1.
*/
bool containsRelatively(ZVector const &v)const;
- /*
+ /**
* Returns true iff the cone is simplicial. That is, iff the dimension of the cone equals the number of facets.
*/
bool isSimplicial()const;
--
an open source computer algebra system
More information about the debian-science-commits
mailing list