Skip to content

Commit 474ffe8

Browse files
authored
[Utilities] fix modify_function! for ScalarQuadraticCoefficientChange (#2408)
1 parent 2be1c9b commit 474ffe8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Test/test_modification.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,8 @@ function test_modification_objective_scalarquadraticcoefficientchange(
10351035
@test (MOI.get(model, attr), T(1) * x * x + T(2) * x * y, config)
10361036
MOI.modify(model, attr, MOI.ScalarQuadraticCoefficientChange(x, y, T(4)))
10371037
@test (MOI.get(model, attr), T(1) * x * x + T(4) * x * y, config)
1038+
MOI.modify(model, attr, MOI.ScalarQuadraticCoefficientChange(y, x, T(6)))
1039+
@test (MOI.get(model, attr), T(1) * x * x + T(6) * x * y, config)
10381040
return
10391041
end
10401042

@@ -1055,5 +1057,7 @@ function test_modification_constraint_scalarquadraticcoefficientchange(
10551057
MOI.modify(model, c, MOI.ScalarQuadraticCoefficientChange(x, x, T(2)))
10561058
MOI.modify(model, c, MOI.ScalarQuadraticCoefficientChange(x, y, -T(3)))
10571059
@test (MOI.get(model, MOI.ConstraintFunction(), c), g, config)
1060+
MOI.modify(model, c, MOI.ScalarQuadraticCoefficientChange(y, x, -T(3)))
1061+
@test (MOI.get(model, MOI.ConstraintFunction(), c), g, config)
10581062
return
10591063
end

src/Utilities/functions.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,9 @@ function modify_function!(
14021402
change::MOI.ScalarQuadraticCoefficientChange{T},
14031403
) where {T}
14041404
indices = findall(f.quadratic_terms) do term
1405-
return term.variable_1 == change.variable_1 &&
1406-
term.variable_2 == change.variable_2
1405+
x, y = term.variable_1, term.variable_2
1406+
return (x == change.variable_1 && y == change.variable_2) ||
1407+
(y == change.variable_1 && x == change.variable_2)
14071408
end
14081409
for j in reverse(indices)
14091410
deleteat!(f.quadratic_terms, j)

0 commit comments

Comments
 (0)