Skip to content

Commit

Permalink
Add VariableBasisStatus (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed May 7, 2024
1 parent 02da577 commit 650846d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,42 @@ function MOI.get(m::Optimizer, attr::MOI.VariablePrimal,
return output
end

#### Variable basis status

function _basis_status(x::Stakey)
if x == MSK_SK_BAS
return BASIC
elseif x == MSK_SK_SUPBAS
return SUPER_BASIC
elseif x == MSK_SK_LOW
return NONBASIC_AT_LOWER
elseif x == MSK_SK_UPR
return NONBASIC_AT_UPPER
# FIXME which one is `NONBASIC` ?
elseif x == MSK_SK_UNK
msg = "The status for the constraint or variable is unknown"
elseif x == MSK_SK_FIX
msg = "The constraint or variable is fixed"
else
@assert x == MSK_SK_INF
msg = "The constraint or variable is infeasible in the bounds"
end
error("Mosek basic status `$msg` has no equivalent in the `MOI.BasisStatusCode` enum.")
end

function MOI.get(m::Optimizer, attr::MOI.VariableBasisStatus, col::ColumnIndex)
return _basis_status(m.solutions[attr.result_index].xxstatus[col.value])
end

function MOI.get(::Optimizer, attr::MOI.VariableBasisStatus, mat::MOI.VariableIndex)
error("$attr not supported for PSD variable $mat")
end

function MOI.get(m::Optimizer, attr::MOI.VariableBasisStatus, vi::MOI.VariableIndex)
MOI.check_result_index_bounds(m, attr)
return MOI.get(m, attr, mosek_index(m, vi))
end

#### Constraint solution values

function MOI.get(
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ end
const config = MOI.Test.Config(
Float64, atol=1e-3, rtol=1e-3,
# TODO remove `MOI.delete` once it is implemented for ACC
exclude=Any[MOI.ConstraintName, MOI.VariableBasisStatus, MOI.ConstraintBasisStatus, MOI.delete], # result in errors for now
exclude=Any[MOI.ConstraintName, MOI.ConstraintBasisStatus, MOI.delete], # result in errors for now
)

@testset "Direct optimizer tests" begin
Expand Down

0 comments on commit 650846d

Please sign in to comment.