diff --git a/Project.toml b/Project.toml index bc6c43e..dab738e 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/MOI_wrapper/MOI_copy.jl b/src/MOI_wrapper/MOI_copy.jl index f15dd7c..1e30786 100644 --- a/src/MOI_wrapper/MOI_copy.jl +++ b/src/MOI_wrapper/MOI_copy.jl @@ -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) diff --git a/test/MOI_wrapper.jl b/test/MOI_wrapper.jl index f3bc4c9..54d2249 100644 --- a/test/MOI_wrapper.jl +++ b/test/MOI_wrapper.jl @@ -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()