polylib 5.22.8
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=(Polyhedron *)0; i<nbPol; i++) {
23 a = Matrix_Read();
25 Matrix_Free(a);
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);
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 fgets(s, 128, stdin);
57 while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
58 fgets(s, 128, stdin);
59
60 switch (func) {
61 case 1:
62 C = DomainUnion(A, B, WS);
63 D = DomainConvex(C, WS);
65 Matrix_Print(stdout,P_VALUE_FMT,d);
66 Matrix_Free(d);
67 Domain_Free(C);
68 Domain_Free(D);
69 break;
70 case 2:
71 D = DomainSimplify(A, B, WS);
73 Matrix_Print(stdout,P_VALUE_FMT,d);
74 Matrix_Free(d);
75 Domain_Free(D);
76 break;
77 case 3:
79 Matrix_Print(stdout,P_VALUE_FMT,a);
81 Matrix_Print(stdout,P_VALUE_FMT,b);
82 break;
83 case 4:
84 a = Polyhedron2Rays(A);
85 Matrix_Print(stdout,P_VALUE_FMT,a);
86 break;
87 case 5:
88
89 /* a = ec , da = c , ed = 1 */
90 right_hermite(a,&c,&d,&e);
91 Matrix_Print(stdout,P_VALUE_FMT,c);
92 Matrix_Print(stdout,P_VALUE_FMT,d);
93 Matrix_Print(stdout,P_VALUE_FMT,e);
94 f = Matrix_Alloc(e->NbRows,c->NbColumns);
95 Matrix_Product(e,c,f);
96 Matrix_Print(stdout,P_VALUE_FMT,f);
97 Matrix_Free(f);
98 f = Matrix_Alloc(d->NbRows,a->NbColumns);
99 Matrix_Product(d,a,f);
100 Matrix_Print(stdout,P_VALUE_FMT,f);
101 Matrix_Free(f);
102 f = Matrix_Alloc(e->NbRows, d->NbColumns);
103 Matrix_Product(e,d,f);
104 Matrix_Print(stdout,P_VALUE_FMT,f);
105 break;
106 case 6:
107
108 /* a = ce , ad = c , de = 1 */
109 left_hermite(a,&c,&d,&e);
110 Matrix_Print(stdout,P_VALUE_FMT,c);
111 Matrix_Print(stdout,P_VALUE_FMT,d);
112 Matrix_Print(stdout,P_VALUE_FMT,e);
113 f = Matrix_Alloc(c->NbRows, e->NbColumns);
114 Matrix_Product(c,e,f);
115 Matrix_Print(stdout,P_VALUE_FMT,f);
116 Matrix_Free(f);
117 f = Matrix_Alloc(a->NbRows, d->NbColumns);
118 Matrix_Product(a,d,f);
119 Matrix_Print(stdout,P_VALUE_FMT,f);
120 Matrix_Free(f);
121 f = Matrix_Alloc(d->NbRows, e->NbColumns);
122 Matrix_Product(d,e,f);
123 Matrix_Print(stdout,P_VALUE_FMT,f);
124 break;
125 case 7:
126
127 /* Polyhedron_Print(stdout,"%5d", A); */
128 /* Matrix_Print(stdout,"%4d", b); */
129
130 C = Polyhedron_Image(A, b, WS);
132 break;
133 case 8:
134
135 printf("%s\n",
136 Polyhedron_Not_Empty(A,B,WS) ? "Not Empty" : "Empty");
137 break;
138 case 9:
139
140 i = PolyhedronLTQ(A,B,1,0,WS);
141 printf("%s\n",
142 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
143 i = PolyhedronLTQ(B,A,1,0,WS);
144 printf("%s\n",
145 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
146 break;
147 case 10:
148 i = GaussSimplify(a,b);
149 Matrix_Print(stdout,P_VALUE_FMT,b);
150 break;
151
152 default:
153 printf("? unknown function\n");
154 }
155
156 Domain_Free(A);
157 Domain_Free(B);
158
159 return 0;
160}
161
162
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:872
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:449
Matrix * Matrix_Read(void)
Definition: matrix.c:209
void Matrix_Print(FILE *Dst, const char *Format, Matrix *Mat)
Definition: matrix.c:115
void left_hermite(Matrix *A, Matrix **Hp, Matrix **Qp, Matrix **Up)
Definition: matrix.c:517
void Matrix_Free(Matrix *Mat)
Definition: matrix.c:71
Polyhedron * Polyhedron_Image(Polyhedron *Pol, Matrix *Func, unsigned NbMaxConstrs)
Definition: polyhedron.c:4204
Polyhedron * DomainConvex(Polyhedron *Pol, unsigned NbMaxConstrs)
Definition: polyhedron.c:3659
Polyhedron * DomainSimplify(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Definition: polyhedron.c:3346
Polyhedron * DomainUnion(Polyhedron *Pol1, Polyhedron *Pol2, unsigned NbMaxRays)
Definition: polyhedron.c:3585
Matrix * Polyhedron2Constraints(Polyhedron *Pol)
Definition: polyhedron.c:2060
Polyhedron * Constraints2Polyhedron(Matrix *Constraints, unsigned NbMaxRays)
Given a matrix of constraints ('Constraints'), construct and return a polyhedron.
Definition: polyhedron.c:1905
void Polyhedron_Print(FILE *Dst, const char *Format, const Polyhedron *Pol)
Definition: polyhedron.c:1639
void Domain_Free(Polyhedron *Pol)
Definition: polyhedron.c:1626
Matrix * Polyhedron2Rays(Polyhedron *Pol)
Given a polyhedron 'Pol', return a matrix of rays.
Definition: polyhedron.c:2672
char s[128]
Definition: polytest.c:8
#define WS
Definition: polytest.c:6
int main()
Definition: polytest.c:10
Definition: types.h:75
unsigned NbRows
Definition: types.h:76
unsigned NbColumns
Definition: types.h:76
struct polyhedron * next
Definition: types.h:99
#define P_VALUE_FMT
Definition: types.h:39