|
142 | 142 | PenaltyRelaxation( |
143 | 143 | penalties = Dict{MOI.ConstraintIndex,Float64}(); |
144 | 144 | default::Union{Nothing,T} = 1.0, |
| 145 | + warn::Bool = true, |
145 | 146 | ) |
146 | 147 |
|
147 | 148 | A problem modifier that, when passed to [`MOI.modify`](@ref), destructively |
@@ -187,6 +188,9 @@ cannot be modified in-place. |
187 | 188 |
|
188 | 189 | To modify variable bounds, rewrite them as linear constraints. |
189 | 190 |
|
| 191 | +If a constraint cannot be modified, a warning is logged and the |
| 192 | +constraint is skipped. The warning can be disabled by setting `warn = false`. |
| 193 | +
|
190 | 194 | ## Example |
191 | 195 |
|
192 | 196 | ```jldoctest |
@@ -242,12 +246,14 @@ true |
242 | 246 | mutable struct PenaltyRelaxation{T} |
243 | 247 | default::Union{Nothing,T} |
244 | 248 | penalties::Dict{MOI.ConstraintIndex,T} |
| 249 | + warn::Bool |
245 | 250 |
|
246 | 251 | function PenaltyRelaxation( |
247 | 252 | p::Dict{MOI.ConstraintIndex,T}; |
248 | 253 | default::Union{Nothing,T} = one(T), |
| 254 | + warn::Bool = true, |
249 | 255 | ) where {T} |
250 | | - return new{T}(default, p) |
| 256 | + return new{T}(default, p, warn) |
251 | 257 | end |
252 | 258 | end |
253 | 259 |
|
@@ -286,7 +292,11 @@ function _modify_penalty_relaxation( |
286 | 292 | map[ci] = MOI.modify(model, ci, ScalarPenaltyRelaxation(penalty)) |
287 | 293 | catch err |
288 | 294 | if err isa MethodError && err.f == MOI.modify |
289 | | - @warn("Skipping PenaltyRelaxation for ConstraintIndex{$F,$S}") |
| 295 | + if relax.warn |
| 296 | + @warn( |
| 297 | + "Skipping PenaltyRelaxation for ConstraintIndex{$F,$S}" |
| 298 | + ) |
| 299 | + end |
290 | 300 | return |
291 | 301 | end |
292 | 302 | rethrow(err) |
|
0 commit comments