SOS constraints in LP file throwing `Malformed SOS constraint` error

I have a large .lp file exported from CPLEX that I want to read into JuMP with read_from_file. However, the SOS constraints are defined in 2 lines each:

 s3:   S1 ::  x : 1
        y : 2

As a result, the parsing doesn’t get the second line and says the constraint is malformed. I can manually edit the file to get things on the same line, but perhaps the parsing can be more robust…

Here is where the error gets thrown: (LP.jl)

function _parse_section(
    # SOS constraints can have all manner of whitespace issues with them.
    # Normalize them here before attempting to do anything else.
    line = replace(line, r"\s+:\s+" => ":")
    line = replace(line, r"\s+::" => "::")
    tokens = _tokenize(line)
    if length(tokens) < 3
        error("Malformed SOS constraint: $(line)")

On related note, when the same file gets exported to .mps from CPLEX, read_from_file also errors, but for another reason: some variable names have spaces, which results in ERROR: Malformed COLUMNS line: x!abc def c621198 -1 (variable x!abc def has a space). Yes, I know it is bad practice to have a space in a variable name (model is not mine).

Urgh. I really just need to write a proper parser for LP files. The current version is a bit of a hack. SOS constraints are non-standard between some implementations, and it doesn’t support spaces in names, (because what sort of name is x!abc def c621198).

1 Like

It works well for the most part. Thanks!