make compute_enode work again in general case
[barvinok.git] / randomtest.c
blob1605b9adaaeed911011383cbbc3334dcf62ba2e9
1 #include <assert.h>
2 #include <unistd.h>
3 #include <sys/times.h>
4 #include <polylib/polylibgmp.h>
5 #include <util.h>
6 #include <barvinok.h>
8 static void time_diff(struct tms *before, struct tms *after)
10 long ticks = sysconf(_SC_CLK_TCK);
11 printf("User: %g; Sys: %g\n",
12 (0.0 + after->tms_utime - before->tms_utime) / ticks,
13 (0.0 + after->tms_stime - before->tms_stime) / ticks);
16 int main()
18 static const int size = 1000;
19 static const int loop = 10;
20 int i, j, d, r, c;
21 Matrix *M;
22 Polyhedron *P;
23 Value cm, cb;
24 struct tms tms_before, tms_between, tms_after;
25 value_init(cm);
26 value_init(cb);
28 for (d = 2; d < 10; ++d) {
29 M = Matrix_Alloc(2*d, 2+d);
30 for (r = 0; r < 2*d; ++r)
31 value_set_si(M->p[r][0], 1);
32 for (i = 0; i < loop; ++i) {
33 for (r = 0; r < 2*d; ++r) {
34 for (c = 1; c < 1+d; ++c) {
35 value_set_si(M->p[r][c], random_int(size));
37 value_set_si(M->p[r][d+1], random_int(2)+1);
39 P = Rays2Polyhedron(M, 2*d);
40 Polyhedron_Print(stdout, P_VALUE_FMT, P);
41 times(&tms_before);
42 manual_count(P, &cm);
43 times(&tms_between);
44 barvinok_count(P, &cb, 100);
45 times(&tms_after);
46 printf("manual: ");
47 value_print(stdout, P_VALUE_FMT, cm);
48 puts("");
49 time_diff(&tms_before, &tms_between);
50 printf("Barvinok: ");
51 value_print(stdout, P_VALUE_FMT, cb);
52 puts("");
53 time_diff(&tms_between, &tms_after);
54 assert(value_eq(cm, cb));
56 Matrix_Free(M);
58 value_clear(cm);
59 value_clear(cb);
60 return 0;