# Mixed integer programming constraint definition

Sorry to ask so much questions but I am in hurry. I would like to know why this procedure doesn't work

A=

matrix(8,4,(1,1,1,-14,0,1,2,-8,-1,1,1,0,0,0,0,-1,1,0,0,0,0,1,0,0,0,0,0,0,0,1))

b= matrix(8,1,(0,0,0,-1,0,0,0,0))

sign=list('==' '==' '>=' '>=' '>='> '>=' '>=' '>=')

x = vector(var('x',n=4, latex_name='x'))

B=A*x

p = MixedIntegerLinearProgram(maximization=False, solver = "GLPK")

x = p.new_variable(integer=True)

for the last line I have tryed

without any success.

edit retag close merge delete

Sort by » oldest newest most voted

Hello, @Cyrille! I can see what you are trying to do. Unfortunately, you are trying to make operations with different data types.

Unfortunately, what you are trying to is not possible using a list, like the sign list that you defined. However, there is another way to do it: you can use the min and max arguments for the add_constraint method. Let me explain with some examples (on the left of the arrow you have the usual notation; on the right, you have the alternative form):

p.add_constraint(-1.0 <= 5*x[0] - 7*x[2] <= 1.0) --------> p.add_constraint(5*x[0] - 7*x[2], min=-1.0, max=1.0)


On the other hand, the instruction var('x',n=4, latex_name='x'), which I gave you in a previous of my answers, is not what you need to achieve this. Sorry, that is my fault. I didn't know what you were trying to do. Instead, you need to do the following:

x = p.new_variable(integer=True, indices=[0..7])


Considering all this, you can write a MILP like the one you present in your question with the following code:

A = matrix(8,4,[1,1,1,-14,0,1,2,-8,-1,1,1,0,0,0,0,-1,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0]) # the coefficients
bmin = [0,0,0,-1,0,0,0,0] # the lower bounds for the constraints
bmax = [0,0,oo,oo,oo,oo,oo,oo] # the upper bounds for the constraints
p = MixedIntegerLinearProgram(maximization=False, solver = "GLPK") # we create the MILP
x = p.new_variable(integer=True, indices=[0..7]) # the new variable will be x[0] ... x[7}
B = A * x # the linear functions for the constraints
# Now we build the constraints using the bounds lists
for i in range(8):
p.show() # this is just to confirm we did it right


I am so sorry that I can't give you a way of doing this using the symbols ==, <= and >=.

more

dsejas one more time thanks

( 2019-10-08 05:04:02 +0100 )edit