Skip to main content

Model

Struct Model 

Source
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>

Source

pub const fn new() -> Self

A model without variables or constraints.

Source

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.

Source

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.

Source

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.

Source

pub fn num_vars(&self) -> usize

The number of variables.

Source

pub fn initial_domains(&self) -> &[D]

The domain each variable starts with, indexed by Var::index.

Source

pub fn num_propagators(&self) -> usize

The number of constraints.

Trait Implementations§

Source§

impl<D: Domain> Default for Model<D>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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>
where Vec<D>: Freeze, Vec<Box<dyn Erased<D>>>: Freeze,

§

impl<D> Move for Model<D>

§

impl<D> Send for Model<D>
where Vec<D>: Send, Vec<Box<dyn Erased<D>>>: Send,

§

impl<D> Sync for Model<D>
where Vec<D>: Sync, Vec<Box<dyn Erased<D>>>: Sync,

§

impl<D> Unpin for Model<D>
where Vec<D>: Unpin, Vec<Box<dyn Erased<D>>>: Unpin,

§

impl<D> UnsafeUnpin for Model<D>
where Vec<D>: UnsafeUnpin, Vec<Box<dyn Erased<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.