polylib 7.01
polytest.c
Go to the documentation of this file.
1/* polytest.c */
2
3#include <stdio.h>
4#include <polylib/polylib.h>
5
6#define WS 0
7
8char s[128];
9
10int main() {
11
12 Matrix *a=NULL, *b=NULL, *c, *d, *e, *f;
13 Polyhedron *A, *B, *C, *D, *last, *tmp;
14 int i, nbPol, nbMat, func;
15
16 fgets(s, 128, stdin);
17 nbPol = nbMat = 0;
18 while ((*s=='#') ||
19 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
20 fgets(s, 128, stdin);
21
22 for (i=0, A=last=NULL; i<nbPol; i++) {
23 a = Matrix_Read();
25 Matrix_Free(a); a = NULL;
26 if (!last) A = last = tmp;
27 else {
28 last->next = tmp;
29 last = tmp;
30 }
31 }
32
33 if (nbMat)
34 { a = Matrix_Read(); }
35
36 fgets(s,128,stdin);
37 nbPol = nbMat = 0;
38 while ( (*s=='#') ||
39 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
40 fgets(s, 128, stdin);
41
42 for (i=0, B=last=(Polyhedron *)0; i<nbPol; i++) {
43 b = Matrix_Read();
45 Matrix_Free(b); b = NULL;
46 if (!last) B = last = tmp;
47 else {
48 last->next = tmp;
49 last = tmp;
50 }
51 }
52
53 if (nbMat) {
54 b = Matrix_Read();
55 }
56
57 fgets(s, 128, stdin);
58 while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
59 fgets(s, 128, stdin);
60
61 switch (func) {
62 case 1:
63 C = DomainUnion(A, B, WS);
64 D = DomainConvex(C, WS);
66 Matrix_Print(stdout,P_VALUE_FMT,d);
67 Matrix_Free(d);
68 Domain_Free(C);
69 Domain_Free(D);
70 break;
71
72 case 2:
73 D = DomainSimplify(A, B, WS);
75 Matrix_Print(stdout,P_VALUE_FMT,d);
76 Matrix_Free(d);
77 Domain_Free(D);
78 break;
79
80 case 3:
81 Matrix_Free(a);
83 Matrix_Print(stdout,P_VALUE_FMT,a);
84 Matrix_Free(b);
86 Matrix_Print(stdout,P_VALUE_FMT,b);
87 break;
88
89 case 4:
90 Matrix_Free(a);
91 a = Polyhedron2Rays(A);
92 Matrix_Print(stdout,P_VALUE_FMT,a);
93 break;
94
95 case 5:
96 /* a = ec , da = c , ed = 1 */
97 right_hermite(a,&c,&d,&e);
98 Matrix_Print(stdout,P_VALUE_FMT,c);
99 Matrix_Print(stdout,P_VALUE_FMT,d);
100 Matrix_Print(stdout,P_VALUE_FMT,e);
101 f = Matrix_Alloc(e->NbRows,c->NbColumns);
102 Matrix_Product(e,c,f);
103 Matrix_Print(stdout,P_VALUE_FMT,f);
104 Matrix_Free(f);
105 f = Matrix_Alloc(d->NbRows,a->NbColumns);
106 Matrix_Product(d,a,f);
107 Matrix_Print(stdout,P_VALUE_FMT,f);
108 Matrix_Free(f);
109 f = Matrix_Alloc(e->NbRows, d->NbColumns);
110 Matrix_Product(e,d,f);
111 Matrix_Print(stdout,P_VALUE_FMT,f);
112 Matrix_Free(f);
113
114 Matrix_Free(c);
115 Matrix_Free(d);
116 Matrix_Free(e);
117 break;
118
119 case 6:
120 /* a = ce , ad = c , de = 1 */
121 left_hermite(a,&c,&d,&e);
122 Matrix_Print(stdout,P_VALUE_FMT,c);
123 Matrix_Print(stdout,P_VALUE_FMT,d);
124 Matrix_Print(stdout,P_VALUE_FMT,e);
125 f = Matrix_Alloc(c->NbRows, e->NbColumns);
126 Matrix_Product(c,e,f);
127 Matrix_Print(stdout,P_VALUE_FMT,f);
128 Matrix_Free(f);
129 f = Matrix_Alloc(a->NbRows, d->NbColumns);
130 Matrix_Product(a,d,f);
131 Matrix_Print(stdout,P_VALUE_FMT,f);
132 Matrix_Free(f);
133 f = Matrix_Alloc(d->NbRows, e->NbColumns);
134 Matrix_Product(d,e,f);
135 Matrix_Print(stdout,P_VALUE_FMT,f);
136 Matrix_Free(f);
137
138 Matrix_Free(c);
139 Matrix_Free(d);
140 Matrix_Free(e);
141 break;
142
143 case 7:
144 /* Polyhedron_Print(stdout,"%5d", A); */
145 /* Matrix_Print(stdout,"%4d", b); */
146
147 C = Polyhedron_Image(A, b, WS);
149 break;
150
151 case 8:
152 printf("%s\n",
153 Polyhedron_Not_Empty(A,B,WS) ? "Not Empty" : "Empty");
154 break;
155
156 case 9:
157 i = PolyhedronLTQ(A,B,1,0,WS);
158 printf("%s\n",
159 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
160 i = PolyhedronLTQ(B,A,1,0,WS);
161 printf("%s\n",
162 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
163 break;
164 case 10:
165 i = GaussSimplify(a,b);
166 Matrix_Print(stdout,P_VALUE_FMT,b);
167 break;
168
169 default:
170 printf("? unknown function\n");
171 }
172
173 // free memory:
174 if(a)
175 Matrix_Free(a);
176 if(b)
177 Matrix_Free(b);
178 Domain_Free(A);
179 Domain_Free(B);
181
182 return 0;
183}
184
185
int PolyhedronLTQ(Polyhedron *Pol1, Polyhedron *Pol2, int INDEX, int PDIM, int NbMaxConstrs)
Definition: alpha.c:129
int Polyhedron_Not_Empty(Polyhedron *P, Polyhedron *C, int MAXRAYS)
Definition: alpha.c:89
int GaussSimplify(Matrix *Mat1, Matrix *Mat2)
Definition: alpha.c:365
void Matrix_Product(Matrix *Mat1, Matrix *Mat2, Matrix *Mat3)
Definition: matrix.c:880
Matrix * Matrix_Alloc(unsigned NbRows, unsigned NbColumns)
Definition: matrix.c:24
void right_hermite(Matrix *A, Matrix **Hp, Matrix **Up, Matrix **Qp)
Definition: matrix.c:448
Matrix * Matrix_Read(void)
Definition: matrix.c:218
void Matrix_Print(FILE *Dst, const char *Format, Matrix *Mat)
Definition: matrix.c:118
void left_hermite(Matrix *A, Matrix **Hp, Matrix **Qp, Matrix **Up)
Definition: matrix.c:523
void Matrix_Free(Matrix *Mat)
Definition: matrix.c:69
Polyhedron * Polyhedron_Image(Polyhedron *Pol, Matrix *Func, unsigned NbMaxConstrs)
Definition: polyhedron.c:4167
Polyhedron * DomainConvex(Polyhedron *Pol, unsigned NbMaxConstrs)
Definition: polyhedron.c:3606
Polyhedron * DomainSimplify(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Definition: polyhedron.c:3291
Polyhedron * DomainUnion(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Definition: polyhedron.c:3530
void polylib_close()
Free all cache allocated memory: call this function before exiting in a memory checker environment li...
Definition: polyhedron.c:4807
Matrix * Polyhedron2Constraints(Polyhedron *Pol)
Definition: polyhedron.c:2067
Polyhedron * Constraints2Polyhedron(Matrix *Constraints, unsigned NbMaxRays)
Given a matrix of constraints ('Constraints'), construct and return a polyhedron.
Definition: polyhedron.c:1912
void Polyhedron_Print(FILE *Dst, const char *Format, const Polyhedron *Pol)
Definition: polyhedron.c:1646
void Domain_Free(Polyhedron *Pol)
Definition: polyhedron.c:1633
Matrix * Polyhedron2Rays(Polyhedron *Pol)
Given a polyhedron 'Pol', return a matrix of rays.
Definition: polyhedron.c:2683
char s[128]
Definition: polytest.c:8
#define WS
Definition: polytest.c:6
int main()
Definition: polytest.c:10
Definition: types.h:88
unsigned NbRows
Definition: types.h:89
unsigned NbColumns
Definition: types.h:89
struct polyhedron * next
Definition: types.h:115
#define P_VALUE_FMT
Definition: types.h:42