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

Commit 812d334

Browse files
authored
Throw UnsupportedAttribute when mip starts not supported. (#76)
* Throw UnsupportedAttribute when mip starts not supported. * Update docstring
1 parent 5cdeef6 commit 812d334

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/solver_interface.jl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,17 @@ Delete the columns `start_col`, `start_col+1`, ..., `end_col` from the model `m`
603603
function delete_variables! end
604604

605605
"""
606-
add_mip_starts!(m, cols::Vector{Int}, x::Vector{Float64})::Nothing
606+
add_mip_starts!(model::M, cols::Vector{Int}, x::Vector{Float64})::Nothing
607607
608-
Add the MIP start `x` for the variables in the columns `cols` of the model `m`.
608+
Add a primal start `x` for the variables in the columns `cols` of `model`.
609+
610+
Note that if this method is implemented, solvers of type `M` must also declare
611+
that they support VariablePrimalStarts by overloading the following method:
612+
613+
function MOI.supports(model::M,
614+
::MOI.VariablePrimalStart,
615+
::Type{MOI.VariableIndex})
616+
return true
617+
end
609618
"""
610619
function add_mip_starts! end

src/variables.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,16 @@ end
200200
#=
201201
MIP starts
202202
=#
203-
function MOI.supports(::LinQuadOptimizer, ::MOI.VariablePrimalStart, ::Type{VarInd})
203+
function MOI.supports(
204+
::LinQuadOptimizer, ::MOI.VariablePrimalStart, ::Type{VarInd})
204205
return false
205206
end
206207

207208
function MOI.set(model::LinQuadOptimizer, ::MOI.VariablePrimalStart,
208209
indices::Vector{VarInd}, values::Vector{Float64})
210+
if !MOI.supports(model, MOI.VariablePrimalStart(), MOI.VariableIndex)
211+
throw(MOI.UnsupportedAttribute(MOI.VariablePrimalStart()))
212+
end
209213
add_mip_starts!(model, get_column.(Ref(model), indices), values)
210214
end
211215

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,9 @@ end
451451
@test model.inner.vartype[1] == Cchar('C')
452452
end
453453
end
454+
455+
@testset "VariablePrimalStart" begin
456+
model = LQOI.MockLinQuadOptimizer()
457+
x = MOI.add_variable(model)
458+
@test_throws MOI.UnsupportedAttribute MOI.set(model, MOI.VariablePrimalStart(), x, 1.0)
459+
end

0 commit comments

Comments
 (0)