Skip to content

Commit 5b5b767

Browse files
committed
.
1 parent 890f627 commit 5b5b767

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

‎src/mbm.jl‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,42 @@ function _maximize_M(
431431
"has not been implemented for MBM subproblems\nF: $(F)")
432432
end
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
################################################################################

‎src/utilities.jl‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,6 @@ function _copy_model(
88
return M()
99
end
1010

11-
"""
12-
copy_model_with_constraints(model, constraints, method)
13-
14-
Create a new model with only the variables (and their bounds)
15-
from `model` and the selected `constraints`. Returns a
16-
`GDPSubmodel` wrapping the new model.
17-
"""
18-
function copy_model_with_constraints(
19-
model::JuMP.AbstractModel,
20-
constraints::Vector{<:DisjunctConstraintRef},
21-
method::_MBM
22-
)
23-
var_type = JuMP.variable_ref_type(model)
24-
sub_model = _copy_model(model)
25-
decision_vars = collect_all_vars(model)
26-
fwd_map = Dict{var_type, Vector{var_type}}()
27-
28-
for var in decision_vars
29-
copy_var = variable_copy(sub_model, var)
30-
fwd_map[var] = [copy_var]
31-
end
32-
33-
for cref in constraints
34-
con = JuMP.constraint_object(cref)
35-
flat_map = Dict(v => only(ws) for (v, ws) in fwd_map)
36-
expr = _replace_variables_in_constraint(con.func, flat_map)
37-
T = one(JuMP.value_type(typeof(sub_model)))
38-
JuMP.@constraint(sub_model, expr * T in con.set)
39-
end
40-
41-
JuMP.set_optimizer(sub_model, method.optimizer)
42-
JuMP.set_silent(sub_model)
43-
44-
return GDPSubmodel(sub_model, decision_vars, fwd_map)
45-
end
46-
4711
"""
4812
copy_and_reformulate(model, decision_vars, reform_method, method)
4913

0 commit comments

Comments
 (0)