fixed a small bug in eval ehrhart
[polylib.git] / source / count.c
blob2c5a8ed65f6cb6d5f8c6b80f608734d8e899bccf
1 /*************************************************/
2 /* count.c */
3 /* program to count the number of points */
4 /* in a parameterized polytope */
5 /* */
6 /* input : polytope */
7 /* context */
8 /* */
9 /* written by Vincent Loechner, aug. 2000. */
10 /* loechner@icps.u-strasbg.fr */
11 /*************************************************/
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
17 #include <polylib/polylib64.h>
18 #define MAXRAYS 1024
20 /****************************************************************/
21 int main(int argc,char *argv[]) {
23 Matrix *C1, *P1;
24 Polyhedron *C, *P, *S;
25 Polyhedron *CC, *PP;
26 Enumeration *en;
27 Value *p;
28 int i,j,k;
29 int m,M;
30 char str[1024];
32 /******* Read the input *********/
33 P1 = Matrix_Read();
34 C1 = Matrix_Read();
35 if(C1->NbColumns < 2) {
36 fprintf(stderr,"Not enough parameters !\n");
37 exit(0);
39 P = Constraints2Polyhedron(P1, MAXRAYS);
40 C = Constraints2Polyhedron(C1, MAXRAYS);
41 Matrix_Free(C1);
42 Matrix_Free(P1);
45 /******* Compute the true context *******/
46 CC = align_context(C,P->Dimension,MAXRAYS);
47 PP = DomainIntersection(P,CC,MAXRAYS);
48 Domain_Free(CC);
49 C1 = Matrix_Alloc(C->Dimension+1,P->Dimension+1);
50 for(i=0;i<C1->NbRows;i++)
51 for(j=0;j<C1->NbColumns;j++)
52 if(i==j-P->Dimension+C->Dimension)
53 value_set_si(C1->p[i][j],1);
54 else
55 value_set_si(C1->p[i][j],0);
56 CC = Polyhedron_Image(PP,C1,MAXRAYS);
57 Domain_Free(C);
58 Domain_Free(PP);
59 Matrix_Free(C1);
60 C = CC;
62 /******* Initialize parameters *********/
63 p = (Value *)malloc(sizeof(Value) * (P->Dimension+2));
64 for(i=0;i<=P->Dimension;i++) {
65 value_init(p[i]);
66 value_set_si(p[i],0);
68 value_init(p[i]);
69 value_set_si(p[i],1);
71 /*** S = scanning list of polyhedra ***/
72 S = Polyhedron_Scan(P,C,MAXRAYS);
74 /******* Count now *********/
75 FOREVER {
76 fflush(stdin);
77 printf("Enter %d parameters : ",C->Dimension);
78 for(k=S->Dimension-C->Dimension+1;k<=S->Dimension;++k) {
79 scanf(" %s", str);
80 value_read(p[k],str);
82 printf("EP( ");
83 value_print(stdout,VALUE_FMT,p[S->Dimension-C->Dimension+1]);
84 for(k=S->Dimension-C->Dimension+2;k<=S->Dimension;++k) {
85 printf(", ");
86 value_print(stdout,VALUE_FMT,p[k]);
88 printf(" ) = %d\n",count_points(1,S,p));
90 for(i=0;i<=(P->Dimension+1);i++)
91 value_clear(p[i]);
92 return(0);
93 } /* main */