Ask Your Question
0

Change in linear programming syntax

asked 10 years ago

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.)

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 10 years ago

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)
Preview: (hide)
link

Comments

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

calc314 gravatar imagecalc314 ( 10 years ago )

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: 10 years ago

Seen: 288 times

Last updated: Feb 24 '15