@@ -20,10 +20,8 @@ function reformulate_disjunction(
2020 upper_con = JuMP. build_constraint (error, con. func,
2121 MOI. LessThan (con. set. upper))
2222 # Create new disjunct constraints
23- JuMP. add_constraint (model,
24- _DisjunctConstraint (lower_con, d))
25- JuMP. add_constraint (model,
26- _DisjunctConstraint (upper_con, d))
23+ JuMP. add_constraint (model,_DisjunctConstraint (lower_con, d))
24+ JuMP. add_constraint (model,_DisjunctConstraint (upper_con, d))
2725 JuMP. delete (model, cref)
2826 end
2927 end
@@ -53,10 +51,14 @@ function _reformulate_disjunct(
5351 d_constraints = _indicator_to_constraints (model)[d]
5452 disjunct_constraints = [c for c in d_constraints if c isa DisjunctConstraintRef]
5553 if ! isempty (disjunct_constraints)
56- method. M[d] = maximum (_maximize_M (model,
57- JuMP. constraint_object (cref),
58- disjunct_constraints,
59- method) for cref in filtered_constraints)
54+ method. M[d] = maximum (
55+ _maximize_M (
56+ model,
57+ JuMP. constraint_object (cref),
58+ disjunct_constraints,
59+ method
60+ ) for cref in filtered_constraints
61+ )
6062 end
6163 end
6264 for cref in filtered_constraints
@@ -78,7 +80,9 @@ function reformulate_disjunct_constraint(
7880 ref_cons = reformulate_disjunction (model, con, method)
7981 new_ref_cons = Vector {JuMP.AbstractConstraint} ()
8082 for ref_con in ref_cons
81- append! (new_ref_cons, reformulate_disjunct_constraint (model, ref_con, bconref, method))
83+ append! (new_ref_cons,
84+ reformulate_disjunct_constraint (model, ref_con, bconref, method)
85+ )
8286 end
8387 return new_ref_cons
8488end
@@ -129,9 +133,11 @@ function reformulate_disjunct_constraint(
129133 con. func[i] - m_sum
130134 )
131135 upper_con = JuMP. build_constraint (error, upper_expr,
132- MOI. Nonnegatives (con. set. dimension))
136+ MOI. Nonnegatives (con. set. dimension)
137+ )
133138 lower_con = JuMP. build_constraint (error, lower_expr,
134- MOI. Nonpositives (con. set. dimension))
139+ MOI. Nonpositives (con. set. dimension)
140+ )
135141 return [upper_con, lower_con]
136142end
137143
@@ -157,7 +163,8 @@ function reformulate_disjunct_constraint(
157163 method:: MBM
158164) where {T, S <: _MOI.GreaterThan }
159165 new_func = JuMP. @expression (model,
160- con. func + sum (method. M[i] * bconref[i] for i in keys (method. M)))
166+ con. func + sum (method. M[i] * bconref[i] for i in keys (method. M))
167+ )
161168 reform_con = JuMP. build_constraint (error, new_func, con. set)
162169 return [reform_con]
163170end
@@ -170,14 +177,17 @@ function reformulate_disjunct_constraint(
170177 method:: MBM
171178) where {T, S <: _MOI.EqualTo }
172179 upper_func = JuMP. @expression (model,
173- con. func - sum (method. M[i] * bconref[i] for i in keys (method. M)))
180+ con. func - sum (method. M[i] * bconref[i] for i in keys (method. M))
181+ )
174182 lower_func = JuMP. @expression (model,
175- con. func + sum (method. M[i] * bconref[i] for i in keys (method. M)))
176-
183+ con. func + sum (method. M[i] * bconref[i] for i in keys (method. M))
184+ )
177185 upper_con = JuMP. build_constraint (error, upper_func,
178- MOI. LessThan (con. set. value))
186+ MOI. LessThan (con. set. value)
187+ )
179188 lower_con = JuMP. build_constraint (error, lower_func,
180- MOI. GreaterThan (con. set. value))
189+ MOI. GreaterThan (con. set. value)
190+ )
181191 return [lower_con, upper_con]
182192end
183193
@@ -203,9 +213,14 @@ function _maximize_M(
203213 constraints:: Vector{<:DisjunctConstraintRef} ,
204214 method:: MBM
205215) where {T, S <: _MOI.Nonpositives , R}
206- return maximum (_maximize_M (model,
207- JuMP. ScalarConstraint (objective. func[i], MOI. LessThan (0.0 )),
208- constraints, method) for i in 1 : objective. set. dimension)
216+ return maximum (
217+ _maximize_M (
218+ model,
219+ JuMP. ScalarConstraint (objective. func[i], MOI. LessThan (0 )),
220+ constraints,
221+ method
222+ ) for i in 1 : objective. set. dimension
223+ )
209224end
210225
211226function _maximize_M (
@@ -214,9 +229,14 @@ function _maximize_M(
214229 constraints:: Vector{<:DisjunctConstraintRef} ,
215230 method:: MBM
216231) where {T, S <: _MOI.Nonnegatives , R}
217- return maximum (_maximize_M (model,
218- JuMP. ScalarConstraint (objective. func[i], MOI. GreaterThan (0.0 )),
219- constraints, method) for i in 1 : objective. set. dimension)
232+ return maximum (
233+ _maximize_M (
234+ model,
235+ JuMP. ScalarConstraint (objective. func[i], MOI. GreaterThan (0 )),
236+ constraints,
237+ method
238+ ) for i in 1 : objective. set. dimension
239+ )
220240end
221241
222242function _maximize_M (
@@ -226,14 +246,22 @@ function _maximize_M(
226246 method:: MBM
227247) where {T, S <: _MOI.Zeros , R}
228248 return max (
229- maximum (_maximize_M (model,
230- JuMP. ScalarConstraint (objective. func[i],
231- MOI. GreaterThan (0.0 )),
232- constraints, method) for i in 1 : objective. set. dimension),
233- maximum (_maximize_M (model,
234- JuMP. ScalarConstraint (objective. func[i],
235- MOI. LessThan (0.0 )),
236- constraints, method) for i in 1 : objective. set. dimension)
249+ maximum (
250+ _maximize_M (
251+ model,
252+ JuMP. ScalarConstraint (objective. func[i], MOI. GreaterThan (0 )),
253+ constraints,
254+ method
255+ ) for i in 1 : objective. set. dimension
256+ ),
257+ maximum (
258+ _maximize_M (
259+ model,
260+ JuMP. ScalarConstraint (objective. func[i], MOI. LessThan (0 )),
261+ constraints,
262+ method
263+ ) for i in 1 : objective. set. dimension
264+ )
237265 )
238266end
239267
@@ -252,15 +280,20 @@ function _maximize_M(
252280 constraints:: Vector{<:DisjunctConstraintRef} ,
253281 method:: MBM
254282) where {T, S <: _MOI.EqualTo }
283+ set_value = objective. set. value
255284 return max (
256- _mini_model (model,
257- JuMP. ScalarConstraint (objective. func,
258- MOI. GreaterThan (objective. set. value)),
259- constraints, method),
260- _mini_model (model,
261- JuMP. ScalarConstraint (objective. func,
262- MOI. LessThan (objective. set. value)),
263- constraints, method)
285+ _mini_model (
286+ model,
287+ JuMP. ScalarConstraint (objective. func, MOI. GreaterThan (set_value)),
288+ constraints,
289+ method
290+ ),
291+ _mini_model (
292+ model,
293+ JuMP. ScalarConstraint (objective. func, MOI. LessThan (set_value)),
294+ constraints,
295+ method
296+ )
264297 )
265298end
266299
@@ -325,21 +358,19 @@ function constraint_to_objective(
325358 sub_model:: JuMP.AbstractModel ,
326359 obj:: JuMP.ScalarConstraint{<:JuMP.AbstractJuMPScalar, MOI.LessThan{T}} ,
327360 new_vars:: Dict{V,K}
328- ) where {T,V <: JuMP.AbstractVariableRef ,
329- K <: JuMP.AbstractVariableRef }
361+ ) where {T,V <: JuMP.AbstractVariableRef , K <: JuMP.AbstractVariableRef }
330362 JuMP. @objective (sub_model, Max,
331- - obj. set. upper +
332- replace_variables_in_constraint (obj . func, new_vars) )
363+ - obj. set. upper + replace_variables_in_constraint (obj . func, new_vars)
364+ )
333365end
334366function constraint_to_objective (
335367 sub_model:: JuMP.AbstractModel ,
336368 obj:: JuMP.ScalarConstraint{<:JuMP.AbstractJuMPScalar, MOI.GreaterThan{T}} ,
337369 new_vars:: Dict{V,K}
338- ) where {T,V <: JuMP.AbstractVariableRef ,
339- K <: JuMP.AbstractVariableRef }
370+ ) where {T,V <: JuMP.AbstractVariableRef , K <: JuMP.AbstractVariableRef }
340371 JuMP. @objective (sub_model, Max,
341- - replace_variables_in_constraint (obj. func, new_vars) +
342- obj . set . lower )
372+ - replace_variables_in_constraint (obj. func, new_vars) + obj . set . lower
373+ )
343374end
344375
345376function constraint_to_objective (
@@ -364,10 +395,10 @@ function replace_variables_in_constraint(
364395end
365396
366397function replace_variables_in_constraint (
367- fun:: JuMP.GenericAffExpr ,
398+ fun:: T ,
368399 var_map:: Dict{<:JuMP.AbstractVariableRef,<:JuMP.AbstractVariableRef}
369- )
370- new_aff = JuMP. zero (JuMP . AffExpr )
400+ ) where {T <: JuMP.GenericAffExpr }
401+ new_aff = JuMP. zero (T )
371402 for (var, coef) in fun. terms
372403 new_var = var_map[var]
373404 JuMP. add_to_expression! (new_aff, coef, new_var)
@@ -377,10 +408,10 @@ function replace_variables_in_constraint(
377408end
378409
379410function replace_variables_in_constraint (
380- fun:: JuMP.GenericQuadExpr ,
411+ fun:: T ,
381412 var_map:: Dict{<:JuMP.AbstractVariableRef,<:JuMP.AbstractVariableRef}
382- )
383- new_quad = JuMP. zero (JuMP . QuadExpr )
413+ ) where {T <: JuMP.GenericQuadExpr }
414+ new_quad = JuMP. zero (T )
384415 for (vars, coef) in fun. terms
385416 JuMP. add_to_expression! (new_quad, coef,
386417 var_map[vars. a], var_map[vars. b])
@@ -398,12 +429,12 @@ function replace_variables_in_constraint(
398429end
399430
400431function replace_variables_in_constraint (
401- fun:: JuMP.GenericNonlinearExpr ,
432+ fun:: T ,
402433 var_map:: Dict{<:JuMP.AbstractVariableRef,<:JuMP.AbstractVariableRef}
403- )
434+ ) where {T <: JuMP.GenericNonlinearExpr }
404435 new_args = Any[replace_variables_in_constraint (arg, var_map)
405436 for arg in fun. args]
406- return JuMP . GenericNonlinearExpr (fun. head, new_args)
437+ return T (fun. head, new_args)
407438end
408439
409440function replace_variables_in_constraint (
0 commit comments