From 9cc15f4e942b72f4b78315f8c1a1e3a483b1d0b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 18 Apr 2020 10:41:39 +0200 Subject: [PATCH 1/2] Ignore comments aftere m and nblocks --- src/FileFormats/SDPA/SDPA.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FileFormats/SDPA/SDPA.jl b/src/FileFormats/SDPA/SDPA.jl index 01e46a74c3..9b9fe9278e 100644 --- a/src/FileFormats/SDPA/SDPA.jl +++ b/src/FileFormats/SDPA/SDPA.jl @@ -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 From 1b509e33e9fb8f9793d291df07b3441f6fc19b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Sat, 18 Apr 2020 13:35:25 +0200 Subject: [PATCH 2/2] Detect dat-s extension as SDPA --- src/FileFormats/FileFormats.jl | 1 + test/FileFormats/SDPA/SDPA.jl | 6 +++--- .../SDPA/models/{example_A.sdpa => example_A.dat-s} | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) rename test/FileFormats/SDPA/models/{example_A.sdpa => example_A.dat-s} (91%) diff --git a/src/FileFormats/FileFormats.jl b/src/FileFormats/FileFormats.jl index 6c1c748198..ae65675bcc 100644 --- a/src/FileFormats/FileFormats.jl +++ b/src/FileFormats/FileFormats.jl @@ -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) diff --git a/test/FileFormats/SDPA/SDPA.jl b/test/FileFormats/SDPA/SDPA.jl index f3cfb4cae2..59266b8e9e 100644 --- a/test/FileFormats/SDPA/SDPA.jl +++ b/test/FileFormats/SDPA/SDPA.jl @@ -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) @@ -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 @@ -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) diff --git a/test/FileFormats/SDPA/models/example_A.sdpa b/test/FileFormats/SDPA/models/example_A.dat-s similarity index 91% rename from test/FileFormats/SDPA/models/example_A.sdpa rename to test/FileFormats/SDPA/models/example_A.dat-s index d760558969..0c0dbd40c2 100644 --- a/test/FileFormats/SDPA/models/example_A.sdpa +++ b/test/FileFormats/SDPA/models/example_A.dat-s @@ -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