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

**URL:** https://discourse.julialang.org/t/sos-constraints-in-lp-file-throwing-malformed-sos-constraint-error/106324
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [November 16, 2023, 4:21pm UTC](https://discourse.julialang.org/t/sos-constraints-in-lp-file-throwing-malformed-sos-constraint-error/106324 "2023-11-16T16:21:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)
#### Post date: [November 16, 2023, 4:21pm UTC](https://discourse.julialang.org/t/sos-constraints-in-lp-file-throwing-malformed-sos-constraint-error/106324/1 "2023-11-16T16:21:37Z")

</div>

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:

```julia
 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)

```julia
function _parse_section(
    ::typeof(_KW_SOS),
    model::Model,
    cache::_ReadCache,
    line::AbstractString,
)
    # 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)")
    end

```

---

<div class="post-metadata">

### Author: ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)
#### Post date: [November 16, 2023, 4:26pm UTC](https://discourse.julialang.org/t/sos-constraints-in-lp-file-throwing-malformed-sos-constraint-error/106324/2 "2023-11-16T16:26:35Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [November 16, 2023, 6:58pm UTC](https://discourse.julialang.org/t/sos-constraints-in-lp-file-throwing-malformed-sos-constraint-error/106324/3 "2023-11-16T18:58:47Z")

</div>

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`).

---

<div class="post-metadata">

### Author: ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)
#### Post date: [November 16, 2023, 7:13pm UTC](https://discourse.julialang.org/t/sos-constraints-in-lp-file-throwing-malformed-sos-constraint-error/106324/4 "2023-11-16T19:13:29Z")

</div>

It works well for the most part. Thanks!
