polylib: types.h Source File

- Main Page
- Classes
- Files

- File List
- File Members

# types.h

Go to the documentation of this file.

    00001 /*
    00002     This file is part of PolyLib.
    00003
    00004     PolyLib is free software: you can redistribute it and/or modify
    00005     it under the terms of the GNU General Public License as published by
    00006     the Free Software Foundation, either version 3 of the License, or
    00007     (at your option) any later version.
    00008
    00009     PolyLib is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00012     GNU General Public License for more details.
    00013
    00014     You should have received a copy of the GNU General Public License
    00015     along with PolyLib.  If not, see <http://www.gnu.org/licenses/>.
    00016 */
    00017
    00018 /* types-polylib.h
    00019      COPYRIGHT
    00020           Both this software and its documentation are
    00021
    00022               Copyright 1993, IRISA /Universite de Rennes I - France
    00023               Copyright 1996,1997,1998, Doran Wilde and Vincent Loechner
    00024               All rights reserved.
    00025
    00026           Permission is granted to copy, use, and distribute
    00027           for any commercial or noncommercial purpose under the terms
    00028           of the GNU General Public license, version 2, June 1991
    00029           (see file : LICENSING).
    00030 */
    00031
    00032 #ifndef _types_polylib_h_
    00033 #define _types_polylib_h_
    00034
    00035 #ifdef GNUMP
    00036 #include<gmp.h>
    00037 #endif
    00038
    00039 #include <limits.h>
    00040
    00041 /*********************** USER DEFINES ******************************/
    00042
    00043 /* first parameter name char.  */
    00044 #define FIRST_PARAMETER_NAME 'P'
    00045
    00046 /******************* END OF USER DEFINES ***************************/
    00047
    00048
    00049 #define PCHAR (FIRST_PARAMETER_NAME-1)
    00050 #define MAXNOOFRAYS 200
    00051
    00052 #if defined(LINEAR_VALUE_IS_LONGLONG)
    00053 #define P_VALUE_FMT "%4lld "
    00054 #elif defined(LINEAR_VALUE_IS_LONG)
    00055 #define P_VALUE_FMT "%4ld "
    00056 #elif defined(LINEAR_VALUE_IS_CHARS)
    00057 #define P_VALUE_FMT "%s "
    00058 #elif defined(LINEAR_VALUE_IS_INT)
    00059 #define P_VALUE_FMT "%4d "
    00060 #else  /* GNUMP */
    00061 #define P_VALUE_FMT "%4s "
    00062 #endif
    00063
    00064 /* Used in lower_upper_bounds */
    00065 #define LB_INFINITY 1
    00066 #define UB_INFINITY 2
    00067
    00068 /* MSB, TOP, and NEXT are defined over integer type, not on value type */
    00069 /* Put a one in the most significant bit of an int (portable) */
    00070 #define MSB ((unsigned)(((unsigned)1)<<(sizeof(int)*8-1)))
    00071
    00072 /* Largest representable positive number */
    00073 #define TOP ((int)(MSB-1))
    00074
    00075 /* Right shift the one bit in b and increment j if the last bit in b is one */
    00076 #define NEXT(j,b) { if (!((b)>>=1)) { (b)=MSB; (j)++; } }
    00077
    00078 /* Status of last Polyhedron operation */
    00079 extern int Pol_status;
    00080
    00081 #define POL_HIGH_BIT    (UINT_MAX - (UINT_MAX >> 1))
    00082 #define POL_NO_DUAL     (POL_HIGH_BIT | 0x0001)
    00083 #define POL_INTEGER     (POL_HIGH_BIT | 0x0002)
    00084 #define POL_ISSET(flags,f)  ((flags & f) == f)
    00085
    00086 typedef struct  {
    00087   unsigned Size;
    00088   Value *p;
    00089 } Vector;
    00090
    00091 typedef struct matrix {
    00092   unsigned NbRows, NbColumns;
    00093   Value **p;
    00094   Value *p_Init;
    00095   int p_Init_size;      /* needed to free the memory allocated by mpz_init */
    00096 } Matrix;
    00097
    00098 /* Macros to init/set/clear/test flags. */
    00099 #define FL_INIT(l, f)   (l) = (f)               /* Specific flags location. */
    00100 #define FL_SET(l, f)    ((l) |= (f))
    00101 #define FL_CLR(l, f)    ((l) &= ~(f))
    00102 #define FL_ISSET(l, f)  ((l) & (f))
    00103
    00104 #define F_INIT(p, f)    FL_INIT((p)->flags, f)  /* Structure element flags. */
    00105 #define F_SET(p, f)     FL_SET((p)->flags, f)
    00106 #define F_CLR(p, f)     FL_CLR((p)->flags, f)
    00107 #define F_ISSET(p, f)   FL_ISSET((p)->flags, f)
    00108
    00109 typedef struct polyhedron {
    00110   unsigned Dimension, NbConstraints, NbRays, NbEq, NbBid;
    00111   Value **Constraint;
    00112   Value **Ray;
    00113   Value *p_Init;
    00114   int p_Init_size;
    00115   struct polyhedron *next;
    00116 #define    POL_INEQUALITIES     0x00000001
    00117 #define    POL_FACETS           0x00000002
    00118 #define    POL_POINTS           0x00000004
    00119 #define    POL_VERTICES         0x00000008
    00120 /* The flags field contains "valid" information,
    00121  * i.e., the structure was created by PolyLib.
    00122  */
    00123 #define    POL_VALID            0x00000010
    00124   unsigned flags;
    00125 } Polyhedron;
    00126
    00127 typedef struct interval {
    00128   Value MaxN, MaxD;
    00129   Value MinN, MinD;
    00130   int MaxI, MinI;
    00131 } Interval;
    00132
    00133 /* Test whether P is an empty polyhedron */
    00134 #define emptyQ(P)                                                       \
    00135         ((F_ISSET(P, POL_INEQUALITIES) && P->NbEq > P->Dimension) ||    \
    00136          (F_ISSET(P, POL_POINTS) && P->NbRays == 0))
    00137
    00138 /* Test whether P is a universe polyheron */
    00139 #define universeQ(P) (P->Dimension==P->NbBid)
    00140
    00141 typedef struct _Param_Vertex {
    00142   Matrix *Vertex; /* Each row is a coordinate of the vertex. The first  */
    00143                   /* "m" values of each row are the coefficients of the */
    00144                   /* parameters. The (m+1)th value is the constant, the */
    00145                   /* The (m+2)th value is the common denominator.       */
    00146   Matrix *Domain; /* Constraints on parameters (in Polyhedral format)   */
    00147   unsigned *Facets; /* Bit array of facets defining the vertex.         */
    00148   struct _Param_Vertex *next;          /* Pointer to the next structure */
    00149 } Param_Vertices;
    00150
    00151 typedef struct _Param_Domain {
    00152   unsigned *F;         /* Bit array of faces */
    00153   Polyhedron *Domain;  /* Pointer to Domain (constraints on parameters) */
    00154   struct _Param_Domain *next; /* Pointer to the next structure  */
    00155 } Param_Domain;
    00156
    00157 typedef struct _Param_Polyhedron {
    00158         int nbV;            /* Number of parameterized vertices            */
    00159         Param_Vertices *V;  /* Pointer to the list of parameteric vertices */
    00160         Param_Domain *D;    /* Pointer to the list of validity domains     */
    00161         Matrix *Constraints;/* Constraints referred to by V->Facets        */
    00162         Matrix *Rays;        /* Lines/rays (non parametric)                 */
    00163 } Param_Polyhedron;
    00164
    00165 #define FORALL_PVertex_in_ParamPolyhedron(_V, _D, _P)   \
    00166 {     int _i, _ix;                                   \
    00167       unsigned _bx;                                  \
    00168       for( _i=0, _ix=0, _bx=MSB, _V=_P->V ;            \
    00169            _V && (_i<_P->nbV) ; _i++, _V=_V->next )      \
    00170       {       if (_D->F[_ix] & _bx)                   \
    00171               {
    00172
    00173 #define END_FORALL_PVertex_in_ParamPolyhedron  \
    00174               }                                \
    00175               NEXT(_ix, _bx);                  \
    00176       }                                        \
    00177 }
    00178
    00179 /* Data structures for pseudo-polynomial */
    00180
    00181 typedef enum { polynomial, periodic, evector } enode_type;
    00182
    00183 #ifdef CLN
    00184 #define POLY_UNION_OR_STRUCT struct
    00185 #else
    00186 #define POLY_UNION_OR_STRUCT union
    00187 #endif
    00188
    00189 typedef struct _evalue {
    00190   Value d;              /* denominator */
    00191   POLY_UNION_OR_STRUCT {
    00192     Value n;            /* numerator (if denominator != 0) */
    00193     struct _enode *p;   /* pointer   (if denominator == 0) */
    00194   } x;
    00195 } evalue;
    00196
    00197 typedef struct _enode {
    00198   enode_type type;      /* polynomial or periodic or evector */
    00199   int size;             /* number of attached pointers */
    00200   int pos;              /* parameter position */
    00201   evalue arr[1];        /* array of rational/pointer */
    00202 } enode;
    00203
    00204 typedef struct _enumeration {
    00205
    00206   Polyhedron *ValidityDomain;    /* contraints on the parameters     */
    00207   evalue EP;                     /* dimension = combined space       */
    00208   struct _enumeration *next;     /* Ehrhart Polynomial, corresponding
    00209                                     to parameter values inside the
    00210                                     domain ValidityDomain below      */
    00211 } Enumeration;
    00212
    00213 /*-----------------------------Example Usage------------------------------*/
    00214 /* enode *e                                                               */
    00215 /*     e->type = polynomial     e->type = periodic   e->type = evector    */
    00216 /*     e->size = degree+1       e->size = period     e->size = length     */
    00217 /*     e->pos  = [1..nb_param]                                            */
    00218 /*     e->arr[i].d = denominator (Value)                                  */
    00219 /*     e->arr[i].x.p = pointer to another enode (if denominator is zero)  */
    00220 /*     e->arr[i].x.n = numerator (Value) (if denominator is non-zero)     */
    00221 /*------------------------------------------------------------------------*/
    00222
    00223 /*------------------------------------------------------------------------*/
    00224 /* This representation has the following advantages:                      */
    00225 /*   -- its dynamic, it can grow/shrink easily                            */
    00226 /*   -- it is easy to evaluate for a given context (values of parameters) */
    00227 /*   -- it allows pseudo-polynomial to be reduced with rules              */
    00228 /*   -- it can be constructed recursively                                 */
    00229 /*------------------------------------------------------------------------*/
    00230
    00231 /* *********************** |Represnting Z-Polyhedron| ******************* */
    00232
    00233
    00234 typedef enum {False = 0, True = 1} Bool;
    00235 typedef Matrix Lattice;
    00236 typedef struct LatticeUnion {
    00237   Lattice *M;
    00238   struct LatticeUnion *next;
    00239 } LatticeUnion;
    00240
    00241 typedef struct ZPolyhedron {
    00242   Lattice *Lat ;
    00243   Polyhedron *P;
    00244   struct ZPolyhedron *next;
    00245 } ZPolyhedron;
    00246
    00247 #ifndef FOREVER
    00248 #define FOREVER for(;;)
    00249 #endif
    00250
    00251 #endif /* _types_polylib_h_ */