Ask Your Question

# 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

## 1 answer

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

## Comments

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

( 2015-02-24 09:25:10 -0500 )edit

## Your Answer

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

Add Answer

## Stats

Asked: 2015-02-24 07:35:43 -0500

Seen: 51 times

Last updated: Feb 24 '15