4 #include <barvinok/util.h>
8 #define EMPTY_DOMAIN -2
10 static int polyhedron_affine_minmax(DD_LPObjectiveType obj
, Polyhedron
*P
,
11 Matrix
*T
, bool rational
)
14 assert(P
->Dimension
== T
->NbColumns
-1);
15 assert(T
->NbRows
== 2);
16 DD_rowrange irev
= P
->NbConstraints
;
17 DD_rowrange rows
= irev
+ P
->NbEq
+ 1;
18 DD_colrange cols
= 1 + P
->Dimension
;
19 lp
= DD_CreateLPData(obj
, DD_Rational
, rows
, cols
);
20 lp
->Homogeneous
= DD_FALSE
;
23 for (DD_rowrange j
= 0; j
< P
->NbConstraints
; ++j
) {
24 for (DD_colrange k
= 0; k
< P
->Dimension
; ++k
) {
25 DD_set_si(lp
->A
[j
][1+k
], 5);
26 DD_set_z(lp
->A
[j
][1+k
], P
->Constraint
[j
][1+k
]);
28 DD_set_z(lp
->A
[j
][0], P
->Constraint
[j
][1+P
->Dimension
]);
30 set_addelem(lp
->equalityset
, j
+1);
31 for (DD_colrange k
= 0; k
< P
->Dimension
; ++k
)
32 DD_neg(lp
->A
[irev
][1+k
], lp
->A
[j
][1+k
]);
33 DD_neg(lp
->A
[irev
][0], lp
->A
[j
][0]);
37 /* objective function */
38 for (DD_colrange k
= 0; k
< P
->Dimension
; ++k
)
39 DD_set_z(lp
->A
[rows
-1][1+k
], T
->p
[0][k
]);
40 DD_set_z(lp
->A
[rows
-1][0], T
->p
[0][P
->Dimension
]);
42 DD_ErrorType err
= DD_NoError
;
43 DD_LPSolve(lp
, DD_DualSimplex
, &err
);
44 assert(err
== DD_NoError
);
47 if (lp
->LPS
== DD_Optimal
) {
49 DD_rat_sign(sign
, obj
, lp
->optvalue
);
51 /* The objective function has integer coefficients,
52 * so the optimal should be an integer (over the integer points)
54 DD_int_sign(sign
, obj
, lp
->optvalue
);
55 } else if (lp
->LPS
== DD_DualInconsistent
) {
60 } else if (lp
->LPS
== DD_Inconsistent
) {
69 enum order_sign
cdd_polyhedron_affine_sign(Polyhedron
*D
, Matrix
*T
,
70 struct barvinok_options
*options
)
73 return order_undefined
;
76 bool rational
= !POL_ISSET(options
->MaxRays
, POL_INTEGER
);
77 int min
= polyhedron_affine_minmax(DD_LPmin
, D
, T
, rational
);
78 if (min
== EMPTY_DOMAIN
)
79 return order_undefined
;
82 int max
= polyhedron_affine_minmax(DD_LPmax
, D
, T
, rational
);
83 assert(max
!= EMPTY_DOMAIN
);