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>
impl<'m, D: Domain> ParallelSolver<'m, D>
Sourcepub fn new(model: &'m Model<D>, threads: usize) -> Self
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.
Sourcepub fn with_var_order(self, order: VarOrder) -> Self
pub fn with_var_order(self, order: VarOrder) -> Self
Sets how workers pick the variable to branch on.
Sourcepub fn with_value_order(self, order: ValueOrder) -> Self
pub fn with_value_order(self, order: ValueOrder) -> Self
Sets how workers order the values of the branching variable.
Sourcepub fn solve<B: Budget<Stats> + Clone + Send>(
&self,
budget: B,
) -> Report<Outcome>
pub fn solve<B: Budget<Stats> + Clone + Send>( &self, budget: B, ) -> Report<Outcome>
Finds one solution, stopping every thread at the first one found.
Sourcepub fn count<B: Budget<Stats> + Clone + Send>(
&self,
limit: u64,
budget: B,
) -> Report<Count>
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.