Skip to content

Commit

Permalink
[Utilities] fix modify_function! for ScalarQuadraticCoefficientChange (
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Jan 23, 2024
1 parent 2be1c9b commit 474ffe8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Test/test_modification.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,8 @@ function test_modification_objective_scalarquadraticcoefficientchange(
@test (MOI.get(model, attr), T(1) * x * x + T(2) * x * y, config)
MOI.modify(model, attr, MOI.ScalarQuadraticCoefficientChange(x, y, T(4)))
@test (MOI.get(model, attr), T(1) * x * x + T(4) * x * y, config)
MOI.modify(model, attr, MOI.ScalarQuadraticCoefficientChange(y, x, T(6)))
@test (MOI.get(model, attr), T(1) * x * x + T(6) * x * y, config)
return
end

Expand All @@ -1055,5 +1057,7 @@ function test_modification_constraint_scalarquadraticcoefficientchange(
MOI.modify(model, c, MOI.ScalarQuadraticCoefficientChange(x, x, T(2)))
MOI.modify(model, c, MOI.ScalarQuadraticCoefficientChange(x, y, -T(3)))
@test (MOI.get(model, MOI.ConstraintFunction(), c), g, config)
MOI.modify(model, c, MOI.ScalarQuadraticCoefficientChange(y, x, -T(3)))
@test (MOI.get(model, MOI.ConstraintFunction(), c), g, config)
return
end
5 changes: 3 additions & 2 deletions src/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1402,8 +1402,9 @@ function modify_function!(
change::MOI.ScalarQuadraticCoefficientChange{T},
) where {T}
indices = findall(f.quadratic_terms) do term
return term.variable_1 == change.variable_1 &&
term.variable_2 == change.variable_2
x, y = term.variable_1, term.variable_2
return (x == change.variable_1 && y == change.variable_2) ||
(y == change.variable_1 && x == change.variable_2)
end
for j in reverse(indices)
deleteat!(f.quadratic_terms, j)
Expand Down

0 comments on commit 474ffe8

Please sign in to comment.