source: git/dyn_modules/callgfanlib/gfan.h @ 8b23bf9

spielwiese
Last change on this file since 8b23bf9 was 58b407, checked in by Hans Schoenemann <hannes@…>, 11 years ago
fix: loading of gfanlib.so, removed HAVE_FANS
  • Property mode set to 100644
File size: 9.4 KB
Line 
1/*
2gfan.h Interface to gfan.cc
3
4Author: monerjan
5*/
6#ifndef GFAN_H
7#define GFAN_H
8
9#include <libpolys/misc/int64vec.h>
10
11#include <setoper.h>
12#include <cdd.h>
13#include <cddmp.h>
14#include <bbfan.h>
15#include <bbcone.h>
16extern int gfanHeuristic;
17
18#ifndef USE_ZFAN
19#define USE_ZFAN
20#endif
21#ifndef USE_ZFAN
22  lists grfan(ideal inputIdeal, int heuristic, bool singleCone);
23#else
24  #include <gfanlib/gfanlib.h>
25  gfan::ZFan *grfan(ideal inputIdeal, int h, bool singleCone);
26#endif
27// lists grcone_by_intvec(ideal inputIdeal);
28
29class facet
30{
31        private:
32                /** \brief Inner normal of the facet, describing it uniquely up to isomorphism */
33                int64vec *fNormal;
34
35                /** \brief An interior point of the facet*/
36                int64vec *interiorPoint;
37
38                /** \brief Universal Cone Number
39                 * The number of the cone the facet belongs to, Set in getConeNormals()
40                 */
41                int UCN;
42
43                /** \brief The codim of the facet
44                 */
45                short codim;
46
47                /** \brief The Groebner basis on the other side of a shared facet
48                 *
49                 * In order not to have to compute the flipped GB twice we store the basis we already get
50                 * when identifying search facets. Thus in the next step of the reverse search we can
51                 * just copy the old cone and update the facet and the gcBasis.
52                 * facet::flibGB is set via facet::setFlipGB() and printed via facet::printFlipGB
53                 */
54                ideal flipGB;           //The Groebner Basis on the other side, computed via gcone::flip
55
56        public:
57                /** \brief Boolean value to indicate whether a facet is flippable or not
58                * This is also used to mark facets that nominally are flippable but which do
59                * not intersect with the positive orthant. This check is done in gcone::getCodim2Normals
60                 */
61                bool isFlippable;       //**flippable facet? */
62                //bool isIncoming;      //Is the facet incoming or outgoing in the reverse search? No longer in use
63                facet *next;            //Pointer to next facet
64                facet *prev;            //Pointer to predecessor. Needed for the SearchList in noRevS
65                facet *codim2Ptr;       //Pointer to (codim-2)-facet. Bit of recursion here ;-)
66                int numCodim2Facets;    //#of (codim-2)-facets of this facet. Set in getCodim2Normals()
67                unsigned numRays;       //Number of spanning rays of the facet
68                ring flipRing;          //the ring on the other side of the facet
69//              int64vec **fRays;
70
71                /** The default constructor. */
72                facet();
73                /** Constructor for lower dimensional faces*/
74                facet(const int &n);
75                /**  The copy constructor */
76                facet(const facet& f);
77                /** A shallow copy of facets*/
78                facet* shallowCopy(const facet& f);
79                void shallowDelete();
80                /** The default destructor */
81                ~facet();
82                /** Comparison operator*/
83//              inline bool operator==(const facet *f,const facet *g);
84                /** \brief Comparison of facets*/
85//              inline bool areEqual(facet *f, facet *g);//Now static
86                /** Stores the facet normal \param int64vec*/
87                inline void setFacetNormal(int64vec *iv);
88                /** Returns the facet normal */
89                inline int64vec *getFacetNormal() const;
90                /** Return a reference to the facet normal*/
91                inline const int64vec *getRef2FacetNormal() const;
92                /** Method to print the facet normal*/
93                inline void printNormal() const;
94                /** Store the flipped GB*/
95                inline void setFlipGB(ideal I);
96                /** Return the flipped GB*/
97                inline ideal getFlipGB();
98                /** Print the flipped GB*/
99                inline void printFlipGB();
100                /** Set the UCN */
101                inline void setUCN(int n);
102                /** \brief Get the UCN
103                 * Returns the UCN iff this != NULL, else -1
104                 */
105                inline int getUCN();
106                /** Store an interior point of the facet */
107                inline void setInteriorPoint(int64vec *iv);
108                inline int64vec *getInteriorPoint();
109                inline const int64vec *getRef2InteriorPoint();
110                /** \brief Debugging function
111                 * prints the facet normal an all (codim-2)-facets that belong to it
112                 */
113                volatile void fDebugPrint();
114                friend class gcone;
115};
116
117
118/**
119 *\brief Implements the cone structure
120 *
121 * A cone is represented by a linked list of facet normals
122 * @see facet
123 */
124
125class gcone
126{
127        private:
128                ideal inputIdeal;       //the original
129                ring baseRing;          //the basering of the cone
130                int64vec *ivIntPt;      //an interior point of the cone
131                int UCN;                //unique number of the cone
132                int pred;               //UCN of the cone this one is derived from
133                static int counter;
134
135        public:
136                /** \brief Pointer to the first facet */
137                facet *facetPtr;        //Will hold the adress of the first facet; set by gcone::getConeNormals
138#ifdef gfanp
139                static float time_getConeNormals;
140                static float time_getCodim2Normals;
141                static float t_getExtremalRays;
142                static float t_ddPolyh;
143                static float time_flip;
144                static float time_flip2;
145                static float t_areEqual;
146                static float t_ffG;
147                static float t_markings;
148                static float t_dd;
149                static float t_kStd;
150                static float time_enqueue;
151                static float time_computeInv;
152                static float t_ddMC;
153                static float t_mI;
154                static float t_iP;
155                static float t_isParallel;
156                static unsigned parallelButNotEqual;
157                static unsigned numberOfFacetChecks;
158#endif
159                /** Matrix to contain the homogeneity/lineality space */
160                static dd_MatrixPtr dd_LinealitySpace;
161                static int lengthOfSearchList;
162                /** Maximum size of the searchlist*/
163                static int maxSize;
164                /** is the ideal homogeneous? */
165                static bool hasHomInput;
166                /** # of variables in the ring */
167                static int numVars;             //#of variables in the ring
168                /** The hilbert function - for the homogeneous case*/
169                static int64vec *hilbertFunction;
170                /** The zero vector. Needed in case of fNormal mismatch*/
171                static int64vec *ivZeroVector;
172
173                /** # of facets of the cone
174                 * This value is set by gcone::getConeNormals
175                 */
176                int numFacets;          //#of facets of the cone
177
178                /**
179                 * At least as a workaround we store the irredundant facets of a matrix here.
180                 * This is needed to compute an interior points of a cone. Note that there
181                 * will be non-flippable facets in it!
182                 */
183                dd_MatrixPtr ddFacets;  //Matrix to store irredundant facets of the cone
184
185                /** Array of intvecs representing the rays of the cone*/
186                int64vec **gcRays;
187                unsigned numRays;       //#rays of the cone
188                /** Contains the Groebner basis of the cone. Is set by gcone::getGB(ideal I)*/
189                ideal gcBasis;          //GB of the cone, set by gcone::getGB();
190                gcone *next;            //Pointer to next cone
191                gcone *prev;
192
193                gcone();
194                gcone(ring r, ideal I);
195                gcone(const gcone& gc, const facet &f);
196                ~gcone();
197                inline int getCounter();
198                inline ring getBaseRing();
199                inline ring getRef2BaseRing();
200                inline void setBaseRing(ring r);
201                inline void setIntPoint(int64vec *iv);
202                inline int64vec *getIntPoint(bool shallow=FALSE);
203                inline void showIntPoint();
204                inline void setNumFacets();
205                inline int getNumFacets();
206                inline int getUCN();
207                inline int getPredUCN();
208                volatile void showFacets(short codim=1);
209//              volatile void showSLA(facet &f);
210//              void idDebugPrint(const ideal &I);
211//              void invPrint(const ideal &I);
212//              bool isMonomial(const ideal &I);
213//              int64vec *ivNeg(const int64vec *iv);
214//              inline int dotProduct(int64vec &iva, int64vec &ivb);
215//              inline int dotProduct(const int64vec &iva, const int64vec &ivb);
216//              inline bool isParallel(const int64vec &a, const int64vec &b);
217                void noRevS(gcone &gcRoot, bool usingIntPoint=FALSE);
218//              inline int intgcd(const int &a, const int &b);
219                void writeConeToFile(const gcone &gc, bool usingIntPoints=FALSE);
220                void readConeFromFile(int gcNum, gcone *gc);
221                int64vec f2M(gcone *gc, facet *f, int n=1);
222//              inline void sortRays(gcone *gc);
223                //The real stuff
224                void getConeNormals(const ideal &I, bool compIntPoint=FALSE);
225                void getCodim2Normals(const gcone &gc);
226                void getExtremalRays(const gcone &gc);
227                void orderRays();
228                void flip(ideal gb, facet *f);
229                void flip2(const ideal &gb, facet *f);
230                void computeInv(const ideal &gb, ideal &inv, const int64vec &f);
231                //poly restOfDiv(poly const &f, ideal const &I); removed with r12286
232                inline ideal ffG(const ideal &H, const ideal &G);
233                inline void getGB(ideal const &inputIdeal);
234                void interiorPoint( dd_MatrixPtr &M, int64vec &iv);//used from flip and optionally from getConeNormals
235//              void interiorPoint2(); //removed Feb 8th, 2010, new method Feb 19th, 2010, again removed Mar 16th, 2010
236                void preprocessInequalities(dd_MatrixPtr &M);
237                ring rCopyAndAddWeight(const ring &r, int64vec *ivw);
238                ring rCopyAndAddWeight2(const ring &, const int64vec *, const int64vec *);
239//              ring rCopyAndChangeWeight(const ring &r, int64vec *ivw);        //NOTE remove
240//              void reverseSearch(gcone *gcAct); //NOTE both removed from r12286
241//              bool isSearchFacet(gcone &gcTmp, facet *testfacet); //NOTE remove
242                void makeInt(const dd_MatrixPtr &M, const int line, int64vec &n);
243//              void normalize();//NOTE REMOVE
244                facet * enqueueNewFacets(facet *f);
245                facet * enqueue2(facet *f);
246//              dd_MatrixPtr facets2Matrix(const gcone &gc);//NOTE remove
247                /** Compute the lineality space Ax=0 and return it as dd_MatrixPtr dd_LinealitySpace*/
248                dd_MatrixPtr computeLinealitySpace();
249                inline bool iv64isStrictlyPositive(const int64vec *);
250                /** Exchange 2 ordertype_a by just 1 */
251                void replaceDouble_ringorder_a_ByASingleOne();
252//              static void gcone::idPrint(ideal &I);
253//              friend class facet;
254};
255lists lprepareResult(gcone *gc, const int n);
256static int64 int64gcd(const int64 &a, const int64 &b);
257static int intgcd(const int &a, const int &b);
258static int dotProduct(const int64vec &iva, const int64vec &ivb);
259static bool isParallel(const int64vec &a, const int64vec &b);
260static int64vec *ivNeg(/*const*/ int64vec *iv);
261static void idDebugPrint(const ideal &I);
262static volatile void showSLA(facet &f);
263static bool isMonomial(const ideal &I);
264static bool ivAreEqual(const int64vec &a, const int64vec &b);
265static bool areEqual2(facet *f, facet *g);
266static bool areEqual( facet *f, facet *g);
267// bool iv64isStrictlyPositive(int64vec *);
268#endif
Note: See TracBrowser for help on using the repository browser.