Skip to main content

ParallelSolver

Struct ParallelSolver 

Source
pub struct ParallelSolver<'m, D> { /* private fields */ }
Expand description

Backtracking search over a shared model on several threads.

Each worker thread owns a Solver and searches subproblems below partial assignments of the first branching variables. Which solution ParallelSolver::solve returns depends on thread timing; counts are exact whenever the search completes.

The budget is cloned into every worker and judges that worker’s own counters. When any worker’s budget runs out, all workers stop and the result is incomplete.

§Examples

use constraint_search::{AllDifferent, Count, Domain, Model, ParallelSolver, Stats};

let mut model = Model::<u16>::new();
let vars = model.add_vars(6, u16::range(6));
model.add(AllDifferent::new(vars));

let report = ParallelSolver::new(&model, 4).count(u64::MAX, |_: &Stats| false);
assert_eq!(report.outcome, Count::Exact(720));

Implementations§

Source§

impl<'m, D: Domain> ParallelSolver<'m, D>

Source

pub fn new(model: &'m Model<D>, threads: usize) -> Self

A parallel solver over model with threads worker threads, branching with VarOrder::Mrv and ValueOrder::Ascending.

§Panics

Panics if threads is 0.

Source

pub fn with_var_order(self, order: VarOrder) -> Self

Sets how workers pick the variable to branch on.

Source

pub fn with_value_order(self, order: ValueOrder) -> Self

Sets how workers order the values of the branching variable.

Source

pub fn solve<B: Budget<Stats> + Clone + Send>( &self, budget: B, ) -> Report<Outcome>

Finds one solution, stopping every thread at the first one found.

Source

pub fn count<B: Budget<Stats> + Clone + Send>( &self, limit: u64, budget: B, ) -> Report<Count>

Counts solutions on all threads, stopping every thread once limit are found.

A limit of 2 decides uniqueness. Threads may find a few solutions past the limit before they see the stop; Count::AtLeast then reports all of them.

Source

pub fn portfolio<B: Budget<Stats> + Clone + Send>( model: &Model<D>, orders: &[(VarOrder, ValueOrder)], budget: B, ) -> Report<Outcome>

Races one thread per (VarOrder, ValueOrder) pair on the whole problem and returns the first solution any of them finds.

§Panics

Panics if orders is empty.

Auto Trait Implementations§

§

impl<'m, D> !RefUnwindSafe for ParallelSolver<'m, D>

§

impl<'m, D> !UnwindSafe for ParallelSolver<'m, D>

§

impl<'m, D> Forget for ParallelSolver<'m, D>

§

impl<'m, D> Freeze for ParallelSolver<'m, D>
where &'m Model<D>: Freeze,

§

impl<'m, D> Move for ParallelSolver<'m, D>

§

impl<'m, D> Send for ParallelSolver<'m, D>
where &'m Model<D>: Send,

§

impl<'m, D> Sync for ParallelSolver<'m, D>
where &'m Model<D>: Sync,

§

impl<'m, D> Unpin for ParallelSolver<'m, D>
where &'m Model<D>: Unpin,

§

impl<'m, D> UnsafeUnpin for ParallelSolver<'m, D>
where &'m Model<D>: UnsafeUnpin,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.