[][src]Struct quickbacktrack::EntropyBackTrackSolver

pub struct EntropyBackTrackSolver<T> where
    T: Puzzle
{ pub original: T, pub state: T, pub prevs: Vec<(T::Pos, T::Val, bool)>, pub choice: Vec<(T::Pos, Vec<T::Val>)>, pub start_choice: Vec<(T::Pos, Vec<T::Val>)>, pub weights: Vec<Vec<f64>>, pub settings: SolveSettings, pub entropy_settings: EntropySolveSettings, }

Solves puzzles using minimum entropy search.

This solver learns from repeatedly attempting to solve the puzzle. The algorithm is inspired by WaveFunctionCollapse.

This solver is general and guaranteed to find a solution, if any. It also uses custom priority of choices in the initial attempts.

The search works by attempting normal backtrack solving, but increasing weights to choices each time they are made. When the algorithm is stuck, it minimizes entropy of common choices. At later attempts, the algorithm will try these common choices first.

When EntropySettings::noise is non-zero, the choices will occationally be shuffled. For more information, see EntropySolveSettings.

Fields

original: T

Stores the original state.

state: T

Stores the state.

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

Stores the previous values of a position before making a choice. If the flag is true, the value was inserted due to a simple choice.

choice: Vec<(T::Pos, Vec<T::Val>)>

Stores the choices for the states.

start_choice: Vec<(T::Pos, Vec<T::Val>)>

The initial choices.

weights: Vec<Vec<f64>>

Stores weights of choices.

settings: SolveSettings

Stores solve settings.

entropy_settings: EntropySolveSettings

Stores entropy solve settings.

Implementations

impl<T> EntropyBackTrackSolver<T> where
    T: Puzzle
[src]

pub fn new(
    puzzle: T,
    start_choice: Vec<(T::Pos, Vec<T::Val>)>,
    entropy_settings: EntropySolveSettings,
    settings: SolveSettings
) -> Self
[src]

Creates a new collapse solver.

pub fn entropy(&self, i: usize) -> f64[src]

Calculates the entropy of a choice.

pub fn min_entropy<G>(&self, g: &mut G) -> Option<(usize, T::Pos)> where
    G: FnMut(&T, T::Pos) -> Vec<T::Val>, 
[src]

Finds the position with least entropy.

pub fn observe(&mut self, pos: T::Pos, new_val: T::Val) where
    T::Pos: PartialEq
[src]

Increase weight of observed state.

pub fn solve<G>(&mut self, g: G) -> (u64, Option<Solution<T>>) where
    G: Copy + FnMut(&T, T::Pos) -> Vec<T::Val>,
    T::Pos: PartialEq
[src]

Attempts to solve puzzle repeatedly, using SolveSettings::max_iterations.

The solver learns by reusing weights from previous attempts.

pub fn solve_single_attempt<G>(&mut self, g: G) -> Option<Solution<T>> where
    G: FnMut(&T, T::Pos) -> Vec<T::Val>,
    T::Pos: PartialEq
[src]

Solves puzzle, using a closure for picking options in preferred order.

This can be called repeated times, limited by SolveSettings::max_iterations to reuse weights from previous attempts.

Auto Trait Implementations

impl<T> RefUnwindSafe for EntropyBackTrackSolver<T> where
    T: RefUnwindSafe,
    <T as Puzzle>::Pos: RefUnwindSafe,
    <T as Puzzle>::Val: RefUnwindSafe

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,