From 93f578c29fbc1a53706a189cfc661a39b069ec61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Martinez=20Su=C3=B1=C3=A9?= <4691852+aemartinez@users.noreply.github.com> Date: Sat, 24 Aug 2024 19:11:10 +0100 Subject: [PATCH 1/3] Fix constraint checking in Forward, BreadthFirst, and Backward planners --- src/planners/backward.jl | 2 +- src/planners/bfs.jl | 2 +- src/planners/forward.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/planners/backward.jl b/src/planners/backward.jl index 5fc0500..556917d 100644 --- a/src/planners/backward.jl +++ b/src/planners/backward.jl @@ -221,7 +221,7 @@ function expand!( # Regress (reverse-execute) the action next_state = regress(domain, state, act; check=false) # Add constraints to regression state - add_constraints!(spec, domain, state) + add_constraints!(spec, domain, next_state) next_id = hash(next_state) # Compute path cost act_cost = get_cost(spec, domain, state, act, next_state) diff --git a/src/planners/bfs.jl b/src/planners/bfs.jl index 6a5e11a..b19b6e7 100644 --- a/src/planners/bfs.jl +++ b/src/planners/bfs.jl @@ -126,7 +126,7 @@ function expand!( # Skip if state has already been encountered if haskey(search_tree, next_id) continue end # Check if next state satisfies trajectory constraints - if is_violated(spec, domain, state) continue end + if is_violated(spec, domain, next_state) continue end # Update backpointer and add next state to queue path_cost = node.path_cost + 1 search_tree[next_id] = PathNode(next_id, next_state, path_cost, diff --git a/src/planners/forward.jl b/src/planners/forward.jl index 9792be2..f901ced 100644 --- a/src/planners/forward.jl +++ b/src/planners/forward.jl @@ -323,7 +323,7 @@ function expand!( next_state = transition(domain, state, act; check=false) next_id = hash(next_state) # Check if next state satisfies trajectory constraints - if is_violated(spec, domain, state) continue end + if is_violated(spec, domain, next_state) continue end # Compute path cost act_cost = get_cost(spec, domain, state, act, next_state) path_cost = node.path_cost + act_cost From 6126004f4ea515ac816695537706acc40e54b382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Martinez=20Su=C3=B1=C3=A9?= <4691852+aemartinez@users.noreply.github.com> Date: Tue, 27 Aug 2024 00:26:19 +0100 Subject: [PATCH 2/3] Check constraints on the initial state --- src/planners/backward.jl | 8 ++++++-- src/planners/bfs.jl | 8 ++++++-- src/planners/forward.jl | 13 +++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/planners/backward.jl b/src/planners/backward.jl index 556917d..030965f 100644 --- a/src/planners/backward.jl +++ b/src/planners/backward.jl @@ -148,8 +148,12 @@ function solve(planner::BackwardPlanner, search_order = UInt[] sol = PathSearchSolution(:in_progress, Term[], Vector{typeof(state)}(), 0, search_tree, queue, search_order) - # Run the search - sol = search!(sol, planner, planner.heuristic, domain, spec) + # Check if initial state satisfies trajectory constraints + if is_violated(spec, domain, state) + sol.status = :failure + else # Run the search + sol = search!(sol, planner, planner.heuristic, domain, spec) + end # Return solution if save_search return sol diff --git a/src/planners/bfs.jl b/src/planners/bfs.jl index b19b6e7..0b49d31 100644 --- a/src/planners/bfs.jl +++ b/src/planners/bfs.jl @@ -57,8 +57,12 @@ function solve(planner::BreadthFirstPlanner, search_order = UInt[] sol = PathSearchSolution(:in_progress, Term[], Vector{typeof(state)}(), 0, search_tree, queue, search_order) - # Run the search - sol = search!(sol, planner, domain, spec) + # Check if initial state satisfies trajectory constraints + if is_violated(spec, domain, state) + sol.status = :failure + else # Run the search + sol = search!(sol, planner, domain, spec) + end # Return solution if save_search return sol diff --git a/src/planners/forward.jl b/src/planners/forward.jl index f901ced..7e8f27d 100644 --- a/src/planners/forward.jl +++ b/src/planners/forward.jl @@ -206,8 +206,12 @@ function solve(planner::ForwardPlanner, precompute!(heuristic, domain, state, spec) # Initialize solution sol = init_sol(planner, heuristic, domain, state, spec) - # Run the search - sol = search!(sol, planner, heuristic, domain, spec) + # Check if initial state satisfies trajectory constraints + if is_violated(spec, domain, state) + sol.status = :failure + else # Run the search + sol = search!(sol, planner, heuristic, domain, spec) + end # Return solution if save_search return sol @@ -378,6 +382,11 @@ function refine!( # Decide between restarting, rerooting, or continuing the search if refine_method == :restart (sol.status == :failure && is_reached(state, sol)) && return sol + # Check if initial state satisfies trajectory constraints + if is_violated(spec, domain, state) + sol.status = :failure + return sol + end reinit_sol!(sol, planner, heuristic, domain, state, spec) elseif refine_method == :reroot reroot!(sol, planner, heuristic, domain, state, spec) From 92ec429505d638660e0e379c855829f9d3d02030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Martinez=20Su=C3=B1=C3=A9?= <4691852+aemartinez@users.noreply.github.com> Date: Tue, 27 Aug 2024 20:37:26 +0100 Subject: [PATCH 3/3] Document BackwardPlanner does not support constraints. --- src/planners/backward.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/planners/backward.jl b/src/planners/backward.jl index 030965f..f53002d 100644 --- a/src/planners/backward.jl +++ b/src/planners/backward.jl @@ -38,7 +38,8 @@ backward search. Returns a [`PathSearchSolution`](@ref) or [`NullSolution`](@ref), similar to [`ForwardPlanner`](@ref). -This planner does not currently support domains with non-Boolean fluents. +This planner does not currently support domains with non-Boolean fluents or +problems involving constraint specifications. [1] B. Bonet and H. Geffner, "Planning as Heuristic Search," Artificial Intelligence, vol. 129, no. 1, pp. 5–33, Jun. 2001,