How to use a variable as a divisor in PuLP

后端 未结 2 1226
别那么骄傲
别那么骄傲 2021-01-13 13:36

I was trying to resolve a LP problem with a constraint that is calculated by dividing variable A by variable B.

The simple version of the problem is as below:

2条回答
  •  旧巷少年郎
    2021-01-13 14:40

    Linear Programming doesn't understand divisions, hence the error :) You have to reformulate it so that the division is formulated linearly. In this case:

    prob += x / (x + y) > 0.5  
    prob += y / (x + y) < 0.4
    

    is equivalent to:

    prob += x > 0.5 * (x + y)
    prob += y < 0.4 * (x + y)
    

    Which are linear constraints. Good luck!

提交回复
热议问题