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
45
typedef
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 */
72
extern
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
82
typedef
struct
{
83
unsigned
Size
;
84
Value
*
p
;
85
int
p_Init_size
;
/* initial allocated size that will be freed */
86
}
Vector
;
87
88
typedef
struct
matrix
{
89
unsigned
NbRows
,
NbColumns
;
90
Value
**
p
;
91
Value
*
p_Init
;
92
int
p_Init_size
;
/* needed to free the memory allocated by mpz_init */
93
}
Matrix
;
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
109
typedef
struct
polyhedron
{
110
unsigned
Dimension
,
NbConstraints
,
NbRays
,
NbEq
,
NbBid
;
111
Value
**
Constraint
;
112
Value
**
Ray
;
113
Value
*
p_Init
;
114
int
p_Init_size
;
115
struct
polyhedron
*
next
;
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
;
125
}
Polyhedron
;
126
127
typedef
struct
interval
{
128
Value
MaxN
,
MaxD
;
129
Value
MinN
,
MinD
;
130
int
MaxI
,
MinI
;
131
}
Interval
;
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
144
typedef
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 */
152
}
Param_Vertices
;
153
154
typedef
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 */
158
}
Param_Domain
;
159
160
typedef
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) */
166
}
Param_Polyhedron
;
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
185
typedef
enum
{
polynomial
,
periodic
,
evector
}
enode_type
;
186
187
#ifdef CLN
188
#define POLY_UNION_OR_STRUCT struct
189
#else
190
#define POLY_UNION_OR_STRUCT union
191
#endif
192
193
typedef
struct
_evalue
{
194
Value
d
;
/* denominator */
195
POLY_UNION_OR_STRUCT
{
196
Value
n
;
/* numerator (if denominator != 0) */
197
struct
_enode
*
p
;
/* pointer (if denominator == 0) */
198
}
199
x
;
200
}
evalue
;
201
202
typedef
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 */
207
}
enode
;
208
209
typedef
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 */
215
}
Enumeration
;
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):
238
typedef
struct
lattice_union
{
239
Matrix
*
M
;
240
struct
lattice_union
*
next
;
241
}
LatticeUnion
;
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')
245
typedef
struct
lbl
{
246
Matrix
*
Lat
;
247
Polyhedron
*
P
;
248
struct
lbl
*
next
;
249
}
LBL
;
250
251
252
#endif
/* _types_polylib_h_ */
Value
int Value
Definition:
arithmetique.h:294
n
static int n
Definition:
polyparam.c:278
Vector
Definition:
types.h:82
Vector::Size
unsigned Size
Definition:
types.h:83
Vector::p_Init_size
int p_Init_size
Definition:
types.h:85
Vector::p
Value * p
Definition:
types.h:84
_Param_Domain
Definition:
types.h:154
_Param_Domain::next
struct _Param_Domain * next
Definition:
types.h:157
_Param_Domain::Domain
Polyhedron * Domain
Definition:
types.h:156
_Param_Domain::F
unsigned * F
Definition:
types.h:155
_Param_Polyhedron
Definition:
types.h:160
_Param_Polyhedron::V
Param_Vertices * V
Definition:
types.h:162
_Param_Polyhedron::D
Param_Domain * D
Definition:
types.h:163
_Param_Polyhedron::Rays
Matrix * Rays
Definition:
types.h:165
_Param_Polyhedron::nbV
int nbV
Definition:
types.h:161
_Param_Polyhedron::Constraints
Matrix * Constraints
Definition:
types.h:164
_Param_Vertex
Definition:
types.h:144
_Param_Vertex::Domain
Matrix * Domain
Definition:
types.h:149
_Param_Vertex::next
struct _Param_Vertex * next
Definition:
types.h:151
_Param_Vertex::Vertex
Matrix * Vertex
Definition:
types.h:145
_Param_Vertex::Facets
unsigned * Facets
Definition:
types.h:150
_enode
Definition:
types.h:202
_enode::pos
int pos
Definition:
types.h:205
_enode::arr
evalue arr[1]
Definition:
types.h:206
_enode::type
enode_type type
Definition:
types.h:203
_enode::size
int size
Definition:
types.h:204
_enumeration
Definition:
types.h:209
_enumeration::ValidityDomain
Polyhedron * ValidityDomain
Definition:
types.h:210
_enumeration::EP
evalue EP
Definition:
types.h:211
_enumeration::next
struct _enumeration * next
Definition:
types.h:212
_evalue
Definition:
types.h:193
_evalue::x
x
Definition:
types.h:199
_evalue::POLY_UNION_OR_STRUCT
POLY_UNION_OR_STRUCT
Definition:
types.h:195
_evalue::p
struct _enode * p
Definition:
types.h:197
_evalue::d
Value d
Definition:
types.h:194
interval
Definition:
types.h:127
interval::MinD
Value MinD
Definition:
types.h:129
interval::MaxI
int MaxI
Definition:
types.h:130
interval::MaxN
Value MaxN
Definition:
types.h:128
interval::MinI
int MinI
Definition:
types.h:130
interval::MinN
Value MinN
Definition:
types.h:129
interval::MaxD
Value MaxD
Definition:
types.h:128
lattice_union
Definition:
types.h:238
lattice_union::M
Matrix * M
Definition:
types.h:239
lattice_union::next
struct lattice_union * next
Definition:
types.h:240
lbl
Definition:
types.h:245
lbl::Lat
Matrix * Lat
Definition:
types.h:246
lbl::P
Polyhedron * P
Definition:
types.h:247
lbl::next
struct lbl * next
Definition:
types.h:248
matrix
Definition:
types.h:88
matrix::NbRows
unsigned NbRows
Definition:
types.h:89
matrix::p
Value ** p
Definition:
types.h:90
matrix::p_Init_size
int p_Init_size
Definition:
types.h:92
matrix::NbColumns
unsigned NbColumns
Definition:
types.h:89
matrix::p_Init
Value * p_Init
Definition:
types.h:91
polyhedron
Definition:
types.h:109
polyhedron::Ray
Value ** Ray
Definition:
types.h:112
polyhedron::Dimension
unsigned Dimension
Definition:
types.h:110
polyhedron::NbConstraints
unsigned NbConstraints
Definition:
types.h:110
polyhedron::p_Init
Value * p_Init
Definition:
types.h:113
polyhedron::NbRays
unsigned NbRays
Definition:
types.h:110
polyhedron::NbBid
unsigned NbBid
Definition:
types.h:110
polyhedron::next
struct polyhedron * next
Definition:
types.h:115
polyhedron::Constraint
Value ** Constraint
Definition:
types.h:111
polyhedron::flags
unsigned flags
Definition:
types.h:124
polyhedron::p_Init_size
int p_Init_size
Definition:
types.h:114
polyhedron::NbEq
unsigned NbEq
Definition:
types.h:110
enode_type
enode_type
Definition:
types.h:185
periodic
@ periodic
Definition:
types.h:185
polynomial
@ polynomial
Definition:
types.h:185
evector
@ evector
Definition:
types.h:185
Param_Vertices
struct _Param_Vertex Param_Vertices
Param_Domain
struct _Param_Domain Param_Domain
Bool
Bool
Definition:
types.h:45
True
@ True
Definition:
types.h:45
False
@ False
Definition:
types.h:45
Enumeration
struct _enumeration Enumeration
Param_Polyhedron
struct _Param_Polyhedron Param_Polyhedron
Polyhedron
struct polyhedron Polyhedron
LBL
struct lbl LBL
Matrix
struct matrix Matrix
Pol_status
int Pol_status
Definition:
polyhedron.c:73
LatticeUnion
struct lattice_union LatticeUnion
Interval
struct interval Interval
enode
struct _enode enode
evalue
struct _evalue evalue
include
polylib
types.h
Generated by
1.9.4