Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/FileFormats/LP/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1109,17 +1109,26 @@ function _parse_constraint_indicator(
)
end

function _is_empty_constraint(state::_LexerState)
return _next_token_is(state, _TOKEN_GREATER_THAN) ||
_next_token_is(state, _TOKEN_LESS_THAN) ||
_next_token_is(state, _TOKEN_EQUAL_TO)
end

# <constraint> :==
# <name> <expression> <set-suffix>
# <name> [<expression>] <set-suffix>
# | <name> <constraint-sos>
# | <name> <constraint-indicator>
function _parse_constraint(state::_LexerState, cache::_ReadCache)
function _parse_constraint(state::_LexerState, cache::_ReadCache{T}) where {T}
name = _parse_name(state, cache)
# Check if this is an SOS constraint
c = if _is_sos_constraint(state)
_parse_constraint_sos(state, cache)
elseif _is_indicator_constraint(state)
_parse_constraint_indicator(state, cache)
elseif _is_empty_constraint(state)
set = _parse_set_suffix(state, cache)::MOI.AbstractScalarSet
MOI.add_constraint(cache.model, zero(MOI.ScalarAffineFunction{T}), set)
else
f = _parse_expression(state, cache)
# The type annotation is needed for JET.
Expand Down
18 changes: 18 additions & 0 deletions test/FileFormats/LP/test_LP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,24 @@ function test_empty_function()
return
end

function test_read_empty_constraint()
model = MOI.FileFormats.LP.Model{Float64}()
read!(IOBuffer("min\nst\n>= 0\nend"), model)
target = MOI.FileFormats.LP.Model{Float64}()
f = zero(MOI.ScalarAffineFunction{Float64})
MOI.add_constraint(target, f, MOI.GreaterThan(0.0))
@test sprint(print, model) == sprint(print, target)
# With name
model = MOI.FileFormats.LP.Model{Float64}()
read!(IOBuffer("min\nst\nc: == 2\nend"), model)
target = MOI.FileFormats.LP.Model{Float64}()
f = zero(MOI.ScalarAffineFunction{Float64})
c = MOI.add_constraint(target, f, MOI.EqualTo(2.0))
MOI.set(target, MOI.ConstraintName(), c, "c")
@test sprint(print, model) == sprint(print, target)
return
end

end # module

TestLP.runtests()
Loading