1

PyLPsolve has some great features I want to use. I have a question, though: How do you define the list of integer variables of the MIP?

That is, in the standard wrapper of lpsolve: solution = lp_solve(f,A,b,e,lvb,uvb,xint) Where xint is the list of indexes of the integer variables of the MIP.

How can I define a non trivial xinf in PyLPSolve?

Happy coding ! and happy optimization !

4

1 回答 1

2

您可以使用 pylpsolve.LP.setInteger(self, indices) 设置整数变量。二进制值变量有一个类似的“setBinary”。这是一个示例(请注意,变量的索引为 0-up):

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()
于 2014-02-20T15:38:57.507 回答