MultiBackTrackSolver

Struct MultiBackTrackSolver 

Source
pub struct MultiBackTrackSolver<T>
where T: Puzzle,
{ pub states: Vec<T>, pub prevs: Vec<Vec<(<T as Puzzle>::Pos, <T as Puzzle>::Val, bool)>>, pub choice: Vec<Vec<(<T as Puzzle>::Pos, Vec<<T as Puzzle>::Val>)>>, pub settings: SolveSettings, }
Expand description

Solves puzzle using multiple strategies at the same time. Each strategy is evaluated one step by turn until a solution is found.

Fields§

§states: Vec<T>

Stores the states.

§prevs: Vec<Vec<(<T as Puzzle>::Pos, <T as Puzzle>::Val, bool)>>

Stores previous values before making choices. The flags is true when made a simple choice.

§choice: Vec<Vec<(<T as Puzzle>::Pos, Vec<<T as Puzzle>::Val>)>>

Stores the choices for the states.

§settings: SolveSettings

Search for simple solutions.

Implementations§

Source§

impl<T> MultiBackTrackSolver<T>
where T: Puzzle,

Source

pub fn new(settings: SolveSettings) -> MultiBackTrackSolver<T>

Creates a new solver.

Source

pub fn solve( self, puzzle: T, strategies: &[(fn(&T) -> Option<<T as Puzzle>::Pos>, fn(&T, <T as Puzzle>::Pos) -> Vec<<T as Puzzle>::Val>)], ) -> Option<Solution<T>>

Solves puzzle, using a closure to look for best position to set a value next, and a closure for picking options in preferred order.

The second closure returns possible values at a given position. The last move in the list has highest priority, because the solver pops the values in turn.

If you have problems compiling, annotate type (fn(&_) -> _, fn(&_, _) -> _) to the list of strategies, e.g. Vec<(fn(&_) -> _, fn(&_, _) -> _)> or &[(fn(&_) -> _, fn(&_, _) -> _)].

Auto Trait Implementations§

§

impl<T> Freeze for MultiBackTrackSolver<T>

§

impl<T> RefUnwindSafe for MultiBackTrackSolver<T>

§

impl<T> Send for MultiBackTrackSolver<T>
where T: Send, <T as Puzzle>::Pos: Send, <T as Puzzle>::Val: Send,

§

impl<T> Sync for MultiBackTrackSolver<T>
where T: Sync, <T as Puzzle>::Pos: Sync, <T as Puzzle>::Val: Sync,

§

impl<T> Unpin for MultiBackTrackSolver<T>
where T: Unpin, <T as Puzzle>::Pos: Unpin, <T as Puzzle>::Val: Unpin,

§

impl<T> UnwindSafe for MultiBackTrackSolver<T>
where T: UnwindSafe, <T as Puzzle>::Pos: UnwindSafe, <T as Puzzle>::Val: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.