Skip to content

[FileFormats.MPS] fix reading models with extra ROWS fields #2793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1435,8 +1435,15 @@ end
# ==============================================================================

function parse_rows_line(data::TempMPSModel{T}, items::Vector{String}) where {T}
if length(items) != 2
if length(items) < 2
error("Malformed ROWS line: $(join(items, " "))")
elseif length(items) > 2
# We could throw an error here, but it seems like other solvers just
# happily ignore the extra fields.
#
# See https://github.com/jump-dev/MathOptInterface.jl/issues/2792
#
# Oscar dislikes the poorly standardized nature of MPS.
end
sense, name = Sense(items[1]), items[2]
if haskey(data.name_to_row, name)
Expand Down
28 changes: 28 additions & 0 deletions test/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function test_failing_models()
joinpath(@__DIR__, "failing_models", filename),
)
end
return
end

function test_empty_row_name()
Expand Down Expand Up @@ -1675,6 +1676,33 @@ function test_duplicate_coefficient()
return
end

function test_issue_2792()
src = """
NAME
ROWS
N OBJ \$t3 0
COLUMNS
x OBJ 2
RHS
rhs OBJ -3
BOUNDS
LO bounds x 1
PL bounds x
ENDATA
"""
model = MPS.Model()
read!(IOBuffer(src), model)
dest = MOI.Utilities.Model{Float64}()
MOI.copy_to(dest, model)
@test MOI.get(dest, MOI.ListOfConstraintTypesPresent()) ==
[(MOI.VariableIndex, MOI.GreaterThan{Float64})]
x = only(MOI.get(dest, MOI.ListOfVariableIndices()))
F = MOI.get(dest, MOI.ObjectiveFunctionType())
f = MOI.get(dest, MOI.ObjectiveFunction{F}())
@test isapprox(f, 2.0 * x + 3.0)
return
end

end # TestMPS

TestMPS.runtests()
2 changes: 1 addition & 1 deletion test/FileFormats/MPS/failing_models/rows_malformed.mps
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NAME
ROWS
N c d
N
COLUMNS
ENDATA
Loading