fixed a small bug in eval ehrhart
[polylib.git] / applications / polytest.c
blob83160b4de390a00ee7ec5a9bd183a7b382c14b6f
1 /* polytest.c */
2 #include <stdio.h>
3 #include <polylib/polylib.h>
6 char s[128];
8 int main() {
10 Matrix *a=NULL, *b=NULL, *c, *d, *e, *f;
11 Polyhedron *A, *B, *C, *D, *last, *tmp;
12 int i, nbPol, nbMat, func;
14 fgets(s, 128, stdin);
15 nbPol = nbMat = 0;
16 while ((*s=='#') ||
17 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
18 fgets(s, 128, stdin);
20 for (i=0, A=last=(Polyhedron *)0; i<nbPol; i++) {
21 a = Matrix_Read();
22 tmp = Constraints2Polyhedron(a,600);
23 Matrix_Free(a);
24 if (!last) A = last = tmp;
25 else {
26 last->next = tmp;
27 last = tmp;
31 if (nbMat)
32 { a = Matrix_Read(); }
34 fgets(s,128,stdin);
35 nbPol = nbMat = 0;
36 while ( (*s=='#') ||
37 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
38 fgets(s, 128, stdin);
40 for (i=0, B=last=(Polyhedron *)0; i<nbPol; i++) {
41 b = Matrix_Read();
42 tmp = Constraints2Polyhedron(b,200);
43 Matrix_Free(b);
44 if (!last) B = last = tmp;
45 else {
46 last->next = tmp;
47 last = tmp;
51 if (nbMat)
52 { b = Matrix_Read(); }
54 fgets(s, 128, stdin);
55 while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
56 fgets(s, 128, stdin);
58 switch (func) {
59 case 1:
60 C = DomainUnion(A, B, 200);
61 D = DomainConvex(C, 200);
62 d = Polyhedron2Constraints(D);
63 Matrix_Print(stdout,P_VALUE_FMT,d);
64 Matrix_Free(d);
65 Domain_Free(C);
66 Domain_Free(D);
67 break;
68 case 2:
69 D = DomainSimplify(A, B, 200);
70 d = Polyhedron2Constraints(D);
71 Matrix_Print(stdout,P_VALUE_FMT,d);
72 Matrix_Free(d);
73 Domain_Free(D);
74 break;
75 case 3:
76 a = Polyhedron2Constraints(A);
77 Matrix_Print(stdout,P_VALUE_FMT,a);
78 b = Polyhedron2Constraints(B);
79 Matrix_Print(stdout,P_VALUE_FMT,b);
80 break;
81 case 4:
82 a = Polyhedron2Rays(A);
83 Matrix_Print(stdout,P_VALUE_FMT,a);
84 break;
85 case 5:
87 /* a = ec , da = c , ed = 1 */
88 right_hermite(a,&c,&d,&e);
89 Matrix_Print(stdout,P_VALUE_FMT,c);
90 Matrix_Print(stdout,P_VALUE_FMT,d);
91 Matrix_Print(stdout,P_VALUE_FMT,e);
92 f = Matrix_Alloc(e->NbRows,c->NbColumns);
93 Matrix_Product(e,c,f);
94 Matrix_Print(stdout,P_VALUE_FMT,f);
95 Matrix_Free(f);
96 f = Matrix_Alloc(d->NbRows,a->NbColumns);
97 Matrix_Product(d,a,f);
98 Matrix_Print(stdout,P_VALUE_FMT,f);
99 Matrix_Free(f);
100 f = Matrix_Alloc(e->NbRows, d->NbColumns);
101 Matrix_Product(e,d,f);
102 Matrix_Print(stdout,P_VALUE_FMT,f);
103 break;
104 case 6:
106 /* a = ce , ad = c , de = 1 */
107 left_hermite(a,&c,&d,&e);
108 Matrix_Print(stdout,P_VALUE_FMT,c);
109 Matrix_Print(stdout,P_VALUE_FMT,d);
110 Matrix_Print(stdout,P_VALUE_FMT,e);
111 f = Matrix_Alloc(c->NbRows, e->NbColumns);
112 Matrix_Product(c,e,f);
113 Matrix_Print(stdout,P_VALUE_FMT,f);
114 Matrix_Free(f);
115 f = Matrix_Alloc(a->NbRows, d->NbColumns);
116 Matrix_Product(a,d,f);
117 Matrix_Print(stdout,P_VALUE_FMT,f);
118 Matrix_Free(f);
119 f = Matrix_Alloc(d->NbRows, e->NbColumns);
120 Matrix_Product(d,e,f);
121 Matrix_Print(stdout,P_VALUE_FMT,f);
122 break;
123 case 7:
125 /* Polyhedron_Print(stdout,"%5d", A); */
126 /* Matrix_Print(stdout,"%4d", b); */
128 C = Polyhedron_Image(A, b, 400);
129 Polyhedron_Print(stdout,P_VALUE_FMT,C);
130 break;
131 case 8:
133 printf("%s\n",
134 Polyhedron_Not_Empty(A,B,600) ? "Not Empty" : "Empty");
135 break;
136 case 9:
138 i = PolyhedronLTQ(A,B,1,0,600);
139 printf("%s\n",
140 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
141 i = PolyhedronLTQ(B,A,1,0,600);
142 printf("%s\n",
143 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
144 break;
145 case 10:
146 i = GaussSimplify(a,b);
147 Matrix_Print(stdout,P_VALUE_FMT,b);
148 break;
150 default:
151 printf("? unknown function\n");
154 Domain_Free(A);
155 Domain_Free(B);
157 return 0;