Conditional statements on variables added to constraints in linear programming

人走茶凉 提交于 2020-03-26 06:43:32

问题


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:


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)



来源:https://stackoverflow.com/questions/57171854/conditional-statements-on-variables-added-to-constraints-in-linear-programming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!