| |||||||||||||||
Indicator and logic constraints Description Examples of formulating linear and nonlinear indicator constraints with Mosel, and of formulating logic constraints for MIP models using the Mosel module 'advmod'. Further explanation of this example: Whitepaper 'MIP formulations and linearizations', Sections 'Indicator constraints' and 'Logic constructs'
Source Files By clicking on a file name, a preview is opened at the bottom of this page.
logctrexpl.mos (!****************************************************** Mosel Example Problems ====================== file logctrexpl.mos ``````````````````` Logical MIP constraints definition via advmod - Example discussed in mipformref whitepaper - (c) 2009 Fair Isaac Corporation author: S. Heipcke, Mar. 2009, rev, Aug. 2023 *******************************************************!) model "testlog" uses "advmod" ! **** 'implies', 'not', and 'and' **** public declarations R=1..2 C: array(range) of linctr L: logctr ! Logical constraint x: array(R) of mpvar end-declarations forall(i in R) x(i) <= 10*i-2 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) ! Same as: L:= x(1)+x(2)>=12 and not x(2)<=5 ! Define (temporary) logical constraint implies(x(1)>=10, L) ! State the implication L:= 0 ! Delete the auxiliary ! **** 'or' and 'xor' **** public 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) public declarations u, v: mpvar C1, C2, C11, C12: linctr C3, C13: logctr end-declarations ! Formulation of u = min{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)| C11:= v >= x(1) - x(2) C12:= v >= x(2) - x(1) C13:= v <= x(1) - x(2) or v <= x(2) - x(1) (! setparam("XPRS_loadnames", true) loadprob(0) writeprob("logtestmat.lp","l") !) setparam("XPRS_verbose", true) maximize(sum(i in R) x(i)) writeln("Solution: ", getobjval) writeln("u=", u.sol, " v=", v.sol, " x=", array(i in R) x(i).sol, " p=", array(i in 1..6) p(i).sol) end-model | |||||||||||||||
© Copyright 2024 Fair Isaac Corporation. |