2 #include <barvinok/util.h>
3 #include <barvinok/options.h>
6 static enum order_sign
interval_minmax(Polyhedron
*I
)
11 assert(I
->Dimension
== 1);
12 POL_ENSURE_VERTICES(I
);
13 for (i
= 0; i
< I
->NbRays
; ++i
) {
14 if (value_pos_p(I
->Ray
[i
][1]))
16 else if (value_neg_p(I
->Ray
[i
][1]))
38 /* Returns the sign of the affine function specified by T on the polyhedron D */
39 enum order_sign
PL_polyhedron_affine_sign(Polyhedron
*D
, Matrix
*T
,
40 struct barvinok_options
*options
)
43 Polyhedron
*I
= Polyhedron_Image(D
, T
, options
->MaxRays
);
44 if (POL_ISSET(options
->MaxRays
, POL_INTEGER
))
45 I
= DomainConstraintSimplify(I
, options
->MaxRays
);
48 I
= Polyhedron_Image(D
, T
, options
->MaxRays
);
50 sign
= interval_minmax(I
);
55 enum lp_result
PL_constraints_opt(Matrix
*C
, Value
*obj
, Value denom
,
56 enum lp_dir dir
, Value
*opt
,
60 Polyhedron
*P
= Constraints2Polyhedron(C
, MaxRays
);
61 res
= PL_polyhedron_opt(P
, obj
, denom
, dir
, opt
);
66 enum lp_result
PL_polyhedron_opt(Polyhedron
*P
, Value
*obj
, Value denom
,
67 enum lp_dir dir
, Value
*opt
)
72 enum lp_result res
= lp_empty
;
74 POL_ENSURE_VERTICES(P
);
80 for (i
= 0; i
< P
->NbRays
; ++ i
) {
81 Inner_Product(P
->Ray
[i
]+1, obj
, P
->Dimension
+1, &val
);
82 if (value_zero_p(P
->Ray
[i
][0]) && value_notzero_p(val
)) {
86 if (value_zero_p(P
->Ray
[i
][1+P
->Dimension
])) {
87 if ((dir
== lp_min
&& value_neg_p(val
)) ||
88 (dir
== lp_max
&& value_pos_p(val
))) {
94 value_multiply(d
, denom
, P
->Ray
[i
][1+P
->Dimension
]);
96 mpz_cdiv_q(val
, val
, d
);
98 mpz_fdiv_q(val
, val
, d
);
99 if (first
|| (dir
== lp_min
? value_lt(val
, *opt
) :
100 value_gt(val
, *opt
)))
101 value_assign(*opt
, val
);
111 enum lp_result
PL_polyhedron_range(Polyhedron
*D
, Value
*obj
, Value denom
,
112 Value
*min
, Value
*max
,
113 struct barvinok_options
*options
)
118 Matrix
*T
= Matrix_Alloc(2, D
->Dimension
+1);
119 Vector_Copy(obj
, T
->p
[0], D
->Dimension
+1);
120 value_assign(T
->p
[1][D
->Dimension
], denom
);
122 I
= Polyhedron_Image(D
, T
, options
->MaxRays
);
124 POL_ENSURE_VERTICES(I
);
130 bounded
= line_minmax(I
, min
, max
);
134 if (value_gt(*min
, *max
))