From d8346c64ba34025c6552f0d885726cb94bac8f19 Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 10 Apr 2024 10:00:15 +1200 Subject: [PATCH] Add test --- .../Constraint/bridges/complex_norm_infinity.jl | 6 ++++++ .../Bridges/Constraint/complex_norm_infinity.jl | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Bridges/Constraint/bridges/complex_norm_infinity.jl b/src/Bridges/Constraint/bridges/complex_norm_infinity.jl index c55c9bbfc8..8a989883a2 100644 --- a/src/Bridges/Constraint/bridges/complex_norm_infinity.jl +++ b/src/Bridges/Constraint/bridges/complex_norm_infinity.jl @@ -41,6 +41,12 @@ function bridge_constraint( s::MOI.NormInfinityCone, ) where {T} fi_s = MOI.Utilities.scalarize(f) + if !iszero(imag(fi_s[1])) + error( + "The epigraph variable `t` in `[t; x] in NormInfinityCone()` " * + "must be real. It is: $(fi_s[1])", + ) + end t = real(fi_s[1]) cis = MOI.ConstraintIndex{MOI.VectorAffineFunction{T},MOI.SecondOrderCone}[] for fi in fi_s[2:end] diff --git a/test/Bridges/Constraint/complex_norm_infinity.jl b/test/Bridges/Constraint/complex_norm_infinity.jl index e1969d7a4d..b6801e636c 100644 --- a/test/Bridges/Constraint/complex_norm_infinity.jl +++ b/test/Bridges/Constraint/complex_norm_infinity.jl @@ -47,6 +47,23 @@ function test_runtests() return end +function test_imag_t() + inner = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()) + model = MOI.Bridges.Constraint.ComplexNormInfinityToSecondOrderCone{Float64}(inner) + x = MOI.add_variables(model, 2) + f_t = (1.0 + 2.0im) * x[1] + f_x = (1.0 + 2.0im) * x[2] + (3.0 + 4.0im) + f = MOI.Utilities.operate(vcat, Complex{Float64}, f_t, f_x) + @test_throws( + ErrorException( + "The epigraph variable `t` in `[t; x] in NormInfinityCone()` " * + "must be real. It is: $f_t", + ), + MOI.add_constraint(model, f, MOI.NormInfinityCone(2)) + ) + return +end + end # module TestConstraintComplexNormInfinityToSecondOrderCone.runtests()