From 474ffe830a73aeff3c92e303476c120e77443711 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 24 Jan 2024 12:04:24 +1300 Subject: [PATCH] [Utilities] fix modify_function! for ScalarQuadraticCoefficientChange (#2408) --- src/Test/test_modification.jl | 4 ++++ src/Utilities/functions.jl | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Test/test_modification.jl b/src/Test/test_modification.jl index 1270d9bdb6..76b58e5da2 100644 --- a/src/Test/test_modification.jl +++ b/src/Test/test_modification.jl @@ -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 @@ -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 diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index 0452b8bb85..2bade074b0 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -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)