@@ -431,6 +431,42 @@ function _maximize_M(
431431 " has not been implemented for MBM subproblems\n F: $(F) " )
432432end
433433
434+ """
435+ copy_model_with_constraints(model, constraints, method)
436+
437+ Create a new model with only the variables (and their bounds)
438+ from `model` and the selected `constraints`. Returns a
439+ `GDPSubmodel` wrapping the new model.
440+ """
441+ function copy_model_with_constraints (
442+ model:: JuMP.AbstractModel ,
443+ constraints:: Vector{<:DisjunctConstraintRef} ,
444+ method:: _MBM
445+ )
446+ var_type = JuMP. variable_ref_type (model)
447+ sub_model = _copy_model (model)
448+ decision_vars = collect_all_vars (model)
449+ fwd_map = Dict {var_type, Vector{var_type}} ()
450+
451+ for var in decision_vars
452+ copy_var = variable_copy (sub_model, var)
453+ fwd_map[var] = [copy_var]
454+ end
455+
456+ for cref in constraints
457+ con = JuMP. constraint_object (cref)
458+ flat_map = Dict (v => only (ws) for (v, ws) in fwd_map)
459+ expr = _replace_variables_in_constraint (con. func, flat_map)
460+ T = one (JuMP. value_type (typeof (sub_model)))
461+ JuMP. @constraint (sub_model, expr * T in con. set)
462+ end
463+
464+ JuMP. set_optimizer (sub_model, method. optimizer)
465+ JuMP. set_silent (sub_model)
466+
467+ return GDPSubmodel (sub_model, decision_vars, fwd_map)
468+ end
469+
434470# ###############################################################################
435471# REPLACE VARIABLES IN CONSTRAINT
436472# ###############################################################################
0 commit comments