Ask Your Question
0

Change in linear programming syntax

asked 2015-02-24 14:35:43 +0100

calc314 gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2015-02-24 15:24:12 +0100

Nathann gravatar image

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)
edit flag offensive delete link more

Comments

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

calc314 gravatar imagecalc314 ( 2015-02-24 16:25:10 +0100 )edit

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: 2015-02-24 14:35:43 +0100

Seen: 259 times

Last updated: Feb 24 '15