0
votes

I am looking for the best way to model and solve the following linear problem using Pulp where I have conditional statements on my variables to be added to the constraints:

Here is an example:

Max (x1*100 - a*80 - b*100) + (x2*80 - c*120 - d*75)

s.t.

a + b = x1

c + d = x2

x1 > 0

x2 > 0

if x1 > 0 then x2 = 0

if x2 > 0 then x1 = 0

a, b, c, d <= 100

I have declared x1, x2, a, b, c, and d as variables in my pulp problem.

I tried to add 2 indicator functions in my obj function (one for x1 and one for x2) but they are not accepted by Pulp.

I found some good answers: Converting conditional constraints to linear constraints in Linear Programming

But do not know the exact wording to use to code it.

1
What are your two indicator functions? - Ṃųỻịgǻňạcểơửṩ
initially I looked at doing: 'Max (x1*100 - a*80 - b*100) * 1(x2=0,1,0) + (x2*80 - c*120 - d*75)*1(x1=0,1,0)' 1 being the indicator function equals to 1 if the condition is true or 0 if it's false - Crij
I also tried to make these indicator functions as binary variables (0 or 1) for pulp 'Max (x1*100 - a*80 - b*100) *indi1 + (x2*80 - c*120 - d*75)*indic2' with an additional constraint indic1 + indic2 = 1 and let Pulp optimize them as well, but it did not like that I multiply 2 variables together (x1 with indic1 and x2 with indic2) - Crij
from your constrains, your objective function should be equivalent to MAX (a * 20 - c * 40 + d * 5). Also you can´t make > constrains, only >=. It is also unclear if a,b,c,d are integers or continuous - juvian
I agree with your comments, thanks for the pointing it out. a, b, c, d, are integers as well. The solution I am looking for is really to model a way so that if the left part of the pblm (x1, a ,b) take any value then the other side can't (must be 0) and vice versa. it's like you have 2 states of nature, you can't be in both and you have to pick the side that maximize the value. let me know if it's not clear - Crij

1 Answers

1
votes

Make 2 Binary Variables X1 and X2

Then set

X1+X2 <=1

And

0 <= x1 <= X1*M
0 <= x2 <= X2*M

where M is a sufficiently large number (note the smaller M is the easier the problem is to solve)