1 /***********************************************************************/
3 /* copyright 1997, Doran Wilde */
4 /* copyright 1997-2000, Vincent Loechner */
5 /***********************************************************************/
7 This file is part of PolyLib.
9 PolyLib is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 PolyLib is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with PolyLib. If not, see <http://www.gnu.org/licenses/>.
30 #include <polylib/polylib.h>
31 #include <polylib/homogenization.h>
37 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
40 struct option options
[] = {
41 { "homogenized", no_argument
, 0, 'h' },
50 define this to print all constraints on the validity domains if not
51 defined, only new constraints (not in validity domain given by the
55 #define EPRINT_ALL_VALIDITY_CONSTRAINTS
59 The following are mainly for debug purposes. You shouldn't need to
60 change anything for daily usage...
64 /** you may define each macro independently
66 <li> #define EDEBUG minimal debug
67 <li> #define EDEBUG1 prints enumeration points
68 <li> #define EDEBUG11 prints number of points
69 <li> #define EDEBUG2 prints domains
70 <li> #define EDEBUG21 prints more domains
71 <li> #define EDEBUG3 prints systems of equations that are solved
72 <li> #define EDEBUG4 prints message for degree reduction
73 <li> #define EDEBUG5 prints result before simplification
74 <li> #define EDEBUG6 prints domains in Preprocess
75 <li> #define EDEBUG61 prints even more in Preprocess
76 <li> #define EDEBUG62 prints domains in Preprocess2
80 /* #define EDEBUG */ /* minimal debug */
81 /* #define EDEBUG1 */ /* prints enumeration points */
82 /* #define EDEBUG11 */ /* prints number of points */
83 /* #define EDEBUG2 */ /* prints domains */
84 /* #define EDEBUG21 */ /* prints more domains */
85 /* #define EDEBUG3 */ /* prints systems of equations that are solved */
86 /* #define EDEBUG4 */ /* prints message for degree reduction */
87 /* #define EDEBUG5 */ /* prints result before simplification */
88 /* #define EDEBUG6 */ /* prints domains in Preprocess */
89 /* #define EDEBUG61 */ /* prints even more in Preprocess */
90 /* #define EDEBUG62 */ /* prints domains in Preprocess2 */
95 Reduce the degree of resulting polynomials
102 define this to print one warning message per domain overflow these
103 overflows should no longer happen since version 4.20
106 #define ALL_OVERFLOW_WARNINGS
110 EPRINT : print results while computing the ehrhart polynomial. this
111 is done by default if you build the executable ehrhart. (If EMAIN is
112 defined). Don't define EMAIN here, it is defined when necessary in
117 Notice: you may however define EPRINT without defining EMAIN, but in
118 this case, you have to initialize the global variable param_name by
119 calling Read_ParamNames before any call to ehrhart. This is NOT
120 recommanded, unless you know what you do. EPRINT causes more debug
121 messages to be printed.
126 int main(int argc
, char **argv
)
133 const char **param_name
;
142 while ((c
= getopt_long(argc
, argv
, "h", options
, &ind
)) != -1) {
152 if(C1
->NbColumns
< 2) {
153 fprintf( stderr
, "Not enough parameters !\n" );
158 P2
= AddANullColumn(P1
);
161 C2
= AddANullColumn(C1
);
165 P
= Constraints2Polyhedron(P1
,WS
);
166 C
= Constraints2Polyhedron(C1
,WS
);
170 /* Read the name of the parameters */
171 param_name
= Read_ParamNames(stdin
,C
->Dimension
- hom
);
173 const char **param_name2
;
174 param_name2
= (const char**)malloc(sizeof(char*) * (C
->Dimension
));
175 for (i
= 0; i
< C
->Dimension
- 1; i
++)
176 param_name2
[i
] = param_name
[i
];
177 param_name2
[C
->Dimension
-1] = "_H";
179 param_name
=param_name2
;
182 en
= Polyhedron_Enumerate(P
,C
,WS
,param_name
);
187 printf("inhomogeneous form:\n");
189 dehomogenize_enumeration(en
, C
->Dimension
, WS
);
190 for (en2
= en
; en2
; en2
= en2
->next
) {
191 Print_Domain(stdout
, en2
->ValidityDomain
, param_name
);
192 print_evalue(stdout
, &en2
->EP
, param_name
);
197 if( isatty(0) && C
->Dimension
!= 0)
198 { /* no tty input or no polyhedron -> no evaluation. */
199 printf("Evaluation of the Ehrhart polynomial :\n");
200 p
= (Value
*)malloc(sizeof(Value
) * (C
->Dimension
));
201 for(i
=0;i
<C
->Dimension
;i
++)
205 printf("Enter %d parameters : ",C
->Dimension
);
206 for(k
=0;k
<C
->Dimension
;++k
) {
208 value_read(p
[k
],str
);
210 fprintf(stdout
,"EP( ");
211 value_print(stdout
,VALUE_FMT
,p
[0]);
212 for(k
=1;k
<C
->Dimension
;++k
) {
214 value_print(stdout
,VALUE_FMT
,p
[k
]);
216 fprintf(stdout
," ) = ");
217 value_print(stdout
,VALUE_FMT
,*(tmp
=compute_poly(en
,p
)));
219 fprintf(stdout
,"\n");
222 #endif /* EP_EVALUATION */
224 Enumeration_Free(en
);
225 Free_ParamNames(param_name
, C
->Dimension
-hom
);
226 Polyhedron_Free( P
);
227 Polyhedron_Free( C
);