Skip to content

Commit d203670

Browse files
committed
fix modify and tests
1 parent 58a9c28 commit d203670

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/MOI_wrapper/MOI_wrapper.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,17 +2166,23 @@ function MOI.modify(
21662166
cols = Vector{Cint}(undef, nels)
21672167
coefs = Vector{Cdouble}(undef, nels)
21682168
for i in 1:nels
2169-
row = Cint(_info(model, cis[i]).row)
2170-
col = column(model, changes[i].variable)
2169+
rows[i] = Cint(_info(model, cis[i]).row)
2170+
cols[i] = column(model, changes[i].variable)
2171+
coefs[i] = changes[i].new_coefficient
2172+
end
2173+
for row in unique(rows)
21712174
nnz = glp_get_mat_row(model, row, C_NULL, C_NULL)
21722175
indices, coefficients = zeros(Cint, nnz), zeros(Cdouble, nnz)
21732176
glp_get_mat_row(model, row, offset(indices), offset(coefficients))
2174-
index = something(findfirst(isequal(col), indices), 0)
2175-
if index > 0
2176-
coefficients[index] = changes[i].new_coefficient
2177-
else
2178-
push!(indices, cols[i])
2179-
push!(coefficients, changes[i].new_coefficient)
2177+
idxs_changed_in_row = findall(x -> x == row, rows)
2178+
for i in idxs_changed_in_row
2179+
index = something(findfirst(isequal(cols[i]), indices), 0)
2180+
if index > 0
2181+
coefficients[index] = coefs[i]
2182+
else
2183+
push!(indices, cols[i])
2184+
push!(coefficients, coefs[i])
2185+
end
21802186
end
21812187
glp_set_mat_row(
21822188
model,

test/MOI_wrapper.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ function test_multiple_modifications()
586586
fc1 = MOI.get(model, MOI.ConstraintFunction(), ci1)
587587
@test MOI.coefficient.(fc1.terms) == [4.0, 1.0, 1.0]
588588
fc2 = MOI.get(model, MOI.ConstraintFunction(), ci2)
589-
@test MOI.coefficient.(fc2.terms) == [2.0, 1.0, 0.5]
589+
@test MOI.coefficient.(fc2.terms) == [0.5, 1.0, 2.0]
590590
end
591591

592592
end # module

0 commit comments

Comments
 (0)