thread safe polylib configuration
[polylib.git] / source / count.c
blob5bce10ab99e948b40cd31d0c5615ed280af3512d
1 /*
2 This file is part of PolyLib.
4 PolyLib is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 PolyLib is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with PolyLib. If not, see <http://www.gnu.org/licenses/>.
18 /*************************************************/
19 /* count.c */
20 /* program to count the number of points */
21 /* in a parameterized polytope */
22 /* */
23 /* input : polytope */
24 /* context */
25 /* */
26 /* written by Vincent Loechner, aug. 2000. */
27 /* loechner@icps.u-strasbg.fr */
28 /*************************************************/
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
34 #include <polylib/polylib.h>
35 #define MAXRAYS 1024
37 /****************************************************************/
38 int main(int argc,char *argv[]) {
40 Matrix *C1, *P1;
41 Polyhedron *C, *P, *S;
42 Polyhedron *CC, *PP;
43 Enumeration *en;
44 Value *p;
45 int i,j,k;
46 int m,M;
47 char str[1024];
48 Value c;
50 /******* Read the input *********/
51 P1 = Matrix_Read();
52 C1 = Matrix_Read();
53 if(C1->NbColumns < 2) {
54 fprintf(stderr,"Not enough parameters !\n");
55 exit(0);
57 P = Constraints2Polyhedron(P1, MAXRAYS);
58 C = Constraints2Polyhedron(C1, MAXRAYS);
59 Matrix_Free(C1);
60 Matrix_Free(P1);
63 /******* Compute the true context *******/
64 CC = align_context(C,P->Dimension,MAXRAYS);
65 PP = DomainIntersection(P,CC,MAXRAYS);
66 Domain_Free(CC);
67 C1 = Matrix_Alloc(C->Dimension+1,P->Dimension+1);
68 for(i=0;i<C1->NbRows;i++)
69 for(j=0;j<C1->NbColumns;j++)
70 if(i==j-P->Dimension+C->Dimension)
71 value_set_si(C1->p[i][j],1);
72 else
73 value_set_si(C1->p[i][j],0);
74 CC = Polyhedron_Image(PP,C1,MAXRAYS);
75 Domain_Free(C);
76 Domain_Free(PP);
77 Matrix_Free(C1);
78 C = CC;
80 /******* Initialize parameters *********/
81 p = (Value *)malloc(sizeof(Value) * (P->Dimension+2));
82 for(i=0;i<=P->Dimension;i++) {
83 value_init(p[i]);
84 value_set_si(p[i],0);
86 value_init(p[i]);
87 value_set_si(p[i],1);
89 /*** S = scanning list of polyhedra ***/
90 S = Polyhedron_Scan(P,C,MAXRAYS);
92 value_init(c);
94 /******* Count now *********/
95 FOREVER {
96 fflush(stdin);
97 printf("Enter %d parameters : ",C->Dimension);
98 for(k=S->Dimension-C->Dimension+1;k<=S->Dimension;++k) {
99 scanf(" %s", str);
100 value_read(p[k],str);
102 printf("EP( ");
103 value_print(stdout,VALUE_FMT,p[S->Dimension-C->Dimension+1]);
104 for(k=S->Dimension-C->Dimension+2;k<=S->Dimension;++k) {
105 printf(", ");
106 value_print(stdout,VALUE_FMT,p[k]);
108 printf(" ) = ");
109 count_points(1,S,p,&c);
110 value_print(stdout,VALUE_FMT,c);
111 printf("\n");
113 for(i=0;i<=(P->Dimension+1);i++)
114 value_clear(p[i]);
115 value_clear(c);
116 return(0);
117 } /* main */