iscc: add typeof operator
[barvinok.git] / basis_reduction.c
blob89920197018cd89fe5ad3c5d0dc64ea5807f2ff5
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 #ifndef HAVE_PIPLIB
24 Matrix *pip_Polyhedron_Reduced_Basis(Polyhedron *P,
25 struct barvinok_options *options)
27 assert(0);
29 Matrix *pip_dual_Polyhedron_Reduced_Basis(Polyhedron *P,
30 struct barvinok_options *options)
32 assert(0);
34 #endif
36 Matrix *isl_Polyhedron_Reduced_Basis(Polyhedron *P,
37 struct barvinok_options *options)
39 int i, j;
40 isl_int v;
41 isl_ctx *ctx = isl_ctx_alloc();
42 isl_dim *dim;
43 int nvar = P->Dimension;
44 isl_basic_set *bset;
45 isl_mat *basis;
46 Matrix *M;
48 assert(ctx);
49 ctx->opt->gbr_only_first = options->gbr_only_first;
51 dim = isl_dim_set_alloc(ctx, 0, nvar);
52 bset = isl_basic_set_new_from_polylib(P, dim);
54 basis = isl_basic_set_reduced_basis(bset);
55 isl_basic_set_free(bset);
57 M = Matrix_Alloc(nvar, nvar);
59 isl_int_init(v);
60 for (i = 0; i < nvar; ++i)
61 for (j = 0; j < nvar; ++j) {
62 isl_mat_get_element(basis, 1 + i, 1 + j, &v);
63 isl_int_get_gmp(v, M->p[i][j]);
65 isl_int_clear(v);
67 isl_mat_free(basis);
69 isl_ctx_free(ctx);
71 return M;
74 Matrix *Polyhedron_Reduced_Basis(Polyhedron *P, struct barvinok_options *options)
76 if (options->gbr_lp_solver == BV_GBR_GLPK)
77 return glpk_Polyhedron_Reduced_Basis(P, options);
78 else if (options->gbr_lp_solver == BV_GBR_CDD)
79 return cdd_Polyhedron_Reduced_Basis(P, options);
80 else if (options->gbr_lp_solver == BV_GBR_PIP)
81 return pip_Polyhedron_Reduced_Basis(P, options);
82 else if (options->gbr_lp_solver == BV_GBR_PIP_DUAL)
83 return pip_dual_Polyhedron_Reduced_Basis(P, options);
84 else if (options->gbr_lp_solver == BV_GBR_ISL)
85 return isl_Polyhedron_Reduced_Basis(P, options);
86 else
87 assert(0);