polylib 5.22.8
testehrhart.c
Go to the documentation of this file.
1/***********************************************************************/
2/* Ehrhart V4.20 */
3/* copyright 1997, Doran Wilde */
4/* copyright 1997-2000, Vincent Loechner */
5/***********************************************************************/
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <ctype.h>
10#include <string.h>
11#include <unistd.h>
12#include <assert.h>
13
14#include <polylib/polylib.h>
16#include "config.h"
17
18#define EP_EVALUATION
19
20#ifndef HAVE_GETOPT_H
21#define getopt_long(a,b,c,d,e) getopt(a,b,c)
22#else
23#include <getopt.h>
24struct option options[] = {
25 { "homogenized", no_argument, 0, 'h' },
26 { 0, 0, 0, 0 }
27};
28#endif
29
30#define WS 0
31
32/**
33
34define this to print all constraints on the validity domains if not
35defined, only new constraints (not in validity domain given by the
36user) are printed
37
38*/
39#define EPRINT_ALL_VALIDITY_CONSTRAINTS
40
41/**
42
43The following are mainly for debug purposes. You shouldn't need to
44change anything for daily usage...
45
46*/
47
48/** you may define each macro independently
49<ol>
50<li> #define EDEBUG minimal debug
51<li> #define EDEBUG1 prints enumeration points
52<li> #define EDEBUG11 prints number of points
53<li> #define EDEBUG2 prints domains
54<li> #define EDEBUG21 prints more domains
55<li> #define EDEBUG3 prints systems of equations that are solved
56<li> #define EDEBUG4 prints message for degree reduction
57<li> #define EDEBUG5 prints result before simplification
58<li> #define EDEBUG6 prints domains in Preprocess
59<li> #define EDEBUG61 prints even more in Preprocess
60<li> #define EDEBUG62 prints domains in Preprocess2
61</ol>
62*/
63
64/* #define EDEBUG */ /* minimal debug */
65/* #define EDEBUG1 */ /* prints enumeration points */
66/* #define EDEBUG11 */ /* prints number of points */
67/* #define EDEBUG2 */ /* prints domains */
68/* #define EDEBUG21 */ /* prints more domains */
69/* #define EDEBUG3 */ /* prints systems of equations that are solved */
70/* #define EDEBUG4 */ /* prints message for degree reduction */
71/* #define EDEBUG5 */ /* prints result before simplification */
72/* #define EDEBUG6 */ /* prints domains in Preprocess */
73/* #define EDEBUG61 */ /* prints even more in Preprocess */
74/* #define EDEBUG62 */ /* prints domains in Preprocess2 */
75
76
77/**
78
79 Reduce the degree of resulting polynomials
80
81*/
82#define REDUCE_DEGREE
83
84/**
85
86define this to print one warning message per domain overflow these
87overflows should no longer happen since version 4.20
88
89*/
90#define ALL_OVERFLOW_WARNINGS
91
92/**
93
94EPRINT : print results while computing the ehrhart polynomial. this
95is done by default if you build the executable ehrhart. (If EMAIN is
96defined). Don't define EMAIN here, it is defined when necessary in
97the makefile.
98
99<p>
100
101Notice: you may however define EPRINT without defining EMAIN, but in
102this case, you have to initialize the global variable param_name by
103calling Read_ParamNames before any call to ehrhart. This is NOT
104recommanded, unless you know what you do. EPRINT causes more debug
105messages to be printed.
106
107*/
108/* #define EPRINT */
109
110int main(int argc, char **argv)
111{
112 int i;
113 char str[1024];
114 Matrix *C1, *P1;
115 Polyhedron *C, *P;
116 Enumeration *en;
117 const char **param_name;
118 int c, ind = 0;
119 int hom = 0;
120
121#ifdef EP_EVALUATION
122 Value *p, *tmp;
123 int k;
124#endif
125
126 while ((c = getopt_long(argc, argv, "h", options, &ind)) != -1) {
127 switch (c) {
128 case 'h':
129 hom = 1;
130 break;
131 }
132 }
133
134 P1 = Matrix_Read();
135 C1 = Matrix_Read();
136 if(C1->NbColumns < 2) {
137 fprintf( stderr, "Not enough parameters !\n" );
138 exit(0);
139 }
140 if (hom) {
141 Matrix *C2, *P2;
142 P2 = AddANullColumn(P1);
143 Matrix_Free(P1);
144 P1 = P2;
145 C2 = AddANullColumn(C1);
146 Matrix_Free(C1);
147 C1 = C2;
148 }
151 Matrix_Free(P1);
152 Matrix_Free(C1);
153
154 /* Read the name of the parameters */
155 param_name = Read_ParamNames(stdin,C->Dimension - hom);
156 if (hom) {
157 const char **param_name2;
158 param_name2 = (const char**)malloc(sizeof(char*) * (C->Dimension));
159 for (i = 0; i < C->Dimension - 1; i++)
160 param_name2[i] = param_name[i];
161 param_name2[C->Dimension-1] = "_H";
162 free(param_name);
163 param_name=param_name2;
164 }
165
166 en = Polyhedron_Enumerate(P,C,WS,param_name);
167
168 if (hom) {
169 Enumeration *en2;
170
171 printf("inhomogeneous form:\n");
172
174 for (en2 = en; en2; en2 = en2->next) {
175 Print_Domain(stdout, en2->ValidityDomain, param_name);
176 print_evalue(stdout, &en2->EP, param_name);
177 }
178 }
179
180#ifdef EP_EVALUATION
181 if( isatty(0) && C->Dimension != 0)
182 { /* no tty input or no polyhedron -> no evaluation. */
183 printf("Evaluation of the Ehrhart polynomial :\n");
184 p = (Value *)malloc(sizeof(Value) * (C->Dimension));
185 for(i=0;i<C->Dimension;i++)
186 value_init(p[i]);
187 FOREVER {
188 fflush(stdin);
189 printf("Enter %d parameters : ",C->Dimension);
190 for(k=0;k<C->Dimension;++k) {
191 scanf("%s",str);
192 value_read(p[k],str);
193 }
194 fprintf(stdout,"EP( ");
195 value_print(stdout,VALUE_FMT,p[0]);
196 for(k=1;k<C->Dimension;++k) {
197 fprintf(stdout,",");
198 value_print(stdout,VALUE_FMT,p[k]);
199 }
200 fprintf(stdout," ) = ");
201 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
202 free(tmp);
203 fprintf(stdout,"\n");
204 }
205 }
206#endif /* EP_EVALUATION */
207
209 Free_ParamNames(param_name, C->Dimension-hom);
210 Polyhedron_Free( P );
211 Polyhedron_Free( C );
212
213 return 0;
214}
215
Matrix * AddANullColumn(Matrix *M)
Definition: Matop.c:268
#define value_read(val, str)
Definition: arithmetique.h:486
#define value_print(Dst, fmt, val)
Definition: arithmetique.h:487
#define value_init(val)
Definition: arithmetique.h:481
Enumeration * Polyhedron_Enumerate(Polyhedron *Pi, Polyhedron *C, unsigned MAXRAYS, const char **param_name)
Procedure to count points in a parameterized polytope.
Definition: ehrhart.c:1870
void print_evalue(FILE *DST, evalue *e, const char **pname)
Definition: ehrhart.c:169
void Enumeration_Free(Enumeration *en)
Definition: ehrhart.c:2225
Value * compute_poly(Enumeration *en, Value *list_args)
Definition: eval_ehrhart.c:137
void dehomogenize_enumeration(Enumeration *en, int nb_params, int maxRays)
dehomogenize an enumeration.
Matrix * Matrix_Read(void)
Definition: matrix.c:209
void Matrix_Free(Matrix *Mat)
Definition: matrix.c:71
const char ** Read_ParamNames(FILE *in, int m)
Definition: param.c:14
void Free_ParamNames(const char **params, int m)
Definition: param.c:63
void Polyhedron_Free(Polyhedron *Pol)
Definition: polyhedron.c:1614
Polyhedron * Constraints2Polyhedron(Matrix *Constraints, unsigned NbMaxRays)
Given a matrix of constraints ('Constraints'), construct and return a polyhedron.
Definition: polyhedron.c:1905
void Print_Domain(FILE *DST, Polyhedron *D, const char **pname)
Definition: polyparam.c:1680
Polyhedron * ValidityDomain
Definition: types.h:191
evalue EP
Definition: types.h:192
struct _enumeration * next
Definition: types.h:193
Definition: types.h:75
unsigned NbColumns
Definition: types.h:76
unsigned Dimension
Definition: types.h:94
struct option options[]
Definition: testehrhart.c:24
int main(int argc, char **argv)
EPRINT : print results while computing the ehrhart polynomial.
Definition: testehrhart.c:110
#define WS
Definition: testehrhart.c:30
#define FOREVER
Definition: types.h:232