polylib: testehrhart.c Source File

- Main Page
- Classes
- Files

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