-
Notifications
You must be signed in to change notification settings - Fork 109
FIX: pulp regression issue #907
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
Open
FirePheonix
wants to merge
7
commits into
pysal:main
Choose a base branch
from
FirePheonix:fix-pulp-regression
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8b4875a
pulp-issue-test
FirePheonix 1db241b
fix(graph): support PuLP v4 API for variable creation
FirePheonix 665b9fd
fix(graph): support PuLP v4 API for constraints
FirePheonix 333a3f7
switch-from-attributes-to-pulp-version
FirePheonix 799e058
lowercase-pulp4
FirePheonix 6a3849a
PULPv4-to-PULP_GE_4
FirePheonix 1826dbd
move-PULP_GE_4
FirePheonix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,13 +108,14 @@ def _spatial_matching( | |
|
|
||
| mp = pulp.LpProblem("optimal-neargraph", sense=pulp.LpMinimize) | ||
| # a match is as binary decision variable, connecting observation i to observation j | ||
| match_vars = pulp.LpVariable.dicts( | ||
| "match", | ||
| lowBound=0, | ||
| upBound=1, | ||
| indices=zip(row, col, strict=True), | ||
| cat="Continuous" if allow_partial_match else "Binary", | ||
| ) | ||
| match_vars = {} | ||
| for i, j in zip(row, col, strict=True): | ||
| name = f"match_{i}_{j}" | ||
| cat = "Continuous" if allow_partial_match else "Binary" | ||
| if hasattr(mp, "add_variable"): | ||
| match_vars[i, j] = mp.add_variable(name, lowBound=0, upBound=1, cat=cat) | ||
| else: | ||
| match_vars[i, j] = pulp.LpVariable(name, lowBound=0, upBound=1, cat=cat) | ||
| # we want to minimize the geographic distance of links in the graph | ||
| mp.objective = pulp.lpSum( | ||
| [ | ||
|
|
@@ -145,11 +146,16 @@ def _spatial_matching( | |
| ] | ||
| ) | ||
| sense = int(not allow_partial_match) | ||
| mp += pulp.LpConstraint(summand, sense=sense, rhs=n_matches) | ||
| if sense == 1: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same sentiment here as above. Did |
||
| mp += summand >= n_matches | ||
| elif sense == 0: | ||
| mp += summand == n_matches | ||
| else: | ||
| mp += summand <= n_matches | ||
| if match_between: # but, we may choose to ignore some sources | ||
| for i in range(n_sources): | ||
| summand = pulp.lpSum([match_vars[j, i] for j in range(n_targets)]) | ||
| mp += pulp.LpConstraint(summand, sense=-1, rhs=n_matches) | ||
| mp += summand <= n_matches | ||
|
|
||
| status = mp.solve(solver) | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the need for a for-loop here. Is there no equivalent
dictsfunctionality inpulp4for batch variable addition?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LpVariable.dicts()names variables using the key directly in the string, so we'd get keys like "match_(0, 1)" instead of tuple keys (i, j).And the rest of the code indexes
match_vars[i, j]as a tuple.Refactoring around that would add more complexity than the for-loop i think?
But let me if there's a cleaner way you have in mind..
and yeah, there IS
addVariables()in pulp4, but it just takes already-createdLpVariableobjects, it's not a true batch creation equivalent.The closest would still be
LpVariable.dicts()+addVariables(), but that gives string keys like "match_(0,_1)" instead of the tuple keys (i, j)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to hold off on changing this unill they stabilize the 4.0 API.
I've just pulled down 4.0.0a3, which adds a
LpProblem.add_variable_dicts()method, which does what we need it to do.Let's wait until things stabilize with the 4.0 release, and move to the equivalent functionality then Let's keep this PR open for now, but it's very likely our implementation will not change this radically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I second @ljwolf sentiment here and over in pysal/spopt#527. Well this ride here and allow
devCI to fail -- no harm, no foul.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FirePheonix -- Let's mark this as Draft so it doesn't accidentally get merged. Same for pysal/spopt#527