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 final_touch if no higher-order polynomials are present #109

Merged
merged 2 commits into from
Mar 4, 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
38 changes: 20 additions & 18 deletions src/QCQP/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,25 +318,27 @@
end
end
end
div = decompose(monos)
for mono in sort(collect(keys(div)))
if haskey(vars, mono)
continue
if !isnothing(monos)
div = decompose(monos)
for mono in sort(collect(keys(div)))
if haskey(vars, mono)
continue

Check warning on line 325 in src/QCQP/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/QCQP/MOI_wrapper.jl#L321-L325

Added lines #L321 - L325 were not covered by tests
end
a = div[mono]
monomial_variable_index(model, vars, div, a)
b = MP.div_multiple(mono, a)
monomial_variable_index(model, vars, div, b)
end
if !isnothing(model.objective)
func, index_to_var = _subs!(model.objective, index_to_var)
obj = _quad_convert(func.polynomial, vars, div)
MOI.set(model.model, MOI.ObjectiveFunction{typeof(obj)}(), obj)

Check warning on line 335 in src/QCQP/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/QCQP/MOI_wrapper.jl#L327-L335

Added lines #L327 - L335 were not covered by tests
end
for S in keys(model.constraints)
F = PolyJuMP.ScalarPolynomialFunction{T,model.constraints[S][1]}
cis = MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
_add_constraints(model, cis, index_to_var, vars, div)

Check warning on line 340 in src/QCQP/MOI_wrapper.jl

View check run for this annotation

Codecov / codecov/patch

src/QCQP/MOI_wrapper.jl#L337-L340

Added lines #L337 - L340 were not covered by tests
end
a = div[mono]
monomial_variable_index(model, vars, div, a)
b = MP.div_multiple(mono, a)
monomial_variable_index(model, vars, div, b)
end
if !isnothing(model.objective)
func, index_to_var = _subs!(model.objective, index_to_var)
obj = _quad_convert(func.polynomial, vars, div)
MOI.set(model.model, MOI.ObjectiveFunction{typeof(obj)}(), obj)
end
for S in keys(model.constraints)
F = PolyJuMP.ScalarPolynomialFunction{T,model.constraints[S][1]}
cis = MOI.get(model, MOI.ListOfConstraintIndices{F,S}())
_add_constraints(model, cis, index_to_var, vars, div)
end
return
end
Expand Down
13 changes: 13 additions & 0 deletions test/qcqp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ function test_objective_and_constraint(x, y, T)
o * a3 * b3 + o * a6
end

function test_no_monomials(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:2] <= 1)
PolyJuMP.@constraint(model, x[1] * x[2] == 0.5)
PolyJuMP.@objective(model, Min, sum(x))
PolyJuMP.optimize!(model)
@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
Loading