Skip to main content

SearchProblem

Trait SearchProblem 

Source
pub trait SearchProblem {
    type State: Clone;
    type Choice: Clone + Ord;
    type Output: Clone + Debug;

    // Required methods
    fn initial_state(&self) -> Self::State;
    fn expand(&self, state: &Self::State, out: &mut Vec<Self::Choice>);
    fn apply(
        &self,
        state: &Self::State,
        choice: &Self::Choice,
    ) -> SearchStep<Self::State>;
    fn finish(&self, state: &Self::State) -> Option<Self::Output>;

    // Provided methods
    fn propagate(&self, state: Self::State) -> SearchStep<Self::State> { ... }
    fn score_state(&self, _state: &Self::State) -> i64 { ... }
    fn estimate_remaining(&self, _state: &Self::State) -> i64 { ... }
    fn bound(&self, _state: &Self::State) -> Option<i64> { ... }
    fn output_score(&self, _output: &Self::Output) -> Option<i64> { ... }
}
Expand description

Generic state-space problem consumed by crate::solve.

Required Associated Types§

Source

type State: Clone

State carried by the frontier.

Source

type Choice: Clone + Ord

Deterministic choice type; choices are sorted before they are explored.

Source

type Output: Clone + Debug

Finished output emitted by the search.

Required Methods§

Source

fn initial_state(&self) -> Self::State

Return the initial search state.

Source

fn expand(&self, state: &Self::State, out: &mut Vec<Self::Choice>)

Append possible choices for state to out.

Source

fn apply( &self, state: &Self::State, choice: &Self::Choice, ) -> SearchStep<Self::State>

Apply one choice to a state, or prune that prefix.

Source

fn finish(&self, state: &Self::State) -> Option<Self::Output>

Return a finished output if this state is terminal.

Provided Methods§

Source

fn propagate(&self, state: Self::State) -> SearchStep<Self::State>

Propagate generic CSP constraints after a state is produced.

Source

fn score_state(&self, _state: &Self::State) -> i64

Deterministic priority score for best-first and A-star search.

Source

fn estimate_remaining(&self, _state: &Self::State) -> i64

Deterministic optimistic remaining estimate for A-star and beam search.

Source

fn bound(&self, _state: &Self::State) -> Option<i64>

Lower-bound score used by branch-and-bound minimization.

Source

fn output_score(&self, _output: &Self::Output) -> Option<i64>

Score for a finished output used by branch-and-bound minimization.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§