Skip to content

Commit

Permalink
Support Update for Nonvalidated Interval Calcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Unknown committed Apr 1, 2018
1 parent 857e010 commit 9ee8900
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 83 deletions.
15 changes: 9 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
language: julia
os:
- linux
- osx
- osx #build never started in travis CI, will trouble shoot later
julia:
- 0.6
- 0.6 # will add nightly later
- nightly
notifications:
email: false
git:
depth: 99999999

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
#matrix:
# allow_failures:
# - julia: nightly

matrix:
allow_failures:
- osx: v0.6
- osx: nightly
- julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
# apt: # apt-get for linux
Expand Down
4 changes: 3 additions & 1 deletion src/EAGOBranchBound.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
module EAGOBranchBound

using IntervalArithmetic: Interval, diam
using IntervalRootFinding: bisect
using EAGOIntervalArithmetic: MCInterval, diam

import IntervalRootFinding.bisect

export BnBSolver, BnBModel, set_Branch_Scheme!, set_Bisect_Func!,
set_Verbosity!, set_to_default!, solveBnB!, getsolution, getobjval,
Expand Down
38 changes: 22 additions & 16 deletions src/src/schemes/Bisect_Method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
Returns two interval boxes 'X1,X2' created by bisecting 'N' in the highest width dimension.
"""
function Bisect_Abs(S::BnBSolver,B::BnBModel,N::Vector{Interval{Float64}})

function bisect(X::MCInterval)
m = mid(X)
return (MCInterval(X.lo, m), MCInterval(m, X.hi))
end

function Bisect_Abs(S::BnBSolver,B::BnBModel{T},N::Vector{T}) where {T}
i::Int64 = indmax(diam.(N))
N1::Interval{Float64},N2::Interval{Float64} = bisect(N[i])
X1::Vector{Interval{Float64}} = deepcopy(N)
X2::Vector{Interval{Float64}} = deepcopy(N)
N1::T,N2::T = bisect(N[i])
X1::Vector{T} = deepcopy(N)
X2::Vector{T} = deepcopy(N)
X1[i] = N1
X2[i] = N2
return X1,X2
Expand All @@ -18,11 +24,11 @@ end
Returns two interval boxes 'X1,X2' created by bisecting 'N' in the highest width dimension after scaling by initial box size.
"""
function Bisect_Rel(S::BnBSolver,B::BnBModel,N::Vector{Interval{Float64}})
function Bisect_Rel(S::BnBSolver,B::BnBModel{T},N::Vector{T}) where {T}
i::Int64 = indmax(diam.(N)./diam.(B.Init_Box))
N1::Interval{Float64},N2::Interval{Float64} = bisect(N[i])
X1::Vector{Interval{Float64}} = deepcopy(N)
X2::Vector{Interval{Float64}} = deepcopy(N)
N1::T,N2::T = bisect(N[i])
X1::Vector{T} = deepcopy(N)
X2::Vector{T} = deepcopy(N)
X1[i] = N1
X2[i] = N2
return X1,X2
Expand All @@ -34,11 +40,11 @@ end
Returns two interval boxes 'X1,X2' created by bisecting 'N' in the highest width
dimension greater than 'nx'.
"""
function Bisect_Abs_Imp(S::BnBSolver,B::BnBModel,N::Vector{Interval{Float64}},nx::Int64)
function Bisect_Abs_Imp(S::BnBSolver,B::BnBModel{T},N::Vector{T},nx::Int64) where {T}
i::Int64 = indmax(diam.(N[(nx+1):end]))
N1::Interval{Float64},N2::Interval{Float64} = bisect(N[nx+i])
X1::Vector{Interval{Float64}} = deepcopy(N)
X2::Vector{Interval{Float64}} = deepcopy(N)
N1::T,N2::T = bisect(N[nx+i])
X1::Vector{T} = deepcopy(N)
X2::Vector{T} = deepcopy(N)
X1[nx+i] = N1
X2[nx+i] = N2
return X1,X2
Expand All @@ -50,11 +56,11 @@ end
Returns two interval boxes 'X1,X2' created by bisecting 'N' in the highest width
dimension greater than 'nx' after scaling by initial box size.
"""
function Bisect_Rel_Imp(S::BnBSolver,B::BnBModel,N::Vector{Interval{Float64}},nx::Int64)
function Bisect_Rel_Imp(S::BnBSolver,B::BnBModel{T},N::Vector{T},nx::Int64) where {T}
i::Int64 = indmax(diam.(N[(nx+1):end])./diam.(B.Init_Box[(nx+1):end]))
N1::Interval{Float64},N2::Interval{Float64} = bisect(N[nx+i])
X1::Vector{Interval{Float64}} = deepcopy(N)
X2::Vector{Interval{Float64}} = deepcopy(N)
N1::T,N2::T = bisect(N[nx+i])
X1::Vector{T} = deepcopy(N)
X2::Vector{T} = deepcopy(N)
X1[nx+i] = N1
X2[nx+i] = N2
return X1,X2
Expand Down
17 changes: 8 additions & 9 deletions src/src/schemes/Branch_Method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Stores two interval boxes `X1,X2` to the bottom of the stack along with their
respective lower, `tL` and upper bounds, `tU` and their position number in the
BnB tree. Also, assigns node numbers.
"""
function BM_breadth!(S::BnBSolver,B::BnBModel,tL::Float64,tU::Float64,
X1::Vector{Interval{Float64}},
X2::Vector{Interval{Float64}},pos::Int64)
function BM_breadth!(S::BnBSolver,B::BnBModel{T},tL::Float64,tU::Float64,
X1::Vector{T},
X2::Vector{T},pos::Int64) where {T}
unshift!(B.box,X1,X2)
unshift!(B.LBD,tL,tL)
unshift!(B.UBD,tU,tU)
Expand All @@ -27,9 +27,9 @@ Stores two interval boxes `X1,X2` to the top of the stack along with their
respective lower, `tL` and upper bounds, `tU` and their position number in the
BnB tree. Also, assigns node numbers.
"""
function BM_depth_best!(S::BnBSolver,B::BnBModel,tL::Float64,tU::Float64,
X1::Vector{Interval{Float64}},
X2::Vector{Interval{Float64}},pos::Int64)
function BM_depth_best!(S::BnBSolver,B::BnBModel{T},tL::Float64,tU::Float64,
X1::Vector{T},
X2::Vector{T},pos::Int64) where {T}
push!(B.box,X1,X2)
push!(B.LBD,tL,tL)
push!(B.UBD,tU,tU)
Expand All @@ -38,7 +38,6 @@ function BM_depth_best!(S::BnBSolver,B::BnBModel,tL::Float64,tU::Float64,
B.max_id += 2
end


"""
BM_Single!(S::BnBSolver,B::BnBModel,tL::Float64,tU::Float64,
X::Vector{Interval{Float64}},pos::Int64)
Expand All @@ -47,8 +46,8 @@ Stores interval box `X` to the top of the stack along with their
respective lower, `tL` and upper bounds, `tU` and their position number in the
BnB tree.
"""
function BM_Single!(S::BnBSolver,B::BnBModel,tL::Float64,tU::Float64,
X::Vector{Interval{Float64}},pos::Int64)
function BM_Single!(S::BnBSolver,B::BnBModel{T},tL::Float64,tU::Float64,
X::Vector{T},pos::Int64) where {T}
push!(B.box,X)
push!(B.LBD,tL)
push!(B.UBD,tU)
Expand Down
14 changes: 8 additions & 6 deletions src/src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ function solveBnB!(x::BnBSolver,y::BnBModel)
pos1 = copy(pos)
xopt1 = copy(x.opt)
x.Preprocess(feas_Pre,nsBox1,yUBDg1,kint1,pos1,xopt1,LBDn,UBDn,x,y)
#println("preprocess-check")
LBD_valt, LBD_solt, LBD_feast, temp_objtL = x.Lower_Prob(nsBox1,kint1,pos1,xopt1,yUBDg1)
#println("lower-check")
println("preprocess-check")
BD_valt, LBD_solt, LBD_feast, temp_objtL = x.Lower_Prob(nsBox1,kint1,pos1,xopt1,yUBDg1)
println("lower-check")
UBD_valt, UBD_solt, UBD_feast, temp_objtU = x.Upper_Prob(nsBox1,kint1,pos1,xopt1,yUBDg1)
#println("upper-check")
println("upper-check")
x.Postprocess(feas_Post,nsBox1,kint1,pos1,xopt1,
temp_objtL,temp_objtU,yLBDg1,yUBDg1)
#println("postprocess-check")
println("postprocess-check")
end
feas_Pre = true
feas_Post = true
Expand All @@ -63,10 +63,12 @@ function solveBnB!(x::BnBSolver,y::BnBModel)

# checks for infeasibility stores solution
if (LBD_feas)

println("ran LBD feas")
println("boolean: $(x.converged(x,y.UBDg,LBD_val))")
if (~x.converged(x,y.UBDg,LBD_val))

# solves & times upper bounding problem
println("ran Upper bound")
tic()
UBD_val,UBD_sol,UBD_feas,temp_objU = x.Upper_Prob(nsBox,k_int,pos,x.opt,y.UBDg)
push!(y.UBDgtime,y.UBDgtime[end]+toq())
Expand Down
62 changes: 31 additions & 31 deletions src/src/types/BnBModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ Stores attributes of stack used to solve BnB problem. Has the following fields:
* `lbcnt::Int64`: number of lower bounding problems solved
* `ubcnt::Int64`: number of upper bounding problems solved
"""
mutable struct BnBModel
Init_Box::Vector{Interval{Float64}}
box::Vector{Vector{Interval{Float64}}} # interval box stack
mutable struct BnBModel{V}
Init_Box::Vector{V}
box::Vector{Vector{V}} # interval box stack
Init_Integer::Vector{Vector{Int64}}
integers::Vector{Vector{Vector{Int64}}}
LBD::Vector{Float64} # lower bounds associated with each stack
Expand All @@ -46,7 +46,7 @@ mutable struct BnBModel
Pretime::Vector{Float64} # Run time history LBD problem
Posttime::Vector{Float64} # Run time history UBD problem
max_id::Int64 # Max node used
pstar::Vector{Interval{Float64}}
pstar::Vector{V}
soln::Vector{Float64}
soln_val::Float64
first_fnd::Bool
Expand All @@ -62,30 +62,30 @@ end
Initializes a `BnBModel` with `.Init_Box` = `X` and `.box` = `[X]`.
"""
BnBModel(X::Vector{Interval{Float64}}) = BnBModel(deepcopy(X),
[deepcopy(X)],
[[1]],
[[[1]]],
[-Inf],
[Inf],
[1],
[1],
-Inf,
Inf,
[-Inf],
[Inf],
[0.0],
[0.0],
[0.0],
[0,0],
1,
deepcopy(X),
[0.0],
Inf,
false,
false,
-1,
0,
0,
Inf)
BnBModel() = BnBModel([Interval(0,1)])
BnBModel(X::Vector{V}) where {V} = BnBModel{V}(deepcopy(X),
[deepcopy(X)],
[[1]],
[[[1]]],
[-Inf],
[Inf],
[1],
[1],
-Inf,
Inf,
[-Inf],
[Inf],
[0.0],
[0.0],
[0.0],
[0,0],
1,
deepcopy(X),
[0.0],
Inf,
false,
false,
-1,
0,
0,
Inf)
#BnBModel() = BnBModel{MCInterval{Float64}}([MCInterval(0.0,1.0)])
14 changes: 10 additions & 4 deletions src/src/utils/Checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Checks that:
Outputs a description of termination check if it returns false.
"""
function Conv_Check(x::BnBSolver,ubd::Float64,lbd::Float64)
return (((ubd-lbd) <= x.BnB_atol) || ((ubd-lbd) <= abs(lbd)*x.BnB_rtol))
return ((abs(ubd-lbd) <= x.BnB_atol) || (abs(ubd-lbd)/(min(abs(lbd),abs(ubd))) <= x.BnB_rtol))
end

"""
Expand All @@ -59,8 +59,14 @@ end
Default check for repeating a node. Always returns false.
"""
function Repeat_Node_Default(x::BnBSolver,y::BnBModel,
Xin::Vector{Interval{Float64}},
Xout::Vector{Interval{Float64}})
function Repeat_Node_Default(x::BnBSolver,y::BnBModel{Interval{T}},
Xin::Vector{Interval{T}},
Xout::Vector{Interval{T}}) where {T<:AbstractFloat}
return false
end

function Repeat_Node_Default(x::BnBSolver,y::BnBModel{MCInterval{T}},
Xin::Vector{MCInterval{T}},
Xout::Vector{MCInterval{T}}) where {T<:AbstractFloat}
return false
end
11 changes: 9 additions & 2 deletions src/src/utils/Display.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ end
Prints node information for the B&B problem. Node id, bound, and interval box.
"""
function print_node!(x::BnBSolver,id::Int64,lbd::Float64,
box::Vector{Interval{Float64}})
box::Vector{Interval{V}}) where {V<:AbstractFloat}
if (x.Verbosity == "Full")
println("Node ID: $(id), Lower Bound: $(lbd), IntervalBox: $(box)")
end
end

function print_node!(x::BnBSolver,id::Int64,lbd::Float64,
box::Vector{MCInterval{V}}) where {V<:AbstractFloat}
if (x.Verbosity == "Full")
println("Node ID: $(id), Lower Bound: $(lbd), IntervalBox: $(box)")
end
Expand All @@ -55,7 +62,7 @@ function print_int!(B::BnBSolver,k_int::Int64,k_nod::Int64,
sbool1 = feasL ? "true" : "false"
sbool2 = feasU ? "true" : "false"
if ((mod(k_int,B.itr_intv)==0))
ptr_arr_temp = [k_int nid lbdp lbd ubd k_nod (ubd-lbd) (ubd-lbd)/abs(lbd) sbool1 sbool2]
ptr_arr_temp = [k_int nid lbdp lbd ubd k_nod abs(ubd-lbd) abs(ubd-lbd)/(min(abs(lbd),abs(ubd))) sbool1 sbool2]
ptr_arr1 = join([@sprintf("%6u",x) for x in ptr_arr_temp[1:2]], ", ")
ptr_arr2 = join([@sprintf("%3.7f",x) for x in ptr_arr_temp[3:5]], ", ")
ptr_arr3 = join([@sprintf("%6u",x) for x in ptr_arr_temp[6:6]], ",")
Expand Down
19 changes: 15 additions & 4 deletions src/src/utils/Processing.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
function default_pre(feas::Bool,X::Vector{Interval{Float64}},UBD::Float64,
function default_pre(feas::Bool,X::Vector{Interval{T}},UBD::Float64,
k::Int64,pos::Int64,opt,LBDn::Float64,UBDn::Float64,x::BnBSolver,
y::BnBModel)
y::BnBModel{Interval{T}}) where {T<:AbstractFloat}
return feas,X
end

function default_post(feas::Bool,X::Vector{Interval{Float64}},k::Int64,
pos::Int64,opt,tempL,tempU,LBD,UBD)
function default_pre(feas::Bool,X::Vector{MCInterval{T}},UBD::Float64,
k::Int64,pos::Int64,opt,LBDn::Float64,UBDn::Float64,x::BnBSolver,
y::BnBModel{MCInterval{T}}) where {T<:AbstractFloat}
return feas,X
end

function default_post(feas::Bool,X::Vector{Interval{T}},k::Int64,
pos::Int64,opt,tempL,tempU,LBD,UBD) where {T<:AbstractFloat}
return feas,X
end

function default_post(feas::Bool,X::Vector{MCInterval{T}},k::Int64,
pos::Int64,opt,tempL,tempU,LBD,UBD) where {T<:AbstractFloat}
return feas,X
end
4 changes: 2 additions & 2 deletions src/src/utils/Set_Options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function set_Bisect_Func!(x::BnBSolver,BF::String,nx::Int64)
end
else
if (BF == "relative midpoint")
x.Bisect_Func = (S::BnBSolver,B::BnBModel,N::Vector{Interval{Float64}}) -> Bisect_Rel_Imp(S,B,N,nx)
x.Bisect_Func = (S::BnBSolver,B::BnBModel,N) -> Bisect_Rel_Imp(S,B,N,nx)
elseif (BF == "absolute midpoint")
x.Bisect_Func = (S::BnBSolver,B::BnBModel,N::Vector{Interval{Float64}}) -> Bisect_Abs_Imp(S,B,N,nx)
x.Bisect_Func = (S::BnBSolver,B::BnBModel,N) -> Bisect_Abs_Imp(S,B,N,nx)
else
error("Invalid bisection method")
end
Expand Down
4 changes: 2 additions & 2 deletions test/Access_Tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using EAGOBranchBound

S = BnBSolver()
B = BnBModel([Interval(1.0,2.0)])
B1 = BnBModel()
#B1 = BnBModel()
tL = 3.0
tU = 5.0
X1 = [Interval(1.0,2.0)]
Expand All @@ -19,7 +19,7 @@ EAGOBranchBound.BM_Single!(S,B,tL,tU,X,pos)
B.soln = [7.0]
B.UBDg = 14.7

@test B1.Init_Box == [Interval(0,1)]
#@test B1.Init_Box == [Interval(0,1)]
@test getsolution(B) == [7.0]
@test getobjval(B) == 14.7
@test getobjbound(B) == 14.7
Expand Down

0 comments on commit 9ee8900

Please sign in to comment.