Skip to content

Commit 300bad6

Browse files
authored
[FileFormats.MPS] allow AbstractString when parsing MPS files (#2892)
1 parent 1effd93 commit 300bad6

File tree

1 file changed

+17
-27
lines changed

1 file changed

+17
-27
lines changed

src/FileFormats/MPS/read.jl

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
@enum(Sense, SENSE_N, SENSE_G, SENSE_L, SENSE_E, SENSE_UNKNOWN)
3636

37-
function Sense(s::String)
37+
function Sense(s)
3838
if s == "G"
3939
return SENSE_G
4040
elseif s == "L"
@@ -158,7 +158,7 @@ end
158158

159159
# `Headers` gets called _alot_ (on every line), so we try very hard to be
160160
# efficient.
161-
function Headers(s::AbstractString)
161+
function Headers(s)
162162
N = length(s)
163163
x = first(s)
164164
if N == 3
@@ -217,8 +217,7 @@ function line_to_items(line)
217217
# whitespace is disallowed in names. If this ever becomes a problem, we
218218
# could change to the fixed MPS format, where the files are split at the
219219
# usual offsets.
220-
items = split(line, r"\s"; keepempty = false)
221-
return String.(items)
220+
return split(line, r"\s"; keepempty = false)
222221
end
223222

224223
"""
@@ -490,23 +489,23 @@ end
490489
# NAME
491490
# ==============================================================================
492491

493-
function parse_name_line(data::TempMPSModel, line::String)
492+
function parse_name_line(data::TempMPSModel, line)
494493
m = match(r"^\s*NAME(.*)"i, line)
495494
if m === nothing
496495
_throw_parse_error(
497496
data,
498497
"This line must be of the form `NAME <problem name>`.",
499498
)
500499
end
501-
data.name = strip(m[1]::AbstractString)
500+
data.name = strip(m[1])
502501
return
503502
end
504503

505504
# ==============================================================================
506505
# ROWS
507506
# ==============================================================================
508507

509-
function parse_rows_line(data::TempMPSModel{T}, items::Vector{String}) where {T}
508+
function parse_rows_line(data::TempMPSModel{T}, items::Vector) where {T}
510509
if length(items) < 2
511510
_throw_parse_error(
512511
data,
@@ -575,7 +574,7 @@ end
575574
# COLUMNS
576575
# ==============================================================================
577576

578-
function parse_single_coefficient(data, row_name::String, column::Int, value)
577+
function parse_single_coefficient(data, row_name, column::Int, value)
579578
if row_name == data.obj_name
580579
data.c[column] += value
581580
return
@@ -619,10 +618,7 @@ function _set_intorg(data::TempMPSModel{T}, column, column_name) where {T}
619618
return
620619
end
621620

622-
function parse_columns_line(
623-
data::TempMPSModel{T},
624-
items::Vector{String},
625-
) where {T}
621+
function parse_columns_line(data::TempMPSModel{T}, items::Vector) where {T}
626622
if length(items) == 3
627623
# [column name] [row name] [value]
628624
column_name, row_name, value = items
@@ -660,7 +656,7 @@ end
660656
# RHS
661657
# ==============================================================================
662658

663-
function parse_single_rhs(data, row_name::String, value, items::Vector{String})
659+
function parse_single_rhs(data, row_name, value, items::Vector)
664660
if row_name == data.obj_name
665661
data.obj_constant = value
666662
return
@@ -691,7 +687,7 @@ function parse_single_rhs(data, row_name::String, value, items::Vector{String})
691687
end
692688

693689
# TODO: handle multiple RHS vectors.
694-
function parse_rhs_line(data::TempMPSModel{T}, items::Vector{String}) where {T}
690+
function parse_rhs_line(data::TempMPSModel{T}, items::Vector) where {T}
695691
if length(items) == 3
696692
# [rhs name] [row name] [value]
697693
rhs_name, row_name, value = items
@@ -724,7 +720,7 @@ end
724720
# E | - | rhs + range | rhs
725721
# ==============================================================================
726722

727-
function parse_single_range(data, row_name::String, value)
723+
function parse_single_range(data, row_name, value)
728724
row = get(data.name_to_row, row_name, nothing)
729725
if row === nothing
730726
_throw_parse_error(
@@ -747,10 +743,7 @@ function parse_single_range(data, row_name::String, value)
747743
end
748744

749745
# TODO: handle multiple RANGES vectors.
750-
function parse_ranges_line(
751-
data::TempMPSModel{T},
752-
items::Vector{String},
753-
) where {T}
746+
function parse_ranges_line(data::TempMPSModel{T}, items::Vector) where {T}
754747
if length(items) == 3
755748
# [rhs name] [row name] [value]
756749
_, row_name, value = items
@@ -775,8 +768,8 @@ end
775768

776769
function _parse_single_bound(
777770
data::TempMPSModel{T},
778-
column_name::String,
779-
bound_type::String,
771+
column_name,
772+
bound_type,
780773
) where {T}
781774
col = get(data.name_to_col, column_name, nothing)
782775
if col === nothing
@@ -813,8 +806,8 @@ end
813806

814807
function _parse_single_bound(
815808
data::TempMPSModel{T},
816-
column_name::String,
817-
bound_type::String,
809+
column_name,
810+
bound_type,
818811
value::T,
819812
) where {T}
820813
col = get(data.name_to_col, column_name, nothing)
@@ -865,10 +858,7 @@ function _parse_single_bound(
865858
end
866859
end
867860

868-
function parse_bounds_line(
869-
data::TempMPSModel{T},
870-
items::Vector{String},
871-
) where {T}
861+
function parse_bounds_line(data::TempMPSModel{T}, items::Vector) where {T}
872862
if length(items) == 3
873863
bound_type, _, column_name = items
874864
_parse_single_bound(data, column_name, bound_type)

0 commit comments

Comments
 (0)