Change in linear programming syntax

Until the recent update in SMC to the latest version of Sage, the following would work:

p = MixedIntegerLinearProgram()
x=p.new_variable(nonnegative=True)
y=p.new_variable(nonnegative=True)
z=p.new_variable(nonnegative=True)
p.set_objective(x + y+ 3*z)

This now gives an error saying that * and + are not defined for these objects.

The following does work, however:

p = MixedIntegerLinearProgram()
x=p.new_variable(nonnegative=True)
y=p.new_variable(nonnegative=True)
z=p.new_variable(nonnegative=True)
p.set_objective(x[0] + y[0]+ 3*z[0])

So, are all new variables in an MILP assumed to be arrays? Is there are way to work with variables as in my first example without using subscripts? (This is mainly for teaching purposes.)

edit retag close merge delete

Sort by ยป oldest newest most voted

I am surprised to hear that the first syntax used to work O_o

This being said, you are not completely lost with the array syntax, e.g.:

sage: p=MixedIntegerLinearProgram()
sage: variables = p.new_variable(nonnegative=True)
sage: x,y,z = variables['x'],variables['y'],variables['z']
sage: p.set_objective(x + y+ 3*z)
more

Okay. That makes sense. Thanks! Also, the new capacity to work with matrices is great!

( 2015-02-24 16:25:10 +0200 )edit

Stats

Seen: 94 times

Last updated: Feb 24 '15