Skip to content

[Bridges] fix deleting bridges before final touch #2678

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 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Bridges/Constraint/bridges/IndicatorToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
model::MOI.ModelLike,
bridge::IndicatorToMILPBridge{T},
) where {T}
if bridge.slack === nothing
return # We're deleting the bridge before final_touch

Check warning on line 130 in src/Bridges/Constraint/bridges/IndicatorToMILPBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/IndicatorToMILPBridge.jl#L129-L130

Added lines #L129 - L130 were not covered by tests
end
MOI.delete.(model, bridge.slack_bounds)
MOI.delete(model, bridge.constraint)
MOI.delete(model, bridge.slack::MOI.VariableIndex)
Expand Down
3 changes: 3 additions & 0 deletions src/Bridges/Constraint/bridges/SOS1ToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
end

function MOI.delete(model::MOI.ModelLike, bridge::SOS1ToMILPBridge)
if isempty(bridge.variables)
return # We're deleting the bridge before final_touch

Check warning on line 120 in src/Bridges/Constraint/bridges/SOS1ToMILPBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/SOS1ToMILPBridge.jl#L119-L120

Added lines #L119 - L120 were not covered by tests
end
MOI.delete(model, bridge.equal_to)
for ci in bridge.less_than
MOI.delete(model, ci)
Expand Down
3 changes: 3 additions & 0 deletions src/Bridges/Constraint/bridges/SOS2ToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
end

function MOI.delete(model::MOI.ModelLike, bridge::SOS2ToMILPBridge)
if isempty(bridge.variables)
return # We're deleting the bridge before final_touch

Check warning on line 120 in src/Bridges/Constraint/bridges/SOS2ToMILPBridge.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Constraint/bridges/SOS2ToMILPBridge.jl#L119-L120

Added lines #L119 - L120 were not covered by tests
end
MOI.delete(model, bridge.equal_to)
for ci in bridge.less_than
MOI.delete(model, ci)
Expand Down
16 changes: 16 additions & 0 deletions test/Bridges/Constraint/IndicatorToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ function test_runtests_error_affine()
return
end

function test_delete_before_final_touch()
model = MOI.Bridges.Constraint.IndicatorToMILP{Float64}(
MOI.Utilities.Model{Float64}(),
)
x = MOI.add_variables(model, 2)
MOI.add_constraint(model, x[1], MOI.ZeroOne())
c = MOI.add_constraint(
model,
MOI.VectorOfVariables(x),
MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.GreaterThan(2.0)),
)
MOI.delete(model, c)
@test !MOI.is_valid(model, c)
return
end

end # module

TestConstraintIndicatorToMILP.runtests()
15 changes: 15 additions & 0 deletions test/Bridges/Constraint/SOS1ToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ function test_runtests_error_affine()
return
end

function test_delete_before_final_touch()
model = MOI.Bridges.Constraint.SOS1ToMILP{Float64}(
MOI.Utilities.Model{Float64}(),
)
x = MOI.add_variables(model, 2)
c = MOI.add_constraint(
model,
MOI.VectorOfVariables(x),
MOI.SOS1([1.0, 2.0]),
)
MOI.delete(model, c)
@test !MOI.is_valid(model, c)
return
end

end # module

TestConstraintSOS1ToMILP.runtests()
15 changes: 15 additions & 0 deletions test/Bridges/Constraint/SOS2ToMILPBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ function test_runtests_error_affine()
return
end

function test_delete_before_final_touch()
model = MOI.Bridges.Constraint.SOS2ToMILP{Float64}(
MOI.Utilities.Model{Float64}(),
)
x = MOI.add_variables(model, 2)
c = MOI.add_constraint(
model,
MOI.VectorOfVariables(x),
MOI.SOS2([1.0, 2.0]),
)
MOI.delete(model, c)
@test !MOI.is_valid(model, c)
return
end

end # module

TestConstraintSOS2ToMILP.runtests()
Loading