Route add_enforced_linear_constraint through the enforced helper setters - #5303
Merged
Mizux merged 1 commit intoAug 27, 2026
Merged
Conversation
Model.add_enforced_linear_constraint and the BoundedLinearExpression branch of _add_enforced_linear_constraint_to_helper wrote the indicator constraint's name, bounds and terms through the non-enforced helper setters (set_constraint_name / set_constraint_lower_bound / set_constraint_upper_bound / add_terms_to_constraint) using the enforced constraint index. Enforced constraints are stored in MPModelProto.general_constraint[i] while those setters address MPModelProto.constraint[i], so the call either crashed on an out-of-range index when no regular constraint existed there, or silently overwrote an unrelated regular constraint's name, bounds and terms and left the indicator constraint empty, dropping the enforced constraint. Use the enforced variants, matching the bool branch just above and the Java and C# ports of ModelBuilder.
winklemad
added a commit
to winklemad/winklemad
that referenced
this pull request
Aug 28, 2026
winklemad
added a commit
to winklemad/winklemad.github.io
that referenced
this pull request
Aug 28, 2026
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 #5302
Model.add_enforced_linear_constraintand theBoundedLinearExpressionbranch of_add_enforced_linear_constraint_to_helperwrote the indicator constraint's name, bounds and terms through the non-enforced helper setters (set_constraint_name/set_constraint_lower_bound/set_constraint_upper_bound/add_terms_to_constraint) while passing the enforced constraint's index.Enforced constraints live in
MPModelProto.general_constraint[i], but those setters addressMPModelProto.constraint[i]. The index spaces are disjoint, so the data landed on an unrelated linear constraint — silently destroying it and leaving the indicator constraint empty — or, when no linear constraint existed at that index,mutable_constraint(i)read out of bounds and the process segfaulted (theDCHECKis compiled out in the release wheel).This change routes every setter in the enforced paths through the
set_enforced_*/add_terms_to_enforced_constraintvariants, matching theboolbranch of the same helper (which was already correct) and the Java and C# ports.Added two regression tests:
test_add_enforced_linear_constraint_without_regular_constraint— an enforced constraint on a model with no prior regular constraint now builds a well-formedgeneral_constraintinstead of crashing.test_add_enforced_linear_constraint_keeps_prior_constraint— a prior regular constraint keeps its own name, bounds and terms, and the enforced constraint carries its own, instead of the two being conflated.Both fail on
main(the first as a segfault, the second on the corrupted proto) and pass with this change.