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 #include <polylib/homogenization.h>
00020 #include "config.h"
00021 
00022 #ifndef HAVE_GETOPT_H
00023 #define getopt_long(a,b,c,d,e) getopt(a,b,c)
00024 #else
00025 #include <getopt.h>
00026 struct option options[] = {
00027     { "homogenized",   no_argument,  0,  'h' },
00028     { 0, 0, 0, 0 }
00029 };
00030 #endif
00031 
00032 #define WS 0
00033 
00034 /** 
00035     
00036 define this to print all constraints on the validity domains if not
00037 defined, only new constraints (not in validity domain given by the
00038 user) are printed
00039 
00040 */
00041 #define EPRINT_ALL_VALIDITY_CONSTRAINTS
00042 
00043 /** 
00044 
00045 The following are mainly for debug purposes. You shouldn't need to
00046 change anything for daily usage...
00047 
00048 */
00049 
00050 /** you may define each macro independently 
00051 <ol>
00052 <li> #define EDEBUG minimal debug 
00053 <li> #define EDEBUG1 prints enumeration points
00054 <li> #define EDEBUG11 prints number of points
00055 <li> #define EDEBUG2 prints domains
00056 <li> #define EDEBUG21 prints more domains
00057 <li> #define EDEBUG3 prints systems of equations that are solved
00058 <li> #define EDEBUG4 prints message for degree reduction
00059 <li> #define EDEBUG5 prints result before simplification 
00060 <li> #define EDEBUG6 prints domains in Preprocess 
00061 <li> #define EDEBUG61 prints even more in Preprocess
00062 <li> #define EDEBUG62 prints domains in Preprocess2
00063 </ol>
00064 */
00065 
00066 /* #define EDEBUG       */              /* minimal debug */
00067 /* #define EDEBUG1      */              /* prints enumeration points */
00068 /* #define EDEBUG11     */              /* prints number of points */
00069 /* #define EDEBUG2      */              /* prints domains */
00070 /* #define EDEBUG21     */              /* prints more domains */
00071 /* #define EDEBUG3      */              /* prints systems of equations that are solved */
00072 /* #define EDEBUG4      */              /* prints message for degree reduction */
00073 /* #define EDEBUG5      */              /* prints result before simplification */
00074 /* #define EDEBUG6      */              /* prints domains in Preprocess */
00075 /* #define EDEBUG61     */              /* prints even more in Preprocess */
00076 /* #define EDEBUG62     */              /* prints domains in Preprocess2 */
00077 
00078 
00079 /**
00080 
00081  Reduce the degree of resulting polynomials
00082 
00083 */
00084 #define REDUCE_DEGREE
00085 
00086 /** 
00087 
00088 define this to print one warning message per domain overflow these
00089 overflows should no longer happen since version 4.20
00090 
00091 */
00092 #define ALL_OVERFLOW_WARNINGS
00093 
00094 /**
00095 
00096 EPRINT : print results while computing the ehrhart polynomial.  this
00097 is done by default if you build the executable ehrhart.  (If EMAIN is
00098 defined).  Don't define EMAIN here, it is defined when necessary in
00099 the makefile.  
00100 
00101 <p>
00102 
00103 Notice: you may however define EPRINT without defining EMAIN, but in
00104 this case, you have to initialize the global variable param_name by
00105 calling Read_ParamNames before any call to ehrhart.  This is NOT
00106 recommanded, unless you know what you do.  EPRINT causes more debug
00107 messages to be printed.
00108 
00109 */
00110 /* #define EPRINT */
00111 
00112 int main(int argc, char **argv)
00113 {
00114     int i;
00115     char str[1024];
00116     Matrix *C1, *P1;
00117     Polyhedron *C, *P;
00118     Enumeration *en;
00119     const char **param_name;
00120     int c, ind = 0;
00121     int hom = 0;
00122   
00123 #ifdef EP_EVALUATION
00124     Value *p, *tmp;
00125     int k;
00126 #endif
00127 
00128     while ((c = getopt_long(argc, argv, "h", options, &ind)) != -1) {
00129         switch (c) {
00130         case 'h':
00131             hom = 1;
00132             break;
00133         }
00134     }
00135 
00136     P1 = Matrix_Read();
00137     C1 = Matrix_Read();
00138     if(C1->NbColumns < 2) {
00139         fprintf( stderr, "Not enough parameters !\n" );
00140         exit(0);
00141     }
00142     if (hom) {
00143         Matrix *C2, *P2;
00144         P2 = AddANullColumn(P1);
00145         Matrix_Free(P1);
00146         P1 = P2;
00147         C2 = AddANullColumn(C1);
00148         Matrix_Free(C1);
00149         C1 = C2;
00150     }
00151     P = Constraints2Polyhedron(P1,WS);
00152     C = Constraints2Polyhedron(C1,WS);
00153     Matrix_Free(P1);
00154     Matrix_Free(C1);
00155   
00156     /* Read the name of the parameters */
00157     param_name = Read_ParamNames(stdin,C->Dimension - hom);
00158     if (hom) {
00159         const char **param_name2;
00160         param_name2 = (const char**)malloc(sizeof(char*) * (C->Dimension));
00161         for (i = 0; i < C->Dimension - 1; i++)
00162             param_name2[i] = param_name[i];
00163         param_name2[C->Dimension-1] = "_H";
00164         free(param_name);
00165         param_name=param_name2;
00166     }
00167 
00168     en = Polyhedron_Enumerate(P,C,WS,param_name);
00169 
00170     if (hom) {
00171         Enumeration *en2;
00172 
00173         printf("inhomogeneous form:\n");
00174       
00175         dehomogenize_enumeration(en, C->Dimension, WS);
00176         for (en2 = en; en2; en2 = en2->next) {
00177             Print_Domain(stdout, en2->ValidityDomain, param_name);
00178             print_evalue(stdout, &en2->EP, param_name);
00179         }
00180     }
00181 
00182 #ifdef EP_EVALUATION
00183     if( isatty(0) && C->Dimension != 0)
00184         {  /* no tty input or no polyhedron -> no evaluation. */
00185             printf("Evaluation of the Ehrhart polynomial :\n");
00186             p = (Value *)malloc(sizeof(Value) * (C->Dimension));
00187             for(i=0;i<C->Dimension;i++) 
00188                 value_init(p[i]);
00189             FOREVER {
00190                 fflush(stdin);
00191                 printf("Enter %d parameters : ",C->Dimension);
00192                 for(k=0;k<C->Dimension;++k) {
00193                     scanf("%s",str);
00194                     value_read(p[k],str);
00195                 }
00196                 fprintf(stdout,"EP( ");
00197                 value_print(stdout,VALUE_FMT,p[0]);
00198                 for(k=1;k<C->Dimension;++k) {
00199                     fprintf(stdout,",");
00200                     value_print(stdout,VALUE_FMT,p[k]);
00201                 }  
00202                 fprintf(stdout," ) = ");
00203                 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
00204                 free(tmp);
00205                 fprintf(stdout,"\n");  
00206             }
00207         }
00208 #endif /* EP_EVALUATION */
00209   
00210     Enumeration_Free(en);
00211     Free_ParamNames(param_name, C->Dimension-hom);
00212     Polyhedron_Free( P );
00213     Polyhedron_Free( C );
00214 
00215     return 0;
00216 }
00217 

Generated on Thu Sep 4 15:28:58 2008 for polylib by doxygen 1.3.5