BoundedCellsBacktrackingStrategy

Struct BoundedCellsBacktrackingStrategy 

Source
pub struct BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Fn(usize) -> usize, FA: Fn(usize) -> Option<usize>, S: Strategy,
{ /* private fields */ }
Expand description

A Strategy which looks for groups in which some number can only occur in a limited number of cells (up to a specified maximum) and tries all of them. It then uses a wrapped strategy to find deductions in all paths. If any of those deductions hold for all options, they are stored in the metadata.

As an example, consider the following situation:

╔═══╤═══╤═══╦═══╤═══╤═══╦═══╤═══╤═══╗
║   │   │   ║   │ 5 │   ║   │   │   ║
╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
║ 1 │ 2 │ 3 ║   │   │   ║   │   │   ║
╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
║ 4 │   │   ║   │   │   ║ X │   │   ║
╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣
║ 2 │   │   ║   │   │   ║ X │   │   ║
╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
║   │   │   ║   │   │ 5 ║   │   │   ║
╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
║ 3 │ 1 │ 4 ║   │   │   ║   │   │   ║
╠═══╪═══╪═══╬═══╪═══╪═══╬═══╪═══╪═══╣
║   │ Y │ Y ║   │   │   ║   │   │   ║
╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
║   │ Y │ Y ║   │   │   ║   │   │   ║
╟───┼───┼───╫───┼───┼───╫───┼───┼───╢
║   │ Y │ Y ║   │   │   ║   │   │   ║
╚═══╧═══╧═══╩═══╧═══╧═══╩═══╧═══╧═══╝

In this configuration, a bounded cells backtracking strategy without any wrapped stratey (i.e. a NoStrategy) with a maximum of 2 cells to consider would find that the cells marked with X cannot be a 5. This is because both in the top-left and the top-central box, there are two places for 5s each, both in the same rows, thus excluding a 5 from the X-cells. Furthermore, if an OnlyCellStrategy with at least 1 application is used as the continuation strategy, the bounded cells backtracking strategy would be able to deduce that fives must always be in columns 2 and 3 in the top-left and top-central box and thus all cells marked with Y cannot be a 5.

Note that this strategy contains some common strategies with different names. For example a bounded cells backtracking strategy with a limit of 2 cells and an OnlyCellStrategy with 1 application would find X-Wings.

Implementations§

Source§

impl<FC, FA, S> BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Fn(usize) -> usize, FA: Fn(usize) -> Option<usize>, S: Strategy,

Source

pub fn new( max_cells_computer: FC, max_applications_computer: FA, continuation_strategy: S, ) -> BoundedCellsBacktrackingStrategy<FC, FA, S>

Creates a new bounded cells backtracking strategy.

§Arguments
  • max_cells_computer: A closure that, given the grid size, computes the maximum number of cells in a group in which a number can be for this strategy to consider all of them.
  • max_applications_computer: A closure that, given the grid size, computes the maximum number of times the continuation strategy may be applied for each considered cell before no further inference is done. If no limit is desired, this may return None.
  • continuation_strategy: The Strategy with which each considered cell is developed to find any inferences.

Trait Implementations§

Source§

impl<FC, FA, S> Clone for BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Fn(usize) -> usize + Clone, FA: Fn(usize) -> Option<usize> + Clone, S: Strategy + Clone,

Source§

fn clone(&self) -> BoundedCellsBacktrackingStrategy<FC, FA, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<FC, FA, S> Strategy for BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Fn(usize) -> usize, FA: Fn(usize) -> Option<usize>, S: Strategy,

Source§

fn apply(&self, sudoku_info: &mut SudokuInfo<impl Constraint + Clone>) -> bool

Applies this strategy to the given Sudoku. The strategy may rely on and modify the information in the given sudoku_info. This instance is given to other strategies that participate in the solution and/or future iterations of the same strategy. It can thus be used to communicate insights. Read more

Auto Trait Implementations§

§

impl<FC, FA, S> Freeze for BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Freeze, FA: Freeze, S: Freeze,

§

impl<FC, FA, S> RefUnwindSafe for BoundedCellsBacktrackingStrategy<FC, FA, S>

§

impl<FC, FA, S> Send for BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Send, FA: Send, S: Send,

§

impl<FC, FA, S> Sync for BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Sync, FA: Sync, S: Sync,

§

impl<FC, FA, S> Unpin for BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: Unpin, FA: Unpin, S: Unpin,

§

impl<FC, FA, S> UnwindSafe for BoundedCellsBacktrackingStrategy<FC, FA, S>
where FC: UnwindSafe, FA: UnwindSafe, S: 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> 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> 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 = 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.
Source§

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

Source§

fn vzip(self) -> V