Struct chinstrap::model::Model

source ·
pub struct Model<D> { /* private fields */ }
Expand description

A model of a constraint satisfaction problem.

Implementations§

Creates a new model with no variables.

Examples
use chinstrap::DefaultModel;

let model = DefaultModel::new();

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);

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);

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])
    }
}

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);

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.