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