Skip to content

Commit 4981334

Browse files
committed
change in interval constraints handling
1 parent 1451a82 commit 4981334

2 files changed

Lines changed: 75 additions & 21 deletions

File tree

src/mbm.jl

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ function reformulate_disjunction(
88
method::MBM
99
)
1010
ref_cons = Vector{JuMP.AbstractConstraint}()
11-
for d in disj.indicators
12-
# Make a copy to avoid modifying during iteration
13-
constraints = copy(_indicator_to_constraints(model)[d])
14-
for cref in constraints
15-
con = JuMP.constraint_object(cref)
16-
if con isa JuMP.ScalarConstraint{<:Any, <:MOI.Interval}
17-
# Create lower and upper bound constraints
18-
lower_con = JuMP.build_constraint(error, con.func,
19-
MOI.GreaterThan(con.set.lower))
20-
upper_con = JuMP.build_constraint(error, con.func,
21-
MOI.LessThan(con.set.upper))
22-
# Create new disjunct constraints
23-
JuMP.add_constraint(model,_DisjunctConstraint(lower_con, d))
24-
JuMP.add_constraint(model,_DisjunctConstraint(upper_con, d))
25-
JuMP.delete(model, cref)
26-
end
27-
end
28-
end
11+
# for d in disj.indicators
12+
# # Make a copy to avoid modifying during iteration
13+
# constraints = copy(_indicator_to_constraints(model)[d])
14+
# for cref in constraints
15+
# con = JuMP.constraint_object(cref)
16+
# if con isa JuMP.ScalarConstraint{<:Any, <:MOI.Interval}
17+
# # Create lower and upper bound constraints
18+
# lower_con = JuMP.build_constraint(error, con.func,
19+
# MOI.GreaterThan(con.set.lower))
20+
# upper_con = JuMP.build_constraint(error, con.func,
21+
# MOI.LessThan(con.set.upper))
22+
# # Create new disjunct constraints
23+
# JuMP.add_constraint(model,_DisjunctConstraint(lower_con, d))
24+
# JuMP.add_constraint(model,_DisjunctConstraint(upper_con, d))
25+
# JuMP.delete(model, cref)
26+
# end
27+
# end
28+
# end
2929
for d in disj.indicators
3030
method.conlvref = [x for x in disj.indicators if x != d]
3131
_reformulate_disjunct(model, ref_cons, d, method)
@@ -191,6 +191,31 @@ function reformulate_disjunct_constraint(
191191
return [lower_con, upper_con]
192192
end
193193

194+
function reformulate_disjunct_constraint(
195+
model::JuMP.AbstractModel,
196+
con::JuMP.ScalarConstraint{T, S},
197+
bconref:: Union{Dict{<:LogicalVariableRef,<:JuMP.AbstractVariableRef},
198+
Dict{<:LogicalVariableRef,<:JuMP.GenericAffExpr}},
199+
method::MBM
200+
) where {T, S <: _MOI.Interval}
201+
set_values = _set_values(con.set)
202+
upper_func = JuMP.@expression(model,
203+
con.func - sum(method.M[i] * bconref[i] for i in keys(method.M))
204+
)
205+
upper_con = JuMP.build_constraint(error, upper_func,
206+
MOI.LessThan(set_values[2])
207+
)
208+
209+
lower_func = JuMP.@expression(model,
210+
con.func + sum(method.M[i] * bconref[i] for i in keys(method.M))
211+
)
212+
lower_con = JuMP.build_constraint(error, lower_func,
213+
MOI.GreaterThan(set_values[1])
214+
)
215+
216+
return [lower_con, upper_con]
217+
end
218+
194219
function reformulate_disjunct_constraint(
195220
::JuMP.AbstractModel,
196221
::F,
@@ -300,6 +325,29 @@ function _maximize_M(
300325
)
301326
end
302327

328+
function _maximize_M(
329+
model::JuMP.AbstractModel,
330+
objective::JuMP.ScalarConstraint{T, S},
331+
constraints::Vector{<:DisjunctConstraintRef},
332+
method::MBM
333+
) where {T, S <: _MOI.Interval}
334+
set_values = _set_values(objective.set) # Returns (lower, upper)
335+
return max(
336+
_mini_model(
337+
model,
338+
JuMP.ScalarConstraint(objective.func, MOI.GreaterThan(set_values[1])),
339+
constraints,
340+
method
341+
),
342+
_mini_model(
343+
model,
344+
JuMP.ScalarConstraint(objective.func, MOI.LessThan(set_values[2])),
345+
constraints,
346+
method
347+
)
348+
)
349+
end
350+
303351
function _maximize_M(
304352
::JuMP.AbstractModel,
305353
::F,
@@ -351,7 +399,8 @@ function _mini_model(
351399
) where {T,S <: Union{_MOI.Nonpositives, _MOI.Nonnegatives,_MOI.Zeros, MOI.EqualTo, MOI.Interval},
352400
C <: Union{DisjunctConstraintRef, DisjunctionRef}}
353401
error("This type of constraints and objective constraint has " *
354-
"not been implemented for MBM subproblems")
402+
"not been implemented for MBM subproblems \n" *
403+
"Objective: $(T) $(S) \nConstraints: $(C)")
355404
end
356405

357406
################################################################################

test/constraints/mbm.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ function test_mini_model()
6666
model = GDPModel()
6767
@variable(model, 0 <= x, start = 1)
6868
@variable(model, 0 <= y)
69-
@variable(model, Y[1:3], Logical)
69+
@variable(model, Y[1:4], Logical)
7070
@constraint(model, con, 3*-x <= 4, Disjunct(Y[1]))
7171
@constraint(model, con2, 3*x + y >= 15, Disjunct(Y[2]))
7272
@constraint(model, infeasiblecon, 3*x + y == 15, Disjunct(Y[3]))
73-
@disjunction(model, [Y[1], Y[2], Y[3]])
73+
@constraint(model, intervalcon, 0 <= x <= 55, Disjunct(Y[4]))
74+
@disjunction(model, [Y[1], Y[2], Y[3], Y[4]])
7475
@test DP._mini_model(model, constraint_object(con),
7576
DisjunctConstraintRef[con2], MBM(HiGHS.Optimizer))== -4
7677
set_upper_bound(x, 1)
@@ -105,6 +106,10 @@ function test_maximize_M()
105106
Disjunct(Y[5]))
106107
@constraint(model, zeros, -x .+ 1 in MOI.Zeros(2), Disjunct(Y[6]))
107108

109+
@test DP._maximize_M(model, constraint_object(interval),
110+
Vector{DisjunctConstraintRef}(
111+
DP._indicator_to_constraints(model)[Y[2]]),
112+
MBM(HiGHS.Optimizer)) == 0.0
108113
@test DP._maximize_M(model, constraint_object(lessthan),
109114
Vector{DisjunctConstraintRef}(
110115
DP._indicator_to_constraints(model)[Y[2]]),

0 commit comments

Comments
 (0)