MILP_Examples I_solutions
MILP_Examples I_solutions
min z: z =c x+h y
T T
subject to: Ax + Gy ³ b
and: 𝑥 ≥ 0; 𝑦 ∈ {0,1}
References:
• H.P. Williams, “Model Building in Mathematical Programming’, Wiley (2013).
• D-S.C. Chen, R.G. Batson and Y. Dang, “Applied Integer Programming”,
Wiley (2011).
• C.A. Floudas, “Nonlinear and Mixed-integer Optimization: Fundamentals and
Applications”, Oxford University Press (1995).
Recap on Integer programming
Logic inference via integer programming
Then
x1 Ú x2 is equivalent to y1 + y2 ³ 1
x1 • x2 y1 = 1, y2 = 1
~ x1 y1 = 0
x1 ® x2 y1 - y2 £ 0
x1 « x2 y1 - y2 = 0
Why integer variables?
66.7% conversion
C2=55+10x2, x2>0 15
Formulation:
min z: z = 50( x1 + x2 ) + 14 x1 + 10 x2 + 75 y1 + 55 y2
subject to: 0.8 x1 + 0.667 x2 ³ 10
Logical constraints: x1 - 12.5 y1 £ 0
x2 - 15.0 y 2 £ 0
Upper bounds
x1 , x2 ³ 0 for reactor sizes
Summary
Also, åa x
j
j j £ b Þ y =1
is handled by å a x - (m - e ) y ³ b + e
j
j j
𝑄! ∧ 𝑄"
Exercises
• Logical constraints
• Blending
• Food manufacture (revisited)
• Commercial allocation
• Integer cuts
Problem 1: Logical Constraints
1 − 𝑌" + 𝑌# + (1 − 𝑌$ ) ≥ 1 → 𝒀𝑨 ≤ 𝟏 − 𝒀𝑩 + 𝒀𝑪
𝑌𝐵 + (1 − 𝑌# ) + (1 − 𝑌$ ) ≥ 1 → 𝒀𝑨≤ 𝟏 + 𝒀𝑩 − 𝒀𝑪
Problem 2: Blending
A blending company needs to purchase up to four out of five
ingredients A, B, C, D and E with unit costs (£/kg) 50, 80, 70, 60 and
90, respectively. The company has a potential market for the final
mixture up to 500 kg, sold at 200 £/kg. If an ingredient is purchased
then a minimum amount of 50 kg should be ordered. Also, due to
technical limitations, ingredient A should not be selected if only one
from B or C is chosen.
Formulate the above problem as a mixed integer linear programming
model, maximising the profit of the company.
Problem 2: Blending
XA, XB, XC, XD, XE = actual quantity of corresponding ingredient in the mixture
YA, YB, YC, YD, YE =1 if corresponding ingredient is in the mixture; 0 otherwise
• Hardness blends linearly and the hardness of the final product must
lie between 3 and 6 18
Problem 3: Food Manufacture (revisited)
Determine:
• In each month, how much raw oils to purchase, used for food
manufacture and sold
So as to:
• Maximise the overall profit (case A)
BUT
• Case B: If an oil is used in any month at least 100 tons must be used
• Case C: The food can be made up to 2 oils in any month
quantity of
quantity of raw products
oil i purchased manufactured in
in month t month t
Bit Yt
20
Problem 3: Food Manufacture (revisited)
Binary variable:
𝐸!, = 1 𝑖𝑓 𝑜𝑖𝑙 𝑖 𝑖𝑠 𝑢𝑠𝑒𝑑 𝑑𝑢𝑟𝑖𝑛𝑔 𝑚𝑜𝑛𝑡ℎ 𝑡; 0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
TOTAL PROFIT
CASE A (LP) £107,843
CASE B (MILP) £107,250
CASE C (MILP) £99,000
24
Problem 4: Commercials Allocation
Given:
• The estimated impact of allocating zero, one, two, or three TV spots
to each product i.
Determine:
• allocation of five spots to the products
So as to:
• maximise the total profit.
26
Problem 4: Commercials Allocation
Indices
i = product: Product1, Product2, and Product3
j = number of spots: 1, 2, and 3
27
Problem 4: Commercials Allocation
Integer Variables
𝑋! : number of TV spots allocated to the product i
𝑋-./012,3 = 0, 1, 2, 3
𝑋-./012,4 = 0, 1, 2, 3
𝑋-./012,5 = 0, 1, 2, 3
28
Problem 4: Commercials Allocation
Auxiliary Binary Variable
1, 𝑖𝑓𝑋! = 𝑗, 𝑖. 𝑒. , 𝑗 𝑇𝑉 𝑠𝑝𝑜𝑡𝑠 𝑎𝑟𝑒 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 𝑖
𝑌!6 = Q
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
𝑌/01234#','
1, 𝑖𝑓 1 𝑇𝑉 𝑠𝑝𝑜𝑡 𝑖𝑠 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 1
=L
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
𝑌/01234#',+
1, 𝑖𝑓 2 𝑇𝑉 𝑠𝑝𝑜𝑡𝑠 𝑎𝑟𝑒 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 1 𝑌/01234#.,'
=L
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 1, 𝑖𝑓 1 𝑇𝑉 𝑠𝑝𝑜𝑡 𝑖𝑠 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 3
=L
𝑌/01234#',. 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
1, 𝑖𝑓 3 𝑇𝑉 𝑠𝑝𝑜𝑡𝑠 𝑎𝑟𝑒 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 1 𝑌/01234#.,+
=L
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 1, 𝑖𝑓 2 𝑇𝑉 𝑠𝑝𝑜𝑡 𝑎𝑟𝑒 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 3
=L
𝑌/01234#+,' 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
1, 𝑖𝑓 1 𝑇𝑉 𝑠𝑝𝑜𝑡 𝑖𝑠 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 2 𝑌/01234#.,.
=L
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒 1, 𝑖𝑓 3 𝑇𝑉 𝑠𝑝𝑜𝑡𝑠 𝑎𝑟𝑒 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 3
=L
𝑌/01234#+,+ 0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
1, 𝑖𝑓 2 𝑇𝑉 𝑠𝑝𝑜𝑡𝑠 𝑎𝑟𝑒 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 2
=L
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
𝑌/01234#+,.
1, 𝑖𝑓 3 𝑇𝑉 𝑠𝑝𝑜𝑡𝑠 𝑎𝑟𝑒 𝑎𝑙𝑙𝑜𝑐𝑎𝑡𝑒𝑑 𝑡𝑜 𝑝𝑟𝑜𝑑𝑢𝑐𝑡 2 29
=L
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Problem 4: Commercials Allocation
Logical constraint:
𝑋! = N 𝑗 X 𝑌!6 , ∀𝑖
6
30
Problem 4: Commercials Allocation
31
Problem 4: Commercials Allocation
Allocation constraints:
! 𝑌NM ≤ 1, ∀𝑖
M
If LHS = 0 (ie. all Yij variables are equal to 0), then 0 TV spot is allocated
to product i.
32
Problem 4: Commercials Allocation
33
Problem 4: Commercials Allocation
! 𝑋N = 𝑇𝑜𝑡𝑎𝑙𝑆𝑝𝑜𝑡𝑁𝑜
N
34
Problem 4: Commercials Allocation
35
Problem 4: Commercials Allocation
36
Problem 4: Commercials Allocation
37
Problem 4: Commercials Allocation
Summary of the optimisation model:
𝑚𝑎𝑥 𝑧 = N 𝑝!6 𝑌!6
!,6
Subject to:
Logical constraints:
𝑋! = N 𝑗 X 𝑌!6 , ∀𝑖
6
Allocation constraints:
N 𝑌!6 ≤ 1, ∀𝑖
6
Total TV spot number constraints:
N 𝑋! = 𝑇𝑜𝑡𝑎𝑙𝑆𝑝𝑜𝑡𝑁𝑜
!
Xi={1,2,3}; Yij = {0,1} 38
Problem 4: Commercials Allocation
3
No of TV spots
0
Product1 Product2 Product3
Y 𝑌$ − Y 𝑌$ ≤ 𝑐𝑎𝑟𝑑 𝑈 − 1
$∈1 $∈2
where
U: set of i where Yi=1 at previous iteration;
L: set of i where Yi=0 at previous iteration,
card(U) denotes the cardinality of set U (i.e. how many members)
Examples:
Yi 1 2 3 4 5
Ex 1 1 1 0 0 1
Ex 2 0 1 1 1 1
Solution of Problem 5
Y 𝑌$ − Y 𝑌$ ≤ 𝑐𝑎𝑟𝑑 𝑈 − 1
$∈1 $∈2
Example1:
Yi 1 2 3 4 5
Ex 1 1 1 0 0 1
Ex1: (1,1,0,0,1)
𝑌! + 𝑌" + 𝑌3 − 𝑌% − 𝑌4 ≤ 3 − 1 = 2
If we replace above solution, we have 1+1+1-0-0 =3 ≤2. which is not
allowed.
Solution of Problem 5
Y 𝑌$ − Y 𝑌$ ≤ 𝑐𝑎𝑟𝑑 𝑈 − 1
$∈1 $∈2
Example 2:
Yi 1 2 3 4 5
Ex 2 0 1 1 1 1
Ex2: (0,1,1,1,1)
𝑌" + 𝑌% + 𝑌4 + 𝑌3 − 𝑌! ≤ 3