Skip to content

Commit

Permalink
do not support linear constraints with constant offset
Browse files Browse the repository at this point in the history
 - because I would need to merge it with lhs/rhs
 - but then I can not modify the constraint with set(, ConstraintSet, )
 - so I just throw AddConstraintNotAllowed
  • Loading branch information
rschwarz committed Dec 22, 2018
1 parent 60c26ec commit b97dcff
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,41 @@ end

function MOI.add_constraint(o::Optimizer, func::MOI.ScalarAffineFunction{Float64},
set::S) where {S <: SS}
if func.constant != 0.0
msg = "SCIP does not support linear constraints with a constant offset."
throw(MOI.AddConstraintNotAllowed{MOI.ScalarAffineFunction{Float64}, S}(msg))
end

allow_modification(o)
scip = get_scip(o)

varidx = [t.variable_index.value for t in func.terms]
coefs = [t.coefficient for t in func.terms]

lhs, rhs = bounds(set)
lhs = lhs == nothing ? -SCIPinfinity(scip) : lhs - func.constant
rhs = rhs == nothing ? SCIPinfinity(scip) : rhs - func.constant
lhs = lhs == nothing ? -SCIPinfinity(scip) : lhs
rhs = rhs == nothing ? SCIPinfinity(scip) : rhs

i = add_linear_constraint(o.mscip, varidx, coefs, lhs, rhs)
return register!(o, CI{MOI.ScalarAffineFunction{Float64}, S}(i))
end

function MOI.set(o::SCIP.Optimizer, ::MOI.ConstraintSet,
ci::CI{MOI.ScalarAffineFunction{Float64},S}, set::S) where {S <: SS}
allow_modification(o)
scip = get_scip(o)
cons = get_cons(o, ci)

lhs, rhs = bounds(set)
lhs = lhs == nothing ? -SCIPinfinity(scip) : lhs
rhs = rhs == nothing ? SCIPinfinity(scip) : rhs

@SC SCIPchgLhsLinear(scip, cons, lhs)
@SC SCIPchgRhsLinear(scip, cons, rhs)

return nothing
end

function MOI.get(o::Optimizer, ::MOI.NumberOfConstraints{F,S}) where {F,S}
haskey(o.cons, (F, S)) ? length(o.cons[F, S]) : 0
end
Expand Down

0 comments on commit b97dcff

Please sign in to comment.