Skip to content

[SDPA] Ignore comments aftere m and nblocks and detect dat-s extension #1077

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 2 commits into from
Apr 19, 2020
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
1 change: 1 addition & 0 deletions src/FileFormats/FileFormats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ function Model(
(".lp", LP.Model),
(".mof.json", MOF.Model),
(".mps", MPS.Model),
(".dat-s", SDPA.Model),
(".sdpa", SDPA.Model)
]
if endswith(filename, ext) || occursin("$(ext).", filename)
Expand Down
8 changes: 6 additions & 2 deletions src/FileFormats/SDPA/SDPA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,16 @@ function Base.read!(io::IO, model::Model{T}) where T
continue
end
num_variables_read = true
MOI.add_variables(model, parse(Int, line))
# According to http://plato.asu.edu/ftp/sdpa_format.txt,
# additional text after the number of variables should be ignored.
MOI.add_variables(model, parse(Int, split(line)[1]))
elseif num_blocks === nothing
if isempty(line)
continue
end
num_blocks = parse(Int, line)
# According to http://plato.asu.edu/ftp/sdpa_format.txt,
# additional text after the number of blocks should be ignored.
num_blocks = parse(Int, split(line)[1])
elseif block_sets === nothing
if isempty(line) && !iszero(num_blocks)
continue
Expand Down
6 changes: 3 additions & 3 deletions test/FileFormats/SDPA/SDPA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function test_write_then_read(model_string::String)
end

function test_read(filename::String, model_string::String)
model1 = SDPA.Model()
model1 = MOI.FileFormats.Model(filename = filename)
MOIU.loadfromstring!(model1, model_string)
(variable_names, constraint_names) = set_var_and_con_names(model1)

Expand Down Expand Up @@ -108,7 +108,7 @@ end
MOI.add_variable(model)
err = ErrorException("Cannot read in file because model is not empty.")
@test_throws err MOI.read_from_file(model,
joinpath(SDPA_MODELS_DIR, "example_A.sdpa"))
joinpath(SDPA_MODELS_DIR, "example_A.dat-s"))
end

@testset "Bad number of blocks" begin
Expand Down Expand Up @@ -190,7 +190,7 @@ write_read_models = [
end

example_models = [
("example_A.sdpa", """
("example_A.dat-s", """
variables: x, y
minobjective: 10x + 20y
c1: [x + -1, 0, x + -2] in PositiveSemidefiniteConeTriangle(2)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"Example from http://plato.asu.edu/ftp/sdpa_format.txt
"A sample problem.
2
2
2 =mdim
2 =nblocks
2 2
10.0 20.0
0 1 1 1 1.0
Expand Down