isl_pw_qpolynomial_from_evalue: rename "dim" parameter to "space"
[barvinok.git] / basis_reduction.c
blob4e32177abbe15f6b829f0b4e4faece680f274887
1 #include <assert.h>
2 #include <isl/options.h>
3 #include <isl/ctx.h>
4 #include <isl/val.h>
5 #include <isl/val_gmp.h>
6 #include <isl/space.h>
7 #include <isl/set.h>
8 #include <isl/mat.h>
9 #include <isl_set_polylib.h>
10 #include <barvinok/basis_reduction.h>
11 #include <barvinok/options.h>
12 #include "config.h"
14 #ifndef HAVE_LIBGLPK
15 Matrix *glpk_Polyhedron_Reduced_Basis(Polyhedron *P,
16 struct barvinok_options *options)
18 assert(0);
20 #endif
22 #ifndef HAVE_LIBCDDGMP
23 Matrix *cdd_Polyhedron_Reduced_Basis(Polyhedron *P,
24 struct barvinok_options *options)
26 assert(0);
28 #endif
30 Matrix *isl_Polyhedron_Reduced_Basis(Polyhedron *P,
31 struct barvinok_options *options)
33 int i, j;
34 isl_val *v;
35 isl_ctx *ctx;
36 isl_space *dim;
37 int nvar = P->Dimension;
38 isl_basic_set *bset;
39 isl_mat *basis;
40 Matrix *M;
42 ctx = isl_ctx_alloc();
43 assert(ctx);
45 isl_options_set_gbr_only_first(ctx, options->gbr_only_first);
47 dim = isl_space_set_alloc(ctx, 0, nvar);
48 bset = isl_basic_set_new_from_polylib(P, dim);
50 basis = isl_basic_set_reduced_basis(bset);
51 isl_basic_set_free(bset);
53 M = Matrix_Alloc(nvar, nvar);
55 for (i = 0; i < nvar; ++i)
56 for (j = 0; j < nvar; ++j) {
57 v = isl_mat_get_element_val(basis, 1 + i, 1 + j);
58 isl_val_get_num_gmp(v, M->p[i][j]);
59 isl_val_free(v);
62 isl_mat_free(basis);
64 isl_ctx_free(ctx);
66 return M;
69 Matrix *Polyhedron_Reduced_Basis(Polyhedron *P, struct barvinok_options *options)
71 if (options->gbr_lp_solver == BV_GBR_GLPK)
72 return glpk_Polyhedron_Reduced_Basis(P, options);
73 else if (options->gbr_lp_solver == BV_GBR_CDD)
74 return cdd_Polyhedron_Reduced_Basis(P, options);
75 else if (options->gbr_lp_solver == BV_GBR_ISL)
76 return isl_Polyhedron_Reduced_Basis(P, options);
77 else
78 assert(0);