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 factv = xwithxmapped toa, and the price ofv = s[v]is at most whatspays inv’s factor, by the contract ofFactPrices; - at a product of children
landrthat 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
impl MasHeuristic
Sourcepub fn build<M: MergeStrategy, S: ShrinkStrategy>(
task: &Task,
config: MergeAndShrink<M, S>,
) -> Self
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.
Sourcepub fn from_factor(task: &Task, factor: &Factor) -> Self
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.
Sourcepub fn num_abstract_states(&self) -> usize
pub fn num_abstract_states(&self) -> usize
The number of abstract states of the root factor.
Trait Implementations§
Source§impl Clone for MasHeuristic
impl Clone for MasHeuristic
Source§impl Debug for MasHeuristic
impl Debug for MasHeuristic
Source§impl DecoupledHeuristic for MasHeuristic
impl DecoupledHeuristic for MasHeuristic
Auto Trait Implementations§
impl Forget for MasHeuristic
impl Freeze for MasHeuristic
impl Move for MasHeuristic
impl RefUnwindSafe for MasHeuristic
impl Send for MasHeuristic
impl Sync for MasHeuristic
impl Unpin for MasHeuristic
impl UnsafeUnpin for MasHeuristic
impl UnwindSafe for MasHeuristic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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