Skip to content

Commit ef30cdc

Browse files
authored
[Bridges] fix bug in QuadToSOCBridge getting ConstraintPrimal (#2240)
1 parent dab02e5 commit ef30cdc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Bridges/Constraint/bridges/quad_to_soc.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ end
229229
function MOI.get(
230230
model::MOI.ModelLike,
231231
attr::Union{MOI.ConstraintPrimal,MOI.ConstraintPrimalStart},
232-
bridge::QuadtoSOCBridge,
233-
)
232+
bridge::QuadtoSOCBridge{T},
233+
) where {T}
234234
# The constraint primal is x'Qx/2 + a'x
235235
# If `less_than` then `Q = U'U` and we have the value of
236236
# `Ux` and `-a'x + ub`, so we get it with
@@ -242,7 +242,7 @@ function MOI.get(
242242
if soc === nothing
243243
return nothing
244244
end
245-
output = sum(soc[i]^2 for i in 3:bridge.dimension)
245+
output = sum(soc[i]^2 for i in 3:bridge.dimension; init = zero(T))
246246
output /= 2
247247
output -= soc[1] * soc[2]
248248
if !bridge.less_than

test/Bridges/Constraint/quad_to_soc.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,21 @@ function test_deletion_of_variable_in_bridged_slacked_objective()
325325
return
326326
end
327327

328+
function test_constraint_primal_no_quad_terms()
329+
inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
330+
model = MOI.Bridges.Constraint.QuadtoSOC{Float64}(inner)
331+
x = MOI.add_variable(model)
332+
f = MOI.ScalarQuadraticFunction(
333+
MOI.ScalarQuadraticTerm{Float64}[],
334+
[MOI.ScalarAffineTerm(1.0, x)],
335+
0.0,
336+
)
337+
c = MOI.add_constraint(model, f, MOI.LessThan(1.0))
338+
MOI.set(model, MOI.ConstraintPrimalStart(), c, 1.0)
339+
@test MOI.get(model, MOI.ConstraintPrimalStart(), c) == 1.0
340+
return
341+
end
342+
328343
end # module
329344

330345
TestConstraintQuadToSOC.runtests()

0 commit comments

Comments
 (0)