new version 5.22.4
[polylib.git] / applications / ehrhart_ranking.c
blob0b81439a55c4f7eeb3daa22428a8b43623613359
1 /* Program for testing the ranking function. */
3 #include <stdio.h>
4 #include <string.h>
5 #include <stdlib.h>
7 #include <polylib/polylib.h>
8 #include <polylib/ranking.h>
10 int main( int argc, char **argv)
12 int i;
13 const char **param_name = NULL;
14 Matrix *M;
15 Polyhedron *P, *D, *C;
16 Enumeration *e, *en;
18 int nb_parms;
20 #ifdef EP_EVALUATION
21 Value *p, *tmp;
22 int k;
23 #endif
25 M = Matrix_Read();
26 P = Constraints2Polyhedron(M, POL_NO_DUAL);
27 Matrix_Free(M);
28 M = Matrix_Read();
29 D = Constraints2Polyhedron(M, POL_NO_DUAL);
30 Matrix_Free(M);
31 M = Matrix_Read();
32 C = Constraints2Polyhedron(M, POL_NO_DUAL);
33 Matrix_Free(M);
35 nb_parms = D->Dimension;
37 /* Read the name of the parameters */
38 param_name = Read_ParamNames(stdin,nb_parms);
40 /* compute a polynomial approximation of the Ehrhart polynomial */
41 printf("============ Ranking function ============\n");
42 e = Polyhedron_LexSmallerEnumerate(P, D, D->Dimension-C->Dimension,
43 C, POL_NO_DUAL);
45 Polyhedron_Free(P);
46 Polyhedron_Free(D);
47 Polyhedron_Free(C);
49 for (en=e; en; en=en->next) {
50 Print_Domain(stdout,en->ValidityDomain, param_name);
51 print_evalue(stdout,&en->EP, param_name);
52 printf( "\n-----------------------------------\n" );
56 #ifdef EP_EVALUATION
57 if( isatty(0) && nb_parms != 0)
58 { /* no tty input or no polyhedron -> no evaluation. */
59 printf("Evaluation of the Ehrhart polynomial :\n");
60 p = (Value *)malloc(sizeof(Value) * (nb_parms));
61 for(i=0;i<nb_parms;i++)
62 value_init(p[i]);
63 FOREVER {
64 fflush(stdin);
65 printf("Enter %d parameters : ",nb_parms);
66 for(k=0;k<nb_parms;++k) {
67 scanf("%s",str);
68 value_read(p[k],str);
70 fprintf(stdout,"EP( ");
71 value_print(stdout,VALUE_FMT,p[0]);
72 for(k=1;k<nb_parms;++k) {
73 fprintf(stdout,",");
74 value_print(stdout,VALUE_FMT,p[k]);
76 fprintf(stdout," ) = ");
77 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
78 free(tmp);
79 fprintf(stdout,"\n");
82 #endif /* EP_EVALUATION */
84 while( e )
86 free_evalue_refs( &(e->EP) );
87 Polyhedron_Free( e->ValidityDomain );
88 en = e ->next;
89 free( e );
90 e = en;
92 Free_ParamNames(param_name, nb_parms);
93 return 0;