isl_list.c: add missing include
[isl.git] / isl_lp.c
blobb4379f7c43bfe83968034ca5c9de46ca3d65fec5
1 #include "isl_ctx.h"
2 #include "isl_lp.h"
3 #include "isl_lp_piplib.h"
4 #include "isl_tab.h"
5 #include "isl_map_private.h"
7 enum isl_lp_result isl_tab_solve_lp(struct isl_basic_map *bmap, int maximize,
8 isl_int *f, isl_int denom, isl_int *opt,
9 isl_int *opt_denom,
10 struct isl_vec **sol)
12 struct isl_tab *tab;
13 enum isl_lp_result res;
14 unsigned dim = isl_basic_map_total_dim(bmap);
16 if (maximize)
17 isl_seq_neg(f, f, 1 + dim);
19 bmap = isl_basic_map_gauss(bmap, NULL);
20 tab = isl_tab_from_basic_map(bmap);
21 res = isl_tab_min(tab, f, bmap->ctx->one, opt, opt_denom, 0);
22 if (res == isl_lp_ok && sol) {
23 *sol = isl_tab_get_sample_value(tab);
24 if (!*sol)
25 res = isl_lp_error;
27 isl_tab_free(tab);
29 if (maximize)
30 isl_seq_neg(f, f, 1 + dim);
32 return res;
35 /* Given a basic map "bmap" and an affine combination of the variables "f"
36 * with denominator "denom", set *opt/*opt_denom to the minimal
37 * (or maximal if "maximize" is true) value attained by f/d over "bmap",
38 * assuming the basic map is not empty and the expression cannot attain
39 * arbitrarily small (or large) values.
40 * If opt_denom is NULL, then *opt is rounded up (or down)
41 * to the nearest integer.
42 * The return value reflects the nature of the result (empty, unbounded,
43 * minmimal or maximal value returned in *opt).
45 enum isl_lp_result isl_basic_map_solve_lp(struct isl_basic_map *bmap, int max,
46 isl_int *f, isl_int d, isl_int *opt,
47 isl_int *opt_denom,
48 struct isl_vec **sol)
50 if (sol)
51 *sol = NULL;
53 if (!bmap)
54 return isl_lp_error;
56 switch (bmap->ctx->lp_solver) {
57 case ISL_LP_PIP:
58 return isl_pip_solve_lp(bmap, max, f, d, opt, opt_denom, sol);
59 case ISL_LP_TAB:
60 return isl_tab_solve_lp(bmap, max, f, d, opt, opt_denom, sol);
61 default:
62 return isl_lp_error;
66 enum isl_lp_result isl_basic_set_solve_lp(struct isl_basic_set *bset, int max,
67 isl_int *f, isl_int d, isl_int *opt,
68 isl_int *opt_denom,
69 struct isl_vec **sol)
71 return isl_basic_map_solve_lp((struct isl_basic_map *)bset, max,
72 f, d, opt, opt_denom, sol);