Question

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 !

Was it helpful?

Solution

You can set integer variables with pylpsolve.LP.setInteger(self, indices). There is an analogous "setBinary" for binary-valued variables. Here's an example (note that variables are indexed 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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top