PyLPsolve 有一些我想使用的很棒的功能。但我有个问题: 如何定义 MIP 的整型变量列表?
也就是说,在 lpsolve 的标准包装中: 解决方案 = lp_solve(f,A,b,e,lvb,uvb,xint) 其中xint是MIP的整型变量的索引列表。
如何在 PyLPSolve 中定义一个不平凡的 xinf?
编码愉快! 祝优化愉快!
最佳答案
您可以使用 pylpsolve.LP.setInteger(self,indices) 设置整数变量。对于二进制值变量,有一个类似的“setBinary”。下面是一个示例(请注意,变量的索引是从 0 开始):
from pylpsolve import LP
lp = LP()
# Specify constraints
lp.addConstraint([[1,1,0], [0,1,2]], "<=", [3.1, 4.1])
# Force the first variable to be integer-valued
lp.setInteger(0)
# Force the second variable to be binary-valued
lp.setBinary(1)
# set objective
lp.setObjective([1,1,1], mode="maximize")
# Run
lp.solve()
# print out the solution:
print lp.getSolution()
关于python - 在 PyLPsolve(Python 的 lpsolve 包装器)中定义整数变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16598985/