Main Page   Compound List   File List   Compound Members   File Members  

testehrhart.c

Go to the documentation of this file.
00001 /***********************************************************************/
00002 /*                Ehrhart V4.20                                        */
00003 /*                copyright 1997, Doran Wilde                          */
00004 /*                copyright 1997-2000, Vincent Loechner                */
00005 /*       Permission is granted to copy, use, and distribute            */
00006 /*       for any commercial or noncommercial purpose under the terms   */
00007 /*       of the GNU General Public license, version 2, June 1991       */
00008 /*       (see file : LICENSING).                                       */
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 
00020 /** 
00021     
00022 define this to print all constraints on the validity domains if not
00023 defined, only new constraints (not in validity domain given by the
00024 user) are printed
00025 
00026 */
00027 #define EPRINT_ALL_VALIDITY_CONSTRAINTS
00028 
00029 /** 
00030 
00031 The following are mainly for debug purposes. You shouldn't need to
00032 change anything for daily usage...
00033 
00034 */
00035 
00036 /** you may define each macro independently 
00037 <ol>
00038 <li> #define EDEBUG minimal debug 
00039 <li> #define EDEBUG1 prints enumeration points
00040 <li> #define EDEBUG11 prints number of points
00041 <li> #define EDEBUG2 prints domains
00042 <li> #define EDEBUG21 prints more domains
00043 <li> #define EDEBUG3 prints systems of equations that are solved
00044 <li> #define EDEBUG4 prints message for degree reduction
00045 <li> #define EDEBUG5 prints result before simplification 
00046 <li> #define EDEBUG6 prints domains in Preprocess 
00047 <li> #define EDEBUG61 prints even more in Preprocess
00048 <li> #define EDEBUG62 prints domains in Preprocess2
00049 </ol>
00050 */
00051 
00052 /* #define EDEBUG       */              /* minimal debug */
00053 /* #define EDEBUG1      */              /* prints enumeration points */
00054 /* #define EDEBUG11     */              /* prints number of points */
00055 /* #define EDEBUG2      */              /* prints domains */
00056 /* #define EDEBUG21     */              /* prints more domains */
00057 /* #define EDEBUG3      */              /* prints systems of equations that are solved */
00058 /* #define EDEBUG4      */              /* prints message for degree reduction */
00059 /* #define EDEBUG5      */              /* prints result before simplification */
00060 /* #define EDEBUG6      */              /* prints domains in Preprocess */
00061 /* #define EDEBUG61     */              /* prints even more in Preprocess */
00062 /* #define EDEBUG62     */              /* prints domains in Preprocess2 */
00063 
00064 
00065 /**
00066 
00067  Reduce the degree of resulting polynomials
00068 
00069 */
00070 #define REDUCE_DEGREE
00071 
00072 /** 
00073 
00074 define this to print one warning message per domain overflow these
00075 overflows should no longer happen since version 4.20
00076 
00077 */
00078 #define ALL_OVERFLOW_WARNINGS
00079 
00080 /**
00081 
00082 EPRINT : print results while computing the ehrhart polynomial.  this
00083 is done by default if you build the executable ehrhart.  (If EMAIN is
00084 defined).  Don't define EMAIN here, it is defined when necessary in
00085 the makefile.  
00086 
00087 <p>
00088 
00089 Notice: you may however define EPRINT without defining EMAIN, but in
00090 this case, you have to initialize the global variable param_name by
00091 calling Read_ParamNames before any call to ehrhart.  This is NOT
00092 recommanded, unless you know what you do.  EPRINT causes more debug
00093 messages to be printed.
00094 
00095 */
00096 /* #define EPRINT */
00097 
00098 int main() {
00099   
00100     int i;
00101     char str[1024];
00102     Matrix *C1, *P1;
00103     Polyhedron *C, *P;
00104     Enumeration *en;
00105     char **param_name;
00106   
00107 #ifdef EP_EVALUATION
00108     Value *p, *tmp;
00109     int k;
00110 #endif
00111 
00112     P1 = Matrix_Read();
00113     C1 = Matrix_Read();
00114     if(C1->NbColumns < 2) {
00115         fprintf( stderr, "Not enough parameters !\n" );
00116         exit(0);
00117     }
00118     P = Constraints2Polyhedron(P1,1024);
00119     C = Constraints2Polyhedron(C1,1024);
00120     Matrix_Free(C1);
00121     Matrix_Free(P1);
00122   
00123     /* Read the name of the parameters */
00124     param_name = Read_ParamNames(stdin,C->Dimension);
00125     en = Polyhedron_Enumerate(P,C,1024,param_name);
00126 
00127 #ifdef EP_EVALUATION
00128     if( isatty(0) && C->Dimension != 0)
00129         {  /* no tty input or no polyhedron -> no evaluation. */
00130             printf("Evaluation of the Ehrhart polynomial :\n");
00131             p = (Value *)malloc(sizeof(Value) * (C->Dimension));
00132             for(i=0;i<C->Dimension;i++) 
00133                 value_init(p[i]);
00134             FOREVER {
00135                 fflush(stdin);
00136                 printf("Enter %d parameters : ",C->Dimension);
00137                 for(k=0;k<C->Dimension;++k) {
00138                     scanf("%s",str);
00139                     value_read(p[k],str);
00140                 }
00141                 fprintf(stdout,"EP( ");
00142                 value_print(stdout,VALUE_FMT,p[0]);
00143                 for(k=1;k<C->Dimension;++k) {
00144                     fprintf(stdout,",");
00145                     value_print(stdout,VALUE_FMT,p[k]);
00146                 }  
00147                 fprintf(stdout," ) = ");
00148                 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
00149                 free(tmp);
00150                 fprintf(stdout,"\n");  
00151             }
00152         }
00153 #endif /* EP_EVALUATION */
00154   
00155     Enumeration_Free(en);
00156     for( i=0 ; i<C->Dimension ; i++ )
00157         free( param_name[i] );
00158     free(param_name);
00159     Polyhedron_Free( P );
00160     Polyhedron_Free( C );
00161 
00162     return 0;
00163 }
00164 

Generated on Mon Mar 15 10:59:51 2004 for polylib by doxygen1.2.18