Skip to content
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SemidefiniteModels = "169818f4-1a3d-53bf-95b3-11177825b1e3"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
MathOptInterface = "0.9.1"
MathOptInterface = "0.9.5"
MathProgBase = "~0.7.0"
SemidefiniteModels = "~0.1.1"
julia = "1"
Expand Down
33 changes: 23 additions & 10 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,10 @@ function MOI.get(m::Optimizer, ::MOI.TerminationStatus)
end
end

function MOI.get(m::Optimizer, ::MOI.PrimalStatus)
function MOI.get(m::Optimizer, attr::MOI.PrimalStatus)
if attr.N > MOI.get(m, MOI.ResultCount())
return MOI.NO_SOLUTION
end
status = m.status
if status == 0
return MOI.FEASIBLE_POINT
Expand All @@ -298,7 +301,10 @@ function MOI.get(m::Optimizer, ::MOI.PrimalStatus)
end
end

function MOI.get(m::Optimizer, ::MOI.DualStatus)
function MOI.get(m::Optimizer, attr::MOI.DualStatus)
if attr.N > MOI.get(m, MOI.ResultCount())
return MOI.NO_SOLUTION
end
status = m.status
if status == 0
return MOI.FEASIBLE_POINT
Expand All @@ -316,10 +322,12 @@ function MOI.get(m::Optimizer, ::MOI.DualStatus)
end

MOI.get(m::Optimizer, ::MOI.ResultCount) = 1
function MOI.get(m::Optimizer, ::MOI.ObjectiveValue)
function MOI.get(m::Optimizer, attr::MOI.ObjectiveValue)
MOI.check_result_index_bounds(m, attr)
return m.objsign * m.pobj + m.objconstant
end
function MOI.get(m::Optimizer, ::MOI.DualObjectiveValue)
function MOI.get(m::Optimizer, attr::MOI.DualObjectiveValue)
MOI.check_result_index_bounds(m, attr)
return m.objsign * m.dobj + m.objconstant
end
struct PrimalSolutionMatrix <: MOI.AbstractModelAttribute end
Expand Down Expand Up @@ -364,23 +372,28 @@ function vectorize_block(M::AbstractMatrix{Cdouble}, blk::Integer, s::Type{MOI.P
return v
end

function MOI.get(optimizer::Optimizer, ::MOI.VariablePrimal, vi::MOI.VariableIndex)
function MOI.get(optimizer::Optimizer, attr::MOI.VariablePrimal, vi::MOI.VariableIndex)
MOI.check_result_index_bounds(optimizer, attr)
blk, i, j = varmap(optimizer, vi)
return block(MOI.get(optimizer, PrimalSolutionMatrix()), blk)[i, j]
end

function MOI.get(optimizer::Optimizer, ::MOI.ConstraintPrimal,
function MOI.get(optimizer::Optimizer, attr::MOI.ConstraintPrimal,
ci::MOI.ConstraintIndex{MOI.VectorOfVariables, S}) where S<:SupportedSets
MOI.check_result_index_bounds(optimizer, attr)
return vectorize_block(MOI.get(optimizer, PrimalSolutionMatrix()), block(optimizer, ci), S)
end
function MOI.get(m::Optimizer, ::MOI.ConstraintPrimal, ci::AFFEQ)
return m.b[ci.value]
function MOI.get(optimizer::Optimizer, attr::MOI.ConstraintPrimal, ci::AFFEQ)
MOI.check_result_index_bounds(optimizer, attr)
return optimizer.b[ci.value]
end

function MOI.get(optimizer::Optimizer, ::MOI.ConstraintDual,
function MOI.get(optimizer::Optimizer, attr::MOI.ConstraintDual,
ci::MOI.ConstraintIndex{MOI.VectorOfVariables, S}) where S<:SupportedSets
MOI.check_result_index_bounds(optimizer, attr)
return vectorize_block(MOI.get(optimizer, DualSlackMatrix()), block(optimizer, ci), S)
end
function MOI.get(optimizer::Optimizer, ::MOI.ConstraintDual, ci::AFFEQ)
function MOI.get(optimizer::Optimizer, attr::MOI.ConstraintDual, ci::AFFEQ)
MOI.check_result_index_bounds(optimizer, attr)
return -MOI.get(optimizer, DualSolutionVector())[ci.value]
end
4 changes: 3 additions & 1 deletion test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ end

@testset "Unit" begin
MOIT.unittest(bridged, config, [
# `NumberOfThreads` not supported.
"number_threads",
# `TimeLimitSec` not supported.
"time_limit_sec",
# SingleVariable objective of bridged variables, will be solved by objective bridges
Expand Down Expand Up @@ -64,5 +66,5 @@ end
# Missing bridges
"rootdets",
# Does not support power and exponential cone
"pow", "logdet", "exp"])
"pow", "dualpow", "logdet", "exp", "dualexp"])
end