Skip to content

Commit

Permalink
Support AlternatingRTHS rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
ztangent committed Sep 22, 2024
1 parent ec6ed4f commit 21e851c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ NetworkLayout = "0.4.5"
OrderedCollections = "1"
PDDL = "0.2.13"
PlanningDomains = "0.1.3"
SymbolicPlanners = "0.1.24"
SymbolicPlanners = "0.1.26"
julia = "1.6"

[extras]
Expand Down
12 changes: 12 additions & 0 deletions src/animate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,15 @@ function add_anim_callback(planner::RTHS, cb::AnimSolveCallback)
planner.planner.callback = cb
return planner
end

function add_anim_callback(planner::AlternatingRTHS, cb::AnimSolveCallback)
# Set top-level callback
planner = copy(planner)
planner.callback = cb
# Set callback for internal forward-search planner
for subplanner in planner.planners
subplanner.planner = copy(subplanner.planner)
subplanner.planner.callback = cb
end
return planner
end
9 changes: 9 additions & 0 deletions src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,12 @@ function render_sol!(
trajectory = @lift PDDL.simulate(domain, $state, collect($sol))
return render_trajectory!(canvas, renderer, domain, trajectory; options...)
end

function render_sol!(
canvas::Canvas, renderer::Renderer,
domain::Domain, state::Observable, sol::Observable{<:MultiSolution};
options...
)
sol = @lift $sol.selector($sol.solutions, $state)
return render_sol!(canvas, renderer, domain, state, sol; options...)
end
10 changes: 10 additions & 0 deletions test/gridworld/doors_keys_gems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ new_state[pddl"(ypos)"] = 4
policy = refine!(policy, rths, domain, new_state, pddl"(has gem1)")
canvas = renderer(domain, new_state, policy, show_goal_tree=true)

# Render multi-solution
rths_bfs = RTHS(GoalCountHeuristic(), h_mult=0.0, max_nodes=10)
rths_astar = RTHS(GoalCountHeuristic(), h_mult=1.0, max_nodes=20)
arths = AlternatingRTHS(rths_bfs, rths_astar)
new_state = copy(state)
new_state[pddl"(xpos)"] = 4
new_state[pddl"(ypos)"] = 4
policy = arths(domain, new_state, pddl"(has gem1)")
canvas = renderer(domain, new_state, policy, show_goal_tree=false)

# Animate plan
plan = collect(sol)
anim = anim_plan(renderer, domain, state, plan; trail_length=10)
Expand Down

0 comments on commit 21e851c

Please sign in to comment.