[SCM] an open source computer algebra system branch, cleanedupstream, updated. 6125e540ca6d66c307958938a9d53b245507c323

Bernhard R. Link brlink at debian.org
Tue Apr 24 15:54:17 UTC 2012


The following commit has been merged in the cleanedupstream branch:
commit 5c7cd22bbd4340c1ce3bd4e0599d4a3eca5702d7
Author: Yue Ren <ren at mathematik.uni-kl.de>
Date:   Tue Mar 6 13:13:16 2012 +0100

    new+chg: gfanlib caches lineality space and span, lineality and span will be given to polymake

diff --git a/callpolymake/polymake.cc b/callpolymake/polymake.cc
index 434f633..5acd7cb 100755
--- a/callpolymake/polymake.cc
+++ b/callpolymake/polymake.cc
@@ -257,8 +257,8 @@ gfan::ZCone PmPolytope2ZPolytope (polymake::perl::Object* pp)
     polymake::Matrix<polymake::Rational> vertrational = pp->give("VERTICES");
 
     gfan::ZMatrix zv, zw, zx;
-    if (ineqrational.cols()!=0)
-    {
+    if (ineqrational.cols()!=0)  // the following branching statements are to cover the cases
+    {                            // when polymake returns an empty matrix
       polymake::Matrix<polymake::Integer> ineqinteger = polymake::polytope::multiply_by_common_denominator(ineqrational);
       zv = PmMatrixInteger2GfZMatrix(&ineqinteger);
     }
@@ -308,25 +308,44 @@ gfan::ZFan PmFan2ZFan (polymake::perl::Object* pf)
 
 polymake::perl::Object ZCone2PmCone (gfan::ZCone* zc)
 {
-  gfan::ZMatrix zm1 = zc->extremeRays();
-  polymake::Matrix<polymake::Integer> extremeRays = GfZMatrix2PmMatrixInteger(&zm1);
-  gfan::ZMatrix zm2 = zc->generatorsOfLinealitySpace();
-  polymake::Matrix<polymake::Integer> lineality = GfZMatrix2PmMatrixInteger(&zm2);
+  polymake::perl::Object gc("Cone<Rational>");
+
+  gfan::ZMatrix inequalities = zc->getInequalities();
+  gc.take("INEQUALITIES") << GfZMatrix2PmMatrixInteger(&inequalities);
+
+  gfan::ZMatrix equations = zc->getEquations();
+  gc.take("EQUATIONS") << GfZMatrix2PmMatrixInteger(&equations);
 
-  polymake::perl::Object gc("Cone");
-  gc.take("INPUT_RAYS") << extremeRays;
-  gc.take("INPUT_LINEALITY") << lineality;
+  if(zc->areExtremeRaysKnown())
+    {  
+      gfan::ZMatrix extremeRays = zc->extremeRays();
+      gc.take("INPUT_RAYS") << GfZMatrix2PmMatrixInteger(&extremeRays);
+    }
+
+  if(zc->areGeneratorsOfLinealitySpaceKnown())
+    {
+      gfan::ZMatrix lineality = zc->generatorsOfLinealitySpace();
+      gc.take("INPUT_LINEALITY") << GfZMatrix2PmMatrixInteger(&lineality);
+    }
 
   return gc;
 }
 
 polymake::perl::Object ZPolytope2PmPolytope (gfan::ZCone* zc)
 {
-  gfan::ZMatrix zm = zc->extremeRays();
-  polymake::Matrix<polymake::Integer> pm = GfZMatrix2PmMatrixInteger(&zm);
-
   polymake::perl::Object pp("Polytope<Rational>");
-  pp.take("VERTICES") << pm;
+
+  gfan::ZMatrix inequalities = zc->getInequalities();
+  gc.take("INEQUALITIES") << GfZMatrix2PmMatrixInteger(&inequalities);
+
+  gfan::ZMatrix equations = zc->getEquations();
+  gc.take("EQUATIONS") << GfZMatrix2PmMatrixInteger(&equations);
+
+  if(zc->areExtremeRays())
+    {
+      gfan::ZMatrix vertices = zc->extremeRays();
+      pp.take("VERTICES") << GfZMatrix2PmMatrixInteger(&zm);
+    }
 
   return pp;
 }
@@ -1934,7 +1953,7 @@ BOOLEAN PMpolytopeViaVertices(leftv res, leftv args)
       }
     }
     else
-      pp.take("POINTS") << pmpoints;
+      pp.take("POINTS") << pmpoints;              // by default, we assume that matrix may contain non-vertices
     
     gfan::ZCone* zp = new gfan::ZCone(PmPolytope2ZPolytope(&pp));
     res->rtyp = polytopeID;
diff --git a/gfanlib/gfanlib_zcone.cpp b/gfanlib/gfanlib_zcone.cpp
index 5a59c20..e77e7f8 100644
--- a/gfanlib/gfanlib_zcone.cpp
+++ b/gfanlib/gfanlib_zcone.cpp
@@ -737,6 +737,9 @@ ZCone::ZCone(int ambientDimension):
   preassumptions(PCP_impliedEquationsKnown|PCP_facetsKnown),
   multiplicity(1),
   haveExtremeRaysBeenCached(false),
+  haveGeneratorsOfSpanBeenCached(false),
+  haveGeneratorsOfLinealitySpaceBeenCached(false),
+  hasQuotientLatticeBasisBeenCached(false),
   linearForms(ZMatrix(0,ambientDimension))
 {
 }
@@ -749,6 +752,9 @@ ZCone::ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, int preass
   preassumptions(preassumptions_),
   multiplicity(1),
   haveExtremeRaysBeenCached(false),
+  haveGeneratorsOfSpanBeenCached(false),
+  haveGeneratorsOfLinealitySpaceBeenCached(false),
+  hasQuotientLatticeBasisBeenCached(false),
   n(inequalities_.getWidth()),
   linearForms(ZMatrix(0,inequalities_.getWidth()))
   {
@@ -765,6 +771,9 @@ ZCone::ZCone(ZMatrix const &inequalities_, ZMatrix const &equations_, ZMatrix co
   preassumptions(preassumptions_),
   multiplicity(1),
   haveExtremeRaysBeenCached(true),
+  haveGeneratorsOfSpanBeenCached(false),
+  haveGeneratorsOfLinealitySpaceBeenCached(false),
+  hasQuotientLatticeBasisBeenCached(false),
   n(inequalities_.getWidth()),
   linearForms(ZMatrix(0,inequalities_.getWidth()))
   {
@@ -1052,7 +1061,7 @@ ZCone ZCone::negated()const
 }
 
 
-ZMatrix ZCone::extremeRays(ZMatrix const *generatorsOfLinealitySpace)const
+ZMatrix ZCone::extremeRays(ZMatrix const *generatorsOfLinealitySpace, bool shouldCache)const
 {
 //  assert((dimension()==ambientDimension()) || (state>=3));
   if(dimension()!=ambientDimension())
@@ -1120,6 +1129,11 @@ ZMatrix ZCone::extremeRays(ZMatrix const *generatorsOfLinealitySpace)const
             QMatrix temp=ZToQMatrix(combineOnTop(equations,*generatorsOfLinealitySpace));
             thePrimitiveVector=QToZVectorPrimitive(temp.reduceAndComputeVectorInKernel());
           }
+          else if(this->haveGeneratorsOfLinealitySpaceBeenCached)
+          {
+            QMatrix temp=ZToQMatrix(combineOnTop(equations,cachedGeneratorsOfLinealitySpace));
+            thePrimitiveVector=QToZVectorPrimitive(temp.reduceAndComputeVectorInKernel());
+          }
           else
           {
             QMatrix linealitySpaceOrth=ZToQMatrix(combineOnTop(this->equations,inequalities));
@@ -1131,9 +1145,12 @@ ZMatrix ZCone::extremeRays(ZMatrix const *generatorsOfLinealitySpace)const
           if(!contains(thePrimitiveVector))thePrimitiveVector=-thePrimitiveVector;
           ret.appendRow(thePrimitiveVector);
     }
-
-  cachedExtremeRays=ret;
-  haveExtremeRaysBeenCached=true;
+  
+  if (shouldCache)
+  {
+    cachedExtremeRays=ret;
+    haveExtremeRaysBeenCached=true;
+  }
 
   return ret;
 }
@@ -1163,6 +1180,34 @@ 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 &quotientLatticeBasis_)
+{
+  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
diff --git a/gfanlib/gfanlib_zcone.h b/gfanlib/gfanlib_zcone.h
index d8f64b6..eeca97c 100644
--- a/gfanlib/gfanlib_zcone.h
+++ b/gfanlib/gfanlib_zcone.h
@@ -18,7 +18,7 @@ A PolyhedralCone is represented by linear inequalities and equations. The inequa
 and stored as the rows of a matrix and the equations are stored as rows of a second matrix.
 
 A cone can be in one of the four states:
-0) Nothing has been done to remove redundancies. This is the initial state.
+0) Nothing has been done to remove redundancies. This is the initial state
 1) A basis for the true, implied equations space has been computed. This means that
    the implied equations have been computed. In particular the dimension of the cone is known.
 2) Redundant inequalities have been computed and have been eliminated.
@@ -100,11 +100,34 @@ class ZCone
   ZMatrix linearForms;
   mutable ZMatrix inequalities;
   mutable ZMatrix equations;
+
   mutable ZMatrix cachedExtremeRays;
 /**
- * If this bool is true it means that cachedExtremeRays contains the extreme rays as found by extremeRays().
+ * If this true it means that cachedExtremeRays contains the extreme rays as found by extremeRays().
  */
   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 
+ * the generators of the lineality space as found by generatorsOfLinealitySpace().
+ */
+  mutable bool haveGeneratorsOfLinealitySpaceBeenCached;
+
+  mutable ZMatrix cachedQuotientLatticeBasis;
+/**
+ * If true it means that cachedQuotientLatticeBasis contains 
+ * the basis of the quotient lattice as found by quotientLatticeBasis().
+ */
+  mutable bool hasQuotientLatticeBasisBeenCached;
+
   void ensureStateAsMinimum(int s)const;
 
   bool isInStateMinimum(int s)const;
@@ -161,7 +184,22 @@ public:
       * Returns true iff it is known that the set of equations span the space of implied equations of the description.
       */
      bool areImpliedEquationsKnown()const{return (state>=1)||(preassumptions&PCP_impliedEquationsKnown);}
-
+     /**
+      * The following functions return true iff the respective data is cashed.
+      */
+     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 &quotientLatticeBasis_);
      /**
       * 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.
@@ -308,7 +346,7 @@ public:
       * If generators for the lineality space are known, they can be supplied. This can
       * speed up computations a lot.
       */
-    ZMatrix extremeRays(ZMatrix const *generatorsOfLinealitySpace=0)const;
+     ZMatrix extremeRays(ZMatrix const *generatorsOfLinealitySpace=0, bool b=true)const;
     /**
        The cone defines two lattices, namely Z^n intersected with the
        span of the cone and Z^n intersected with the lineality space of

-- 
an open source computer algebra system



More information about the debian-science-commits mailing list