简体   繁体   English

如何在python中使用PuLP索引约束

[英]How to index the constraints with PuLP in python

I would like to index the constraints in the CPLEX lp file like below: 我想索引CPLEX lp文件中的约束,如下所示:

_20160421_LHRSINBA0011_Cap#0:   X_20160421_LHRSIN00001_50454 <= 234.5
_20160421_LHRSINBA0015_Cap#1:   X_20160421_LHRSIN00002_50464 + X_20160421_LHRSYD00001_60314 <= 114.5

But I don't know how to do it with PuLP. 但是我不知道如何使用PuLP。

If by indexing you mean change the name of each of the constraints so that you can retrieve them easily then it's simple: 如果通过索引意味着更改每个约束的名称,以便可以轻松检索它们,那么很简单:

problem += X_20160421_LHRSIN00001_50454 <= 234.5, "_20160421_LHRSINBA0011_Cap#0"
problem += X_20160421_LHRSIN00002_50464 + X_20160421_LHRSYD00001_60314 <= 114.5, "_20160421_LHRSINBA0015_Cap#1"

Then when you're searching for a particular constraint, you can use: 然后,当您搜索特定约束时,可以使用:

[constraint for (c_name, constraint) in problem.constraints.items() if "_Cap#1" in c_name]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM