Skip to content

Commit

Permalink
Fix _to_polynomial for ScalarAffineFunction and ScalarQuadraticFuncti…
Browse files Browse the repository at this point in the history
…on (#112)

* Fix _to_polynomial for ScalarAffineFunction and ScalarQuadraticFunction

* Update test/qcqp.jl
  • Loading branch information
odow authored Mar 6, 2024
1 parent 29fa416 commit f96a40b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/nl_to_polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ function _to_polynomial!(d, ::Type{T}, vi::MOI.VariableIndex) where {T}
return d[vi]
end

function _to_polynomial!(
d,
::Type{T},
f::Union{MOI.ScalarAffineFunction,MOI.ScalarQuadraticFunction},
) where {T}
return _to_polynomial!(d, T, convert(MOI.ScalarNonlinearFunction, f))
end

function _to_polynomial!(
d,
::Type{T},
Expand Down
16 changes: 16 additions & 0 deletions test/qcqp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,22 @@ function test_unbound_polynomial(x, y, T)
return
end

function test_scalar_nonlinear_function(x, y, T)
inner = Model{T}()
model = PolyJuMP.JuMP.GenericModel{T}() do
return PolyJuMP.QCQP.Optimizer{T}(MOI.Utilities.MockOptimizer(inner))
end
PolyJuMP.@variable(model, 0 <= x <= 1)
PolyJuMP.@expression(model, f, 0 + x)
PolyJuMP.@expression(model, g, x^2)
PolyJuMP.@constraint(model, f * g == 0)
PolyJuMP.optimize!(model)
F, S = ScalarQuadraticFunction{T}, EqualTo{T}
@test MOI.get(inner, MOI.NumberOfConstraints{F,S}()) == 2
@test MOI.get(inner, MOI.NumberOfVariables()) == 2
return
end

function runtests(x, y)
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
Expand Down

0 comments on commit f96a40b

Please sign in to comment.