Skip to content

Commit

Permalink
Fix copy_to with empty constraint rows (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Sep 26, 2023
1 parent 4bfc9f2 commit f8052b4
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,7 +1,7 @@
name = "GLPK"
uuid = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
repo = "https://github.com/jump-dev/GLPK.jl.git"
version = "1.1.2"
version = "1.1.3"

[deps]
GLPK_jll = "e8aa6df9-e6ca-548a-97ff-1f85fc5b8b98"
Expand Down
2 changes: 1 addition & 1 deletion src/MOI_wrapper/MOI_copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function _extract_row_data(src, map, cache, ::Type{S}) where {S}
F = MOI.ScalarAffineFunction{Float64}
ci_map = map.con_map[F, S]
nnz = length(cache.I)
row = nnz == 0 ? 1 : cache.I[end] + 1
row = length(cache.rl) + 1
for ci in MOI.get(src, MOI.ListOfConstraintIndices{F,S}())
f = MOI.get(src, MOI.ConstraintFunction(), ci)
if !MOI.Utilities.is_canonical(f)
Expand Down
22 changes: 22 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,28 @@ function test_attribute_TimeLimitSec()
return
end

function test_copy_to_bug_HiGHS_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 = GLPK.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 # module

TestMOIWrapper.runtests()

2 comments on commit f8052b4

@odow
Copy link
Member Author

@odow odow commented on f8052b4 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/92218

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.1.3 -m "<description of version>" f8052b4d5b522f6782d9248551e43ae8b060e373
git push origin v1.1.3

Please sign in to comment.