2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
13 #include "isl_piplib.h"
14 #include "isl_map_piplib.h"
16 static void copy_solution(struct isl_vec
*vec
, int maximize
, isl_int
*opt
,
17 isl_int
*opt_denom
, PipQuast
*sol
)
25 isl_seq_cpy_from_pip(opt
,
26 &sol
->list
->vector
->the_vector
[0], 1);
27 isl_seq_cpy_from_pip(opt_denom
,
28 &sol
->list
->vector
->the_deno
[0], 1);
30 mpz_fdiv_q(*opt
, sol
->list
->vector
->the_vector
[0],
31 sol
->list
->vector
->the_deno
[0]);
33 mpz_cdiv_q(*opt
, sol
->list
->vector
->the_vector
[0],
34 sol
->list
->vector
->the_deno
[0]);
41 isl_int_set_si(vec
->el
[0], 1);
42 for (i
= 0, list
= sol
->list
->next
; list
; ++i
, list
= list
->next
) {
43 isl_seq_cpy_from_pip(&vec
->el
[1 + i
],
44 &list
->vector
->the_deno
[0], 1);
45 isl_int_lcm(vec
->el
[0], vec
->el
[0], vec
->el
[1 + i
]);
47 for (i
= 0, list
= sol
->list
->next
; list
; ++i
, list
= list
->next
) {
48 isl_seq_cpy_from_pip(&tmp
, &list
->vector
->the_deno
[0], 1);
49 isl_int_divexact(tmp
, vec
->el
[0], tmp
);
50 isl_seq_cpy_from_pip(&vec
->el
[1 + i
],
51 &list
->vector
->the_vector
[0], 1);
52 isl_int_mul(vec
->el
[1 + i
], vec
->el
[1 + i
], tmp
);
57 enum isl_lp_result
isl_pip_solve_lp(struct isl_basic_map
*bmap
, int maximize
,
58 isl_int
*f
, isl_int denom
, isl_int
*opt
,
62 enum isl_lp_result res
= isl_lp_ok
;
63 PipMatrix
*domain
= NULL
;
68 total
= isl_basic_map_total_dim(bmap
);
69 domain
= isl_basic_map_to_pip(bmap
, 0, 1, 0);
72 entier_set_si(domain
->p
[0][1], -1);
73 isl_int_set(domain
->p
[0][domain
->NbColumns
- 1], f
[0]);
74 isl_seq_cpy_to_pip(domain
->p
[0]+2, f
+1, total
);
76 options
= pip_options_init();
79 options
->Urs_unknowns
= -1;
80 options
->Maximize
= maximize
;
82 sol
= pip_solve(domain
, NULL
, -1, options
);
83 pip_options_free(options
);
88 *vec
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
93 else if (entier_zero_p(sol
->list
->vector
->the_deno
[0]))
94 res
= isl_lp_unbounded
;
96 copy_solution(*vec
, maximize
, opt
, opt_denom
, sol
);
97 pip_matrix_free(domain
);
102 pip_matrix_free(domain
);