Skip to main content

MasHeuristic

Struct MasHeuristic 

Source
pub struct MasHeuristic { /* private fields */ }
Expand description

A merge-and-shrink heuristic adapted to decoupled states; admissible, so it can drive crate::astar.

A merge-and-shrink abstraction maps each explicit state through a merge tree of lookup tables to an abstract state with an admissible goal distance. A decoupled state stands for many explicit states at once, so the adapter evaluates the tree on FactPrices instead of on one state: bottom-up, every tree node gets the cheapest price bound of each of its abstract states, and the estimate is the cheapest bound + distance at the root.

§Admissibility

For a tree node n, let F(n) be the factors (the leaves, and the center as one more) that its variables touch, and for a member state s let P_n(s) be the sum of the prices s pays in the factors of F(n). By induction, cost_n(a) <= P_n(s) for every member state s that n maps to a:

  • at a variable v, cost(a) is the cheapest price of a fact v = x with x mapped to a, and the price of v = s[v] is at most what s pays in v’s factor, by the contract of FactPrices;
  • at a product of children l and r that touch disjoint sets of factors, P_n = P_l + P_r, so the sum of the children’s bounds is a bound;
  • if they share a factor, its price must not be counted twice (two variables of one leaf are bought with one leaf state), and P_n >= max(P_l, P_r) makes the larger bound a bound.

At the root F contains every factor, so a member state s mapped to a costs at least cost(a) to reach and at least dist(a) (the abstraction is admissible) to complete; the minimum over all abstract states is a lower bound on the cheapest completion through any member state. Pruned abstract states (None in a table) are dead ends or unreachable from the initial state; every member state of a decoupled state is reachable, so skipping them is safe.

§Construction

merge_and_shrink::MergeAndShrinkHeuristic keeps its merge tree private, so MasHeuristic::build re-runs the merge loop from the public parts of merge_and_shrink. Label reduction is not public either, so MergeAndShrink::label_reduction is ignored; that only weakens shrinking, never admissibility.

§Examples

use decoupled_search::{Factoring, MasHeuristic, astar};
use merge_and_shrink::{Bisimulation, LinearMerge, MergeAndShrink};
use sas_plus::{Effect, Fact, Operator, State, Task, Variable};

let op = |pre: Vec<Fact>, eff: Fact| Operator {
    name: "op".into(),
    pre,
    eff: vec![Effect::new(eff)],
    cost: 2,
};
let task = Task {
    variables: vec![Variable::new("truck", 2), Variable::new("pkg", 3)],
    operators: vec![
        op(vec![Fact::new(0, 0)], Fact::new(0, 1)),
        op(vec![Fact::new(0, 0), Fact::new(1, 0)], Fact::new(1, 2)),
        op(vec![Fact::new(0, 1), Fact::new(1, 2)], Fact::new(1, 1)),
    ],
    initial: State(vec![0, 0]),
    goal: vec![Fact::new(1, 1)],
    axioms: vec![],
};

let merge = LinearMerge::in_variable_order(task.num_variables());
let h = MasHeuristic::build(&task, MergeAndShrink::new(merge, Bisimulation));
let plan = astar(&task, &Factoring::fork(&task), &h)?.expect("solvable");
assert_eq!(plan.cost, 6);

Implementations§

Source§

impl MasHeuristic

Source

pub fn build<M: MergeStrategy, S: ShrinkStrategy>( task: &Task, config: MergeAndShrink<M, S>, ) -> Self

Builds the merge-and-shrink abstraction of task with the merge strategy, shrink strategy, size limit and pruning of config, as MergeAndShrink::build would, except that label reduction is not applied (see the module documentation).

§Panics

Panics if task has no variables, if config.max_states is 0, or if the merge strategy picks the same factor twice or one already merged.

Source

pub fn from_factor(task: &Task, factor: &Factor) -> Self

The heuristic of a finished merge-and-shrink factor over all variables of task, whose labels are task’s operator ids.

Source

pub fn num_abstract_states(&self) -> usize

The number of abstract states of the root factor.

Trait Implementations§

Source§

impl Clone for MasHeuristic

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 Debug for MasHeuristic

Source§

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

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

impl DecoupledHeuristic for MasHeuristic

Source§

fn estimate(&self, facts: &FactPrices<'_>) -> Option<u64>

An estimate of the cost still to pay from a decoupled state beyond the cost of its global actions: leaf prices plus all further operators. None declares that no goal is reachable from it; the search then prunes the state. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.