Skip to content

Commit fc6e918

Browse files
authored
[FileFormats.LP] fix reading file with variable-coefficient-variable (#2076)
1 parent 299163f commit fc6e918

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/FileFormats/LP/LP.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,8 @@ function _get_term(token_types, token_values, offset)
542542
@assert token_types[offset] == _TOKEN_VARIABLE
543543
x = MOI.VariableIndex(Int64(token_values[offset]))
544544
offset += 1
545-
if offset > length(token_types) || token_types[offset] == _TOKEN_SIGN
545+
if offset > length(token_types) ||
546+
token_types[offset] in (_TOKEN_SIGN, _TOKEN_COEFFICIENT)
546547
return MOI.ScalarAffineTerm(coef, x), offset
547548
end
548549
term = if token_types[offset] == _TOKEN_QUADRATIC_DIAG

test/FileFormats/LP/LP.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,21 @@ function test_wrong_way_bounds()
738738
return
739739
end
740740

741+
function test_variable_coefficient_variable()
742+
io = IOBuffer()
743+
write(io, "Minimize\nobj: x -1 y\nEnd")
744+
seekstart(io)
745+
model = MOI.FileFormats.LP.Model()
746+
read!(io, model)
747+
out = IOBuffer()
748+
write(out, model)
749+
seekstart(out)
750+
file = read(out, String)
751+
@test file ==
752+
"minimize\nobj: 1 x - 1 y\nsubject to\nBounds\nx >= 0\ny >= 0\nEnd\n"
753+
return
754+
end
755+
741756
function runtests()
742757
for name in names(@__MODULE__, all = true)
743758
if startswith("$(name)", "test_")

0 commit comments

Comments
 (0)