update pet to version 0.06
[barvinok/uuh.git] / basis_reduction.c
blobc1c185fc13a8e0e90fb4721843a11bab9b4ec473
1 #include <assert.h>
2 #include <isl/options.h>
3 #include <isl/val_gmp.h>
4 #include <isl_set_polylib.h>
5 #include <barvinok/basis_reduction.h>
6 #include <barvinok/options.h>
7 #include "config.h"
9 #ifndef HAVE_LIBGLPK
10 Matrix *glpk_Polyhedron_Reduced_Basis(Polyhedron *P,
11 struct barvinok_options *options)
13 assert(0);
15 #endif
17 #ifndef HAVE_LIBCDDGMP
18 Matrix *cdd_Polyhedron_Reduced_Basis(Polyhedron *P,
19 struct barvinok_options *options)
21 assert(0);
23 #endif
25 Matrix *isl_Polyhedron_Reduced_Basis(Polyhedron *P,
26 struct barvinok_options *options)
28 int i, j;
29 isl_val *v;
30 isl_ctx *ctx;
31 isl_space *dim;
32 int nvar = P->Dimension;
33 isl_basic_set *bset;
34 isl_mat *basis;
35 Matrix *M;
37 ctx = isl_ctx_alloc();
38 assert(ctx);
40 isl_options_set_gbr_only_first(ctx, options->gbr_only_first);
42 dim = isl_space_set_alloc(ctx, 0, nvar);
43 bset = isl_basic_set_new_from_polylib(P, dim);
45 basis = isl_basic_set_reduced_basis(bset);
46 isl_basic_set_free(bset);
48 M = Matrix_Alloc(nvar, nvar);
50 for (i = 0; i < nvar; ++i)
51 for (j = 0; j < nvar; ++j) {
52 v = isl_mat_get_element_val(basis, 1 + i, 1 + j);
53 isl_val_get_num_gmp(v, M->p[i][j]);
54 isl_val_free(v);
57 isl_mat_free(basis);
59 isl_ctx_free(ctx);
61 return M;
64 Matrix *Polyhedron_Reduced_Basis(Polyhedron *P, struct barvinok_options *options)
66 if (options->gbr_lp_solver == BV_GBR_GLPK)
67 return glpk_Polyhedron_Reduced_Basis(P, options);
68 else if (options->gbr_lp_solver == BV_GBR_CDD)
69 return cdd_Polyhedron_Reduced_Basis(P, options);
70 else if (options->gbr_lp_solver == BV_GBR_ISL)
71 return isl_Polyhedron_Reduced_Basis(P, options);
72 else
73 assert(0);