HiGHS
HiGHS copied to clipboard
highspy: Highs.val should work for highs_linear_expression
In my modeling, I'm carrying around several linear expressions where sometimes I'm only interested in the value of the expressions and not the individual variables. It would be nice if that could be supported.
h = highspy.Highs()
x = h.addVariable(ub=3, obj=1)
y = h.addVariable(ub=4, obj=1)
h.maximize()
assert abs(h.val(x)-3) < 1e-6
assert abs(h.val(y)-4) < 1e-6
assert abs(h.val(x+y)-7) < 1e-6 #AttributeError: 'highs_linear_expression' object has no attribute 'index'
This is a simple feature (if we limit to linear expressions). I've already added support in #1891. Will commit when I've finished with all the new tests and suitable highspy coverage.
Note: it also supports constant addition and all in/equality variants. Strict inequalities (<,>) aren't supported.
h.val(x - 3)
h.val(x + y - 7)
h.val(x + y <= 7) # returns True/False
...
Closed by #1942