Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Throw UnsupportedAttribute when mip starts not supported. (#76)
Browse files Browse the repository at this point in the history
* Throw UnsupportedAttribute when mip starts not supported.

* Update docstring
  • Loading branch information
odow authored Nov 17, 2018
1 parent 5cdeef6 commit 812d334
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/solver_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,17 @@ Delete the columns `start_col`, `start_col+1`, ..., `end_col` from the model `m`
function delete_variables! end

"""
add_mip_starts!(m, cols::Vector{Int}, x::Vector{Float64})::Nothing
add_mip_starts!(model::M, cols::Vector{Int}, x::Vector{Float64})::Nothing
Add the MIP start `x` for the variables in the columns `cols` of the model `m`.
Add a primal start `x` for the variables in the columns `cols` of `model`.
Note that if this method is implemented, solvers of type `M` must also declare
that they support VariablePrimalStarts by overloading the following method:
function MOI.supports(model::M,
::MOI.VariablePrimalStart,
::Type{MOI.VariableIndex})
return true
end
"""
function add_mip_starts! end
6 changes: 5 additions & 1 deletion src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,16 @@ end
#=
MIP starts
=#
function MOI.supports(::LinQuadOptimizer, ::MOI.VariablePrimalStart, ::Type{VarInd})
function MOI.supports(
::LinQuadOptimizer, ::MOI.VariablePrimalStart, ::Type{VarInd})
return false
end

function MOI.set(model::LinQuadOptimizer, ::MOI.VariablePrimalStart,
indices::Vector{VarInd}, values::Vector{Float64})
if !MOI.supports(model, MOI.VariablePrimalStart(), MOI.VariableIndex)
throw(MOI.UnsupportedAttribute(MOI.VariablePrimalStart()))
end
add_mip_starts!(model, get_column.(Ref(model), indices), values)
end

Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,9 @@ end
@test model.inner.vartype[1] == Cchar('C')
end
end

@testset "VariablePrimalStart" begin
model = LQOI.MockLinQuadOptimizer()
x = MOI.add_variable(model)
@test_throws MOI.UnsupportedAttribute MOI.set(model, MOI.VariablePrimalStart(), x, 1.0)
end

0 comments on commit 812d334

Please sign in to comment.