update isl for normalization of isl_term_get_div result
[barvinok.git] / basis_reduction.c
blobd87a044f650956cf2a967b525d982d980a6ee213
1 #include <assert.h>
2 #include <isl/options.h>
3 #include <isl_set_polylib.h>
4 #include <barvinok/basis_reduction.h>
5 #include <barvinok/options.h>
6 #include "config.h"
8 #ifndef HAVE_LIBGLPK
9 Matrix *glpk_Polyhedron_Reduced_Basis(Polyhedron *P,
10 struct barvinok_options *options)
12 assert(0);
14 #endif
16 #ifndef HAVE_LIBCDDGMP
17 Matrix *cdd_Polyhedron_Reduced_Basis(Polyhedron *P,
18 struct barvinok_options *options)
20 assert(0);
22 #endif
24 Matrix *isl_Polyhedron_Reduced_Basis(Polyhedron *P,
25 struct barvinok_options *options)
27 int i, j;
28 isl_int v;
29 isl_ctx *ctx;
30 isl_space *dim;
31 int nvar = P->Dimension;
32 isl_basic_set *bset;
33 isl_mat *basis;
34 Matrix *M;
35 int isl_gbr_only_first;
37 ctx = isl_ctx_alloc_with_options(&barvinok_options_args, options);
38 assert(ctx);
40 isl_gbr_only_first = isl_options_get_gbr_only_first(ctx);
41 isl_options_set_gbr_only_first(ctx, options->gbr_only_first);
43 dim = isl_space_set_alloc(ctx, 0, nvar);
44 bset = isl_basic_set_new_from_polylib(P, dim);
46 basis = isl_basic_set_reduced_basis(bset);
47 isl_basic_set_free(bset);
49 M = Matrix_Alloc(nvar, nvar);
51 isl_int_init(v);
52 for (i = 0; i < nvar; ++i)
53 for (j = 0; j < nvar; ++j) {
54 isl_mat_get_element(basis, 1 + i, 1 + j, &v);
55 isl_int_get_gmp(v, M->p[i][j]);
57 isl_int_clear(v);
59 isl_mat_free(basis);
61 isl_ctx_free(ctx);
63 isl_options_set_gbr_only_first(ctx, isl_gbr_only_first);
65 return M;
68 Matrix *Polyhedron_Reduced_Basis(Polyhedron *P, struct barvinok_options *options)
70 if (options->gbr_lp_solver == BV_GBR_GLPK)
71 return glpk_Polyhedron_Reduced_Basis(P, options);
72 else if (options->gbr_lp_solver == BV_GBR_CDD)
73 return cdd_Polyhedron_Reduced_Basis(P, options);
74 else if (options->gbr_lp_solver == BV_GBR_ISL)
75 return isl_Polyhedron_Reduced_Basis(P, options);
76 else
77 assert(0);