Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in solution_summary: duals can be things other than scalars #3846

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading