diff --git a/src/FileFormats/MPS/read.jl b/src/FileFormats/MPS/read.jl index a3436184e1..f623c457d5 100644 --- a/src/FileFormats/MPS/read.jl +++ b/src/FileFormats/MPS/read.jl @@ -776,19 +776,24 @@ end # TODO: handle multiple RHS vectors. function parse_rhs_line(data::TempMPSModel{T}, items) where {T} - if length(items) == 3 + if length(items) == 2 + # [row name] [value] + parse_single_rhs(data, items[1], parse(T, items[2]), items) + elseif length(items) == 3 # [rhs name] [row name] [value] - rhs_name, row_name, value = items - parse_single_rhs(data, row_name, parse(T, value), items) + parse_single_rhs(data, items[2], parse(T, items[3]), items) + elseif length(items) == 4 + # [row name 1] [value 1] [row name 2] [value 2] + parse_single_rhs(data, items[1], parse(T, items[2]), items) + parse_single_rhs(data, items[3], parse(T, items[4]), items) elseif length(items) == 5 # [rhs name] [row name 1] [value 1] [row name 2] [value 2] - rhs_name, row_name_1, value_1, row_name_2, value_2 = items - parse_single_rhs(data, row_name_1, parse(T, value_1), items) - parse_single_rhs(data, row_name_2, parse(T, value_2), items) + parse_single_rhs(data, items[2], parse(T, items[3]), items) + parse_single_rhs(data, items[4], parse(T, items[5]), items) else _throw_parse_error( data, - "Malformed RHS line: expected three or five fields.", + "Malformed RHS line: expected 2, 3, 4, or 5 fields.", ) end return diff --git a/test/FileFormats/MPS/failing_models/rhs_malformed.mps b/test/FileFormats/MPS/failing_models/rhs_malformed.mps index b56683624a..1f0f470860 100644 --- a/test/FileFormats/MPS/failing_models/rhs_malformed.mps +++ b/test/FileFormats/MPS/failing_models/rhs_malformed.mps @@ -6,5 +6,5 @@ COLUMNS x c 1 x d 1 RHS - rhs d con 1 + foo ENDATA diff --git a/test/FileFormats/MPS/failing_models/rhs_malformed2.mps b/test/FileFormats/MPS/failing_models/rhs_malformed2.mps deleted file mode 100644 index 0e279c9f56..0000000000 --- a/test/FileFormats/MPS/failing_models/rhs_malformed2.mps +++ /dev/null @@ -1,10 +0,0 @@ -NAME -ROWS - N c - G d -COLUMNS - x c 1 - x d 1 -RHS - rhs con1 1 -ENDATA diff --git a/test/FileFormats/MPS/test_MPS.jl b/test/FileFormats/MPS/test_MPS.jl index 369f1fa0c5..6ed2e9aa84 100644 --- a/test/FileFormats/MPS/test_MPS.jl +++ b/test/FileFormats/MPS/test_MPS.jl @@ -1786,6 +1786,50 @@ function test_parse_header() return end +function test_issue_2941() + src = """ + NAME + ROWS + E c2 + E c3 + E c4a + E c4b + E c5a + E c5b + COLUMNS + x c2 1.0 + x c3 1.0 + x c4a 1.0 + x c4b 1.0 + x c5a 1.0 + x c5b 1.0 + RHS + c2 1.1 + rhs c3 1.2 + c4a 1.3 c4b 1.4 + rhs c5a 1.5 c5b 1.6 + BOUNDS + LO bounds x 1 + ENDATA + """ + model = MPS.Model() + read!(IOBuffer(src), model) + dest = MOI.Utilities.Model{Float64}() + MOI.copy_to(dest, model) + for (c_name, rhs) in [ + "c2" => 1.1, + "c3" => 1.2, + "c4a" => 1.3, + "c4b" => 1.4, + "c5a" => 1.5, + "c5b" => 1.6, + ] + ci = MOI.get(dest, MOI.ConstraintIndex, c_name) + @test MOI.get(dest, MOI.ConstraintSet(), ci).value == rhs + end + return +end + end # TestMPS TestMPS.runtests()