Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Evaluation of a LinearFunction

I would like to substitute values for the variables in a LinearFunction object. For example:

sage: lp.<x> = MixedIntegerLinearProgram()
sage: f = 2*x[0] + x[1]
sage: f
2*x_0 + x_1
sage: type(f)
<type 'sage.numerical.linear_functions.LinearFunction'>

The object f is not callable, and also the following does nothing (even though the Sage online help suggests that it should do something):

sage: f.subs({x[0]:1.0, x[1]:2.0})
2*x_0 + x_1

I can do what I want to do by writing some code to work with the output of f.dict(), but does Sage have a cleaner way to evaluate a linear function?