Evaluation of a LinearFunction

asked 2016-05-24 08:25:53 -0600

Evan gravatar image

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?

edit retag flag offensive close merge delete