Skip to content

Commit f4028f7

Browse files
authored
Resolve clash with add_constraint (#183)
1 parent 56a0e81 commit f4028f7

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/constraint.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,18 @@ end
174174
_non_constant(a::Vector{T}) where T = convert.(MOI.ScalarAffineFunction{T}, a)
175175
_non_constant(a::Vector{<:MOI.AbstractFunction}) = a
176176

177-
function add_constraint(model::MOI.ModelLike, p, cone::SOSLikeCone; kws...)
177+
# Add constraint with `p` having coefficients being MOI functions.
178+
# This is needed as a workaround as JuMP does not support complex numbers yet.
179+
# We can remove it when https://github.com/jump-dev/JuMP.jl/pull/2391 is done
180+
# We overload `JuMP.add_constraint` to avoid clash with the name.
181+
function JuMP.add_constraint(model::MOI.ModelLike, p, cone::SOSLikeCone; kws...)
178182
coefs = MOI.Utilities.vectorize(_non_constant(MP.coefficients(p)))
179183
monos = MP.monomials(p)
180184
set = JuMP.moi_set(cone, monos; kws...)
181185
return MOI.add_constraint(model, coefs, set)
182186
end
183-
function add_constraint(model::JuMP.Model, p, cone::SOSLikeCone; kws...)
184-
ci = add_constraint(JuMP.backend(model), p, cone; kws...)
187+
function JuMP.add_constraint(model::JuMP.Model, p, cone::SOSLikeCone; kws...)
188+
ci = JuMP.add_constraint(JuMP.backend(model), p, cone; kws...)
185189
return JuMP.ConstraintRef(model, ci, PolyJuMP.PolynomialShape(MP.monomials(p)))
186190
end
187191

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,3 @@ include("sospoly.jl")
4141
include("domain.jl")
4242
include("sosquartic.jl")
4343
include("equalitypolyconstr.jl")
44-
include("extract.jl")

0 commit comments

Comments
 (0)