Struct coin_cbc::raw::Model

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

A CBC MILP model.

Their methods are a direct translation from the C API. For documentation, see the official API documentation.

Implementations§

source§

impl Model

source

pub fn new() -> Self

source

pub fn version() -> &'static str

source

pub fn load_problem( &mut self, numcols: usize, numrows: usize, start: &[c_int], index: &[c_int], value: &[f64], collb: Option<&[f64]>, colub: Option<&[f64]>, obj: Option<&[f64]>, rowlb: Option<&[f64]>, rowub: Option<&[f64]> )

source

pub fn read_mps(&mut self, filename: &CStr)

source

pub fn write_mps(&self, filename: &CStr)

source

pub fn set_initial_solution(&mut self, sol: &[f64])

source

pub fn num_elements(&self) -> usize

source

pub fn vector_starts(&self) -> &[c_int]

source

pub fn indices(&self) -> &[c_int]

source

pub fn elements(&self) -> &[f64]

source

pub fn max_name_length(&self) -> usize

source

pub fn num_rows(&self) -> usize

source

pub fn num_cols(&self) -> usize

source

pub fn set_obj_sense(&mut self, sense: Sense)

source

pub fn obj_sense(&self) -> Sense

source

pub fn row_lower(&self) -> &[f64]

source

pub fn set_row_lower(&mut self, i: usize, value: f64)

source

pub fn row_upper(&self) -> &[f64]

source

pub fn set_row_upper(&mut self, i: usize, value: f64)

source

pub fn obj_coefficients(&self) -> &[f64]

source

pub fn set_obj_coeff(&mut self, i: usize, value: f64)

source

pub fn col_lower(&self) -> &[f64]

source

pub fn set_col_lower(&mut self, i: usize, value: f64)

source

pub fn col_upper(&self) -> &[f64]

source

pub fn set_col_upper(&mut self, i: usize, value: f64)

source

pub fn is_integer(&self, i: usize) -> bool

source

pub fn set_continuous(&mut self, i: usize)

source

pub fn set_integer(&mut self, i: usize)

source

pub fn add_sos( &mut self, row_starts: &[c_int], col_indices: &[c_int], weights: &[f64], sos_type: SOSConstraintType )

Adds multiple SOS constraints num_rows: the number of SOS constraints to add row_starts: The indices at which each new constraint starts in the col_indices array, plus one last element that indicates the size of col_indices array. col_indices: The index of each variable to include in the constraints. You create this array by concatenating the indices of the columns in each constraint.

source

pub fn print_model(&self, arg_prefix: &CStr)

source

pub fn set_parameter(&mut self, name: &CStr, value: &CStr)

source

pub fn solve(&mut self) -> c_int

source

pub fn sum_primal_infeasibilities(&self) -> f64

source

pub fn number_primal_infeasibilities(&self) -> c_int

source

pub fn check_solution(&mut self)

source

pub fn iteration_count(&self) -> c_int

source

pub fn is_abandoned(&self) -> bool

source

pub fn is_proven_optimal(&self) -> bool

source

pub fn is_proven_infeasible(&self) -> bool

source

pub fn is_continuous_unbounded(&self) -> bool

source

pub fn is_node_limit_reached(&self) -> bool

source

pub fn is_seconds_limit_reached(&self) -> bool

source

pub fn is_solution_limit_reached(&self) -> bool

source

pub fn is_initial_solve_abandoned(&self) -> bool

source

pub fn is_initial_solve_proven_optimal(&self) -> bool

source

pub fn is_initial_solve_proven_primal_infeasible(&self) -> bool

source

pub fn row_activity(&self) -> &[f64]

Available on crate feature cbc-310 only.

Primal row solution This function is not available on libcbc < 3.10

source

pub fn col_solution(&self) -> &[f64]

Primal column solution

source

pub fn reduced_cost(&self) -> &[f64]

Available on crate feature cbc-310 only.

Dual column solution. This function is not available on libcbc < 3.10.

source

pub fn obj_value(&self) -> f64

Examples found in repository?
examples/knapsack.rs (line 51)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
fn main() {
    // a simple knapsack problem
    // Maximize  5x[1] + 3x[2] + 2x[3] + 7x[4] + 4x[5]
    // s.t.      2x[1] + 8x[2] + 4x[3] + 2x[4] + 5x[5] <= 10
    // All x binary

    // Create the problem.
    let mut m = Model::default();

    // The columns. m.add_binary() returns a typed indentifier for a
    // column.
    let cols = [
        m.add_binary(),
        m.add_binary(),
        m.add_binary(),
        m.add_binary(),
        m.add_binary(),
    ];

    // The row. m.add_row() returns a typed identifier for a row.
    let row = m.add_row();

    // Set the bound of the knapsack constraint.
    m.set_row_upper(row, 10.);

    // Set weights of the constraint.
    m.set_weight(row, cols[0], 2.);
    m.set_weight(row, cols[1], 8.);
    m.set_weight(row, cols[2], 4.);
    m.set_weight(row, cols[3], 2.);
    m.set_weight(row, cols[4], 5.);

    // Set objective coefficients
    m.set_obj_coeff(cols[0], 5.);
    m.set_obj_coeff(cols[1], 3.);
    m.set_obj_coeff(cols[2], 2.);
    m.set_obj_coeff(cols[3], 7.);
    m.set_obj_coeff(cols[4], 4.);

    // Set objective sense.
    m.set_obj_sense(Sense::Maximize);

    // Solve the problem. Returns the solution
    let sol = m.solve();

    // Check the result. sol.raw() returns a shared reference to the
    // raw bindings, allowing to use all getters.
    assert_eq!(Status::Finished, sol.raw().status());
    assert_eq!(16., sol.raw().obj_value());

    // Check for the solution.
    assert_eq!(1., sol.col(cols[0]));
    assert_eq!(0., sol.col(cols[1]));
    assert_eq!(0., sol.col(cols[2]));
    assert_eq!(1., sol.col(cols[3]));
    assert_eq!(1., sol.col(cols[4]));
}
source

pub fn best_possible_value(&self) -> f64

source

pub fn print_solution(&self)

source

pub fn status(&self) -> Status

Examples found in repository?
examples/knapsack.rs (line 50)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
fn main() {
    // a simple knapsack problem
    // Maximize  5x[1] + 3x[2] + 2x[3] + 7x[4] + 4x[5]
    // s.t.      2x[1] + 8x[2] + 4x[3] + 2x[4] + 5x[5] <= 10
    // All x binary

    // Create the problem.
    let mut m = Model::default();

    // The columns. m.add_binary() returns a typed indentifier for a
    // column.
    let cols = [
        m.add_binary(),
        m.add_binary(),
        m.add_binary(),
        m.add_binary(),
        m.add_binary(),
    ];

    // The row. m.add_row() returns a typed identifier for a row.
    let row = m.add_row();

    // Set the bound of the knapsack constraint.
    m.set_row_upper(row, 10.);

    // Set weights of the constraint.
    m.set_weight(row, cols[0], 2.);
    m.set_weight(row, cols[1], 8.);
    m.set_weight(row, cols[2], 4.);
    m.set_weight(row, cols[3], 2.);
    m.set_weight(row, cols[4], 5.);

    // Set objective coefficients
    m.set_obj_coeff(cols[0], 5.);
    m.set_obj_coeff(cols[1], 3.);
    m.set_obj_coeff(cols[2], 2.);
    m.set_obj_coeff(cols[3], 7.);
    m.set_obj_coeff(cols[4], 4.);

    // Set objective sense.
    m.set_obj_sense(Sense::Maximize);

    // Solve the problem. Returns the solution
    let sol = m.solve();

    // Check the result. sol.raw() returns a shared reference to the
    // raw bindings, allowing to use all getters.
    assert_eq!(Status::Finished, sol.raw().status());
    assert_eq!(16., sol.raw().obj_value());

    // Check for the solution.
    assert_eq!(1., sol.col(cols[0]));
    assert_eq!(0., sol.col(cols[1]));
    assert_eq!(0., sol.col(cols[2]));
    assert_eq!(1., sol.col(cols[3]));
    assert_eq!(1., sol.col(cols[4]));
}
source

pub fn secondary_status(&self) -> SecondaryStatus

Trait Implementations§

source§

impl Clone for Model

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Model

source§

fn default() -> Self

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

impl Drop for Model

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Model

§

impl !Send for Model

§

impl !Sync for Model

§

impl Unpin for Model

§

impl UnwindSafe for Model

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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.