Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix _to_polynomial for ScalarAffineFunction and ScalarQuadraticFunction #112

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
return d[vi]
end

function _to_polynomial!(

Check warning on line 60 in src/nl_to_polynomial.jl

View check run for this annotation

Codecov / codecov/patch

src/nl_to_polynomial.jl#L60

Added line #L60 was not covered by tests
d,
::Type{T},
f::Union{MOI.ScalarAffineFunction,MOI.ScalarQuadraticFunction},
) where {T}
return _to_polynomial!(d, T, convert(MOI.ScalarNonlinearFunction, f))

Check warning on line 65 in src/nl_to_polynomial.jl

View check run for this annotation

Codecov / codecov/patch

src/nl_to_polynomial.jl#L65

Added line #L65 was not covered by tests
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

odow marked this conversation as resolved.
Show resolved Hide resolved
function runtests(x, y)
for name in names(@__MODULE__; all = true)
if startswith("$name", "test_")
Expand Down
Loading