Skip to content

Commit 4e26305

Browse files
authored
Use throw_if_scalar_and_constant_not_zero when appropriate (#2753)
1 parent 36912e1 commit 4e26305

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

src/Bridges/Constraint/bridges/VectorizeBridge.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ function bridge_constraint(
4545
scalar_f::G,
4646
set::MOI.Utilities.ScalarLinearSet{T},
4747
) where {T,F,S,G}
48-
scalar_const = MOI.constant(scalar_f, T)
49-
if !iszero(scalar_const)
50-
throw(MOI.ScalarFunctionConstantNotZero{T,G,typeof(set)}(scalar_const))
51-
end
48+
MOI.throw_if_scalar_and_constant_not_zero(scalar_f, typeof(set))
5249
set_const = MOI.constant(set)
5350
vector_f = MOI.Utilities.operate(
5451
vcat,

src/Utilities/mockoptimizer.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,8 @@ function MOI.add_constraint(
181181
) where {T}
182182
if !mock.add_con_allowed
183183
throw(MOI.AddConstraintNotAllowed{typeof(func),typeof(set)}())
184-
elseif mock.scalar_function_constant_non_zero && !iszero(func.constant)
185-
throw(
186-
MOI.ScalarFunctionConstantNotZero{T,typeof(func),typeof(set)}(
187-
func.constant,
188-
),
189-
)
184+
elseif mock.scalar_function_constant_non_zero
185+
MOI.throw_if_scalar_and_constant_not_zero(func, typeof(set))
190186
end
191187
ci = MOI.add_constraint(mock.inner_model, xor_indices(func), set)
192188
return xor_index(ci)

0 commit comments

Comments
 (0)