00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004
00005 #include <polylib/polylib.h>
00006
00007
00008 void Union_Read(Polyhedron **P, Polyhedron **C, const char ***param_name)
00009 {
00010 Matrix *pm;
00011 Polyhedron *ptmp;
00012 unsigned NbRows, NbColumns;
00013 char s[1025], param[1025];
00014 int i, j, c, f;
00015
00016 *P = NULL;
00017 pm = Matrix_Read();
00018 f=1;
00019 while( f )
00020 {
00021 do
00022 {
00023 if( fgets(s, 1024, stdin) == 0 )
00024 f=0;
00025 }
00026 while ( (*s=='#' || *s=='\n') && f );
00027
00028 if( f && sscanf(s, "%d %d", &NbRows, &NbColumns)==2 )
00029 {
00030
00031 if( *P )
00032 if( pm->NbColumns != ((*P)->Dimension)+2 )
00033 {
00034 fprintf( stderr,
00035 "Polyhedra must be in the same dimension space !\n");
00036 exit(0);
00037 }
00038 ptmp = Constraints2Polyhedron(pm, 200);
00039 ptmp->next = *P;
00040 *P = ptmp;
00041 Matrix_Free(pm);
00042
00043
00044 pm = Matrix_Alloc(NbRows, NbColumns);
00045 Matrix_Read_Input( pm );
00046 }
00047 else
00048 break;
00049 }
00050
00051
00052 *C = Constraints2Polyhedron(pm, 200);
00053 Matrix_Free(pm);
00054
00055
00056 if( f )
00057 {
00058 char **pp = (char **)malloc((*C)->Dimension*sizeof(char *));
00059 *param_name = (const char **)pp;
00060
00061 c = 0;
00062 for( i=0 ; i<(*C)->Dimension ; ++i )
00063 {
00064 j=0;
00065 for( ; ; ++c )
00066 {
00067 if( s[c]==' ' || s[c]=='\n' || s[c]==0 ) {
00068 if( j==0 )
00069 continue;
00070 else
00071 break;
00072 }
00073 param[j++] = s[c];
00074 }
00075
00076
00077 if( j==0 )
00078 break;
00079 param[j] = 0;
00080 pp[i] = (char *)malloc(j);
00081 strcpy(pp[i], param);
00082 }
00083 if( i != (*C)->Dimension )
00084 {
00085 free( *param_name );
00086 *param_name = Read_ParamNames(NULL,(*C)->Dimension);
00087 }
00088 }
00089 else
00090 *param_name = Read_ParamNames(NULL,(*C)->Dimension);
00091
00092 }
00093
00094 void recurse(Polyhedron *C, const char **param_name, Enumeration *e,
00095 Value *pmin, Value *pmax, Value *p, int l )
00096 {
00097 Value z, *tmp; int k;
00098 value_init( z );
00099 if( l == C->Dimension )
00100 {
00101 fprintf(stdout,"EP( ");
00102 value_print(stdout,VALUE_FMT,p[0]);
00103 for(k=1;k<C->Dimension;++k) {
00104 fprintf(stdout,",");
00105 value_print(stdout,VALUE_FMT,p[k]);
00106 }
00107 fprintf(stdout," ) = ");
00108 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(e,p)));
00109 value_clear( *tmp );
00110 free(tmp);
00111 fprintf(stdout,"\n");
00112 }
00113 else
00114 {
00115 for( value_assign( z, pmin[l]) ; value_le(z,pmax[l]) ; value_increment(z,z) )
00116 {
00117 value_assign( p[l], z );
00118 recurse ( C, param_name, e, pmin, pmax, p, l+1 );
00119 }
00120 }
00121
00122 }
00123
00124
00125
00126 int main( int argc, char **argv)
00127 {
00128 Polyhedron *P, *C;
00129 const char **param_name;
00130 Enumeration *e, *en;
00131 Value *pmin, *pmax, *p; int i, k; char str[256], *s;
00132
00133 if( argc != 1 )
00134 {
00135 fprintf( stderr, " Usage : %s [< file]\n", argv[0] );
00136 return( -1 );
00137 }
00138
00139 Union_Read( &P, &C, ¶m_name );
00140
00141 e = Domain_Enumerate( P, C, 200, param_name );
00142
00143 for( en=e ; en ; en=en->next )
00144 {
00145 Print_Domain(stdout,en->ValidityDomain, param_name);
00146 print_evalue(stdout,&en->EP, param_name);
00147 printf( "\n-----------------------------------\n" );
00148 }
00149
00150 if( isatty(0) && C->Dimension != 0)
00151 {
00152 printf("Evaluation of the Ehrhart polynomial :\n");
00153 pmin = (Value *)malloc(sizeof(Value) * (C->Dimension));
00154 pmax = (Value *)malloc(sizeof(Value) * (C->Dimension));
00155 p = (Value *)malloc(sizeof(Value) * (C->Dimension));
00156 for(i=0;i<C->Dimension;i++)
00157 {
00158 value_init(pmin[i]);
00159 value_init(pmax[i]);
00160 value_init(p[i]);
00161 }
00162 FOREVER {
00163 fflush(stdin);
00164 printf("Enter %d parameters (or intervals, comma separated) : ",C->Dimension);
00165 for(k=0;k<C->Dimension;++k)
00166 {
00167 scanf("%s",str);
00168 if( (s=strpbrk(str,",")) )
00169 { *s = 0;
00170 value_read(pmin[k],str);
00171 value_read(pmax[k],(s+1));
00172 }
00173 else
00174 { value_read(pmin[k],str);
00175 value_assign(pmax[k],pmin[k]);
00176 }
00177 }
00178
00179 recurse( C, param_name, e, pmin, pmax, p, 0 );
00180
00181 }
00182 }
00183
00184 return( 0 );
00185 }
00186