Skip to content
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

[Bridges] fix deleting variable in Bridges.Variable.VectorizeBridge #2393

Merged
merged 7 commits into from
Jan 8, 2024
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
10 changes: 7 additions & 3 deletions src/Bridges/Variable/bridges/vectorize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@
return [bridge.vector_constraint]
end

# References
function MOI.delete(model::MOI.ModelLike, bridge::VectorizeBridge)
MOI.delete(model, bridge.variable)
return
# It isn't safe to delete the variable because the constant may appear in
# other parts of the model (like the objective, or right-hand side sets).
err = MOI.DeleteNotAllowed(

Check warning on line 104 in src/Bridges/Variable/bridges/vectorize.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/bridges/vectorize.jl#L104

Added line #L104 was not covered by tests
bridge.variable,
"Cannot delete variable because it is bridged by the `VectorizeBridge`.",
)
return throw(err)

Check warning on line 108 in src/Bridges/Variable/bridges/vectorize.jl

View check run for this annotation

Codecov / codecov/patch

src/Bridges/Variable/bridges/vectorize.jl#L108

Added line #L108 was not covered by tests
end

# Attributes, Bridge acting as a constraint
Expand Down
14 changes: 7 additions & 7 deletions test/Bridges/Variable/vectorize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ function test_exp3_with_add_constrained_variable_y()
MOI.set(bridged_mock, MOI.VariablePrimalStart(), y, 1.0)
@test MOI.get(mock, MOI.VariablePrimalStart(), z) == -4
@test MOI.get(bridged_mock, MOI.VariablePrimalStart(), y) == 1
return
end

_test_delete_bridged_variable(
bridged_mock,
y,
MOI.LessThan{Float64},
2,
((MOI.VectorOfVariables, MOI.Nonpositives, 0),),
)
function test_delete_variable()
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
model = MOI.Bridges.Variable.Vectorize{Float64}(inner)
x, _ = MOI.add_constrained_variable(model, MOI.GreaterThan(1.0))
@test_throws MOI.DeleteNotAllowed{MOI.VariableIndex} MOI.delete(model, x)
return
end

Expand Down
11 changes: 0 additions & 11 deletions test/Bridges/lazy_bridge_optimizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,6 @@ function _test_SDPA_format(T)
@test MOI.Bridges.bridge_type(bridged, MOI.RotatedSecondOrderCone) ==
MOI.Bridges.Variable.RSOCtoPSDBridge{T}
x, cx = MOI.add_constrained_variable(bridged, MOI.LessThan(one(T)))
_test_delete_bridged_variable(
bridged,
x,
MOI.LessThan{T},
1,
(
(MOI.VectorOfVariables, MOI.Nonnegatives, 0),
(MOI.VectorOfVariables, MOI.Nonpositives, 0),
),
used_bridges = 2,
)
@test !MOI.supports_constraint(
bridged,
MOI.VectorAffineFunction{T},
Expand Down
Loading