Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
1.99k stars 511 forks source link

Sort indices while removing constraints to fix #3127 #3281

Closed kutlay closed 2 months ago

kutlay commented 4 months ago

Fixes #3127

Summary/Motivation:

Issue 3127 showed that HiGHs solution was different when the same variable was fixed and unfixed. A solution should not change after fixing and unfixing the same variable. The issue showed the hint that HiGHs solver was expecting the deleted row indices to be sorted. This fix sorts the indices before sending it to the solver.

Unfortunately, HiGHs code doesn't explain why the indices supplied to deleteRows need to be sorted: https://github.com/ERGO-Code/HiGHS/blob/13363c9f1252b015cf6527132eb9cf8f4b5bf020/src/lp_data/Highs.cpp#L2871-L2883

However, the error message indicates that they need to be sorted, so I can't think of any problems sorting the indices in pyomo other than slight degradation in performance because of sorting.

Changes proposed in this PR:

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.
kutlay commented 3 months ago

@jsiirola Thank you for the help! Changes are done and it should be good to go now.

mrmundt commented 3 months ago

@kutlay - can you please install the latest version of black and run black -S -C on your code? Thank you!

kutlay commented 3 months ago

@mrmundt sorry for the delay, the black reformatting is done. You can kick off the workflow again.

mrmundt commented 3 months ago

@kutlay - FYI, the pypy job will fail, but it's not your fault.

blnicho commented 2 months ago

We're waiting for Jenkins to run on this before merging.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 88.46%. Comparing base (53d5cad) to head (072c2c5).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #3281 +/- ## ========================================== + Coverage 86.46% 88.46% +1.99% ========================================== Files 801 867 +66 Lines 96758 98214 +1456 ========================================== + Hits 83661 86883 +3222 + Misses 13097 11331 -1766 ``` | [Flag](https://app.codecov.io/gh/Pyomo/pyomo/pull/3281/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pyomo) | Coverage Δ | | |---|---|---| | [linux](https://app.codecov.io/gh/Pyomo/pyomo/pull/3281/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pyomo) | `86.27% <ø> (ø)` | | | [osx](https://app.codecov.io/gh/Pyomo/pyomo/pull/3281/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pyomo) | `75.56% <ø> (ø)` | | | [other](https://app.codecov.io/gh/Pyomo/pyomo/pull/3281/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pyomo) | `86.46% <ø> (+<0.01%)` | :arrow_up: | | [win](https://app.codecov.io/gh/Pyomo/pyomo/pull/3281/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pyomo) | `83.76% <ø> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Pyomo#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.