Skip to content

Commit

Permalink
Add reachability / fail-fast check to planners.
Browse files Browse the repository at this point in the history
  • Loading branch information
ztangent committed Nov 3, 2023
1 parent fedb439 commit 4154d91
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/planners/backward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export ProbBackwardPlanner, ProbBackwardAStarPlanner
h_mult::Float32 = 1.0f0,
max_nodes::Int = typemax(Int),
max_time::Float64 = Inf,
fail_fast::Bool = false,
save_search::Bool = false,
save_search_order::Bool = save_search,
verbose::Bool = false,
Expand Down Expand Up @@ -60,6 +61,8 @@ $(FIELDS)
max_nodes::Int = typemax(Int)
"Maximum time in seconds before planner times out."
max_time::Float64 = Inf
"Flag to terminate search if the heuristic estimates an infinite cost."
fail_fast::Bool = false
"Flag to save the search tree and frontier in the returned solution."
save_search::Bool = false
"Flag to save the node expansion order in the returned solution."
Expand Down Expand Up @@ -120,7 +123,7 @@ ProbBackwardAStarPlanner(heuristic::Heuristic; search_noise=1.0, kwargs...) =
function Base.copy(p::BackwardPlanner)
return BackwardPlanner(p.heuristic, p.search_noise,
p.g_mult, p.h_mult, p.max_nodes, p.max_time,
p.save_search, p.save_search_order,
p.fail_fast, p.save_search, p.save_search_order,
p.verbose, p.callback)
end

Expand Down Expand Up @@ -173,6 +176,9 @@ function search!(sol::PathSearchSolution, planner::BackwardPlanner,
sol.status = :max_nodes # Node budget reached
elseif time() - start_time >= planner.max_time
sol.status = :max_time # Time budget reached
elseif planner.fail_fast && priority[1] == Inf
sol.status = :failure # Search space exhausted
break
end
if sol.status == :in_progress
# Dequeue current node
Expand Down
8 changes: 7 additions & 1 deletion src/planners/forward.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export ProbForwardPlanner, ProbAStarPlanner
h_mult::Float32 = 1.0f0,
max_nodes::Int = typemax(Int),
max_time::Float64 = Inf,
fail_fast::Bool = false,
save_search::Bool = false,
save_search_order::Bool = save_search,
verbose::Bool = false,
Expand Down Expand Up @@ -54,6 +55,8 @@ $(FIELDS)
max_nodes::Int = typemax(Int)
"Maximum time in seconds before planner times out."
max_time::Float64 = Inf
"Flag to terminate search if the heuristic estimates an infinite cost."
fail_fast::Bool = false
"Flag to save the search tree and frontier in the returned solution."
save_search::Bool = false
"Flag to save the node expansion order in the returned solution."
Expand Down Expand Up @@ -154,7 +157,7 @@ ProbAStarPlanner(heuristic::Heuristic; search_noise=1.0, kwargs...) =
function Base.copy(p::ForwardPlanner)
return ForwardPlanner(p.heuristic, p.search_noise,
p.g_mult, p.h_mult, p.max_nodes, p.max_time,
p.save_search, p.save_search_order,
p.fail_fast, p.save_search, p.save_search_order,
p.verbose, p.callback)
end

Expand Down Expand Up @@ -204,6 +207,9 @@ function search!(sol::PathSearchSolution, planner::ForwardPlanner,
sol.status = :max_nodes # Node budget reached
elseif time() - start_time >= planner.max_time
sol.status = :max_time # Time budget reached
elseif planner.fail_fast && priority[1] == Inf
sol.status = :failure # Search space exhausted
break
end
if sol.status == :in_progress
# Dequeue current node
Expand Down

0 comments on commit 4154d91

Please sign in to comment.