# Reuse of already entered parameters

I would like to know if there is a general procedure to reuse some already enter parameters. For instance In

MixedIntegerLinearProgram

one can enter an inequation as

p.add_constraint( a[1,1]x + a[1,2]x + c[1,3]*x >= b )

and now I need a[1, 1] ..., a[1, 3] and b

to write

pol = Polyhedron(ieqs = [[-b , a[1, 1], a[1, 2]],...].

And when the result of a calculaton is verbose --- composed of strings and numbers ---, how to keep only the interesting part ?

edit retag close merge delete

Hello, @Cyrille! I think I have been able to answer the first part of your question (see below).

Concerning the last part of your question,

And when the result of a calculation is verbose --- composed of strings and numbers ---, how to keep only the interesting part ?

I am afraid I didn't understand that part. Could you show a specific example or give a little more detail?

Sort by » oldest newest most voted

Hello, @Cyrille! I am not completely sure that I understood your question, but you could store constants in a matrix and a vector. For example, suppose you want to rewrite the following MILP:

LP = MixedIntegerLinearProgram(maximization=True)
x = LP.new_variable(nonnegative=True)
LP.set_objective(5*x - 4*x)


Then you could define a matrix A containing all the coefficients for the variables, and a vector containing all the constant terms. In this particular case,

A = matrix(3, 2, [-2, -1, -1, -1, -1, -2])
b = vector([-1.5, -1, -1])


Now, you can rewrite the problem as you indicate in your question:

LP = MixedIntegerLinearProgram(maximization=True)
x = LP.new_variable(nonnegative=True)
LP.set_objective(5*x + 4*x)


And you even can reuse the numbers in the Polyhedron command. For example,

pol = Polyhedron(ieqs = [[-b, A[0,0], A[0,1]], [-b, A[1,0], A[1,1]], [-b, A[2,0], A[2,1]], [0, 1, 0], [0, 0, 1]])
pol.show()


will show you the polyhedron of this MILP in particular.

However, notice that this method has its drawbacks: For example, you should always write the inequalities as >= in order to make them correspond with the way Polyhedron(ieqs=...) draws. Another disadvantage is that the Polyhedron command doesn't take into account that your variables are nonnegative, so you should add those restrictions manually as I did in the last piece of code (note the [0, 1, 0], [0, 0, 1]).

If all you want is to draw the feasible polyhedron of a MILP, you can use the polyhedron method (yes, lowercase letters), like in the following example:

pol = LP.polyhedron()
pol.show()


This will work, no matter how you write your problem, or the inequalities, and you don't need to do any special for non-negative variables (this is already taken into account due to the command x = LP.new_variable(nonnegative=True)).

more