Repository navigation
Keep binary bounds in nested add_variable_dicts and add_variable_matrix - #964
Merged
Merged
Conversation
Both functions turned cat=LpBinary into LpInteger before recursing over the remaining index sets, so the inner calls no longer saw LpBinary and created integer variables with (-inf, inf) bounds. Keep the original category for the recursive calls. Fixes #963.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #963.
The bug only shows up with two or more index sets, which is probably why it works for some people and not others.
add_variable_dicts()andadd_variable_matrix()turncat=LpBinaryinto bounds[0, 1]and categoryLpInteger, but they do it by reassigningcat. With more than one index set they then recurse with thatcat(nowLpInteger) and the originallowBound/upBound(None), so the leaf call never seesLpBinaryand creates integer variables with bounds(-inf, inf). A 1-D call never recurses and gets the right bounds, andadd_variable_dict()doesn't recurse either.On
master(4.0.1):Change
Both functions now use a separate local for the converted category, so the recursive calls get the original
catand do the binary conversion at the leaf as before.Tests
PuLPModelTest.test_binary_variables_with_several_indicesbuilds a 2-D binary dict and matrix and checks every variable isIntegerwith bounds[0, 1]. Onmasterit fails withAssertionError: -inf != 0; with the fix it passes.uv run --all-extras --no-extra mosek python -m unittest discover -s pulp/tests(Windows, Python 3.14): 1041 tests, OK (skipped=605).ruff check pulpandruff format pulp --checkpass.ty check pulpreports the same 2 warnings as onmaster(resource.getrusageinpulp/utilities.py, which doesn't exist on Windows).