polylib 7.01
types.h
Go to the documentation of this file.
1/* types-polylib.h
2 COPYRIGHT
3 Both this software and its documentation are
4
5 Copyright 1993, IRISA /Universite de Rennes I - France
6 Copyright 1996,1997,1998, Doran Wilde and Vincent Loechner
7 All rights reserved.
8
9*/
10
11#ifndef _types_polylib_h_
12#define _types_polylib_h_
13
14#ifdef GNUMP
15#include <gmp.h>
16#endif
17
18#include <limits.h>
19
20/*********************** USER DEFINES ******************************/
21
22/* first parameter name char. */
23#define FIRST_PARAMETER_NAME 'P'
24
25/******************* END OF USER DEFINES ***************************/
26
27
28/* ******************** global defines ************************* */
29
30#define PCHAR (FIRST_PARAMETER_NAME - 1)
31#define MAXNOOFRAYS 200
32
33#if defined(LINEAR_VALUE_IS_LONGLONG)
34#define P_VALUE_FMT "%4lld "
35#elif defined(LINEAR_VALUE_IS_LONG)
36#define P_VALUE_FMT "%4ld "
37#elif defined(LINEAR_VALUE_IS_CHARS)
38#define P_VALUE_FMT "%s "
39#elif defined(LINEAR_VALUE_IS_INT)
40#define P_VALUE_FMT "%4d "
41#else /* GNUMP */
42#define P_VALUE_FMT "%4s "
43#endif
44
45typedef enum { False = 0, True = 1 } Bool;
46
47#ifndef FOREVER
48#define FOREVER for (;;)
49#endif
50
51/* Used in lower_upper_bounds */
52#define LB_INFINITY 1
53#define UB_INFINITY 2
54
55/* MSB, TOP, and NEXT are defined over integer type, not on value type */
56/* Put a one in the most significant bit of an int (portable) */
57#define MSB ((unsigned)(((unsigned)1) << (sizeof(int) * 8 - 1)))
58
59/* Largest representable positive number */
60#define TOP ((int)(MSB - 1))
61
62/* Right shift the one bit in b and increment j if the last bit in b is one */
63#define NEXT(j, b) \
64 { \
65 if (!((b) >>= 1)) { \
66 (b) = MSB; \
67 (j)++; \
68 } \
69 }
70
71/* Status of last Polyhedron operation */
72extern int Pol_status;
73
74#define POL_HIGH_BIT (UINT_MAX - (UINT_MAX >> 1))
75#define POL_NO_DUAL (POL_HIGH_BIT | 0x0001)
76#define POL_INTEGER (POL_HIGH_BIT | 0x0002)
77#define POL_ISSET(flags, f) ((flags & f) == f)
78
79
80/* ******************** vectors and matrices ************************* */
81
82typedef struct {
83 unsigned Size;
85 int p_Init_size; /* initial allocated size that will be freed */
86} Vector;
87
88typedef struct matrix {
89 unsigned NbRows, NbColumns;
92 int p_Init_size; /* needed to free the memory allocated by mpz_init */
94
95
96/* *********************** polyhedra **************************** */
97
98/* Macros to init/set/clear/test flags. */
99#define FL_INIT(l, f) (l) = (f) /* Specific flags location. */
100#define FL_SET(l, f) ((l) |= (f))
101#define FL_CLR(l, f) ((l) &= ~(f))
102#define FL_ISSET(l, f) ((l) & (f))
103
104#define F_INIT(p, f) FL_INIT((p)->flags, f) /* Structure element flags. */
105#define F_SET(p, f) FL_SET((p)->flags, f)
106#define F_CLR(p, f) FL_CLR((p)->flags, f)
107#define F_ISSET(p, f) FL_ISSET((p)->flags, f)
108
109typedef struct polyhedron {
116#define POL_INEQUALITIES 0x00000001
117#define POL_FACETS 0x00000002
118#define POL_POINTS 0x00000004
119#define POL_VERTICES 0x00000008
120/* The flags field contains "valid" information,
121 * i.e., the structure was created by PolyLib.
122 */
123#define POL_VALID 0x00000010
124 unsigned flags;
126
127typedef struct interval {
130 int MaxI, MinI;
132
133/* Test whether P is an empty polyhedron */
134#define emptyQ(P) \
135 ((F_ISSET(P, POL_INEQUALITIES) && P->NbEq > P->Dimension) || \
136 (F_ISSET(P, POL_POINTS) && P->NbRays == 0))
137
138/* Test whether P is a universe polyhedron */
139#define universeQ(P) (P->Dimension == P->NbBid)
140
141
142/* ******************** parametric polyhedra ************************* */
143
144typedef struct _Param_Vertex {
145 Matrix *Vertex; /* Each row is a coordinate of the vertex. The first */
146 /* "m" values of each row are the coefficients of the */
147 /* parameters. The (m+1)th value is the constant, the */
148 /* The (m+2)th value is the common denominator. */
149 Matrix *Domain; /* Constraints on parameters (in Polyhedral format) */
150 unsigned *Facets; /* Bit array of facets defining the vertex. */
151 struct _Param_Vertex *next; /* Pointer to the next structure */
153
154typedef struct _Param_Domain {
155 unsigned *F; /* Bit array of faces */
156 Polyhedron *Domain; /* Pointer to Domain (constraints on parameters) */
157 struct _Param_Domain *next; /* Pointer to the next structure */
159
160typedef struct _Param_Polyhedron {
161 int nbV; /* Number of parameterized vertices */
162 Param_Vertices *V; /* Pointer to the list of parameteric vertices */
163 Param_Domain *D; /* Pointer to the list of validity domains */
164 Matrix *Constraints; /* Constraints referred to by V->Facets */
165 Matrix *Rays; /* Lines/rays (non parametric) */
167
168#define FORALL_PVertex_in_ParamPolyhedron(_V, _D, _P) \
169 { \
170 int _i, _ix; \
171 unsigned _bx; \
172 for (_i = 0, _ix = 0, _bx = MSB, _V = _P->V; _V && (_i < _P->nbV); \
173 _i++, _V = _V->next) { \
174 if (_D->F[_ix] & _bx) {
175
176#define END_FORALL_PVertex_in_ParamPolyhedron \
177 } \
178 NEXT(_ix, _bx); \
179 } \
180 }
181
182
183/* ******************** pseudo-polynomials ************************* */
184
186
187#ifdef CLN
188#define POLY_UNION_OR_STRUCT struct
189#else
190#define POLY_UNION_OR_STRUCT union
191#endif
192
193typedef struct _evalue {
194 Value d; /* denominator */
196 Value n; /* numerator (if denominator != 0) */
197 struct _enode *p; /* pointer (if denominator == 0) */
198 }
201
202typedef struct _enode {
203 enode_type type; /* polynomial or periodic or evector */
204 int size; /* number of attached pointers */
205 int pos; /* parameter position */
206 evalue arr[1]; /* array of rational/pointer */
208
209typedef struct _enumeration {
210 Polyhedron *ValidityDomain; /* contraints on the parameters */
211 evalue EP; /* dimension = combined space */
212 struct _enumeration *next; /* Ehrhart Polynomial, corresponding
213 to parameter values inside the
214 domain ValidityDomain below */
216
217/*-----------------------------Example Usage------------------------------*/
218/* enode *e */
219/* e->type = polynomial e->type = periodic e->type = evector */
220/* e->size = degree+1 e->size = period e->size = length */
221/* e->pos = [1..nb_param] */
222/* e->arr[i].d = denominator (Value) */
223/* e->arr[i].x.p = pointer to another enode (if denominator is zero) */
224/* e->arr[i].x.n = numerator (Value) (if denominator is non-zero) */
225/*------------------------------------------------------------------------*/
226
227/*------------------------------------------------------------------------*/
228/* This representation has the following advantages: */
229/* -- its dynamic, it can grow/shrink easily */
230/* -- it is easy to evaluate for a given context (values of parameters) */
231/* -- it allows pseudo-polynomial to be reduced with rules */
232/* -- it can be constructed recursively */
233/*------------------------------------------------------------------------*/
234
235
236/* *********************** LBLs **************************** */
237// union of lattices (or affine functions):
238typedef struct lattice_union {
242
243// The same LBL structure is used to represent a single LBL or a union of LBLs
244// as the image of a polyhedral domain ('P') by an affine function ('Lat')
245typedef struct lbl {
248 struct lbl *next;
250
251
252#endif /* _types_polylib_h_ */
int Value
Definition: arithmetique.h:294
static int n
Definition: polyparam.c:278
Definition: types.h:82
unsigned Size
Definition: types.h:83
int p_Init_size
Definition: types.h:85
Value * p
Definition: types.h:84
struct _Param_Domain * next
Definition: types.h:157
Polyhedron * Domain
Definition: types.h:156
unsigned * F
Definition: types.h:155
Param_Vertices * V
Definition: types.h:162
Param_Domain * D
Definition: types.h:163
Matrix * Rays
Definition: types.h:165
Matrix * Constraints
Definition: types.h:164
Matrix * Domain
Definition: types.h:149
struct _Param_Vertex * next
Definition: types.h:151
Matrix * Vertex
Definition: types.h:145
unsigned * Facets
Definition: types.h:150
Definition: types.h:202
int pos
Definition: types.h:205
evalue arr[1]
Definition: types.h:206
enode_type type
Definition: types.h:203
int size
Definition: types.h:204
Polyhedron * ValidityDomain
Definition: types.h:210
evalue EP
Definition: types.h:211
struct _enumeration * next
Definition: types.h:212
Definition: types.h:193
POLY_UNION_OR_STRUCT
Definition: types.h:195
struct _enode * p
Definition: types.h:197
Value d
Definition: types.h:194
Value MinD
Definition: types.h:129
int MaxI
Definition: types.h:130
Value MaxN
Definition: types.h:128
int MinI
Definition: types.h:130
Value MinN
Definition: types.h:129
Value MaxD
Definition: types.h:128
Matrix * M
Definition: types.h:239
struct lattice_union * next
Definition: types.h:240
Definition: types.h:245
Matrix * Lat
Definition: types.h:246
Polyhedron * P
Definition: types.h:247
struct lbl * next
Definition: types.h:248
Definition: types.h:88
unsigned NbRows
Definition: types.h:89
Value ** p
Definition: types.h:90
int p_Init_size
Definition: types.h:92
unsigned NbColumns
Definition: types.h:89
Value * p_Init
Definition: types.h:91
Value ** Ray
Definition: types.h:112
unsigned Dimension
Definition: types.h:110
unsigned NbConstraints
Definition: types.h:110
Value * p_Init
Definition: types.h:113
unsigned NbRays
Definition: types.h:110
unsigned NbBid
Definition: types.h:110
struct polyhedron * next
Definition: types.h:115
Value ** Constraint
Definition: types.h:111
unsigned flags
Definition: types.h:124
int p_Init_size
Definition: types.h:114
unsigned NbEq
Definition: types.h:110
enode_type
Definition: types.h:185
@ periodic
Definition: types.h:185
@ polynomial
Definition: types.h:185
@ evector
Definition: types.h:185
struct _Param_Vertex Param_Vertices
struct _Param_Domain Param_Domain
Bool
Definition: types.h:45
@ True
Definition: types.h:45
@ False
Definition: types.h:45
struct _enumeration Enumeration
struct _Param_Polyhedron Param_Polyhedron
struct polyhedron Polyhedron
struct lbl LBL
struct matrix Matrix
int Pol_status
Definition: polyhedron.c:73
struct lattice_union LatticeUnion
struct interval Interval
struct _enode enode
struct _evalue evalue