pub struct SasProblem<'a> { /* private fields */ }Expand description
A Task viewed as a WidthProblem: one feature per fact var = value,
and the number of unsatisfied goal facts as #g.
Implementations§
Source§impl<'a> SasProblem<'a>
impl<'a> SasProblem<'a>
Sourcepub fn h_add(&self, state: &State) -> Option<u64>
pub fn h_add(&self, state: &State) -> Option<u64>
The additive heuristic h_add of state: the sum, over all goal facts,
of the cheapest delete-relaxed cost of reaching that fact.
Each fact true in state costs 0. A fact made true by a rule costs the
rule’s cost plus the sum of its conditions’ costs, minimised over all
rules. Operator effects become rules with the operator’s precondition
and the effect’s conditions; axioms become rules of cost 0. Derived
variables are read from state as given, so pass a state with axioms
evaluated, such as one from Task::initial_state or Task::apply.
Returns None when some goal fact is unreachable even under the delete
relaxation. On tasks without axioms this proves state a dead end.
With axioms it may not: no rule makes a derived variable’s default
value true, so a default that does not hold in state is unreachable.
h_add is not admissible: shared subgoals are counted once per goal
fact that needs them. The value saturates at u64::MAX instead of
overflowing.
These are the costs whose best supporters
RelaxedPlan::relaxed_plan_features extracts its relaxed plan from.
§Examples
Picking up a key (cost 2) and then opening a door with it (cost 3), with both “holding the key” and “door open” as goals:
use sas_plus::{Effect, Fact, Operator, State, Task, Variable};
use width_search::sas::SasProblem;
let task = Task {
variables: vec![Variable::new("key", 2), Variable::new("door", 2)],
operators: vec![
Operator {
name: "pick-up-key".into(),
pre: vec![],
eff: vec![Effect::new(Fact::new(0, 1))],
cost: 2,
},
Operator {
name: "open-door".into(),
pre: vec![Fact::new(0, 1)],
eff: vec![Effect::new(Fact::new(1, 1))],
cost: 3,
},
],
initial: State(vec![0, 0]),
goal: vec![Fact::new(0, 1), Fact::new(1, 1)],
axioms: vec![],
};
let problem = SasProblem::new(&task);
// key: 2, door: 2 + 3. The key's cost is counted twice, so h_add (7)
// overestimates the optimal plan cost (5).
assert_eq!(problem.h_add(&task.initial_state()), Some(7));
assert_eq!(problem.h_add(&State(vec![1, 0])), Some(3));
assert_eq!(problem.h_add(&State(vec![1, 1])), Some(0));Trait Implementations§
Source§impl GoalCount for SasProblem<'_>
impl GoalCount for SasProblem<'_>
Source§fn unsatisfied_goals(&self, state: &State) -> usize
fn unsatisfied_goals(&self, state: &State) -> usize
#g).Source§impl RelaxedPlan for SasProblem<'_>
The relaxed plan is extracted from h_add best supporters, and its
features are all effects of its operators, as in LAPKT. Axioms on the way
are followed but contribute no features of their own.
impl RelaxedPlan for SasProblem<'_>
The relaxed plan is extracted from h_add best supporters, and its
features are all effects of its operators, as in LAPKT. Axioms on the way
are followed but contribute no features of their own.
Source§impl WidthProblem for SasProblem<'_>
impl WidthProblem for SasProblem<'_>
Source§fn initial_state(&self) -> State
fn initial_state(&self) -> State
Source§fn successors(&self, state: &State, out: &mut Vec<(OpId, State)>)
fn successors(&self, state: &State, out: &mut Vec<(OpId, State)>)
(action, successor) pairs of state into out.Source§fn features(&self, state: &State, out: &mut Vec<u32>)
fn features(&self, state: &State, out: &mut Vec<u32>)
< num_features()) true in state into out.Source§fn num_features(&self) -> usize
fn num_features(&self) -> usize
WidthProblem::features
must be below it.