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

Generated on Mon Sep 12 14:48:29 2005 for polylib by doxygen 1.3.5