Ask Your Question
0

Reuse of already entered parameters

asked 2019-10-06 19:03:35 +0100

Cyrille gravatar image

updated 2020-10-11 23:10:00 +0100

slelievre gravatar image

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[0] + a[1,2]x[1] + c[1,3]*x[2] >= b [1])

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

to write

pol = Polyhedron(ieqs = [[-b [1], 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 flag offensive close merge delete

Comments

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?

dsejas gravatar imagedsejas ( 2019-10-06 20:58:40 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-10-06 20:56:28 +0100

dsejas gravatar image

updated 2019-10-06 20:57:21 +0100

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.add_constraint(-2*x[1] - x[2] >= 1.5)
LP.add_constraint(-x[1] - x[2] >= 1)
LP.add_constraint(-x[1] - 2*x[2] >= 1)
LP.set_objective(5*x[1] - 4*x[2])

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.add_constraint(A[0,0]*x[1] + A[0,1]*x[2] >= b[0])
LP.add_constraint(A[1,0]*x[1] + A[1,1]*x[2] >= b[1])
LP.add_constraint(A[2,0]*x[1] + A[2,1]*x[2] >= b[2])
LP.set_objective(5*x[1] + 4*x[2])

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

pol = Polyhedron(ieqs = [[-b[0], A[0,0], A[0,1]], [-b[1], A[1,0], A[1,1]], [-b[2], 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)).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-10-06 19:03:35 +0100

Seen: 269 times

Last updated: Oct 11 '20