Skip to content

Commit

Permalink
Fix copy_to with empty constraint rows
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Sep 26, 2023
1 parent 6a39882 commit 62eb929
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ function _extract_row_data(
::Type{S},
) where {S}
F = MOI.ScalarAffineFunction{Float64}
row = length(I) == 0 ? 1 : I[end] + 1
row = length(rowlower) + 1
list = _constraints(src, MOI.ScalarAffineFunction{Float64}, S)
numrows = length(list)
_add_sizehint!(rowlower, numrows)
Expand Down
19 changes: 19 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,25 @@ function test_attribute_TimeLimitSec()
return
end

function test_copy_to_bug_172()
model = MOI.Utilities.Model{Float64}()
x = MOI.add_variable(model)
F = MOI.ScalarAffineFunction{Float64}
c1 = MOI.add_constraint(model, 2.0 * x, MOI.GreaterThan(0.0))
c2 = MOI.add_constraint(model, zero(F), MOI.GreaterThan(0.0))
c3 = MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(1.0))
h = HiGHS.Optimizer()
MOI.set(h, MOI.Silent(), true)
index_map = MOI.copy_to(h, model)
y = index_map[x]
@test MOI.get(h, MOI.ConstraintFunction(), index_map[c1]) 2.0 * y
@test MOI.get(h, MOI.ConstraintFunction(), index_map[c2]) g
@test MOI.get(h, MOI.ConstraintFunction(), index_map[c3]) 1.0 * y
MOI.optimize!(h)
@test MOI.get(h, MOI.TerminationStatus()) == MOI.OPTIMAL
return
end

end

TestMOIHighs.runtests()

0 comments on commit 62eb929

Please sign in to comment.