diff --git a/cpp/src/io/mps_parser.cpp b/cpp/src/io/mps_parser.cpp index 7d3a52ee48..acdef68e63 100644 --- a/cpp/src/io/mps_parser.cpp +++ b/cpp/src/io/mps_parser.cpp @@ -222,6 +222,24 @@ ObjSenseType convert_to_obj_sense(const std::string& str) } } +RowType convert_to_row_type(char c) +{ + switch (c) { + case 'N': return Objective; + case 'L': return LesserThanOrEqual; + case 'G': return GreaterThanOrEqual; + case 'E': return Equality; + default: + mps_parser_expects( + false, + error_type_t::ValidationError, + "Invalid row type '%c' (0x%02x) found in ROWS section; expected N, L, G, or E", + (c >= 0x20 && c < 0x7f) ? c : '?', + static_cast(c)); + return Objective; // unreachable; mps_parser_expects throws + } +} + template void mps_parser_t::fill_problem(mps_data_model_t& problem) { @@ -785,13 +803,13 @@ void mps_parser_t::parse_rows(std::string_view line) std::string name; if (fixed_mps_format) { - type = static_cast(line[1]); + type = convert_to_row_type(line[1]); name = trim(line.substr(4, 8)); // max of 8 chars allowed } else { std::stringstream ss{std::string(line)}; char read_word; ss >> read_word; - type = static_cast(read_word); + type = convert_to_row_type(read_word); ss >> name; }