I there a way to specify two constraints for the same variable when using Puthon PuLP for a linear program

做~自己de王妃 提交于 2019-12-11 04:46:47

问题


I was wondering if there is a way two have a variable with two different constraints when using Python PuLP.

prob += lpSum([evaptwohundredF[i] * component_vars[i] for i in name]) >= 30.0000, "evaptwohundredFrequirement"
prob += lpSum([evaptwohundredF[i] * component_vars[i] for i in name]) <=70.0000, "evaptwohundredFrequirement"

This is an example fo what i would want where the same variable has two constraints so >= 30 and <= 70, but the problem is that i get an error which says 'pulp.constants.PulpError: overlapping constraint names: evaptwohundredrequirement', so how would i have it allow both constraints?


回答1:


I'm not a big pulp-user, but what you ask for is obviously allowed in Linear-Programming (and therefore in probably all modelling-tools).

The problem in your case: pulp expects a unique identifier / str for each constraint (and your's are equal).

Do something like (only changed the constraint-names):

prob += lpSum([evaptwohundredF[i] * component_vars[i] for i in name]) >= 30.0000, "evaptwohundredFrequirement_a"
prob += lpSum([evaptwohundredF[i] * component_vars[i] for i in name]) <=70.0000, "evaptwohundredFrequirement_b"


来源:https://stackoverflow.com/questions/45510382/i-there-a-way-to-specify-two-constraints-for-the-same-variable-when-using-puthon

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