Skip to content

Commit f8052b4

Browse files
authored
Fix copy_to with empty constraint rows (#228)
1 parent 4bfc9f2 commit f8052b4

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "GLPK"
22
uuid = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
33
repo = "https://github.com/jump-dev/GLPK.jl.git"
4-
version = "1.1.2"
4+
version = "1.1.3"
55

66
[deps]
77
GLPK_jll = "e8aa6df9-e6ca-548a-97ff-1f85fc5b8b98"

src/MOI_wrapper/MOI_copy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function _extract_row_data(src, map, cache, ::Type{S}) where {S}
124124
F = MOI.ScalarAffineFunction{Float64}
125125
ci_map = map.con_map[F, S]
126126
nnz = length(cache.I)
127-
row = nnz == 0 ? 1 : cache.I[end] + 1
127+
row = length(cache.rl) + 1
128128
for ci in MOI.get(src, MOI.ListOfConstraintIndices{F,S}())
129129
f = MOI.get(src, MOI.ConstraintFunction(), ci)
130130
if !MOI.Utilities.is_canonical(f)

test/MOI_wrapper.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,28 @@ function test_attribute_TimeLimitSec()
629629
return
630630
end
631631

632+
function test_copy_to_bug_HiGHS_172()
633+
model = MOI.Utilities.Model{Float64}()
634+
x = MOI.add_variable(model)
635+
F = MOI.ScalarAffineFunction{Float64}
636+
c1 = MOI.add_constraint(model, 2.0 * x, MOI.GreaterThan(0.0))
637+
c2 = MOI.add_constraint(model, zero(F), MOI.GreaterThan(0.0))
638+
c3 = MOI.add_constraint(model, 1.0 * x, MOI.EqualTo(1.0))
639+
h = GLPK.Optimizer()
640+
MOI.set(h, MOI.Silent(), true)
641+
index_map = MOI.copy_to(h, model)
642+
y = index_map[x]
643+
@test MOI.get(h, MOI.ConstraintFunction(), index_map[c1]) 2.0 * y
644+
@test MOI.get(h, MOI.ConstraintFunction(), index_map[c2]) zero(F)
645+
@test MOI.get(h, MOI.ConstraintFunction(), index_map[c3]) 1.0 * y
646+
@test MOI.get(h, MOI.ConstraintSet(), index_map[c1]) == MOI.GreaterThan(0.0)
647+
@test MOI.get(h, MOI.ConstraintSet(), index_map[c2]) == MOI.GreaterThan(0.0)
648+
@test MOI.get(h, MOI.ConstraintSet(), index_map[c3]) == MOI.EqualTo(1.0)
649+
MOI.optimize!(h)
650+
@test MOI.get(h, MOI.TerminationStatus()) == MOI.OPTIMAL
651+
return
652+
end
653+
632654
end # module
633655

634656
TestMOIWrapper.runtests()

0 commit comments

Comments
 (0)