Skip to content

Commit 1c49e73

Browse files
committed
Update
1 parent 630081f commit 1c49e73

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/Utilities/matrix_of_constraints.jl

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -707,20 +707,14 @@ function MOI.modify(
707707
ci::MOI.ConstraintIndex,
708708
change::Union{MOI.ScalarConstantChange,MOI.VectorConstantChange},
709709
)
710-
try
711-
modify_constants(model.constants, rows(model, ci), change.new_constant)
712-
catch err
713-
if err isa MethodError
714-
throw(
715-
MOI.ModifyConstraintNotAllowed(
716-
ci,
717-
change,
718-
"`modify_constants` is not implemented for " *
719-
"`$(typeof(model.constants))`",
720-
),
721-
)
722-
end
723-
rethrow(err)
710+
ret = modify_constants(
711+
model.constants,
712+
rows(model, ci),
713+
change.new_constant,
714+
)
715+
if ret == _ModifyConstantsNotImplemented()
716+
msg = "`modify_constants` is not implemented for `$(typeof(model.constants))`"
717+
throw(MOI.ModifyConstraintNotAllowed(ci, change, msg))
724718
end
725719
return
726720
end
@@ -748,6 +742,15 @@ function MOI.modify(
748742
return
749743
end
750744

745+
# See https://github.com/jump-dev/MathOptInterface.jl/pull/2976
746+
# Ideally we would have made it so that `modify_constants` operated like
747+
# `modify_coefficients` and returned a `Bool` indicating success. But we didn't,
748+
# so here's a hacky work-around to catch if the method is not implemented
749+
# without resorting to a try-catch.
750+
struct _ModifyConstantsNotImplemented end
751+
752+
modify_constants(args...) = _ModifyConstantsNotImplemented()
753+
751754
function modify_constants(
752755
b::AbstractVector{T},
753756
row::Integer,

0 commit comments

Comments
 (0)