ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 24 Feb 2015 09:25:10 -0600Change in linear programming syntaxhttp://ask.sagemath.org/question/25913/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.)
Tue, 24 Feb 2015 07:35:43 -0600http://ask.sagemath.org/question/25913/change-in-linear-programming-syntax/Answer by Nathann for <p>Until the recent update in SMC to the latest version of Sage, the following would work:</p>
<pre><code>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)
</code></pre>
<p>This now gives an error saying that * and + are not defined for these objects.</p>
<p>The following does work, however:</p>
<pre><code>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])
</code></pre>
<p>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.)</p>
http://ask.sagemath.org/question/25913/change-in-linear-programming-syntax/?answer=25915#post-id-25915I 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)
Tue, 24 Feb 2015 08:24:12 -0600http://ask.sagemath.org/question/25913/change-in-linear-programming-syntax/?answer=25915#post-id-25915Comment by calc314 for <p>I am surprised to hear that the first syntax used to work O_o</p>
<p>This being said, you are not completely lost with the array syntax, e.g.:</p>
<pre><code> 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)
</code></pre>
http://ask.sagemath.org/question/25913/change-in-linear-programming-syntax/?comment=25918#post-id-25918Okay. That makes sense. Thanks! Also, the new capacity to work with matrices is great!Tue, 24 Feb 2015 09:25:10 -0600http://ask.sagemath.org/question/25913/change-in-linear-programming-syntax/?comment=25918#post-id-25918