Skip to content

Commit

Permalink
Fix copy_to with empty constraint rows (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 26, 2023
1 parent 6a39882 commit a923088
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "HiGHS"
uuid = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
version = "1.6.0"
version = "1.6.1"

[deps]
HiGHS_jll = "8fd58aa0-07eb-5a78-9b36-339c94fd15ea"
Expand Down
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
22 changes: 22 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,28 @@ 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]) zero(F)
@test MOI.get(h, MOI.ConstraintFunction(), index_map[c3]) 1.0 * y
@test MOI.get(h, MOI.ConstraintSet(), index_map[c1]) == MOI.GreaterThan(0.0)
@test MOI.get(h, MOI.ConstraintSet(), index_map[c2]) == MOI.GreaterThan(0.0)
@test MOI.get(h, MOI.ConstraintSet(), index_map[c3]) == MOI.EqualTo(1.0)
MOI.optimize!(h)
@test MOI.get(h, MOI.TerminationStatus()) == MOI.OPTIMAL
return
end

end

TestMOIHighs.runtests()

2 comments on commit a923088

@odow
Copy link
Member Author

@odow odow commented on a923088 Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92216

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.6.1 -m "<description of version>" a92308854215ac57980acc576fc4d89ed21573a0
git push origin v1.6.1

Please sign in to comment.