Minimize total cost of shopping cart with discount rules

32 Views Asked by At

Here is the problem I am trying to solve, given 2 items to purchase from 2 stores with a discount for Store 1, what is the cheapest way to purchase the items?

Discount for Store 1, 50% off with minimum spend of $10 with the discount amount capped at $6. 
For example, purchasing both items from Store 1 will cost $15 with a 50% discount of $7.50. 
However, with the discount capped at $6, the maximum discount that Store 1 can give is $6.

Item 1 Store 1 = $5
Item 1 Store 2 = $10
Item 2 Store 1 = $10
Item 2 Store 2 = $5

The obvious answer would be to purchase both items from Store 1, at a cost of $10 + $5 - $6 = $9

Here is my formulation, which I got stuck when the discount amount is less than $6 not calculating correctly.

Item 1 Store 1 = x1 = $5
Item 1 Store 2 = x2 = $10
Item 2 Store 1 = x3 = $10
Item 2 Store 2 = x4 = $5
Min Spend Discount Binary = x6
Max Spend Discount Binary = x7

Minimize
 obj: 5 x1 + 10 x2 + 10 x3 + 5 x4 - 6 x6 
+ [ - 5 x1*x5 + 5 x1*x6 - 10 x3*x5 + 10 x3*x6 ] / 2 # apply discount and compensate amount if exceeds capped discount

Subject To
 c1: x1 + x2 = 1 // need to purchase item 1 from either store
 c2: x3 + x4 = 1 // need to purchase item 2 from either store
 c3: 5 x1 + 10 x3 - 10 x5 >= 0 // min spend for item 1 and item 2 from store 1 needs to exceed $10
 c4: x5 - x6 = 0 // this is the part that I got stuck, this works when the total cost exceeds the discount cap but doesn't work when it's below the cap

Bounds
 0 <= x1 <= 1
 0 <= x2 <= 1
 0 <= x3 <= 1
 0 <= x4 <= 1
 0 <= x5 <= 1
 0 <= x6 <= 1

Binaries
 x1 x2 x3 x4 x5 x6
End 

I'm sure I'm missing something with the fourth constraint (c4), any ideas on how this problem should be formulated?