You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MOI.is_valid can be falsely positive for bridged constraints #2696
Here is a case where the false positive silently corrupts a model.
With a solver that supports Integer but not ZeroOne (MosekTools, for example), ZeroOneBridge adds an internal VariableIndex-in-Integer constraint. is_valid reports that constraint as a user constraint, and delete removes it.
The ZeroOne constraint stays valid, but the solver no longer has integrality on the variable.
The delete checks added in #2818 cover deleting variables, not deleting the constraint directly.
import MathOptInterface as MOI
MOI.Utilities.@model(
IntegerOnlyModel,
(MOI.Integer,),
(MOI.EqualTo, MOI.GreaterThan, MOI.LessThan, MOI.Interval),
(),
(),
(),
(MOI.ScalarAffineFunction,),
(),
(),
)
function MOI.supports_constraint(
::IntegerOnlyModel,
::Type{MOI.VariableIndex},
::Type{MOI.ZeroOne},
)
returnfalseend
model = MOI.instantiate(IntegerOnlyModel{Float64}; with_bridge_type = Float64)
x = MOI.add_variable(model)
c = MOI.add_constraint(model, x, MOI.ZeroOne())
ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.Integer}(x.value)
@show MOI.get(model, MOI.ListOfConstraintIndices{MOI.VariableIndex,MOI.Integer}())
@show MOI.is_valid(model, ci)
MOI.delete(model, ci)
@show MOI.is_valid(model, c)
@show MOI.get(model.model, MOI.ListOfConstraintTypesPresent())
The comment on is_valid says users won't have the internal index "except by luck/enumeration", but JuMP builds a VariableIndex constraint's index from the variable's .value, so JuMP hits this through ordinary calls. is_integer(b) returns true for a variable declared only with @variable(model, b, Bin). fix_discrete_variables then calls unset_integer(b), which runs the delete above, and its undo function throws:
ERROR: Cannot set variable b to integer because it is already binary.
Activity
odow commentedon Apr 2, 2025
[Bridges] add a test_broken test for #2696
[Bridges] add a test_broken test for #2696 (#2705)
m-bossart commentedon Nov 4, 2026
Here is a case where the false positive silently corrupts a model.
With a solver that supports
Integerbut notZeroOne(MosekTools, for example),ZeroOneBridgeadds an internalVariableIndex-in-Integerconstraint.is_validreports that constraint as a user constraint, anddeleteremoves it.The
ZeroOneconstraint stays valid, but the solver no longer has integrality on the variable.The delete checks added in #2818 cover deleting variables, not deleting the constraint directly.
The comment on
is_validsays users won't have the internal index "except by luck/enumeration", but JuMP builds aVariableIndexconstraint's index from the variable's.value, so JuMP hits this through ordinary calls.is_integer(b)returnstruefor a variable declared only with@variable(model, b, Bin).fix_discrete_variablesthen callsunset_integer(b), which runs the delete above, and its undo function throws:Found while computing MILP duals with MosekTools in
direct_model(jump-dev/MosekTools.jl#222).MathOptInterface v1.54.0, JuMP v1.32.1, Julia 1.13.0.
blegat commentedon Nov 5, 2026
Actually, #3013 fixes the first issue @odow reported in this issue.
Hide native bridge constraints from is_valid
Track bridge-owned constraints without scanning on queries
Hide native bridge constraints from is_valid
Track bridge-owned constraints without scanning on queries
Hide native bridge constraints from is_valid
Track bridge-owned constraints without scanning on queries