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     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         char **param_name2 = (char**)malloc(sizeof(char*) * (C->Dimension));
00160         for (i = 0; i < C->Dimension - 1; i++)
00161             param_name2[i] = param_name[i];
00162         param_name2[C->Dimension-1] = "_H";
00163         free(param_name);
00164         param_name=param_name2;
00165     }
00166 
00167     en = Polyhedron_Enumerate(P,C,WS,param_name);
00168 
00169     if (hom) {
00170         Enumeration *en2;
00171 
00172         printf("inhomogeneous form:\n");
00173       
00174         dehomogenize_enumeration(en, C->Dimension, WS);
00175         for (en2 = en; en2; en2 = en2->next) {
00176             Print_Domain(stdout, en2->ValidityDomain, param_name);
00177             print_evalue(stdout, &en2->EP, param_name);
00178         }
00179     }
00180 
00181 #ifdef EP_EVALUATION
00182     if( isatty(0) && C->Dimension != 0)
00183         {  /* no tty input or no polyhedron -> no evaluation. */
00184             printf("Evaluation of the Ehrhart polynomial :\n");
00185             p = (Value *)malloc(sizeof(Value) * (C->Dimension));
00186             for(i=0;i<C->Dimension;i++) 
00187                 value_init(p[i]);
00188             FOREVER {
00189                 fflush(stdin);
00190                 printf("Enter %d parameters : ",C->Dimension);
00191                 for(k=0;k<C->Dimension;++k) {
00192                     scanf("%s",str);
00193                     value_read(p[k],str);
00194                 }
00195                 fprintf(stdout,"EP( ");
00196                 value_print(stdout,VALUE_FMT,p[0]);
00197                 for(k=1;k<C->Dimension;++k) {
00198                     fprintf(stdout,",");
00199                     value_print(stdout,VALUE_FMT,p[k]);
00200                 }  
00201                 fprintf(stdout," ) = ");
00202                 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
00203                 free(tmp);
00204                 fprintf(stdout,"\n");  
00205             }
00206         }
00207 #endif /* EP_EVALUATION */
00208   
00209     Enumeration_Free(en);
00210     for( i=0 ; i < C->Dimension - hom; i++ )
00211         free( param_name[i] );
00212     free(param_name);
00213     Polyhedron_Free( P );
00214     Polyhedron_Free( C );
00215 
00216     return 0;
00217 }
00218 

Generated on Mon Sep 12 15:15:11 2005 for polylib by doxygen 1.3.5