Skip to content

Commit

Permalink
Add coefficient_type kwarg to dual_optimizer (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermebodin authored Dec 21, 2024
1 parent 208b284 commit 7d0816c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@

export DualOptimizer, dual_optimizer

function dual_optimizer(optimizer_constructor)
return () -> DualOptimizer(MOI.instantiate(optimizer_constructor))
function dual_optimizer(
optimizer_constructor;
coefficient_type::Type{T} = Float64,
) where {T<:Number}
return () -> DualOptimizer{T}(MOI.instantiate(optimizer_constructor))
end

struct DualOptimizer{T,OT<:MOI.ModelLike} <: MOI.AbstractOptimizer
Expand Down
4 changes: 3 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
CSDP = "0a46da34-8e4b-519e-b418-48813639ff34"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
Hypatia = "b99e6be6-89ff-11e8-14f8-45c827f4f8f2"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Expand All @@ -9,4 +10,5 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[compat]
CSDP = "1.0.0"
HiGHS = "1.1.0"
SCS = "1.0.1"
Hypatia = "0.8.1"
SCS = "1.0.1"
24 changes: 24 additions & 0 deletions test/Solvers/hypatia_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2017: Guilherme Bodin, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

import Hypatia

@testset "Solve problems with different coefficient_type" begin
function mineig(::Type{T}) where {T}
model = GenericModel{T}(
Dualization.dual_optimizer(
Hypatia.Optimizer{T};
coefficient_type = T,
),
)
JuMP.set_silent(model)
@variable(model, x[1:3, 1:3] in PSDCone())
@constraint(model, sum(x[i, i] for i in 1:3) == 1)
@objective(model, Min, sum(x[i, i] for i in 1:3))
optimize!(model)
return objective_value(model)
end
@test mineig(Float64) mineig(Float32)
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ primal_power_cone_optimizer = []
include("Solvers/highs_test.jl")
include("Solvers/csdp_test.jl")
include("Solvers/scs_test.jl")
include("Solvers/hypatia_test.jl")

include("Tests/test_JuMP_dualize.jl")
include("Tests/test_MOI_wrapper.jl")
Expand Down

0 comments on commit 7d0816c

Please sign in to comment.