From 43ef6553c4bb54d6ef598cf9da940391c78b1710 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Wed, 29 May 2024 12:09:01 -0400 Subject: [PATCH 1/2] add relative tolerance to BranchAndBoundEnclosure --- src/algorithms.jl | 3 ++- src/branchandbound.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/algorithms.jl b/src/algorithms.jl index 405b0a6f..663dcd00 100644 --- a/src/algorithms.jl +++ b/src/algorithms.jl @@ -195,5 +195,6 @@ julia> enclose(x -> -x^3/6 + 5x, 1..4, BranchAndBoundEnclosure(tol=1e-2); df=x-> """ Base.@kwdef struct BranchAndBoundEnclosure <: AbstractIterativeRangeAlgorithm maxdepth = 10 - tol = 1e-3 + atol = 1e-6 + rtol = 1e-3 end diff --git a/src/branchandbound.jl b/src/branchandbound.jl index 5baf54fd..aa73cc65 100644 --- a/src/branchandbound.jl +++ b/src/branchandbound.jl @@ -19,7 +19,7 @@ function _branch_bound(bab::BranchAndBoundEnclosure, f::Function, X::Interval_or fX = f(X) # TODO: allow user to choose how to evaluate this (mean value, natural enclosure) # if tolerance or maximum number of iteration is met, return current enclosure - if diam(fX) <= bab.tol || cnt == bab.maxdepth + if diam(fX) <= min(bab.atol, bab.rtol * minimum(fX)) || cnt == bab.maxdepth return hull(fX, initial) end From 0025c2ac67165993a4d190c50529f246f8fdfdff Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Wed, 29 May 2024 17:26:05 -0400 Subject: [PATCH 2/2] fix --- src/branchandbound.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/branchandbound.jl b/src/branchandbound.jl index aa73cc65..a46a6de1 100644 --- a/src/branchandbound.jl +++ b/src/branchandbound.jl @@ -19,7 +19,8 @@ function _branch_bound(bab::BranchAndBoundEnclosure, f::Function, X::Interval_or fX = f(X) # TODO: allow user to choose how to evaluate this (mean value, natural enclosure) # if tolerance or maximum number of iteration is met, return current enclosure - if diam(fX) <= min(bab.atol, bab.rtol * minimum(fX)) || cnt == bab.maxdepth + min_abs = in_interval(0, fX) ? zero(fX.lo) : min(abs(fX.lo), abs(fX.hi)) + if diam(fX) <= max(bab.atol, bab.rtol * min_abs) || cnt == bab.maxdepth return hull(fX, initial) end