isl_tab_cone_is_bounded: start over after computing sign_of_max
[platform/upstream/isl.git] / isl_lp_piplib.c
1 #include "isl_map.h"
2 #include "isl_lp.h"
3 #include "isl_piplib.h"
4 #include "isl_map_piplib.h"
5
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)
9 {
10         enum isl_lp_result res = isl_lp_ok;
11         PipMatrix       *domain = NULL;
12         PipOptions      *options;
13         PipQuast        *sol;
14         unsigned         total;
15
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_int_set(domain->p[0][domain->NbColumns - 1], f[0]);
22         isl_seq_cpy_to_pip(domain->p[0]+2, f+1, total);
23
24         options = pip_options_init();
25         if (!options)
26                 goto error;
27         options->Urs_unknowns = -1;
28         options->Maximize = maximize;
29         options->Nq = 0;
30         sol = pip_solve(domain, NULL, -1, options);
31         pip_options_free(options);
32         if (!sol)
33                 goto error;
34
35         if (!sol->list)
36                 res = isl_lp_empty;
37         else if (entier_zero_p(sol->list->vector->the_deno[0]))
38                 res = isl_lp_unbounded;
39         else {
40                 if (opt_denom) {
41                         isl_seq_cpy_from_pip(opt,
42                                  &sol->list->vector->the_vector[0], 1);
43                         isl_seq_cpy_from_pip(opt_denom,
44                                  &sol->list->vector->the_deno[0], 1);
45                 } else if (maximize)
46                         mpz_fdiv_q(*opt, sol->list->vector->the_vector[0],
47                                          sol->list->vector->the_deno[0]);
48                 else
49                         mpz_cdiv_q(*opt, sol->list->vector->the_vector[0],
50                                          sol->list->vector->the_deno[0]);
51         }
52         pip_matrix_free(domain);
53         pip_quast_free(sol);
54         return res;
55 error:
56         if (domain)
57                 pip_matrix_free(domain);
58         return isl_lp_error;
59 }