sasoptpy.Model.get_variable_coef

Model.get_variable_coef(self, var)[source]

Returns the objective value coefficient of a variable

Parameters
varVariable or string

Variable whose objective value is requested. It can be either the variable object itself, or the name of the variable.

Returns
coeffloat

Objective value coefficient of the given variable

Examples

>>> x = m.add_variable(name='x')
>>> y = m.add_variable(name='y')
>>> m.set_objective(4 * x - 5 * y, name='obj', sense=so.MAX)
>>> print(m.get_variable_coef(x))
4.0
>>> print(m.get_variable_coef('y'))
-5.0