Repository navigation
Fix constraints that MiniZinc.Model supported but could not write - #123
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #123 +/- ##
==========================================
+ Coverage 98.38% 98.39% +0.01%
==========================================
Files 5 5
Lines 681 687 +6
==========================================
+ Hits 670 676 +6
Misses 11 11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
MiniZinc.Model reported support for VariableIndex in Semicontinuous, Semiinteger and Parameter, but `write` ignored those constraints, so the solve returned a wrong answer. For example, `x in Semiinteger(2, 3)` with `x <= 1`, maximizing x, returned x = 1 instead of 0. It also reported support for scalar affine, quadratic and nonlinear functions in Interval, ZeroOne and Integer, and for VectorOfVariables in Reified LessThan, GreaterThan and EqualTo, but `write` could not handle them, so optimize! threw a MethodError. In JuMP this includes `@constraint(model, 1 <= x + y <= 2)` and `@constraint(model, [z, x] in MOI.Reified(MOI.LessThan(1)))`. Returning false from supports_constraint lets the bridges reformulate them into constraints that `write` supports.
odow
force-pushed
the
coey/unsupported-constraints
branch
from
October 26, 2026 22:51
a63c645 to
07e55a1
Compare
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.
MiniZinc.Modelreported support for some constraints thatwritecannot handle.VariableIndexinSemicontinuous,SemiintegerandParameterwere ignored when writing the model, so the solve returned a wrong answer:Similarly,
@variable(model, p in Parameter(2))was written asvar int: p;, with no value.These threw a
MethodErrorwhen writing the model:ScalarAffineFunction,ScalarQuadraticFunctionandScalarNonlinearFunctioninInterval,ZeroOneandIntegerVectorOfVariablesinReified{LessThan},Reified{GreaterThan}andReified{EqualTo}supports_constraintnow returnsfalsefor all of these, like the existingVectorAffineFunctionoverride, so the bridges can reformulate them into constraints thatwritehandles. Both examples now return the right answer.For the interval example, the bridge adds a slack variable:
constraint 1*x + 1*y + -1*x3 = 0;withx3in1..2. Writingconstraint x + y in 1..2;directly would avoid that. I went with the bridges to match the existing override, but I can switch to writingIntervaldirectly if you prefer.Without bridges, the
Interval,ZeroOneandIntegercases still throw theMethodError, becauseMOI.copy_todoesn't checksupports_constraintfor them.Please merge #122 first: with only this PR,
p * y * y <= 18withp in Parameter(2)is written as((1*p*y + 0 * y) - 18) <= 0.