File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -252,10 +252,11 @@ function modify_constants end
252252 row::Integer,
253253 col::Integer,
254254 new_coefficient,
255- )
255+ )::Bool
256256
257257Modify `coefficients` in-place to store `new_coefficient` at position
258- `(row, col)`.
258+ `(row, col)`. Return `true` if the entry existed and was modified, and `false`
259+ if no entry exists at `(row, col)` in the sparse structure and `new_coefficient` is nonzero.
259260
260261This function must be implemented to enable
261262[`MOI.ScalarCoefficientChange`](@ref) for [`MatrixOfConstraints`](@ref).
@@ -719,15 +720,20 @@ function MOI.modify(
719720 ci:: MOI.ConstraintIndex ,
720721 change:: MOI.ScalarCoefficientChange ,
721722)
722- try
723- modify_coefficients (
724- model. coefficients,
725- rows (model, ci),
726- change. variable. value,
727- change. new_coefficient,
723+ if ! modify_coefficients (
724+ model. coefficients,
725+ rows (model, ci),
726+ change. variable. value,
727+ change. new_coefficient,
728+ )
729+ throw (
730+ MOI. ModifyConstraintNotAllowed (
731+ ci,
732+ change,
733+ " cannot set a new non-zero coefficient because no entry " *
734+ " exists in the sparse matrix of `MatrixOfConstraints`" ,
735+ ),
728736 )
729- catch
730- throw (MOI. ModifyConstraintNotAllowed (ci, change))
731737 end
732738 return
733739end
Original file line number Diff line number Diff line change @@ -172,14 +172,9 @@ function modify_coefficients(
172172 r = _shift (row, OneBasedIndexing (), _indexing (A))
173173 if idx <= last (range) && A. rowval[idx] == r
174174 A. nzval[idx] = new_coefficient
175- elseif ! iszero (new_coefficient)
176- error (
177- " Cannot set a new non-zero coefficient at ($row , $col ) because " *
178- " no entry exists in the sparse matrix. Adding new entries to a " *
179- " `MutableSparseMatrixCSC` after `final_touch` is not supported." ,
180- )
175+ return true
181176 end
182- return
177+ return iszero (new_coefficient)
183178end
184179
185180"""
You can’t perform that action at this time.
0 commit comments