From eddbe2ce8ffde3604aed672660991c96edf8597c Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 9 Oct 2024 15:45:10 +1300 Subject: [PATCH 1/2] Fix bug in solution_summary: duals can be things other than scalars --- src/solution_summary.jl | 4 ++-- test/test_solution_summary.jl | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/solution_summary.jl b/src/solution_summary.jl index 6999f1b84bf..97a43b18ca9 100644 --- a/src/solution_summary.jl +++ b/src/solution_summary.jl @@ -21,7 +21,7 @@ struct _SolutionSummary{T} relative_gap::Union{Missing,T} dual_objective_value::Union{Missing,T} primal_solution::Union{Missing,Dict{String,T}} - dual_solution::Union{Missing,Dict{String,T}} + dual_solution::Union{Missing,Dict{String,Any}} # Work counters solve_time::Union{Missing,Float64} barrier_iterations::Union{Missing,Int} @@ -232,7 +232,7 @@ function _get_solution_dict(model, result) end function _get_constraint_dict(model, result) - dict = Dict{String,value_type(typeof(model))}() + dict = Dict{String,Any}() for (F, S) in list_of_constraint_types(model) for constraint in all_constraints(model, F, S) constraint_name = name(constraint) diff --git a/test/test_solution_summary.jl b/test/test_solution_summary.jl index 95aa3414110..42642e0ddfb 100644 --- a/test/test_solution_summary.jl +++ b/test/test_solution_summary.jl @@ -164,4 +164,45 @@ function test_solution_summary() return end +function test_solution_summary_vector_dual() + model = Model() do + return MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) + end + @variable(model, x[1:2]) + @constraint(model, c, x >= 0) + optimize!(model) + mock = unsafe_backend(model) + MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL) + MOI.set(mock, MOI.RawStatusString(), "solver specific string") + MOI.set(mock, MOI.ResultCount(), 1) + MOI.set(mock, MOI.PrimalStatus(), MOI.FEASIBLE_POINT) + MOI.set(mock, MOI.DualStatus(), MOI.FEASIBLE_POINT) + MOI.set(mock, MOI.VariablePrimal(), optimizer_index.(x), [1.0, 2.0]) + MOI.set(mock, MOI.ConstraintDual(), optimizer_index.(c), [3.0, 4.0]) + ret = """ + * Solver : Mock + + * Status + Result count : 1 + Termination status : OPTIMAL + Message from the solver: + "solver specific string" + + * Candidate solution (result #1) + Primal status : FEASIBLE_POINT + Dual status : FEASIBLE_POINT + Objective value : 0.00000e+00 + Dual objective value : 0.00000e+00 + Primal solution : + x[1] : 1.00000e+00 + x[2] : 2.00000e+00 + Dual solution : + c : [3.00000e+00,4.00000e+00] + + * Work counters + """ + @test sprint(show, solution_summary(model; verbose = true)) == ret + return end + +end # module From 7a057e0a8c4911616bc7571cf50c921357e6b16a Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 9 Oct 2024 15:48:51 +1300 Subject: [PATCH 2/2] Fix formatting --- test/test_solution_summary.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_solution_summary.jl b/test/test_solution_summary.jl index 42642e0ddfb..17f770d0aec 100644 --- a/test/test_solution_summary.jl +++ b/test/test_solution_summary.jl @@ -166,7 +166,7 @@ end function test_solution_summary_vector_dual() model = Model() do - return MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) + return MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}()) end @variable(model, x[1:2]) @constraint(model, c, x >= 0)