omega/polyfunc.cc: avoid warning
[barvinok.git] / test.c
blob831bdc5c6f8dc3767de9286dba6f6dbc6dd84501
1 #include <assert.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <polylib/polylibgmp.h>
6 #include <barvinok/util.h>
7 #include <barvinok/barvinok.h>
8 #include "config.h"
10 #ifdef HAVE_GROWING_CHERNIKOVA
11 #define MAXRAYS POL_NO_DUAL
12 #else
13 #define MAXRAYS 600
14 #endif
16 #ifdef HAVE_SYS_TIMES_H
18 #include <sys/times.h>
20 static void time_diff(struct tms *before, struct tms *after)
22 long ticks = sysconf(_SC_CLK_TCK);
23 printf("User: %g; Sys: %g\n",
24 (0.0 + after->tms_utime - before->tms_utime) / ticks,
25 (0.0 + after->tms_stime - before->tms_stime) / ticks);
28 #else
30 struct tms {};
31 static void times(struct tms* time)
34 static void time_diff(struct tms *before, struct tms *after)
38 #endif
40 int main()
42 int i, nbPol, nbVec, func, j;
43 Polyhedron *A, *B, *C, *D, *E, *F, *G;
44 char s[128];
46 nbPol = nbVec = 0;
47 fgets(s, 128, stdin);
48 while ((*s=='#') ||
49 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "V %d", &nbVec)<1)) )
50 fgets(s, 128, stdin);
52 for (i = 0; i < nbPol; ++i) {
53 Matrix *M = Matrix_Read();
54 A = Constraints2Polyhedron(M, MAXRAYS);
55 Matrix_Free(M);
56 fgets(s, 128, stdin);
57 while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
58 fgets(s, 128, stdin);
60 switch(func) {
61 case 0: {
62 Value cb, ck;
63 value_init(cb);
64 value_init(ck);
65 fgets(s, 128, stdin);
66 /* workaround for apparent bug in older gmps */
67 *strchr(s, '\n') = '\0';
68 while ((*s=='#') || (value_read(ck, s) != 0)) {
69 fgets(s, 128, stdin);
70 /* workaround for apparent bug in older gmps */
71 *strchr(s, '\n') = '\0';
73 barvinok_count(A, &cb, MAXRAYS);
74 if (value_ne(cb, ck))
75 return -1;
76 value_clear(cb);
77 value_clear(ck);
78 break;
80 case 1:
81 Polyhedron_Print(stdout, P_VALUE_FMT, A);
82 B = Polyhedron_Polar(A, MAXRAYS);
83 Polyhedron_Print(stdout, P_VALUE_FMT, B);
84 C = Polyhedron_Polar(B, MAXRAYS);
85 Polyhedron_Print(stdout, P_VALUE_FMT, C);
86 Polyhedron_Free(C);
87 Polyhedron_Free(B);
88 break;
89 case 2:
90 Polyhedron_Print(stdout, P_VALUE_FMT, A);
91 for (j = 0; j < A->NbRays; ++j) {
92 B = supporting_cone(A, j);
93 Polyhedron_Print(stdout, P_VALUE_FMT, B);
94 Polyhedron_Free(B);
96 break;
97 case 3:
98 Polyhedron_Print(stdout, P_VALUE_FMT, A);
99 C = B = NULL;
100 barvinok_decompose(A,&B,&C);
101 puts("Pos:");
102 Polyhedron_Print(stdout, P_VALUE_FMT, B);
103 puts("Neg:");
104 Polyhedron_Print(stdout, P_VALUE_FMT, C);
105 Domain_Free(B);
106 Domain_Free(C);
107 break;
108 case 4: {
109 Value cm, cb;
110 struct tms tms_before, tms_between, tms_after;
111 value_init(cm);
112 value_init(cb);
113 Polyhedron_Print(stdout, P_VALUE_FMT, A);
114 times(&tms_before);
115 manual_count(A, &cm);
116 times(&tms_between);
117 barvinok_count(A, &cb, 100);
118 times(&tms_after);
119 printf("manual: ");
120 value_print(stdout, P_VALUE_FMT, cm);
121 puts("");
122 time_diff(&tms_before, &tms_between);
123 printf("Barvinok: ");
124 value_print(stdout, P_VALUE_FMT, cb);
125 puts("");
126 time_diff(&tms_between, &tms_after);
127 value_clear(cm);
128 value_clear(cb);
129 break;
131 case 5:
132 Polyhedron_Print(stdout, P_VALUE_FMT, A);
133 B = triangulate_cone(A, 100);
134 Polyhedron_Print(stdout, P_VALUE_FMT, B);
135 check_triangulization(A, B);
136 Domain_Free(B);
137 break;
138 case 6:
139 Polyhedron_Print(stdout, P_VALUE_FMT, A);
140 B = remove_equalities(A);
141 Polyhedron_Print(stdout, P_VALUE_FMT, B);
142 Polyhedron_Free(B);
143 break;
144 case 8: {
145 evalue *EP;
146 Matrix *M = Matrix_Read();
147 char **param_name;
148 C = Constraints2Polyhedron(M, MAXRAYS);
149 Matrix_Free(M);
150 Polyhedron_Print(stdout, P_VALUE_FMT, A);
151 Polyhedron_Print(stdout, P_VALUE_FMT, C);
152 EP = barvinok_enumerate_ev(A, C, MAXRAYS);
153 param_name = Read_ParamNames(stdin, C->Dimension);
154 print_evalue(stdout, EP, param_name);
155 free_evalue_refs(EP);
156 free(EP);
157 Polyhedron_Free(C);
159 case 9:
160 Polyhedron_Print(stdout, P_VALUE_FMT, A);
161 Polyhedron_Polarize(A);
162 C = B = NULL;
163 barvinok_decompose(A,&B,&C);
164 for (D = B; D; D = D->next)
165 Polyhedron_Polarize(D);
166 for (D = C; D; D = D->next)
167 Polyhedron_Polarize(D);
168 puts("Pos:");
169 Polyhedron_Print(stdout, P_VALUE_FMT, B);
170 puts("Neg:");
171 Polyhedron_Print(stdout, P_VALUE_FMT, C);
172 Domain_Free(B);
173 Domain_Free(C);
174 break;
176 Polyhedron_Free(A);
178 for (i = 0; i < nbVec; ++i) {
179 Vector *V = Vector_Read();
180 Matrix *M = unimodular_complete(V);
181 Matrix_Print(stdout, P_VALUE_FMT, M);
182 Matrix_Free(M);
183 Vector_Free(V);
186 return 0;