update isl for normalization of isl_term_get_div result
[barvinok.git] / polytope_scan.c
blobf14139b2a0478ea15c8d4001015e98fba5028315
1 #include <assert.h>
2 #include <unistd.h>
3 #include <stdlib.h>
4 #include <strings.h>
5 #include <barvinok/util.h>
6 #include <barvinok/options.h>
7 #include <barvinok/basis_reduction.h>
9 #define ALLOCN(type,n) (type*)malloc((n) * sizeof(type))
11 struct options {
12 struct barvinok_options *barvinok;
13 int direct;
16 ISL_ARGS_START(struct options, options_args)
17 ISL_ARG_CHILD(struct options, barvinok, NULL, &barvinok_options_args, NULL)
18 ISL_ARG_BOOL(struct options, direct, 'd', "direct", 0,
19 "don't apply generalized basis reduction first")
20 ISL_ARGS_END
22 ISL_ARG_DEF(options, struct options, options_args)
24 static void scan_poly(Polyhedron *S, int pos, Value *z, Matrix *T)
26 if (!S) {
27 int k;
28 Vector *v;
30 v = Vector_Alloc(T->NbRows);
31 Matrix_Vector_Product(T, z+1, v->p);
32 value_print(stdout, VALUE_FMT, v->p[0]);
33 for (k=1; k < pos; ++k) {
34 printf(", ");
35 value_print(stdout,VALUE_FMT, v->p[k]);
37 Vector_Free(v);
38 printf("\n");
39 } else {
40 int ok;
41 Value LB, UB, tmp;
42 value_init(LB);
43 value_init(UB);
44 value_init(tmp);
45 ok = !(lower_upper_bounds(1+pos, S, z, &LB, &UB));
46 assert(ok);
47 for (value_assign(tmp,LB); value_le(tmp,UB); value_increment(tmp,tmp)) {
48 value_assign(z[pos+1], tmp);
49 scan_poly(S->next, pos+1, z, T);
51 value_set_si(z[pos+1], 0);
52 value_clear(LB);
53 value_clear(UB);
54 value_clear(tmp);
58 int main(int argc, char **argv)
60 Polyhedron *A, *P, *U, *S;
61 Value *p;
62 int i, j, ok;
63 Matrix *basis, *T, *inv;
64 int c, ind = 0;
65 struct options *options = options_new_with_defaults();
67 argc = options_parse(options, argc, argv, ISL_ARG_ALL);
69 A = Polyhedron_Read(options->barvinok->MaxRays);
71 if (options->direct) {
72 inv = Identity(A->Dimension+1);
73 P = A;
74 } else {
75 basis = Polyhedron_Reduced_Basis(A, options->barvinok);
77 T = Matrix_Alloc(A->Dimension+1, A->Dimension+1);
78 inv = Matrix_Alloc(A->Dimension+1, A->Dimension+1);
79 for (i = 0; i < A->Dimension; ++i)
80 for (j = 0; j < A->Dimension; ++j)
81 value_assign(T->p[i][j], basis->p[i][j]);
82 value_set_si(T->p[A->Dimension][A->Dimension], 1);
83 Matrix_Free(basis);
85 ok = Matrix_Inverse(T, inv);
86 assert(ok);
87 Matrix_Free(T);
89 P = Polyhedron_Preimage(A, inv, options->barvinok->MaxRays);
90 Polyhedron_Free(A);
93 U = Universe_Polyhedron(0);
94 S = Polyhedron_Scan(P, U, options->barvinok->MaxRays);
96 p = ALLOCN(Value, P->Dimension+2);
97 for(i=0;i<=P->Dimension;i++) {
98 value_init(p[i]);
99 value_set_si(p[i],0);
101 value_init(p[i]);
102 value_set_si(p[i],1);
104 scan_poly(S, 0, p, inv);
106 Matrix_Free(inv);
107 for(i=0;i<=(P->Dimension+1);i++)
108 value_clear(p[i]);
109 free(p);
110 Domain_Free(S);
111 Polyhedron_Free(P);
112 Polyhedron_Free(U);
113 options_free(options);
114 return 0;