Skip to content

Commit 2a0b37a

Browse files
committed
bug fixes
1 parent 45de93c commit 2a0b37a

File tree

6 files changed

+28
-48
lines changed

6 files changed

+28
-48
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DisjunctiveProgramming"
22
uuid = "0d27d021-0159-4c7d-b4a7-9ccb5d9366cf"
33
authors = ["hdavid16 <[email protected]>"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
77
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"

src/bigm.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Perform Big-M reformulation on a linear or quadratic constraint at index k of co
77
88
Perform Big-M reformulaiton on a nonlinear constraint at index k of constraint j in disjunct i.
99
10-
big_m_reformulation!(constr::AbstractArray, bin_var, M, i, j, k)
10+
big_m_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, M, i, j, k)
1111
1212
Perform Big-M reformulation on a constraint at index k of constraint j in disjunct i.
1313
"""
@@ -36,5 +36,5 @@ function big_m_reformulation!(constr::NonlinearConstraintRef, bin_var, M, i, j,
3636
#update constraint
3737
replace_constraint(constr, gx, op, rhs)
3838
end
39-
big_m_reformulation!(constr::AbstractArray, bin_var, M, i, j, k) =
39+
big_m_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, M, i, j, k) =
4040
big_m_reformulation(constr[k], bin_var, M, i, j, k)

src/bounds.jl

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,13 @@ end
3030
3131
Get bounds on a variable.
3232
33-
get_bounds(var::VariableRef, bounds_dict::Dict)
33+
get_bounds(var, bounds_dict::Dict)
3434
35-
Get bounds on a variable. Check if a bounds dictionary has ben provided with bounds for that value.
35+
Get bounds on a variable. Check if a bounds dictionary has been provided with bounds for that value.
3636
37-
get_bounds(var::AbstractArray, bounds_dict::Dict, LB, UB)
37+
get_bounds(var::AbstractArray{VariableRef}, bounds_dict::Dict, LB, UB)
3838
3939
Update lower bound `LB` and upper bound `UB` on a variable container.
40-
41-
get_bounds(var::Array{VariableRef}, bounds_dict::Dict)
42-
43-
Get lower and upper bounds on a variable array.
44-
45-
get_bounds(var::Containers.DenseAxisArray, bounds_dict::Dict)
46-
47-
Get lower and upper bounds on a variable DenseAxisArray.
48-
49-
get_gounds(var::Containers.SparseAxisArray, bounds_dict::Dict)
50-
51-
Get lower and upper bounds on a variable SparseAxisArray.
5240
"""
5341
function get_bounds(var::VariableRef)
5442
LB = has_lower_bound(var) ? lower_bound(var) : (is_binary(var) ? 0 : -Inf)
@@ -62,7 +50,7 @@ function get_bounds(var::VariableRef, bounds_dict::Dict)
6250
return get_bounds(var)
6351
end
6452
end
65-
function get_bounds(var::AbstractArray, bounds_dict::Dict, LB, UB)
53+
function get_bounds(var::AbstractArray{VariableRef}, bounds_dict::Dict, LB, UB)
6654
#populate UB and LB
6755
for idx in eachindex(var)
6856
LB[idx], UB[idx] = get_bounds(var[idx], bounds_dict)

src/constraint.jl

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@ JuMP.name(con_ref::NonlinearConstraintRef) = ""
99
1010
Check constraints in a disjunction Tuple.
1111
12-
check_constraint!(m::Model, constr_j::Union{Tuple,Array}, constr_list::Vector)
12+
check_constraint!(m::Model, constr_j, constr_list::Vector)
1313
14-
Check constraints in a nested Tuple or Array of constraints and update `constr_list`.
14+
Check nested constraint and update `constr_list`.
1515
16-
check_constraint!(m::Model, constr_j::ConstraintRef, constr_list::Vector)
17-
18-
Check constraint `constr_j` in position `j` of a disjunct and update `constr_list`.
19-
20-
check_constraint!(m::Model, constr::ConstraintRef)
16+
check_constraint!(m::Model, constr)
2117
2218
Check constraint in a Model.
2319
24-
check_constraint!(m::Model, constr::AbstractArray)
25-
26-
Check constraint block in a model.
27-
2820
check_constraint!(m::Model, constr::Nothing)
2921
3022
Return nothing for an empty disjunct.
@@ -34,9 +26,12 @@ function check_constraint!(m::Model, constr::Tuple)
3426
map(constr_j -> check_constraint!(m, constr_j, constr_list), constr)
3527
return Tuple(constr_list)
3628
end
37-
function check_constraint!(m::Model, constr_j::Union{Tuple,Array}, constr_list::Vector)
29+
function check_constraint!(m::Model, constr_j::Tuple, constr_list::Vector)
3830
map(constr_jk -> check_constraint!(m, constr_jk, constr_list), constr_j)
3931
end
32+
function check_constraint!(m::Model, constr_j::AbstractArray{<:ConstraintRef}, constr_list::Vector)
33+
push!(constr_list, check_constraint!(m, constr_j))
34+
end
4035
function check_constraint!(m::Model, constr_j::ConstraintRef, constr_list::Vector)
4136
push!(constr_list, check_constraint!(m, constr_j))
4237
end
@@ -54,7 +49,7 @@ function check_constraint!(m::Model, constr::ConstraintRef)
5449
end
5550
return new_constr
5651
end
57-
function check_constraint!(m::Model, constr::AbstractArray)
52+
function check_constraint!(m::Model, constr::AbstractArray{<:ConstraintRef})
5853
@assert all(is_valid.(m, constr)) "$constr is not a valid constraint."
5954
if !any(is_interval_constraint.(constr)) && !any(is_equality_constraint.(constr))
6055
new_constr = constr
@@ -87,19 +82,15 @@ Split a nonlinear constraint that is an Interval or EqualTo constraint.
8782
8883
split_constraint(m::Model, constr::ConstraintRef, constr_name::String = name(constr))
8984
90-
Split a linear or quadratic constraint that is MOI.Interval or MOI.EqualTo.
85+
Split a linear or quadratic constraint.
9186
92-
split_constraint(m::Model, func::Union{AffExpr,QuadExpr}, lb::Float64, ub::Float64, lb_name::String, ub_name::String)
93-
94-
Create split constraint for linear or quadratic constraint.
87+
split_constraint(m::Model, constr_obj::ScalarConstraint, lb_name::String, ub_name::String)
9588
96-
split_constraint(m::Model, constr_obj::ScalarConstraint{T,<:MOI.EqualTo}, lb_name::String, ub_name::String)
89+
Split a constraint that is a MOI.EqualTo or MOI.Interval.
9790
98-
Split a constraint that is a MOI.EqualTo.
99-
100-
split_constraint(m::Model, constr_obj::ScalarConstraint{T,<:MOI.Interval}, lb_name::String, ub_name::String)
91+
split_constraint(m::Model, func::Union{AffExpr,QuadExpr}, lb::Float64, ub::Float64, lb_name::String, ub_name::String)
10192
102-
Split a constraint that is a MOI.Interval
93+
Create split constraint for linear or quadratic constraint.
10394
10495
split_constraint(m::Model, constr::ConstraintRef, constr_func_expr::Expr, lb::Float64, ub::Float64)
10596
@@ -168,7 +159,7 @@ split_constraint(args...) = nothing
168159

169160
delete_original_constraint!(m::Model, constr::ConstraintRef) = delete(m,constr)
170161
delete_original_constraint!(m::Model, constr::NonlinearConstraintRef) = nothing
171-
delete_original_constraint!(m::Model, constr::AbstractArray) = map(c -> delete_original_constraint!(m,c), constr)
162+
delete_original_constraint!(m::Model, constr::AbstractArray{<:ConstraintRef}) = map(c -> delete_original_constraint!(m,c), constr)
172163

173164
"""
174165
parse_constraint(constr::ConstraintRef)

src/hull.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Apply the hull reformulation to a linear constraint.
1010
1111
Apply the hull reformulation to a nonlinear constraint (includes quadratic) at index k of constraint j in disjunct i.
1212
13-
hull_reformulation!(constr::AbstractArray, bin_var, eps, i, j, k)
13+
hull_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, eps, i, j, k)
1414
1515
Call the hull reformulation on a constraint at index k of constraint j in disjunct i.
1616
"""
@@ -68,7 +68,7 @@ function hull_reformulation!(constr::ConstraintRef, bin_var, eps, i, j, k)
6868
pers_func = simplify(pers_func)
6969
replace_constraint(constr, pers_func, op, rhs)
7070
end
71-
hull_reformulation!(constr::AbstractArray, bin_var, eps, i, j, k) =
71+
hull_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, eps, i, j, k) =
7272
hull_reformulation!(constr[k], bin_var, eps, i, j, k)
7373

7474
"""
@@ -107,7 +107,7 @@ end
107107
108108
Disaggreagate a variable with lower bound `LB`, upper bound `UB`, and name `base_name`.
109109
110-
add_disaggregated_variable(m::Model, var::AbstractArray, LB, UB, base_name)
110+
add_disaggregated_variable(m::Model, var::AbstractArray{VariableRef}, LB, UB, base_name)
111111
112112
Disaggregate a variable block stored in an Array or DenseAxisArray.
113113
@@ -125,7 +125,7 @@ function add_disaggregated_variable(m::Model, var::VariableRef, LB, UB, base_nam
125125
base_name = base_name
126126
)
127127
end
128-
function add_disaggregated_variable(m::Model, var::AbstractArray, LB, UB, base_name)
128+
function add_disaggregated_variable(m::Model, var::AbstractArray{VariableRef}, LB, UB, base_name)
129129
idxs = Iterators.product(axes(var)...)
130130
var_i_array = [
131131
add_disaggregated_variable(m, var[idx...], LB[idx...], UB[idx...], "$base_name[$(join(idx,","))]")

src/reformulate.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ end
5454
5555
Reformulate a Tuple of constraints.
5656
57-
reformulate_constraint(constr::AbstractArray, bin_var, reformulation, param, i, j = missing)
57+
reformulate_constraint(constr::AbstractArray{<:ConstraintRef}, bin_var, reformulation, param, i, j = missing)
5858
5959
Reformulate a block of constraints.
6060
@@ -67,7 +67,7 @@ function reformulate_constraint(constr::Tuple, bin_var, reformulation, param, i)
6767
reformulate_constraint(constr_j, bin_var, reformulation, param, i, j)
6868
end
6969
end
70-
function reformulate_constraint(constr::AbstractArray, bin_var, reformulation, param, i, j = missing)
70+
function reformulate_constraint(constr::AbstractArray{<:ConstraintRef}, bin_var, reformulation, param, i, j = missing)
7171
for k in eachindex(constr)
7272
reformulate_constraint(constr[k], bin_var, reformulation, param, i, j, k)
7373
end
@@ -79,3 +79,4 @@ function reformulate_constraint(constr::ConstraintRef, bin_var, reformulation, p
7979
hull_reformulation!(constr, bin_var, param, i, j, k)
8080
end
8181
end
82+
reformulate_constraint(args...) = nothing

0 commit comments

Comments
 (0)