Skip to content

Commit

Permalink
Add LHS constraint modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Feb 16, 2021
1 parent 78f5902 commit 3c9adef
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 28 deletions.
58 changes: 40 additions & 18 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1391,24 +1391,46 @@ function _set_name_to_constraint_index(
return
end

# TODO(odow): doesn't look like HiGHS supports these.
#
# function MOI.modify(
# model::Optimizer,
# c::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},S},
# chg::MOI.ScalarCoefficientChange{Float64}
# ) where {S<:_SCALAR_SETS}
# return
# end
#
# function MOI.set(
# model::Optimizer,
# ::MOI.ConstraintFunction,
# c::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64}, <:_SCALAR_SETS},
# f::MOI.ScalarAffineFunction{Float64}
# )
# return
# end
function MOI.modify(
model::Optimizer,
c::MOI.ConstraintIndex{MOI.ScalarAffineFunction{Float64},S},
chg::MOI.ScalarCoefficientChange{Float64}
) where {S<:_SCALAR_SETS}
ret = Highs_changeCoeff(
model,
row(model, c),
column(model, chg.variable),
chg.new_coefficient,
)
_check_ret(ret)
return
end

function MOI.set(
model::Optimizer,
::MOI.ConstraintFunction,
c::MOI.ConstraintIndex{F,S},
f::F
) where {F<:MOI.ScalarAffineFunction{Float64},S<:_SCALAR_SETS}
if !iszero(f.constant)
throw(MOI.ScalarFunctionConstantNotZero{Float64,F,S}(f.constant))
end
# This loop is a bit slow because we query the existing function first, and
# then set each coefficient one-by-one. It's probably okay until someone
# complainsm but it will require some upstream changes to introduce a faster
# way of modifying a list of coefficients.
old = MOI.get(model, MOI.ConstraintFunction(), c)
terms = Dict(x.variable_index => 0.0 for x in old.terms)
for term in f.terms
terms[term.variable_index] = term.coefficient
end
r = row(model, c)
for (k, v) in terms
ret = Highs_changeCoeff(model, r, column(model, k), v)
_check_ret(ret)
end
return
end

###
### Optimize methods.
Expand Down
11 changes: 1 addition & 10 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ MOI.set(OPTIMIZER, MOI.Silent(), true)
const CONFIG = MOI.Test.TestConfig(
basis = true,

# TODO(odow): add support for modifying the constraint matrix.
modify_lhs = false,
# TODO(odow): add infeasibility certificates.
infeas_certificates = false,
)
Expand Down Expand Up @@ -46,14 +44,7 @@ function test_unittest()
end

function test_modificationtest()
# TODO(odow): HiGHS doesn't support modifying the constraint matrix, so use
# a caching optimizer.
MOI.empty!(OPTIMIZER)
cache = MOI.Utilities.CachingOptimizer(
MOI.Utilities.Model{Float64}(),
OPTIMIZER,
)
return MOI.Test.modificationtest(cache, CONFIG)
return MOI.Test.modificationtest(OPTIMIZER, CONFIG)
end

function test_contlineartest()
Expand Down

0 comments on commit 3c9adef

Please sign in to comment.