Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

highspy: Highs.val should work for highs_linear_expression #1892

Closed
few opened this issue Aug 24, 2024 · 2 comments
Closed

highspy: Highs.val should work for highs_linear_expression #1892

few opened this issue Aug 24, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@few
Copy link
Contributor

few commented Aug 24, 2024

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'
@jajhall jajhall added the enhancement New feature or request label Aug 25, 2024
@jajhall jajhall self-assigned this Aug 29, 2024
@mathgeekcoder
Copy link
Contributor

mathgeekcoder commented Aug 30, 2024

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
...

mathgeekcoder added a commit to mathgeekcoder/HiGHS that referenced this issue Sep 16, 2024
Major highspy update:
* changed `highs_linear_expression` to be immutable by default
* improved callback support
* improved test coverage (99%)
* performance and usability enhancements
* Support `__iadd__`, `__imul__`, etc.
* Updated chain comparison support in immutable setting
* `h.val()` can take `highs_linear_expression`
* `expr == [lb,ub]` -> `lb <= expr <= ub` syntax
* `qsum`
* added pretty print `__repr__` and `__str__`
* added KeyboardInterrupt support
* added user interrupt
* fixed slicing issues with numpy and highs
* added `resetGlobalScheduler`
* released GIL for `Presolve`
* fixed issues with deadlock on Windows
* fixed MIP solution callback issue
* support `getExpr` that creates a `highs_linear_expression` from existing row

Should address multiple issues: ERGO-Code#1865, ERGO-Code#1882, ERGO-Code#1888, ERGO-Code#1892, ERGO-Code#1903, ERGO-Code#1904, and perhaps ERGO-Code#1905
@jajhall
Copy link
Member

jajhall commented Sep 26, 2024

Closed by #1942

@jajhall jajhall closed this as completed Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants