Initial version of the integer set library
[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 {
9         enum isl_lp_result res = isl_lp_ok;
10         PipMatrix       *domain = NULL;
11         PipOptions      *options;
12         PipQuast        *sol;
13         unsigned         total;
14
15         total = bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div;
16         domain = isl_basic_map_to_pip(bmap, 0, 1, 0);
17         if (!domain)
18                 goto error;
19         entier_set_si(domain->p[0][1], -1);
20         isl_seq_cpy_to_pip(domain->p[0]+2, f, total);
21
22         options = pip_options_init();
23         if (!options)
24                 goto error;
25         options->Urs_unknowns = -1;
26         options->Maximize = maximize;
27         options->Nq = 0;
28         sol = pip_solve(domain, NULL, -1, options);
29         pip_options_free(options);
30         if (!sol)
31                 goto error;
32
33         if (!sol->list)
34                 res = isl_lp_empty;
35         else if (entier_zero_p(sol->list->vector->the_deno[0]))
36                 res = isl_lp_unbounded;
37         else {
38                 if (maximize)
39                         mpz_fdiv_q(*opt, sol->list->vector->the_vector[0],
40                                          sol->list->vector->the_deno[0]);
41                 else
42                         mpz_cdiv_q(*opt, sol->list->vector->the_vector[0],
43                                          sol->list->vector->the_deno[0]);
44         }
45         pip_matrix_free(domain);
46         pip_quast_free(sol);
47         return res;
48 error:
49         if (domain)
50                 pip_matrix_free(domain);
51         return isl_lp_error;
52 }