Logical constraints
Note
Historically users needed to explicitly convert logical propositions
to algebraic form prior to invoking the GDP MI(N)LP reformulations
or the GDPopt solver. However, this is mathematically incorrect
since the GDP MI(N)LP reformulations themselves convert logical
formulations to algebraic formulations. The current recommended
practice is to pass the entire (mixed logical / algebraic) model to
the MI(N)LP reformulations or GDPopt directly.
There are several approaches to convert logical constraints into
algebraic form.
Factorable Programming
The second transformation (contrib.logical_to_disjunctive) leverages
ideas from factorable programming to first generate an equivalent set of
“factored” logical constraints form by traversing each logical
proposition and replacing each logical operator with an additional
Boolean variable and then adding the “simple” logical constraint that
equates the new Boolean variable with the single logical operator.
The resulting “simple” logical constraints are converted to either MIP
or GDP form: if the constraint contains only Boolean variables, then
then MIP representation is emitted. Logical constraints with mixed
integer-Boolean arguments (e.g., atmost, atleast, exactly, etc.)
are converted to a disjunctive representation.
As this transformation both avoids the conversion into sympy and only
requires a single traversal of each logical constraint,
contrib.logical_to_disjunctive is significantly faster than
core.logical_to_linear at the cost of a larger model. In practice,
the cost of the larger model is negated by the effectiveness of the MIP
presolve in most solvers.