00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <polylib/polylib.h>
00021
00022 #define WS 0
00023
00024 char s[128];
00025
00026 int main() {
00027
00028 Matrix *a=NULL, *b=NULL, *c, *d, *e, *f;
00029 Polyhedron *A, *B, *C, *D, *last, *tmp;
00030 int i, nbPol, nbMat, func;
00031
00032 fgets(s, 128, stdin);
00033 nbPol = nbMat = 0;
00034 while ((*s=='#') ||
00035 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
00036 fgets(s, 128, stdin);
00037
00038 for (i=0, A=last=(Polyhedron *)0; i<nbPol; i++) {
00039 a = Matrix_Read();
00040 tmp = Constraints2Polyhedron(a,WS);
00041 Matrix_Free(a);
00042 if (!last) A = last = tmp;
00043 else {
00044 last->next = tmp;
00045 last = tmp;
00046 }
00047 }
00048
00049 if (nbMat)
00050 { a = Matrix_Read(); }
00051
00052 fgets(s,128,stdin);
00053 nbPol = nbMat = 0;
00054 while ( (*s=='#') ||
00055 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "M %d", &nbMat)<1)) )
00056 fgets(s, 128, stdin);
00057
00058 for (i=0, B=last=(Polyhedron *)0; i<nbPol; i++) {
00059 b = Matrix_Read();
00060 tmp = Constraints2Polyhedron(b,WS);
00061 Matrix_Free(b);
00062 if (!last) B = last = tmp;
00063 else {
00064 last->next = tmp;
00065 last = tmp;
00066 }
00067 }
00068
00069 if (nbMat)
00070 { b = Matrix_Read(); }
00071
00072 fgets(s, 128, stdin);
00073 while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
00074 fgets(s, 128, stdin);
00075
00076 switch (func) {
00077 case 1:
00078 C = DomainUnion(A, B, WS);
00079 D = DomainConvex(C, WS);
00080 d = Polyhedron2Constraints(D);
00081 Matrix_Print(stdout,P_VALUE_FMT,d);
00082 Matrix_Free(d);
00083 Domain_Free(C);
00084 Domain_Free(D);
00085 break;
00086 case 2:
00087 D = DomainSimplify(A, B, WS);
00088 d = Polyhedron2Constraints(D);
00089 Matrix_Print(stdout,P_VALUE_FMT,d);
00090 Matrix_Free(d);
00091 Domain_Free(D);
00092 break;
00093 case 3:
00094 a = Polyhedron2Constraints(A);
00095 Matrix_Print(stdout,P_VALUE_FMT,a);
00096 b = Polyhedron2Constraints(B);
00097 Matrix_Print(stdout,P_VALUE_FMT,b);
00098 break;
00099 case 4:
00100 a = Polyhedron2Rays(A);
00101 Matrix_Print(stdout,P_VALUE_FMT,a);
00102 break;
00103 case 5:
00104
00105
00106 right_hermite(a,&c,&d,&e);
00107 Matrix_Print(stdout,P_VALUE_FMT,c);
00108 Matrix_Print(stdout,P_VALUE_FMT,d);
00109 Matrix_Print(stdout,P_VALUE_FMT,e);
00110 f = Matrix_Alloc(e->NbRows,c->NbColumns);
00111 Matrix_Product(e,c,f);
00112 Matrix_Print(stdout,P_VALUE_FMT,f);
00113 Matrix_Free(f);
00114 f = Matrix_Alloc(d->NbRows,a->NbColumns);
00115 Matrix_Product(d,a,f);
00116 Matrix_Print(stdout,P_VALUE_FMT,f);
00117 Matrix_Free(f);
00118 f = Matrix_Alloc(e->NbRows, d->NbColumns);
00119 Matrix_Product(e,d,f);
00120 Matrix_Print(stdout,P_VALUE_FMT,f);
00121 break;
00122 case 6:
00123
00124
00125 left_hermite(a,&c,&d,&e);
00126 Matrix_Print(stdout,P_VALUE_FMT,c);
00127 Matrix_Print(stdout,P_VALUE_FMT,d);
00128 Matrix_Print(stdout,P_VALUE_FMT,e);
00129 f = Matrix_Alloc(c->NbRows, e->NbColumns);
00130 Matrix_Product(c,e,f);
00131 Matrix_Print(stdout,P_VALUE_FMT,f);
00132 Matrix_Free(f);
00133 f = Matrix_Alloc(a->NbRows, d->NbColumns);
00134 Matrix_Product(a,d,f);
00135 Matrix_Print(stdout,P_VALUE_FMT,f);
00136 Matrix_Free(f);
00137 f = Matrix_Alloc(d->NbRows, e->NbColumns);
00138 Matrix_Product(d,e,f);
00139 Matrix_Print(stdout,P_VALUE_FMT,f);
00140 break;
00141 case 7:
00142
00143
00144
00145
00146 C = Polyhedron_Image(A, b, WS);
00147 Polyhedron_Print(stdout,P_VALUE_FMT,C);
00148 break;
00149 case 8:
00150
00151 printf("%s\n",
00152 Polyhedron_Not_Empty(A,B,WS) ? "Not Empty" : "Empty");
00153 break;
00154 case 9:
00155
00156 i = PolyhedronLTQ(A,B,1,0,WS);
00157 printf("%s\n",
00158 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
00159 i = PolyhedronLTQ(B,A,1,0,WS);
00160 printf("%s\n",
00161 i==-1 ? "A<B" : i==1 ? "A>B" : i==0 ? "A><B" : "error");
00162 break;
00163 case 10:
00164 i = GaussSimplify(a,b);
00165 Matrix_Print(stdout,P_VALUE_FMT,b);
00166 break;
00167
00168 default:
00169 printf("? unknown function\n");
00170 }
00171
00172 Domain_Free(A);
00173 Domain_Free(B);
00174
00175 return 0;
00176 }
00177
00178