polylib: types.h Source File

- Main Page
- Classes
- Files

# types.h

Go to the documentation of this file.

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