Logic constructs
Mosel provides the type logctr for defining and working with logic constraints in MIP models. The implementation of these constraints is based on indicator constraints. Logic constraints are composed with linear constraints using the operations and, or, xor, implies, and not as shown in the following example (the type logctr and the corresponding subroutines including indicator are documented in the chapter mmxprs of the Mosel Language Reference Manual). Mosel models using logic constraints must include the package advmod instead of the Xpress Optimizer library mmxprs.
uses "advmod" ! **** 'implies', 'not', and 'and' **** declarations R = 1..3 C: array(range) of linctr x: array(R) of mpvar end-declarations C(1):= x(1)>=10 C(2):= x(2)<=5 C(3):= x(1)+x(2)>=12 implies(C(1), C(3) and not C(2)) forall(j in 1..3) C(j):=0 ! Delete the auxiliary constraints ! Same as: implies(x(1)>=10, x(1)+x(2)>=12 and not x(2)<=5) ! **** 'or' and 'xor' **** declarations p: array(1..6) of mpvar end-declarations forall(i in 1..6) p(i) is_binary ! Choose at least one of projects 1,2,3 (option A) ! or at least two of projects 2,4,5,6 (option B) p(1) + p(2) + p(3) >= 1 or p(2) + p(4) + p(5) + p(6) >= 2 ! Choose either option A or option B, but not both xor(p(1) + p(2) + p(3) >= 1, p(2) + p(4) + p(5) + p(6) >= 2)
These logic constructs, particularly the logic or, can be used for the formulation of minimum or maximum values of a set of variables and also for absolute values:
- Minimum values: y = min{x1, x2, ..., xn} for continuous variables x1, ..., xn
- Logic formulation:
y ≤ xi ∀ i=1,...,n y ≥ x1 or ... or y ≥ xn
- Logic formulation:
- Maximum values: y = max{x1, x2, ..., xn} for continuous variables x1, ..., xn
- Logic formulation:
y ≥ xi ∀ i=1,...,n y ≤ x1 or ... or y ≤ xn
- Logic formulation:
- Absolute values: y = | x1 - x2| for two variables x1, x2
- Modeling y = | x1 - x2| is equivalent to y = max{ x1 - x2, x2 - x1 }
- Logic formulation:
y ≥ x1 - x2 y ≥ x2 - x1 y ≤ x1 - x2 or y ≤ x2 - x1
- Example implementation with Mosel:
declarations x: array(1..2) of mpvar y, u, v: mpvar C1, C2: linctr C3: logctr end-declarations ! Formulation of y = min{x(1), x(2)} C1:= y <= x(1) C2:= y <= x(2) C3:= y >= x(1) or y >= x(2) ! Formulation of u = max{x(1), x(2)} C1:= u >= x(1) C2:= u >= x(2) C3:= u <= x(1) or u <= x(2) ! Formulation of v = |x(1) - x(2)| C1:= v >= x(1) - x(2) C2:= v >= x(2) - x(1) C3:= v <= x(1) - x(2) or v <= x(2) - x(1)
© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.