Skip to content

Commit

Permalink
Fix final_touch if no higher-order polynomials are present
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Mar 3, 2024
1 parent 36c4aa2 commit 6f982e7
Showing 1 changed file with 20 additions and 18 deletions.
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 @@ function MOI.Utilities.final_touch(model::Optimizer{T}, _) where {T}
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

0 comments on commit 6f982e7

Please sign in to comment.