Skip to content

Commit

Permalink
implement more problem modification
Browse files Browse the repository at this point in the history
  • Loading branch information
rschwarz committed Dec 22, 2018
1 parent c6ed123 commit 60c26ec
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ function MOI.add_constraint(o::Optimizer, func::MOI.SingleVariable,
return register!(o, CI{MOI.SingleVariable, S}(i))
end

function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet,
ci::CI{MOI.SingleVariable,S}, set::S) where {S <: SS}
allow_modification(o)
var = get_var(o, VI(ci.value)) # cons index is actually var index
lb, ub = bounds(set)
lb == nothing || @SC SCIPchgVarLb(get_scip(o), var, lb)
ub == nothing || @SC SCIPchgVarUb(get_scip(o), var, ub)
return nothing
end

function MOI.add_constraint(o::Optimizer, func::MOI.ScalarAffineFunction{Float64},
set::S) where {S <: SS}
allow_modification(o)
Expand Down Expand Up @@ -247,6 +257,22 @@ function MOI.get(o::Optimizer, ::MOI.ObjectiveSense)
MOI.MIN_SENSE
end

function MOI.modify(o::Optimizer, ci::CI{MOI.ScalarAffineFunction{Float64}, <:SS},
change::MOI.ScalarCoefficientChange{Float64})
allow_modification(o)
@SC SCIPchgCoefLinear(get_scip(o), get_cons(o, ci),
get_var(o, change.variable), change.new_coefficient)
return nothing
end

function MOI.modify(o::Optimizer,
::MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}},
change::MOI.ScalarCoefficientChange{Float64})
allow_modification(o)
@SC SCIPchgVarObj(get_scip(o), get_var(o, change.variable),
change.new_coefficient)
return nothing
end

## optimization and results

Expand Down Expand Up @@ -282,6 +308,8 @@ function MOI.get(o::Optimizer, ::MOI.PrimalStatus)
SCIPgetNSols(get_scip(o)) > 0 ? MOI.FEASIBLE_POINT : MOI.NO_SOLUTION
end

MOI.get(o::Optimizer, ::MOI.ResultCount) = SCIPgetNSols(get_scip(o))

function MOI.get(o::Optimizer, ::MOI.ObjectiveValue)
scip = get_scip(o)
return SCIPgetSolOrigObj(scip, SCIPgetBestSol(scip))
Expand Down

0 comments on commit 60c26ec

Please sign in to comment.