Skip to content

Commit

Permalink
Merge pull request #6 from Wu-Chenyang/main
Browse files Browse the repository at this point in the history
fix `timeout` and add `timer`
  • Loading branch information
Wu-Chenyang authored Mar 20, 2022
2 parents e8593eb + 64dc6f2 commit 582d687
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/AdaOPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ parameters match the definitions in the paper exactly.
Further information can be found in the field docstrings (e.g.
`?AdaOPSSolver.xi`)
"""
@with_kw struct AdaOPSSolver{N, R<:AbstractRNG} <: Solver
@with_kw struct AdaOPSSolver{N, R<:AbstractRNG, T} <: Solver
"The target gap between the upper and the lower bound at the root of the AdaOPS tree."
epsilon_0::Float64 = 1e-3

Expand Down Expand Up @@ -140,7 +140,12 @@ Further information can be found in the field docstrings (e.g.
tree_in_info::Bool = false

"Issue an warning when the planning time surpass the time limit by `timeout_warning_threshold` times"
timeout_warning_threshold::Float64 = T_max * 2.0
timeout_warning_threshold::Float64 = T_max * 2.0

"Search iterations end when `timer() - start_time ≥ T_max`.
Default to `() -> 1e-9*time_ns()`, which gets the current system time.
Switch to `() -> 1e-6*CPUtime_us()` when the CPU time is concerned."
timer::T = () -> 1e-9*time_ns()

"Number of pre-allocated belief nodes"
num_b::Int = 50_000
Expand Down
8 changes: 4 additions & 4 deletions src/planner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ function build_tree(p::AdaOPSPlanner, b0)
D = AdaOPSTree(p, b0)
b = 1
trial = 1
start = CPUtime_us()

Depth = sizehint!(Int[], 2000)
sol = solver(p)
start = sol.timer()
while D.u[1]-D.l[1] > sol.epsilon_0 &&
CPUtime_us()-start < sol.T_max*1e6 &&
sol.timer()-start < sol.T_max &&
trial <= sol.max_trials
push!(Depth, explore!(D, 1, p))
trial += 1
end
if (CPUtime_us()-start)*1e-6 > sol.T_max*sol.timeout_warning_threshold
if sol.timer()-start > sol.timeout_warning_threshold
@warn(@sprintf("Surpass the time limit. The actual runtime is %3.1fs.
Hyperparameters: delta=%4.2f, m_min=%3d, m_max=%3d, zeta=%4.2f, grid=%s, bounds=%s",
(CPUtime_us()-start)*1e-6, sol.delta, sol.m_min, sol.m_max, sol.zeta, typeof(sol.grid), typeof(sol.bounds)))
sol.timer()-start, sol.delta, sol.m_min, sol.m_max, sol.zeta, typeof(sol.grid), typeof(sol.bounds)))
info_analysis(Dict(:tree=>D, :depth=>Depth))
end
return D, Depth
Expand Down

0 comments on commit 582d687

Please sign in to comment.