Convert multiple existential variables in an equality into a single one
[barvinok.git] / test.c
blobcb39378ea781ce4d304ce0b677ef72a518629f9b
1 #include <assert.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <sys/times.h>
5 #include <polylib/polylibgmp.h>
6 #include <util.h>
7 #include <barvinok.h>
9 static void time_diff(struct tms *before, struct tms *after)
11 long ticks = sysconf(_SC_CLK_TCK);
12 printf("User: %g; Sys: %g\n",
13 (0.0 + after->tms_utime - before->tms_utime) / ticks,
14 (0.0 + after->tms_stime - before->tms_stime) / ticks);
17 int main()
19 int i, nbPol, nbVec, func, j;
20 Polyhedron *A, *B, *C, *D, *E, *F, *G;
21 char s[128];
23 nbPol = nbVec = 0;
24 fgets(s, 128, stdin);
25 while ((*s=='#') ||
26 ((sscanf(s, "D %d", &nbPol)<1) && (sscanf(s, "V %d", &nbVec)<1)) )
27 fgets(s, 128, stdin);
29 for (i = 0; i < nbPol; ++i) {
30 Matrix *M = Matrix_Read();
31 A = Constraints2Polyhedron(M, 600);
32 Matrix_Free(M);
33 fgets(s, 128, stdin);
34 while ((*s=='#') || (sscanf(s, "F %d", &func)<1))
35 fgets(s, 128, stdin);
37 switch(func) {
38 case 0: {
39 Value cb, ck;
40 value_init(cb);
41 value_init(ck);
42 fgets(s, 128, stdin);
43 while ((*s=='#') || (value_read(ck, s) != 0))
44 fgets(s, 128, stdin);
45 barvinok_count(A, &cb, 100);
46 if (value_ne(cb, ck))
47 return -1;
48 value_clear(cb);
49 value_clear(ck);
50 break;
52 case 1:
53 Polyhedron_Print(stdout, P_VALUE_FMT, A);
54 B = Polyhedron_Polar(A, 600);
55 Polyhedron_Print(stdout, P_VALUE_FMT, B);
56 C = Polyhedron_Polar(B, 600);
57 Polyhedron_Print(stdout, P_VALUE_FMT, C);
58 Polyhedron_Free(C);
59 Polyhedron_Free(B);
60 break;
61 case 2:
62 Polyhedron_Print(stdout, P_VALUE_FMT, A);
63 for (j = 0; j < A->NbRays; ++j) {
64 B = supporting_cone(A, j);
65 Polyhedron_Print(stdout, P_VALUE_FMT, B);
66 Polyhedron_Free(B);
68 break;
69 case 3:
70 Polyhedron_Print(stdout, P_VALUE_FMT, A);
71 C = B = NULL;
72 barvinok_decompose(A,&B,&C);
73 puts("Pos:");
74 Polyhedron_Print(stdout, P_VALUE_FMT, B);
75 puts("Neg:");
76 Polyhedron_Print(stdout, P_VALUE_FMT, C);
77 Domain_Free(B);
78 Domain_Free(C);
79 break;
80 case 4: {
81 Value cm, cb;
82 struct tms tms_before, tms_between, tms_after;
83 value_init(cm);
84 value_init(cb);
85 Polyhedron_Print(stdout, P_VALUE_FMT, A);
86 times(&tms_before);
87 manual_count(A, &cm);
88 times(&tms_between);
89 barvinok_count(A, &cb, 100);
90 times(&tms_after);
91 printf("manual: ");
92 value_print(stdout, P_VALUE_FMT, cm);
93 puts("");
94 time_diff(&tms_before, &tms_between);
95 printf("Barvinok: ");
96 value_print(stdout, P_VALUE_FMT, cb);
97 puts("");
98 time_diff(&tms_between, &tms_after);
99 value_clear(cm);
100 value_clear(cb);
101 break;
103 case 5:
104 Polyhedron_Print(stdout, P_VALUE_FMT, A);
105 B = triangularize_cone(A, 100);
106 Polyhedron_Print(stdout, P_VALUE_FMT, B);
107 check_triangulization(A, B);
108 Domain_Free(B);
109 break;
110 case 6:
111 Polyhedron_Print(stdout, P_VALUE_FMT, A);
112 B = remove_equalities(A);
113 Polyhedron_Print(stdout, P_VALUE_FMT, B);
114 Polyhedron_Free(B);
115 break;
116 case 7: {
117 Value f;
118 value_init(f);
119 Polyhedron_Print(stdout, P_VALUE_FMT, A);
120 B = Polyhedron_Reduce(A, &f);
121 Polyhedron_Print(stdout, P_VALUE_FMT, B);
122 Polyhedron_Free(B);
123 printf("factor: ");
124 value_print(stdout, P_VALUE_FMT, f);
125 puts("");
126 value_clear(f);
127 break;
129 case 8: {
130 Enumeration *en;
131 Matrix *M = Matrix_Read();
132 char **param_name;
133 C = Constraints2Polyhedron(M, 600);
134 Matrix_Free(M);
135 Polyhedron_Print(stdout, P_VALUE_FMT, A);
136 Polyhedron_Print(stdout, P_VALUE_FMT, C);
137 en = barvinok_enumerate(A, C, 600);
138 param_name = Read_ParamNames(stdin, C->Dimension);
139 print_evalue(stdout, &en->EP, param_name);
140 Enumeration_Free(en);
141 Polyhedron_Free(C);
143 case 9:
144 Polyhedron_Print(stdout, P_VALUE_FMT, A);
145 Polyhedron_Polarize(A);
146 C = B = NULL;
147 barvinok_decompose(A,&B,&C);
148 for (D = B; D; D = D->next)
149 Polyhedron_Polarize(D);
150 for (D = C; D; D = D->next)
151 Polyhedron_Polarize(D);
152 puts("Pos:");
153 Polyhedron_Print(stdout, P_VALUE_FMT, B);
154 puts("Neg:");
155 Polyhedron_Print(stdout, P_VALUE_FMT, C);
156 Domain_Free(B);
157 Domain_Free(C);
158 break;
160 Polyhedron_Free(A);
162 for (i = 0; i < nbVec; ++i) {
163 Vector *V = Vector_Read();
164 Matrix *M = unimodular_complete(V);
165 Matrix_Print(stdout, P_VALUE_FMT, M);
166 Matrix_Free(M);
167 Vector_Free(V);
170 return 0;