Skip to content

Commit 30087ba

Browse files
authored
Merge pull request #1077 from JuliaOpt/bl/sdpa_ignore
[SDPA] Ignore comments aftere m and nblocks and detect dat-s extension
2 parents 8a65679 + 1b509e3 commit 30087ba

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/FileFormats/FileFormats.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function Model(
7777
(".lp", LP.Model),
7878
(".mof.json", MOF.Model),
7979
(".mps", MPS.Model),
80+
(".dat-s", SDPA.Model),
8081
(".sdpa", SDPA.Model)
8182
]
8283
if endswith(filename, ext) || occursin("$(ext).", filename)

src/FileFormats/SDPA/SDPA.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,16 @@ function Base.read!(io::IO, model::Model{T}) where T
256256
continue
257257
end
258258
num_variables_read = true
259-
MOI.add_variables(model, parse(Int, line))
259+
# According to http://plato.asu.edu/ftp/sdpa_format.txt,
260+
# additional text after the number of variables should be ignored.
261+
MOI.add_variables(model, parse(Int, split(line)[1]))
260262
elseif num_blocks === nothing
261263
if isempty(line)
262264
continue
263265
end
264-
num_blocks = parse(Int, line)
266+
# According to http://plato.asu.edu/ftp/sdpa_format.txt,
267+
# additional text after the number of blocks should be ignored.
268+
num_blocks = parse(Int, split(line)[1])
265269
elseif block_sets === nothing
266270
if isempty(line) && !iszero(num_blocks)
267271
continue

test/FileFormats/SDPA/SDPA.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function test_write_then_read(model_string::String)
4949
end
5050

5151
function test_read(filename::String, model_string::String)
52-
model1 = SDPA.Model()
52+
model1 = MOI.FileFormats.Model(filename = filename)
5353
MOIU.loadfromstring!(model1, model_string)
5454
(variable_names, constraint_names) = set_var_and_con_names(model1)
5555

@@ -108,7 +108,7 @@ end
108108
MOI.add_variable(model)
109109
err = ErrorException("Cannot read in file because model is not empty.")
110110
@test_throws err MOI.read_from_file(model,
111-
joinpath(SDPA_MODELS_DIR, "example_A.sdpa"))
111+
joinpath(SDPA_MODELS_DIR, "example_A.dat-s"))
112112
end
113113

114114
@testset "Bad number of blocks" begin
@@ -190,7 +190,7 @@ write_read_models = [
190190
end
191191

192192
example_models = [
193-
("example_A.sdpa", """
193+
("example_A.dat-s", """
194194
variables: x, y
195195
minobjective: 10x + 20y
196196
c1: [x + -1, 0, x + -2] in PositiveSemidefiniteConeTriangle(2)

test/FileFormats/SDPA/models/example_A.sdpa renamed to test/FileFormats/SDPA/models/example_A.dat-s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"Example from http://plato.asu.edu/ftp/sdpa_format.txt
22
"A sample problem.
3-
2
4-
2
3+
2 =mdim
4+
2 =nblocks
55
2 2
66
10.0 20.0
77
0 1 1 1 1.0

0 commit comments

Comments
 (0)