Skip to main content

HSetAdd

Struct HSetAdd 

Source
pub struct HSetAdd<'r> { /* private fields */ }
Expand description

The set-additive heuristic h_sa (Keyder & Geffner 2008): like h_add, but each fact carries a relaxed plan, a set of operators, instead of a cost, so an operator shared by two subgoals is counted once.

A rule conditions → head offers the union of its conditions’ plans plus its operator; the head keeps the cheapest offer (by summed operator cost). The offers are swept until no plan gets cheaper (Bellman-Ford), and the estimate is the cost of the union of the goal facts’ plans. Each offer costs at most h_add’s sum, so h_sa <= h_add. Without conditional effects the union is a relaxed plan, so h_max <= h_sa; with them, a relaxed plan may need one operator twice (before and after an effect condition holds), which the set counts once, so h_sa can fall below h_max. Not admissible.

One sweep is O(rules × operators / 64); sweeps repeat until nothing improves.

§Examples

use planning_heuristics::{HAdd, HSetAdd, Heuristic};
use sas_plus::{Effect, Fact, Operator, State, Task, Variable};

// `tool` (cost 3) is needed for both goals: h_add counts it twice, h_sa once.
let op = |name: &str, pre: Vec<Fact>, eff: Fact, cost: u32| Operator {
    name: name.into(),
    pre,
    eff: vec![Effect::new(eff)],
    cost,
};
let task = Task {
    variables: vec![Variable::new("tool", 2), Variable::new("a", 2), Variable::new("b", 2)],
    operators: vec![
        op("tool", vec![], Fact::new(0, 1), 3),
        op("a", vec![Fact::new(0, 1)], Fact::new(1, 1), 1),
        op("b", vec![Fact::new(0, 1)], Fact::new(2, 1), 1),
    ],
    initial: State(vec![0, 0, 0]),
    goal: vec![Fact::new(1, 1), Fact::new(2, 1)],
    axioms: vec![],
};
let state = task.initial_state();

assert_eq!(HAdd::new(&task).estimate(&state), Some(8));
let mut h_sa = HSetAdd::new(&task);
assert_eq!(h_sa.estimate(&state), Some(5));
assert_eq!(h_sa.plan(&state).unwrap(), [0, 1, 2]);

Implementations§

Source§

impl HSetAdd<'static>

Source

pub fn new(task: &Task) -> Self

Builds h_sa for task, owning its relaxation.

Source§

impl<'r> HSetAdd<'r>

Source

pub fn with_relaxation(relaxation: &'r Relaxation) -> Self

Builds h_sa over a shared relaxation.

Source

pub fn value(&mut self, state: &State) -> Option<u64>

h_sa of state; None if the goal is relaxed-unreachable.

§Panics

Panics if state has fewer values than the task has variables.

Source

pub fn plan(&mut self, state: &State) -> Option<Vec<OpId>>

The relaxed plan behind HSetAdd::value, as operators ascending; None for a dead end. Applying them repeatedly under the delete relaxation reaches the goal.

§Panics

Panics if state has fewer values than the task has variables.

Trait Implementations§

Source§

impl<'r> Clone for HSetAdd<'r>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'r> Debug for HSetAdd<'r>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Heuristic<State> for HSetAdd<'_>

Source§

fn estimate(&mut self, state: &State) -> Option<u32>

Estimates the remaining cost from state to a goal. Read more

Auto Trait Implementations§

§

impl<'r> Forget for HSetAdd<'r>

§

impl<'r> Freeze for HSetAdd<'r>

§

impl<'r> Move for HSetAdd<'r>

§

impl<'r> RefUnwindSafe for HSetAdd<'r>

§

impl<'r> Send for HSetAdd<'r>

§

impl<'r> Sync for HSetAdd<'r>

§

impl<'r> Unpin for HSetAdd<'r>

§

impl<'r> UnsafeUnpin for HSetAdd<'r>

§

impl<'r> UnwindSafe for HSetAdd<'r>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.