Skip to content

[FileFormats] fix writing unsupported variable types #2654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2025
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
8 changes: 8 additions & 0 deletions src/FileFormats/LP/LP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
(MOI.VectorAffineFunction,)
)

function MOI.supports_constraint(

Check warning on line 49 in src/FileFormats/LP/LP.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/LP/LP.jl#L49

Added line #L49 was not covered by tests
::Model,
::Type{MOI.VariableIndex},
::Type{<:Union{MOI.Parameter,MOI.Semicontinuous,MOI.Semiinteger}},
)
return false
end

function MOI.supports_constraint(
::Model{T},
::Type{MOI.VectorAffineFunction{T}},
Expand Down
8 changes: 8 additions & 0 deletions src/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
return false
end

function MOI.supports_constraint(

Check warning on line 77 in src/FileFormats/MPS/MPS.jl

View check run for this annotation

Codecov / codecov/patch

src/FileFormats/MPS/MPS.jl#L77

Added line #L77 was not covered by tests
::Model,
::Type{MOI.VariableIndex},
::Type{<:Union{MOI.Parameter,MOI.Semicontinuous,MOI.Semiinteger}},
)
return false
end

function MOI.supports_constraint(
::Model{T},
::Type{MOI.VectorOfVariables},
Expand Down
17 changes: 17 additions & 0 deletions test/FileFormats/CBF/CBF.jl
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,23 @@ function test_supports_quadratic_objective()
return
end

function test_unsupported_variable_types()
model = CBF.Model()
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Parameter(2.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semicontinuous(2.0, 3.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semiinteger(2.0, 3.0)),
)
return
end

end # module

TestCBF.runtests()
17 changes: 17 additions & 0 deletions test/FileFormats/LP/LP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,23 @@ function test_unable_to_parse_bound()
return
end

function test_unsupported_variable_types()
model = LP.Model()
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Parameter(2.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semicontinuous(2.0, 3.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semiinteger(2.0, 3.0)),
)
return
end

end # module

TestLP.runtests()
17 changes: 17 additions & 0 deletions test/FileFormats/MPS/MPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,23 @@ function test_malformed_indicator()
return
end

function test_unsupported_variable_types()
model = MPS.Model()
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Parameter(2.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semicontinuous(2.0, 3.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semiinteger(2.0, 3.0)),
)
return
end

end # TestMPS

TestMPS.runtests()
33 changes: 24 additions & 9 deletions test/FileFormats/NL/NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@

module TestNLModel

using Test

import MathOptInterface as MOI
const NL = MOI.FileFormats.NL
import MathOptInterface.FileFormats: NL

using Test
function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
return
end

function _test_nlexpr(
expr::NL._NLExpr,
Expand Down Expand Up @@ -1352,14 +1363,18 @@ function test_copy_name_issue_2445()
return
end

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
function test_unsupported_variable_types()
for set in (
MOI.Parameter(2.0),
MOI.Semicontinuous(2.0, 3.0),
MOI.Semiinteger(2.0, 3.0),
)
src = MOI.Utilities.Model{Float64}()
MOI.add_constrained_variable(src, set)
dest = NL.Model()
@test_throws MOI.UnsupportedConstraint MOI.copy_to(dest, src)
end
return
end

end
Expand Down
17 changes: 17 additions & 0 deletions test/FileFormats/SDPA/SDPA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,23 @@ function test_integer_before_variables()
return
end

function test_unsupported_variable_types()
model = SDPA.Model()
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Parameter(2.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semicontinuous(2.0, 3.0)),
)
@test_throws(
MOI.UnsupportedConstraint,
MOI.add_constrained_variable(model, MOI.Semiinteger(2.0, 3.0)),
)
return
end

end # module

TestSDPA.runtests()
Loading