Skip to content

Commit

Permalink
Fix bug in solution_summary: duals can be things other than scalars (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 9, 2024
1 parent c00952d commit 5b4bb8d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/solution_summary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
41 changes: 41 additions & 0 deletions test/test_solution_summary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5b4bb8d

Please sign in to comment.