pub struct Model<D> { /* private fields */ }Expand description
A constraint problem: variables, their initial domains and the propagators over them.
A model is built once and then only read. It is Send + Sync, so one model can serve
any number of Solvers, on one thread or several.
§Examples
use constraint_search::{AllDifferent, Domain, Model};
let mut model = Model::<u16>::new();
let vars = model.add_vars(3, u16::range(3));
model.add(AllDifferent::new(vars));
assert_eq!(model.num_vars(), 3);Implementations§
Source§impl<D: Domain> Model<D>
impl<D: Domain> Model<D>
Sourcepub fn add_var(&mut self, domain: D) -> Var
pub fn add_var(&mut self, domain: D) -> Var
Adds a variable that may take any value of domain.
§Panics
Panics if domain is empty or if the model already has u32::MAX variables.
Sourcepub fn add_vars(&mut self, count: usize, domain: D) -> Vec<Var>
pub fn add_vars(&mut self, count: usize, domain: D) -> Vec<Var>
Adds count variables that may each take any value of domain.
§Panics
Panics if domain is empty or if the model would exceed u32::MAX variables.
Sourcepub fn add(&mut self, propagator: impl Propagator<D> + 'static) -> &mut Self
pub fn add(&mut self, propagator: impl Propagator<D> + 'static) -> &mut Self
Adds a constraint.
§Panics
Panics if the scope of propagator holds a variable that is not in the model.
Sourcepub fn initial_domains(&self) -> &[D]
pub fn initial_domains(&self) -> &[D]
The domain each variable starts with, indexed by Var::index.
Sourcepub fn num_propagators(&self) -> usize
pub fn num_propagators(&self) -> usize
The number of constraints.
Trait Implementations§
Auto Trait Implementations§
impl<D> !RefUnwindSafe for Model<D>
impl<D> !UnwindSafe for Model<D>
impl<D> Forget for Model<D>
impl<D> Freeze for Model<D>
impl<D> Move for Model<D>
impl<D> Send for Model<D>
impl<D> Sync for Model<D>
impl<D> Unpin for Model<D>
impl<D> UnsafeUnpin for Model<D>
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