diff --git a/src/FileFormats/LP/read.jl b/src/FileFormats/LP/read.jl index 41fbd70ff1..d8ec61a507 100644 --- a/src/FileFormats/LP/read.jl +++ b/src/FileFormats/LP/read.jl @@ -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 + # :== -# +# [] # | # | -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. diff --git a/test/FileFormats/LP/test_LP.jl b/test/FileFormats/LP/test_LP.jl index a2c58dddbf..67ac4c4985 100644 --- a/test/FileFormats/LP/test_LP.jl +++ b/test/FileFormats/LP/test_LP.jl @@ -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()