Skip to content

Commit 6114219

Browse files
committed
Fix geomean bridge
1 parent d1bebd5 commit 6114219

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/Bridges/Constraint/geomean.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ function bridge_constraint(::Type{GeoMeanBridge{T, F, G}}, model,
5959

6060
xl1 = MOI.SingleVariable(xij[1])
6161
sN = one(T) / N
62-
function _getx(i)
62+
A = MOIU.promote_operation(*, T, T, MOI.SingleVariable)
63+
function _getx(i)::A
6364
if i > n
6465
return sN * xl1
6566
else
@@ -69,10 +70,9 @@ function bridge_constraint(::Type{GeoMeanBridge{T, F, G}}, model,
6970

7071
t = f_scalars[1]
7172
# With sqrt(2)^l*t - xl1, we should scale both the ConstraintPrimal and ConstraintDual
72-
tubc = MOIU.add_scalar_constraint(model,
73-
MOIU.operate!(+, T, t, -sN * xl1),
74-
MOI.LessThan(zero(T)),
75-
allow_modify_function=true)
73+
tubc = MOIU.add_scalar_constraint(
74+
model, MOIU.operate!(+, T, t, -sN * xl1), MOI.LessThan(zero(T)),
75+
allow_modify_function=true)
7676

7777
socrc = Vector{CI{G, MOI.RotatedSecondOrderCone}}(undef, N-1)
7878
offset = offsetnext = 0
@@ -83,13 +83,13 @@ function bridge_constraint(::Type{GeoMeanBridge{T, F, G}}, model,
8383
a = _getx(2j-1)
8484
b = _getx(2j)
8585
else
86-
a = one(T) * MOI.SingleVariable(xij[offsetnext+2j-1])
87-
b = one(T) * MOI.SingleVariable(xij[offsetnext+2j])
86+
a = convert(A, MOI.SingleVariable(xij[offsetnext+2j-1]))
87+
b = convert(A, MOI.SingleVariable(xij[offsetnext+2j]))
8888
end
8989
c = MOI.SingleVariable(xij[offset+j])
90-
socrc[offset + j] = MOI.add_constraint(model,
91-
MOIU.operate(vcat, T, a, b, c),
92-
MOI.RotatedSecondOrderCone(3))
90+
socrc[offset + j] = MOI.add_constraint(
91+
model, MOIU.operate(vcat, T, a, b, c),
92+
MOI.RotatedSecondOrderCone(3))
9393
end
9494
offset = offsetnext
9595
end

test/Bridges/Constraint/geomean.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
using Test
2+
3+
using MathOptInterface
4+
const MOI = MathOptInterface
5+
const MOIT = MathOptInterface.Test
6+
const MOIU = MathOptInterface.Utilities
7+
const MOIB = MathOptInterface.Bridges
8+
9+
include("../utilities.jl")
10+
11+
mock = MOIU.MockOptimizer(MOIU.Model{Float64}())
12+
config = MOIT.TestConfig()
13+
114
@testset "GeoMean" begin
215
mock.optimize! = (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, [ones(4); 2; 2; 2])
316
bridged_mock = MOIB.Constraint.GeoMean{Float64}(mock)

0 commit comments

Comments
 (0)