Skip to content

Commit 406f7cd

Browse files
authored
[FileFormats.MPS] fix reading models with extra ROWS fields (#2793)
1 parent 703a15e commit 406f7cd

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/FileFormats/MPS/MPS.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,15 @@ end
14351435
# ==============================================================================
14361436

14371437
function parse_rows_line(data::TempMPSModel{T}, items::Vector{String}) where {T}
1438-
if length(items) != 2
1438+
if length(items) < 2
14391439
error("Malformed ROWS line: $(join(items, " "))")
1440+
elseif length(items) > 2
1441+
# We could throw an error here, but it seems like other solvers just
1442+
# happily ignore the extra fields.
1443+
#
1444+
# See https://github.com/jump-dev/MathOptInterface.jl/issues/2792
1445+
#
1446+
# Oscar dislikes the poorly standardized nature of MPS.
14401447
end
14411448
sense, name = Sense(items[1]), items[2]
14421449
if haskey(data.name_to_row, name)

test/FileFormats/MPS/MPS.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function test_failing_models()
8888
joinpath(@__DIR__, "failing_models", filename),
8989
)
9090
end
91+
return
9192
end
9293

9394
function test_empty_row_name()
@@ -1675,6 +1676,33 @@ function test_duplicate_coefficient()
16751676
return
16761677
end
16771678

1679+
function test_issue_2792()
1680+
src = """
1681+
NAME
1682+
ROWS
1683+
N OBJ \$t3 0
1684+
COLUMNS
1685+
x OBJ 2
1686+
RHS
1687+
rhs OBJ -3
1688+
BOUNDS
1689+
LO bounds x 1
1690+
PL bounds x
1691+
ENDATA
1692+
"""
1693+
model = MPS.Model()
1694+
read!(IOBuffer(src), model)
1695+
dest = MOI.Utilities.Model{Float64}()
1696+
MOI.copy_to(dest, model)
1697+
@test MOI.get(dest, MOI.ListOfConstraintTypesPresent()) ==
1698+
[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
1699+
x = only(MOI.get(dest, MOI.ListOfVariableIndices()))
1700+
F = MOI.get(dest, MOI.ObjectiveFunctionType())
1701+
f = MOI.get(dest, MOI.ObjectiveFunction{F}())
1702+
@test isapprox(f, 2.0 * x + 3.0)
1703+
return
1704+
end
1705+
16781706
end # TestMPS
16791707

16801708
TestMPS.runtests()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
NAME
22
ROWS
3-
N c d
3+
N
44
COLUMNS
55
ENDATA

0 commit comments

Comments
 (0)