Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hdavid16 committed May 11, 2022
1 parent 45de93c commit 2a0b37a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DisjunctiveProgramming"
uuid = "0d27d021-0159-4c7d-b4a7-9ccb5d9366cf"
authors = ["hdavid16 <[email protected]>"]
version = "0.2.0"
version = "0.2.1"

[deps]
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
Expand Down
4 changes: 2 additions & 2 deletions src/bigm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Perform Big-M reformulation on a linear or quadratic constraint at index k of co
Perform Big-M reformulaiton on a nonlinear constraint at index k of constraint j in disjunct i.
big_m_reformulation!(constr::AbstractArray, bin_var, M, i, j, k)
big_m_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, M, i, j, k)
Perform Big-M reformulation on a constraint at index k of constraint j in disjunct i.
"""
Expand Down Expand Up @@ -36,5 +36,5 @@ function big_m_reformulation!(constr::NonlinearConstraintRef, bin_var, M, i, j,
#update constraint
replace_constraint(constr, gx, op, rhs)
end
big_m_reformulation!(constr::AbstractArray, bin_var, M, i, j, k) =
big_m_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, M, i, j, k) =
big_m_reformulation(constr[k], bin_var, M, i, j, k)
20 changes: 4 additions & 16 deletions src/bounds.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,13 @@ end
Get bounds on a variable.
get_bounds(var::VariableRef, bounds_dict::Dict)
get_bounds(var, bounds_dict::Dict)
Get bounds on a variable. Check if a bounds dictionary has ben provided with bounds for that value.
Get bounds on a variable. Check if a bounds dictionary has been provided with bounds for that value.
get_bounds(var::AbstractArray, bounds_dict::Dict, LB, UB)
get_bounds(var::AbstractArray{VariableRef}, bounds_dict::Dict, LB, UB)
Update lower bound `LB` and upper bound `UB` on a variable container.
get_bounds(var::Array{VariableRef}, bounds_dict::Dict)
Get lower and upper bounds on a variable array.
get_bounds(var::Containers.DenseAxisArray, bounds_dict::Dict)
Get lower and upper bounds on a variable DenseAxisArray.
get_gounds(var::Containers.SparseAxisArray, bounds_dict::Dict)
Get lower and upper bounds on a variable SparseAxisArray.
"""
function get_bounds(var::VariableRef)
LB = has_lower_bound(var) ? lower_bound(var) : (is_binary(var) ? 0 : -Inf)
Expand All @@ -62,7 +50,7 @@ function get_bounds(var::VariableRef, bounds_dict::Dict)
return get_bounds(var)
end
end
function get_bounds(var::AbstractArray, bounds_dict::Dict, LB, UB)
function get_bounds(var::AbstractArray{VariableRef}, bounds_dict::Dict, LB, UB)
#populate UB and LB
for idx in eachindex(var)
LB[idx], UB[idx] = get_bounds(var[idx], bounds_dict)
Expand Down
37 changes: 14 additions & 23 deletions src/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,14 @@ JuMP.name(con_ref::NonlinearConstraintRef) = ""
Check constraints in a disjunction Tuple.
check_constraint!(m::Model, constr_j::Union{Tuple,Array}, constr_list::Vector)
check_constraint!(m::Model, constr_j, constr_list::Vector)
Check constraints in a nested Tuple or Array of constraints and update `constr_list`.
Check nested constraint and update `constr_list`.
check_constraint!(m::Model, constr_j::ConstraintRef, constr_list::Vector)
Check constraint `constr_j` in position `j` of a disjunct and update `constr_list`.
check_constraint!(m::Model, constr::ConstraintRef)
check_constraint!(m::Model, constr)
Check constraint in a Model.
check_constraint!(m::Model, constr::AbstractArray)
Check constraint block in a model.
check_constraint!(m::Model, constr::Nothing)
Return nothing for an empty disjunct.
Expand All @@ -34,9 +26,12 @@ function check_constraint!(m::Model, constr::Tuple)
map(constr_j -> check_constraint!(m, constr_j, constr_list), constr)
return Tuple(constr_list)
end
function check_constraint!(m::Model, constr_j::Union{Tuple,Array}, constr_list::Vector)
function check_constraint!(m::Model, constr_j::Tuple, constr_list::Vector)
map(constr_jk -> check_constraint!(m, constr_jk, constr_list), constr_j)
end
function check_constraint!(m::Model, constr_j::AbstractArray{<:ConstraintRef}, constr_list::Vector)
push!(constr_list, check_constraint!(m, constr_j))
end
function check_constraint!(m::Model, constr_j::ConstraintRef, constr_list::Vector)
push!(constr_list, check_constraint!(m, constr_j))
end
Expand All @@ -54,7 +49,7 @@ function check_constraint!(m::Model, constr::ConstraintRef)
end
return new_constr
end
function check_constraint!(m::Model, constr::AbstractArray)
function check_constraint!(m::Model, constr::AbstractArray{<:ConstraintRef})
@assert all(is_valid.(m, constr)) "$constr is not a valid constraint."
if !any(is_interval_constraint.(constr)) && !any(is_equality_constraint.(constr))
new_constr = constr
Expand Down Expand Up @@ -87,19 +82,15 @@ Split a nonlinear constraint that is an Interval or EqualTo constraint.
split_constraint(m::Model, constr::ConstraintRef, constr_name::String = name(constr))
Split a linear or quadratic constraint that is MOI.Interval or MOI.EqualTo.
Split a linear or quadratic constraint.
split_constraint(m::Model, func::Union{AffExpr,QuadExpr}, lb::Float64, ub::Float64, lb_name::String, ub_name::String)
Create split constraint for linear or quadratic constraint.
split_constraint(m::Model, constr_obj::ScalarConstraint, lb_name::String, ub_name::String)
split_constraint(m::Model, constr_obj::ScalarConstraint{T,<:MOI.EqualTo}, lb_name::String, ub_name::String)
Split a constraint that is a MOI.EqualTo or MOI.Interval.
Split a constraint that is a MOI.EqualTo.
split_constraint(m::Model, constr_obj::ScalarConstraint{T,<:MOI.Interval}, lb_name::String, ub_name::String)
split_constraint(m::Model, func::Union{AffExpr,QuadExpr}, lb::Float64, ub::Float64, lb_name::String, ub_name::String)
Split a constraint that is a MOI.Interval
Create split constraint for linear or quadratic constraint.
split_constraint(m::Model, constr::ConstraintRef, constr_func_expr::Expr, lb::Float64, ub::Float64)
Expand Down Expand Up @@ -168,7 +159,7 @@ split_constraint(args...) = nothing

delete_original_constraint!(m::Model, constr::ConstraintRef) = delete(m,constr)
delete_original_constraint!(m::Model, constr::NonlinearConstraintRef) = nothing
delete_original_constraint!(m::Model, constr::AbstractArray) = map(c -> delete_original_constraint!(m,c), constr)
delete_original_constraint!(m::Model, constr::AbstractArray{<:ConstraintRef}) = map(c -> delete_original_constraint!(m,c), constr)

"""
parse_constraint(constr::ConstraintRef)
Expand Down
8 changes: 4 additions & 4 deletions src/hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Apply the hull reformulation to a linear constraint.
Apply the hull reformulation to a nonlinear constraint (includes quadratic) at index k of constraint j in disjunct i.
hull_reformulation!(constr::AbstractArray, bin_var, eps, i, j, k)
hull_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, eps, i, j, k)
Call the hull reformulation on a constraint at index k of constraint j in disjunct i.
"""
Expand Down Expand Up @@ -68,7 +68,7 @@ function hull_reformulation!(constr::ConstraintRef, bin_var, eps, i, j, k)
pers_func = simplify(pers_func)
replace_constraint(constr, pers_func, op, rhs)
end
hull_reformulation!(constr::AbstractArray, bin_var, eps, i, j, k) =
hull_reformulation!(constr::AbstractArray{<:ConstraintRef}, bin_var, eps, i, j, k) =
hull_reformulation!(constr[k], bin_var, eps, i, j, k)

"""
Expand Down Expand Up @@ -107,7 +107,7 @@ end
Disaggreagate a variable with lower bound `LB`, upper bound `UB`, and name `base_name`.
add_disaggregated_variable(m::Model, var::AbstractArray, LB, UB, base_name)
add_disaggregated_variable(m::Model, var::AbstractArray{VariableRef}, LB, UB, base_name)
Disaggregate a variable block stored in an Array or DenseAxisArray.
Expand All @@ -125,7 +125,7 @@ function add_disaggregated_variable(m::Model, var::VariableRef, LB, UB, base_nam
base_name = base_name
)
end
function add_disaggregated_variable(m::Model, var::AbstractArray, LB, UB, base_name)
function add_disaggregated_variable(m::Model, var::AbstractArray{VariableRef}, LB, UB, base_name)
idxs = Iterators.product(axes(var)...)
var_i_array = [
add_disaggregated_variable(m, var[idx...], LB[idx...], UB[idx...], "$base_name[$(join(idx,","))]")
Expand Down
5 changes: 3 additions & 2 deletions src/reformulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
Reformulate a Tuple of constraints.
reformulate_constraint(constr::AbstractArray, bin_var, reformulation, param, i, j = missing)
reformulate_constraint(constr::AbstractArray{<:ConstraintRef}, bin_var, reformulation, param, i, j = missing)
Reformulate a block of constraints.
Expand All @@ -67,7 +67,7 @@ function reformulate_constraint(constr::Tuple, bin_var, reformulation, param, i)
reformulate_constraint(constr_j, bin_var, reformulation, param, i, j)
end
end
function reformulate_constraint(constr::AbstractArray, bin_var, reformulation, param, i, j = missing)
function reformulate_constraint(constr::AbstractArray{<:ConstraintRef}, bin_var, reformulation, param, i, j = missing)
for k in eachindex(constr)
reformulate_constraint(constr[k], bin_var, reformulation, param, i, j, k)
end
Expand All @@ -79,3 +79,4 @@ function reformulate_constraint(constr::ConstraintRef, bin_var, reformulation, p
hull_reformulation!(constr, bin_var, param, i, j, k)
end
end
reformulate_constraint(args...) = nothing

2 comments on commit 2a0b37a

@hdavid16
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60045

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 2a0b37a078d7b711cc92cc2285c782acc5faa5f5
git push origin v0.2.1

Please sign in to comment.