polylib 5.22.8
ehrhart_ranking.c
Go to the documentation of this file.
1/* Program for testing the ranking function. */
2
3#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6
7#include <polylib/polylib.h>
8#include <polylib/ranking.h>
9
10int main( int argc, char **argv)
11{
12 int i;
13 const char **param_name = NULL;
14 Matrix *M;
15 Polyhedron *P, *D, *C;
16 Enumeration *e, *en;
17
18 int nb_parms;
19
20#ifdef EP_EVALUATION
21 Value *p, *tmp;
22 int k;
23#endif
24
25 M = Matrix_Read();
27 Matrix_Free(M);
28 M = Matrix_Read();
30 Matrix_Free(M);
31 M = Matrix_Read();
33 Matrix_Free(M);
34
35 nb_parms = D->Dimension;
36
37 /* Read the name of the parameters */
38 param_name = Read_ParamNames(stdin,nb_parms);
39
40 /* compute a polynomial approximation of the Ehrhart polynomial */
41 printf("============ Ranking function ============\n");
43 C, POL_NO_DUAL);
44
48
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" );
53 }
54
55
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);
69 }
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]);
75 }
76 fprintf(stdout," ) = ");
77 value_print(stdout,VALUE_FMT,*(tmp=compute_poly(en,p)));
78 free(tmp);
79 fprintf(stdout,"\n");
80 }
81 }
82#endif /* EP_EVALUATION */
83
84 while( e )
85 {
86 free_evalue_refs( &(e->EP) );
88 en = e ->next;
89 free( e );
90 e = en;
91 }
92 Free_ParamNames(param_name, nb_parms);
93 return 0;
94}
#define value_read(val, str)
Definition: arithmetique.h:486
#define value_print(Dst, fmt, val)
Definition: arithmetique.h:487
#define value_init(val)
Definition: arithmetique.h:481
void free_evalue_refs(evalue *e)
releases all memory referenced by e.
Definition: ehrhart.c:115
void print_evalue(FILE *DST, evalue *e, const char **pname)
Definition: ehrhart.c:169
int main(int argc, char **argv)
Value * compute_poly(Enumeration *en, Value *list_args)
Definition: eval_ehrhart.c:137
Matrix * Matrix_Read(void)
Definition: matrix.c:209
void Matrix_Free(Matrix *Mat)
Definition: matrix.c:71
const char ** Read_ParamNames(FILE *in, int m)
Definition: param.c:14
void Free_ParamNames(const char **params, int m)
Definition: param.c:63
void Polyhedron_Free(Polyhedron *Pol)
Definition: polyhedron.c:1614
Polyhedron * Constraints2Polyhedron(Matrix *Constraints, unsigned NbMaxRays)
Given a matrix of constraints ('Constraints'), construct and return a polyhedron.
Definition: polyhedron.c:1905
void Print_Domain(FILE *DST, Polyhedron *D, const char **pname)
Definition: polyparam.c:1680
Enumeration * Polyhedron_LexSmallerEnumerate(Polyhedron *P, Polyhedron *D, unsigned dim, Polyhedron *C, unsigned MAXRAYS)
Returns the number of points in P that are lexicographically smaller than a given point in D.
Definition: ranking.c:179
Polyhedron * ValidityDomain
Definition: types.h:191
evalue EP
Definition: types.h:192
struct _enumeration * next
Definition: types.h:193
Definition: types.h:75
unsigned Dimension
Definition: types.h:94
#define POL_NO_DUAL
Definition: types.h:66
#define FOREVER
Definition: types.h:232