pub struct Model<D> { /* private fields */ }
Expand description
A model of a constraint satisfaction problem.
Implementations§
source§impl<D: IntDomain> Model<D>
impl<D: IntDomain> Model<D>
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new model with no variables.
Examples
use chinstrap::DefaultModel;
let model = DefaultModel::new();
sourcepub fn create_int_var<R>(&mut self, range: R) -> VarTokenwhere
R: Into<IntDomBounds<D::Value>>,
pub fn create_int_var<R>(&mut self, range: R) -> VarTokenwhere
R: Into<IntDomBounds<D::Value>>,
Adds a new integer variable to the model, returning a VarToken
representing that variable.
The initial domain can be specified using a..b
or a..=b
syntax.
Examples
use chinstrap::Model;
use chinstrap::domain::RangeDom;
let mut model = Model::<RangeDom<i32>>::new();
let x = model.create_int_var(0..10);
let y = model.create_int_var(0..=9);
sourcepub fn create_int_var_array<R>(
&mut self,
range: R,
length: usize
) -> Vec<VarToken>where
R: Into<IntDomBounds<D::Value>>,
pub fn create_int_var_array<R>(
&mut self,
range: R,
length: usize
) -> Vec<VarToken>where
R: Into<IntDomBounds<D::Value>>,
Adds new integer variables to the model, returning the tokens in a Vec<VarToken>
.
The initial domain can be specified using a..b
or a..=b
syntax.
Examples
use chinstrap::Model;
use chinstrap::domain::RangeDom;
let mut model = Model::<RangeDom<i32>>::new();
let xs = model.create_int_var_array(0..10, 5);
assert_eq!(model.num_vars(), 5);
assert_eq!(xs.len(), 5);
sourcepub fn create_int_var_matrix<R>(
&mut self,
range: R,
rows: usize,
cols: usize
) -> Vec<Vec<VarToken>>where
R: Into<IntDomBounds<D::Value>>,
pub fn create_int_var_matrix<R>(
&mut self,
range: R,
rows: usize,
cols: usize
) -> Vec<Vec<VarToken>>where
R: Into<IntDomBounds<D::Value>>,
Adds new integer variables to the model, returning the tokens in a Vec<Vec<<VarToken>>
.
The initial domain can be specified using a..b
or a..=b
syntax.
Examples
use chinstrap::Model;
use chinstrap::domain::RangeDom;
let mut model = Model::<RangeDom<i32>>::new();
let xs = model.create_int_var_matrix(0..10, 3, 4);
assert_eq!(model.num_vars(), 3 * 4);
for row in 0..3 {
for col in 0..4 {
println!("{}", xs[row][col])
}
}
sourcepub fn num_vars(&self) -> usize
pub fn num_vars(&self) -> usize
Returns the total number of variables in the model.
Examples
use chinstrap::Model;
use chinstrap::domain::RangeDom;
let mut model = Model::<RangeDom<i32>>::new();
assert_eq!(model.num_vars(), 0);
let x = model.create_int_var(0..10);
assert_eq!(model.num_vars(), 1);