update isl for removal of isl_div
[barvinok.git] / basis_reduction.c
blob99f2a1a690d21bd3bc21018840f6ae3d39ed6bf6
1 #include <assert.h>
2 #include <isl_set_polylib.h>
3 #include <barvinok/basis_reduction.h>
4 #include <barvinok/options.h>
5 #include "config.h"
7 #ifndef HAVE_LIBGLPK
8 Matrix *glpk_Polyhedron_Reduced_Basis(Polyhedron *P,
9 struct barvinok_options *options)
11 assert(0);
13 #endif
15 #ifndef HAVE_LIBCDDGMP
16 Matrix *cdd_Polyhedron_Reduced_Basis(Polyhedron *P,
17 struct barvinok_options *options)
19 assert(0);
21 #endif
23 Matrix *isl_Polyhedron_Reduced_Basis(Polyhedron *P,
24 struct barvinok_options *options)
26 int i, j;
27 isl_int v;
28 isl_ctx *ctx;
29 isl_space *dim;
30 int nvar = P->Dimension;
31 isl_basic_set *bset;
32 isl_mat *basis;
33 Matrix *M;
34 int isl_gbr_only_first = options->isl->gbr_only_first;
36 options->isl->gbr_only_first = options->gbr_only_first;
37 ctx = isl_ctx_alloc_with_options(barvinok_options_arg, options);
38 assert(ctx);
40 dim = isl_space_set_alloc(ctx, 0, nvar);
41 bset = isl_basic_set_new_from_polylib(P, dim);
43 basis = isl_basic_set_reduced_basis(bset);
44 isl_basic_set_free(bset);
46 M = Matrix_Alloc(nvar, nvar);
48 isl_int_init(v);
49 for (i = 0; i < nvar; ++i)
50 for (j = 0; j < nvar; ++j) {
51 isl_mat_get_element(basis, 1 + i, 1 + j, &v);
52 isl_int_get_gmp(v, M->p[i][j]);
54 isl_int_clear(v);
56 isl_mat_free(basis);
58 isl_ctx_free(ctx);
60 options->isl->gbr_only_first = isl_gbr_only_first;
62 return M;
65 Matrix *Polyhedron_Reduced_Basis(Polyhedron *P, struct barvinok_options *options)
67 if (options->gbr_lp_solver == BV_GBR_GLPK)
68 return glpk_Polyhedron_Reduced_Basis(P, options);
69 else if (options->gbr_lp_solver == BV_GBR_CDD)
70 return cdd_Polyhedron_Reduced_Basis(P, options);
71 else if (options->gbr_lp_solver == BV_GBR_ISL)
72 return isl_Polyhedron_Reduced_Basis(P, options);
73 else
74 assert(0);