Skip to content

Require binary variables in logical constraints #1005

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

Merged
merged 22 commits into from
Jun 5, 2025
Merged

Conversation

Joao-Dionisio
Copy link
Member

@Joao-Dionisio Joao-Dionisio commented May 28, 2025

Fix #1004

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #1004 by enforcing that logical constraints only accept binary variables.

  • Added a failing test for non-variable inputs to logical constraints
  • Inserted runtime type checks in Cython methods handling logical constraints
  • Documented the fix in the changelog

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
tests/test_cons.py Added test_cons_logical_fail marked xfail to catch non-Variable inputs in OR cons
src/pyscipopt/scip.pxi Added isinstance checks for vars in logical-constraint methods; tweaked branchVarVal signature
CHANGELOG.md Logged the segmentation-fault fix when expressions were used in logical constraints
Comments suppressed due to low confidence (2)

tests/test_cons.py:90

  • Instead of xfail, use with pytest.raises(TypeError) to explicitly assert the exception; this ensures the test only passes when the correct error is raised.
m.addConsOr([x1*x3, x2*x4], result1)

src/pyscipopt/scip.pxi:8775

  • [nitpick] The signature indentation and mixed annotation style differ from surrounding methods. Align the indentation and consider adding a type for value or reverting to the original untyped signature for consistency.
def branchVarVal(self, Variable variable, value):

@DominikKamp
Copy link
Contributor

The suppressed suggestions seem to make more sense than the unsuppressed suggestions.

@Joao-Dionisio Joao-Dionisio marked this pull request as draft May 28, 2025 12:51
Co-authored-by: DominikKamp <[email protected]>
@Joao-Dionisio Joao-Dionisio marked this pull request as ready for review May 28, 2025 15:23
@DominikKamp
Copy link
Contributor

Could you explain when test functions also need to be called?

@Joao-Dionisio
Copy link
Member Author

Joao-Dionisio commented May 29, 2025

Could you explain when test functions also need to be called?

Ah, I didn't understand what you were saying at first, but if you're talking about the test_benders, then I shouldn't have pushed. I just use it to make it easier for me to debug something with VSCode. (Here I deleted more mallocs than I should've, causing a segfault)

So the answer is never, actually :)

@DominikKamp
Copy link
Contributor

There are also other test files where this landed in the source, could you check?

@Joao-Dionisio
Copy link
Member Author

Yeah, had one in the numerical tests, thank you! Okay, so everything is done now, right?

@DominikKamp
Copy link
Contributor

Well, now that the logic seems fixed, the code review can begin...

@Joao-Dionisio
Copy link
Member Author

You know, Dominik, I have a draft for a song titled "Every Commit you Make (Every Breath You Take - Dominik Edition)". It's times like these that I think I should pick up my guitar again 😆

Copy link
Contributor

@DominikKamp DominikKamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After resolving the remaining threads, this is fine.

@Joao-Dionisio
Copy link
Member Author

That should be it, then. Thank you for the awesome review, Dominik!

@Joao-Dionisio Joao-Dionisio merged commit 37a1ed6 into master Jun 5, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: .addConsOr will cause the Python kernel to crash
2 participants