@@ -19,7 +19,14 @@ struct SolFileResults <: MOI.ModelLike
19
19
end
20
20
21
21
"""
22
- SolFileResults(filename::String, model::Model)
22
+ SolFileResults(
23
+ filename::String,
24
+ model::Model;
25
+ suffix_lower_bound_duals::Vector{String} =
26
+ ["ipopt_zL_out", "lower_bound_duals"],
27
+ suffix_uuper_bound_duals::Vector{String} =
28
+ ["ipopt_zU_out", "upper_bound_duals"],
29
+ )
23
30
24
31
Parse the `.sol` file `filename` created by solving `model` and return a
25
32
`SolFileResults` struct.
@@ -28,8 +35,8 @@ The returned struct supports the `MOI.get` API for querying result attributes
28
35
such as [`MOI.TerminationStatus`](@ref), [`MOI.VariablePrimal`](@ref), and
29
36
[`MOI.ConstraintDual`](@ref).
30
37
"""
31
- function SolFileResults (filename:: String , model:: Model )
32
- return open (io -> SolFileResults (io, model), filename, " r" )
38
+ function SolFileResults (filename:: String , model:: Model ; kwargs ... )
39
+ return open (io -> SolFileResults (io, model; kwargs ... ), filename, " r" )
33
40
end
34
41
35
42
"""
@@ -46,7 +53,8 @@ All other attributes are un-set.
46
53
"""
47
54
function SolFileResults (
48
55
raw_status:: String ,
49
- termination_status:: MOI.TerminationStatusCode ,
56
+ termination_status:: MOI.TerminationStatusCode ;
57
+ kwargs... ,
50
58
)
51
59
return SolFileResults (
52
60
nothing ,
261
269
262
270
_readline (io:: IO , T) = parse (T, _readline (io))
263
271
264
- function SolFileResults (io:: IO , model:: Model )
272
+ function SolFileResults (
273
+ io:: IO ,
274
+ model:: Model ;
275
+ suffix_lower_bound_duals:: Vector{String} = [
276
+ " ipopt_zL_out" ,
277
+ " lower_bound_duals" ,
278
+ ],
279
+ suffix_upper_bound_duals:: Vector{String} = [
280
+ " ipopt_zU_out" ,
281
+ " upper_bound_duals" ,
282
+ ],
283
+ )
265
284
# This function is based on a Julia translation of readsol.c, available at
266
285
# https://github.com/ampl/asl/blob/64919f75fa7a438f4b41bce892dcbe2ae38343ee/src/solvers/readsol.c
267
286
# and under the following license:
@@ -345,21 +364,17 @@ function SolFileResults(io::IO, model::Model)
345
364
items = split (line, " " )
346
365
n_suffix = parse (Int, items[3 ])
347
366
suffix = _readline (io)
348
- if ! (suffix == " ipopt_zU_out" || suffix == " ipopt_zL_out" )
349
- for _ in 1 : n_suffix
350
- _ = readline (io)
351
- end
352
- continue
353
- end
354
367
for i in 1 : n_suffix
355
- items = split (_readline (io), " " )
356
- x = model. order[parse (Int, items[1 ])+ 1 ]
357
- dual = parse (Float64, items[2 ])
358
- if suffix == " ipopt_zU_out"
359
- zU_out[x] = dual
368
+ if suffix in suffix_upper_bound_duals
369
+ items = split (_readline (io), " " )
370
+ x = model. order[parse (Int, items[1 ])+ 1 ]
371
+ zU_out[x] = parse (Float64, items[2 ])
372
+ elseif suffix in suffix_lower_bound_duals
373
+ items = split (_readline (io), " " )
374
+ x = model. order[parse (Int, items[1 ])+ 1 ]
375
+ zL_out[x] = parse (Float64, items[2 ])
360
376
else
361
- @assert suffix == " ipopt_zL_out"
362
- zL_out[x] = dual
377
+ _ = _readline (io)
363
378
end
364
379
end
365
380
end
0 commit comments