Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello, @Cyrille! The problem with your code is that the constructor MixedIntegerLinearProgram() doesn't have a binary keyword, which is hinted by the error message created by your program:

TypeError: __init__() got an unexpected keyword argument 'binary'

(This is referring to the __init__() method of MixedIntegerLinearProgram(), which has to do with object-oriented programming. This detail is not too relevant in this case, so let's ignore it.)

The new_variable() is the one that has this binary argument. Notice that this is in agreement to standard definitions of mixed integer linear programming (MILP), where it is the variables that are binary, integer, etc., with the program inheriting that nomenclature. Fro example, we say binary program to stand for the clearer but longer program with binary variables.

One other correction you will need to do is to define A and U1 as a matrix and vector, respectively, in order to be able to make the product and comparison in your constraint A*x <= U1. This is because product between a list of lists (your current A) and a variable from a MILP (your current x) is not define, nor is it the comparison with a list (your current U1.)

With those considerations, this should work as intended:

A = matrix([[1,0,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,0,0,1,0,0,0,0,0],[0,0,1,0,0,0,0,0,0,1,0,0],[0,0,0,0,1,0,0,1,0,0,0,0],[0,0,0,0,0,1,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1,0,0,1]])
U1 = vector([1,1,1,1,1,1])
p = MixedIntegerLinearProgram()
x = p.new_variable(binary=true)
p.add_constraint(A*x <= U1)

I hope this helps!