00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <ctype.h>
00030 #include <string.h>
00031 #include <unistd.h>
00032 #include <assert.h>
00033
00034 #include <polylib/polylib.h>
00035 #include <polylib/homogenization.h>
00036 #include "config.h"
00037
00038 #define EP_EVALUATION
00039
00040 #ifndef HAVE_GETOPT_H
00041 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
00042 #else
00043 #include <getopt.h>
00044 struct option options[] = {
00045 { "homogenized", no_argument, 0, 'h' },
00046 { 0, 0, 0, 0 }
00047 };
00048 #endif
00049
00050 #define WS 0
00051
00052
00053
00054
00055
00056
00057
00058
00059 #define EPRINT_ALL_VALIDITY_CONSTRAINTS
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 #define REDUCE_DEGREE
00103
00104
00105
00106
00107
00108
00109
00110 #define ALL_OVERFLOW_WARNINGS
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 int main(int argc, char **argv)
00131 {
00132 int i;
00133 char str[1024];
00134 Matrix *C1, *P1;
00135 Polyhedron *C, *P;
00136 Enumeration *en;
00137 const char **param_name;
00138 int c, ind = 0;
00139 int hom = 0;
00140
00141 #ifdef EP_EVALUATION
00142 Value *p, *tmp;
00143 int k;
00144 #endif
00145
00146 while ((c = getopt_long(argc, argv, "h", options, &ind)) != -1) {
00147 switch (c) {
00148 case 'h':
00149 hom = 1;
00150 break;
00151 }
00152 }
00153
00154 P1 = Matrix_Read();
00155 C1 = Matrix_Read();
00156 if(C1->NbColumns < 2) {
00157 fprintf( stderr, "Not enough parameters !\n" );
00158 exit(0);
00159 }
00160 if (hom) {
00161 Matrix *C2, *P2;
00162 P2 = AddANullColumn(P1);
00163 Matrix_Free(P1);
00164 P1 = P2;
00165 C2 = AddANullColumn(C1);
00166 Matrix_Free(C1);
00167 C1 = C2;
00168 }
00169 P = Constraints2Polyhedron(P1,WS);
00170 C = Constraints2Polyhedron(C1,WS);
00171 Matrix_Free(P1);
00172 Matrix_Free(C1);
00173
00174
00175 param_name = Read_ParamNames(stdin,C->Dimension - hom);
00176 if (hom) {
00177 const char **param_name2;
00178 param_name2 = (const char**)malloc(sizeof(char*) * (C->Dimension));
00179 for (i = 0; i < C->Dimension - 1; i++)
00180 param_name2[i] = param_name[i];
00181 param_name2[C->Dimension-1] = "_H";
00182 free(param_name);
00183 param_name=param_name2;
00184 }
00185
00186 en = Polyhedron_Enumerate(P,C,WS,param_name);
00187
00188 if (hom) {
00189 Enumeration *en2;
00190
00191 printf("inhomogeneous form:\n");
00192
00193 dehomogenize_enumeration(en, C->Dimension, WS);
00194 for (en2 = en; en2; en2 = en2->next) {
00195 Print_Domain(stdout, en2->ValidityDomain, param_name);
00196 print_evalue(stdout, &en2->EP, param_name);
00197 }
00198 }
00199
00200 #ifdef EP_EVALUATION
00201 if( isatty(0) && C->Dimension != 0)
00202 {
00203 printf("Evaluation of the Ehrhart polynomial :\n");
00204 p = (Value *)malloc(sizeof(Value) * (C->Dimension));
00205 for(i=0;i<C->Dimension;i++)
00206 value_init(p[i]);
00207 FOREVER {
00208 fflush(stdin);
00209 printf("Enter %d parameters : ",C->Dimension);
00210 for(k=0;k<C->Dimension;++k) {
00211 scanf("%s",str);
00212 value_read(p[k],str);
00213 }
00214 fprintf(stdout,"EP( ");
00215 value_print(stdout,VALUE_FMT,p[0]);
00216 for(k=1;k<C->Dimension;++k) {
00217 fprintf(stdout,",");
00218 value_print(stdout,VALUE_FMT,p[k]);
00219 }
00220 fprintf(stdout," ) = ");
00221 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
00222 free(tmp);
00223 fprintf(stdout,"\n");
00224 }
00225 }
00226 #endif
00227
00228 Enumeration_Free(en);
00229 Free_ParamNames(param_name, C->Dimension-hom);
00230 Polyhedron_Free( P );
00231 Polyhedron_Free( C );
00232
00233 return 0;
00234 }
00235