Skip to content

Commit c611a46

Browse files
authored
[Bridges] fix bridge weights for SOS(1|2)ToMILPBridge (#2723)
1 parent d966e88 commit c611a46

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

src/Bridges/Constraint/bridges/SOS1ToMILPBridge.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ end
6161
const SOS1ToMILP{T,OT<:MOI.ModelLike} =
6262
SingleBridgeOptimizer{SOS1ToMILPBridge{T},OT}
6363

64+
# We need to weight this bridge such that `VectorAffineFunction-in-SOS1` is
65+
# bridged (if possible) by `VectorSlack + VectorOfVariables-in-SOS1`.
66+
#
67+
# See MathOptInterface#2722 for details.
68+
MOI.Bridges.bridging_cost(::Type{<:SOS1ToMILPBridge}) = 10.0
69+
6470
function bridge_constraint(
6571
::Type{SOS1ToMILPBridge{T,F}},
6672
model::MOI.ModelLike,

src/Bridges/Constraint/bridges/SOS2ToMILPBridge.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ end
6161
const SOS2ToMILP{T,OT<:MOI.ModelLike} =
6262
SingleBridgeOptimizer{SOS2ToMILPBridge{T},OT}
6363

64+
# We need to weight this bridge such that `VectorAffineFunction-in-SOS2` is
65+
# bridged (if possible) by `VectorSlack + VectorOfVariables-in-SOS2`.
66+
#
67+
# See MathOptInterface#2722 for details.
68+
MOI.Bridges.bridging_cost(::Type{<:SOS2ToMILPBridge}) = 10.0
69+
6470
function bridge_constraint(
6571
::Type{SOS2ToMILPBridge{T,F}},
6672
model::MOI.ModelLike,

test/Bridges/Constraint/SOS1ToMILPBridge.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,38 @@ function test_delete_before_final_touch()
134134
return
135135
end
136136

137+
MOI.Utilities.@model(
138+
Model2722,
139+
(),
140+
(MOI.EqualTo,),
141+
(MOI.Zeros,),
142+
(MOI.SOS1,),
143+
(),
144+
(MOI.ScalarAffineFunction,),
145+
(MOI.VectorOfVariables,),
146+
(MOI.VectorAffineFunction,),
147+
)
148+
149+
function MOI.supports_constraint(
150+
::Model2722{T},
151+
::Type{MOI.VectorAffineFunction{T}},
152+
::Type{MOI.SOS1{T}},
153+
) where {T}
154+
return false
155+
end
156+
157+
function test_bridge_does_not_apply_if_vector_slack_exists()
158+
inner = Model2722{Float64}()
159+
model = MOI.Bridges.full_bridge_optimizer(inner, Float64)
160+
x = MOI.add_variables(model, 3)
161+
f = MOI.Utilities.vectorize(1.0 .* x)
162+
c = MOI.add_constraint(model, f, MOI.SOS1([1.0, 2.0, 3.0]))
163+
@test model.constraint_map[c] isa MOI.Bridges.Constraint.VectorSlackBridge
164+
F, S = MOI.VectorOfVariables, MOI.SOS1{Float64}
165+
@test (F, S) in MOI.get(inner, MOI.ListOfConstraintTypesPresent())
166+
return
167+
end
168+
137169
end # module
138170

139171
TestConstraintSOS1ToMILP.runtests()

test/Bridges/Constraint/SOS2ToMILPBridge.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,38 @@ function test_delete_before_final_touch()
144144
return
145145
end
146146

147+
MOI.Utilities.@model(
148+
Model2722,
149+
(),
150+
(MOI.EqualTo,),
151+
(MOI.Zeros,),
152+
(MOI.SOS2,),
153+
(),
154+
(MOI.ScalarAffineFunction,),
155+
(MOI.VectorOfVariables,),
156+
(MOI.VectorAffineFunction,),
157+
)
158+
159+
function MOI.supports_constraint(
160+
::Model2722{T},
161+
::Type{MOI.VectorAffineFunction{T}},
162+
::Type{MOI.SOS2{T}},
163+
) where {T}
164+
return false
165+
end
166+
167+
function test_bridge_does_not_apply_if_vector_slack_exists()
168+
inner = Model2722{Float64}()
169+
model = MOI.Bridges.full_bridge_optimizer(inner, Float64)
170+
x = MOI.add_variables(model, 3)
171+
f = MOI.Utilities.vectorize(1.0 .* x)
172+
c = MOI.add_constraint(model, f, MOI.SOS2([1.0, 2.0, 3.0]))
173+
@test model.constraint_map[c] isa MOI.Bridges.Constraint.VectorSlackBridge
174+
F, S = MOI.VectorOfVariables, MOI.SOS2{Float64}
175+
@test (F, S) in MOI.get(inner, MOI.ListOfConstraintTypesPresent())
176+
return
177+
end
178+
147179
end # module
148180

149181
TestConstraintSOS2ToMILP.runtests()

0 commit comments

Comments
 (0)