Skip to content
Merged

Dual #16

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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ will run the solver with default options.

## Use with JuMP

> [!WARNING]
> The values of `dual` and `objective_dual` of QPALM currently do not
> seem to be consistent with JuMP's convention. Help is welcome to figure out the issue.
> [!INFO]
> For the dual values to be computed and be available with `JuMP.dual` and `JuMP.objective_dual`,
> you need set the attribute `enable_dual_termination` before calling `JuMP.optimize!` as shown below.

To use QPALM with JuMP, use `QPALM.Optimizer`:

```julia
using JuMP, QPALM
model = Model(QPALM.Optimizer)
# If duals are needed
set_attribute(model, "enable_dual_termination", true)
```
11 changes: 10 additions & 1 deletion src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
m::Int
n::Int
result::Union{Nothing,Results}
has_dual::Bool
objective_constant::Float64
max_sense::Bool
silent::Bool
Expand All @@ -59,6 +60,7 @@ mutable struct Optimizer <: MOI.AbstractOptimizer
0,
0,
nothing,
false,
0,
false,
false,
Expand Down Expand Up @@ -207,6 +209,7 @@ function MOI.copy_to(dest::Optimizer, src::OptimizerCache)
bmax=row_bounds.upper,
options...,
)
dest.has_dual = false
dest.m, dest.n = size(A)
dest.start_x = nothing
dest.start_y = nothing
Expand Down Expand Up @@ -321,6 +324,9 @@ end

function MOI.get(optimizer::Optimizer, attr::MOI.DualObjectiveValue)
MOI.check_result_index_bounds(optimizer, attr)
if !optimizer.has_dual
return NaN
end
return _flip_sense(optimizer, optimizer.result.info.dual_objective) + optimizer.objective_constant
end

Expand Down Expand Up @@ -363,7 +369,7 @@ const _DUAL_STATUS_MAP = Dict{Int,MOI.ResultStatusCode}(
)

function MOI.get(optimizer::Optimizer, attr::MOI.DualStatus)
if attr.result_index > MOI.get(optimizer, MOI.ResultCount())
if !optimizer.has_dual || attr.result_index > MOI.get(optimizer, MOI.ResultCount())
return MOI.NO_SOLUTION
end
return _DUAL_STATUS_MAP[optimizer.result.info.status_val]
Expand All @@ -375,6 +381,9 @@ function MOI.get(
ci::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},S},
) where {S}
MOI.check_result_index_bounds(optimizer, attr)
if !optimizer.has_dual
return NaN
end
return _flip_sense(optimizer, optimizer.result.y[ci.value])
end

Expand Down
2 changes: 2 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function test_runtests()
@test model.optimizer.model.model_cache isa
MOI.Utilities.UniversalFallback{QPALM.OptimizerCache}
MOI.set(model, MOI.Silent(), true)
# FIXME Throws LADEL ERROR: MATRIX (POSSIBLY) NOT FULL RANK (diagonal element of 0.000000e+00)
#MOI.set(model, MOI.RawOptimizerAttribute("enable_dual_termination"), true)
config = MOI.Test.Config(;
atol = 1e-3,
rtol = 1e-3,
Expand Down
Loading