Merge ssh://repo.or.cz/srv/git/polylib
[polylib.git] / applications / ehrhart_ranking.c
blobf199207a86dcf63cbffc562e25ed35870d26f3ea
1 /* Program for testing the ranking function. */
2 /*
3 This file is part of PolyLib.
5 PolyLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 PolyLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with PolyLib. If not, see <http://www.gnu.org/licenses/>.
20 #include <stdio.h>
21 #include <string.h>
22 #include <stdlib.h>
24 #include <polylib/polylib.h>
25 #include <polylib/ranking.h>
27 int main( int argc, char **argv)
29 int i;
30 const char **param_name = NULL;
31 Matrix *M;
32 Polyhedron *P, *D, *C;
33 Enumeration *e, *en;
35 int nb_parms;
37 #ifdef EP_EVALUATION
38 Value *p, *tmp;
39 int k;
40 #endif
42 M = Matrix_Read();
43 P = Constraints2Polyhedron(M, POL_NO_DUAL);
44 Matrix_Free(M);
45 M = Matrix_Read();
46 D = Constraints2Polyhedron(M, POL_NO_DUAL);
47 Matrix_Free(M);
48 M = Matrix_Read();
49 C = Constraints2Polyhedron(M, POL_NO_DUAL);
50 Matrix_Free(M);
52 nb_parms = D->Dimension;
54 /* Read the name of the parameters */
55 param_name = Read_ParamNames(stdin,nb_parms);
57 /* compute a polynomial approximation of the Ehrhart polynomial */
58 printf("============ Ranking function ============\n");
59 e = Polyhedron_LexSmallerEnumerate(P, D, D->Dimension-C->Dimension,
60 C, POL_NO_DUAL);
62 Polyhedron_Free(P);
63 Polyhedron_Free(D);
64 Polyhedron_Free(C);
66 for (en=e; en; en=en->next) {
67 Print_Domain(stdout,en->ValidityDomain, param_name);
68 print_evalue(stdout,&en->EP, param_name);
69 printf( "\n-----------------------------------\n" );
73 #ifdef EP_EVALUATION
74 if( isatty(0) && nb_parms != 0)
75 { /* no tty input or no polyhedron -> no evaluation. */
76 printf("Evaluation of the Ehrhart polynomial :\n");
77 p = (Value *)malloc(sizeof(Value) * (nb_parms));
78 for(i=0;i<nb_parms;i++)
79 value_init(p[i]);
80 FOREVER {
81 fflush(stdin);
82 printf("Enter %d parameters : ",nb_parms);
83 for(k=0;k<nb_parms;++k) {
84 scanf("%s",str);
85 value_read(p[k],str);
87 fprintf(stdout,"EP( ");
88 value_print(stdout,VALUE_FMT,p[0]);
89 for(k=1;k<nb_parms;++k) {
90 fprintf(stdout,",");
91 value_print(stdout,VALUE_FMT,p[k]);
93 fprintf(stdout," ) = ");
94 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
95 free(tmp);
96 fprintf(stdout,"\n");
99 #endif /* EP_EVALUATION */
101 while( e )
103 free_evalue_refs( &(e->EP) );
104 Polyhedron_Free( e->ValidityDomain );
105 en = e ->next;
106 free( e );
107 e = en;
109 Free_ParamNames(param_name, nb_parms);
110 return 0;