pub struct Line { /* private fields */ }Expand description
A line of cells, each EMPTY (0) or FILLED (1), holding the given runs of filled
cells in order, separated by at least one empty cell.
Propagation is complete: it considers every placement of the runs that fits the current
domains, and keeps exactly the cell values some placement uses. Values other than 0 and 1
are removed. Each run costs O(n · k · L) for n cells, k runs and the longest run L.
§Examples
A line of five cells with runs 3 and 1 has a single placement:
use constraint_search::{Domain, Domains, Line, Propagator};
let mut domains = Domains::<u16>::new();
let cells: Vec<_> = (0..5).map(|_| domains.add(u16::range(2))).collect();
Line::new(cells.iter().copied(), [3, 1]).propagate(&mut domains, &mut Default::default())?;
let picture: Vec<_> = cells.iter().map(|&c| domains.value(c).unwrap()).collect();
assert_eq!(picture, [1, 1, 1, 0, 1]);Implementations§
Source§impl Line
impl Line
Sourcepub fn new(
cells: impl IntoIterator<Item = Var>,
runs: impl IntoIterator<Item = usize>,
) -> Self
pub fn new( cells: impl IntoIterator<Item = Var>, runs: impl IntoIterator<Item = usize>, ) -> Self
The line over cells holding runs filled cells in order.
§Panics
Panics if a run has length 0 or a cell appears twice.
Trait Implementations§
impl Eq for Line
Source§impl<D: Domain> Propagator<D> for Line
impl<D: Domain> Propagator<D> for Line
Source§type Scratch = LineScratch
type Scratch = LineScratch
Working memory reused across calls;
() for none. See the trait docs.Source§fn scope(&self) -> &[Var]
fn scope(&self) -> &[Var]
The variables the constraint is over. A change to any of them wakes the propagator.
Source§fn propagate(
&self,
domains: &mut Domains<D>,
scratch: &mut LineScratch,
) -> Result<(), Inconsistent>
fn propagate( &self, domains: &mut Domains<D>, scratch: &mut LineScratch, ) -> Result<(), Inconsistent>
Removes the values the constraint rules out, using
scratch as working memory. Read moreimpl StructuralPartialEq for Line
Auto Trait Implementations§
impl Forget for Line
impl Freeze for Line
impl Move for Line
impl RefUnwindSafe for Line
impl Send for Line
impl Sync for Line
impl Unpin for Line
impl UnsafeUnpin for Line
impl UnwindSafe for Line
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
Mutably borrows from an owned value. Read more