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