polylib: testehrhart.c Source File

- Main Page
- Classes
- Files

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