2 #include <piplib/piplibMP.h>
5 static PipQuast
*solve_lp(int maximize
, Matrix
*C
, Value
*f
, Value denom
)
12 domain
= pip_matrix_alloc(C
->NbRows
+1, C
->NbColumns
+1);
13 value_set_si(domain
->p
[0][0], 0);
14 value_set_si(domain
->p
[0][1], -1);
15 Vector_Copy(f
, domain
->p
[0]+2, C
->NbColumns
-1);
16 for (i
= 0; i
< C
->NbRows
; ++i
) {
17 value_assign(domain
->p
[i
+1][0], C
->p
[i
][0]);
18 Vector_Copy(C
->p
[i
]+1, domain
->p
[i
+1]+2, C
->NbColumns
-1);
21 options
= pip_options_init();
22 options
->Urs_unknowns
= -1;
23 options
->Maximize
= maximize
;
25 sol
= pip_solve(domain
, NULL
, -1, options
);
26 pip_matrix_free(domain
);
27 pip_options_free(options
);
32 static enum lp_result
constraints_affine_minmax(int maximize
, Matrix
*C
,
33 Value
*f
, Value denom
, Value
*opt
)
35 enum lp_result res
= lp_ok
;
36 PipQuast
*sol
= solve_lp(maximize
, C
, f
, denom
);
40 else if (value_zero_p(sol
->list
->vector
->the_deno
[0]))
44 mpz_fdiv_q(*opt
, sol
->list
->vector
->the_vector
[0],
45 sol
->list
->vector
->the_deno
[0]);
47 mpz_cdiv_q(*opt
, sol
->list
->vector
->the_vector
[0],
48 sol
->list
->vector
->the_deno
[0]);
54 enum lp_result
pip_constraints_opt(Matrix
*C
, Value
*obj
, Value denom
,
55 enum lp_dir dir
, Value
*opt
)
57 int maximize
= dir
== lp_min
? 0 : 1;
58 return constraints_affine_minmax(maximize
, C
, obj
, denom
, opt
);
61 enum lp_result
pip_polyhedron_range(Polyhedron
*D
, Value
*obj
, Value denom
,
62 Value
*min
, Value
*max
,
63 struct barvinok_options
*options
)
71 Polyhedron_Matrix_View(D
, &M
, D
->NbConstraints
);
72 res
= constraints_affine_minmax(0, &M
, obj
, denom
, min
);
75 res
= constraints_affine_minmax(1, &M
, obj
, denom
, max
);