add isl_map_from_range
[isl.git] / isl_lp_piplib.c
blob609093affa079d3f6c9311da00823f9557da00de
1 #include "isl_map.h"
2 #include "isl_lp.h"
3 #include "isl_piplib.h"
4 #include "isl_map_piplib.h"
6 enum isl_lp_result isl_pip_solve_lp(struct isl_basic_map *bmap, int maximize,
7 isl_int *f, isl_int denom, isl_int *opt,
8 isl_int *opt_denom)
10 enum isl_lp_result res = isl_lp_ok;
11 PipMatrix *domain = NULL;
12 PipOptions *options;
13 PipQuast *sol;
14 unsigned total;
16 total = isl_basic_map_total_dim(bmap);
17 domain = isl_basic_map_to_pip(bmap, 0, 1, 0);
18 if (!domain)
19 goto error;
20 entier_set_si(domain->p[0][1], -1);
21 isl_seq_cpy_to_pip(domain->p[0]+2, f, total);
23 options = pip_options_init();
24 if (!options)
25 goto error;
26 options->Urs_unknowns = -1;
27 options->Maximize = maximize;
28 options->Nq = 0;
29 sol = pip_solve(domain, NULL, -1, options);
30 pip_options_free(options);
31 if (!sol)
32 goto error;
34 if (!sol->list)
35 res = isl_lp_empty;
36 else if (entier_zero_p(sol->list->vector->the_deno[0]))
37 res = isl_lp_unbounded;
38 else {
39 if (opt_denom) {
40 isl_seq_cpy_from_pip(opt,
41 &sol->list->vector->the_vector[0], 1);
42 isl_seq_cpy_from_pip(opt_denom,
43 &sol->list->vector->the_deno[0], 1);
44 } else if (maximize)
45 mpz_fdiv_q(*opt, sol->list->vector->the_vector[0],
46 sol->list->vector->the_deno[0]);
47 else
48 mpz_cdiv_q(*opt, sol->list->vector->the_vector[0],
49 sol->list->vector->the_deno[0]);
51 pip_matrix_free(domain);
52 pip_quast_free(sol);
53 return res;
54 error:
55 if (domain)
56 pip_matrix_free(domain);
57 return isl_lp_error;