Struct SolvedModel

Source
pub struct SolvedModel { /* private fields */ }
Expand description

A solved linear programming model.

Implementations§

Source§

impl SolvedModel

Source

pub fn num_cols(&self) -> usize

Returns the number of columns in the model.

Source

pub fn num_rows(&self) -> usize

Returns the number of rows in the model.

Source

pub fn status(&self) -> Status

Returns the Status of the model.

Examples found in repository?
examples/simple_model.rs (line 12)
3fn main() {
4    let mut lp = Model::new();
5    let col1 = lp.add_col(vec![], 1.0, 0.0, 5.0);
6    let _col2 = lp.add_col(vec![], 1.0, 0.0, 10.0);
7    let row = lp.add_row(vec![1.0, 1.0], 1.0, 5.0);
8    assert_eq!(lp.num_cols(), 2);
9    assert_eq!(lp.num_rows(), 1);
10
11    let lp = lp.optimize();
12    let result = lp.status();
13    assert_eq!(result, Status::Optimal);
14    assert!((lp.obj_val() - 5.0).abs() < 1e-6);
15    let dual_sol = lp.dual_solution();
16    assert_eq!(dual_sol.len(), 1);
17    assert!((dual_sol[0] - 1.0).abs() < 1e-6);
18
19    let mut lp = Model::from(lp);
20    lp.remove_row(row);
21    assert_eq!(lp.num_rows(), 0);
22    let lp = lp.optimize();
23    let new_result = lp.status();
24    assert_eq!(new_result, Status::Optimal);
25    assert!((lp.obj_val() - 15.0).abs() < 1e-6);
26    let primal_sol = lp.primal_solution();
27    assert_eq!(primal_sol.len(), 2);
28    assert!((primal_sol[0] - 5.0).abs() < 1e-6);
29    assert!((primal_sol[1] - 10.0).abs() < 1e-6);
30
31    let mut lp = Model::from(lp);
32    lp.remove_col(col1);
33    assert_eq!(lp.num_cols(), 1);
34    let lp = lp.optimize();
35    let new_result = lp.status();
36    assert_eq!(new_result, Status::Optimal);
37    assert!((lp.obj_val() - 10.0).abs() < 1e-6);
38
39    assert!(lp.solving_time() >= 0.0);
40}
Source

pub fn obj_val(&self) -> f64

Returns the objective value of the model.

Examples found in repository?
examples/simple_model.rs (line 14)
3fn main() {
4    let mut lp = Model::new();
5    let col1 = lp.add_col(vec![], 1.0, 0.0, 5.0);
6    let _col2 = lp.add_col(vec![], 1.0, 0.0, 10.0);
7    let row = lp.add_row(vec![1.0, 1.0], 1.0, 5.0);
8    assert_eq!(lp.num_cols(), 2);
9    assert_eq!(lp.num_rows(), 1);
10
11    let lp = lp.optimize();
12    let result = lp.status();
13    assert_eq!(result, Status::Optimal);
14    assert!((lp.obj_val() - 5.0).abs() < 1e-6);
15    let dual_sol = lp.dual_solution();
16    assert_eq!(dual_sol.len(), 1);
17    assert!((dual_sol[0] - 1.0).abs() < 1e-6);
18
19    let mut lp = Model::from(lp);
20    lp.remove_row(row);
21    assert_eq!(lp.num_rows(), 0);
22    let lp = lp.optimize();
23    let new_result = lp.status();
24    assert_eq!(new_result, Status::Optimal);
25    assert!((lp.obj_val() - 15.0).abs() < 1e-6);
26    let primal_sol = lp.primal_solution();
27    assert_eq!(primal_sol.len(), 2);
28    assert!((primal_sol[0] - 5.0).abs() < 1e-6);
29    assert!((primal_sol[1] - 10.0).abs() < 1e-6);
30
31    let mut lp = Model::from(lp);
32    lp.remove_col(col1);
33    assert_eq!(lp.num_cols(), 1);
34    let lp = lp.optimize();
35    let new_result = lp.status();
36    assert_eq!(new_result, Status::Optimal);
37    assert!((lp.obj_val() - 10.0).abs() < 1e-6);
38
39    assert!(lp.solving_time() >= 0.0);
40}
Source

pub fn primal_solution(&self) -> Vec<f64>

Returns the primal solution of the model.

Examples found in repository?
examples/simple_model.rs (line 26)
3fn main() {
4    let mut lp = Model::new();
5    let col1 = lp.add_col(vec![], 1.0, 0.0, 5.0);
6    let _col2 = lp.add_col(vec![], 1.0, 0.0, 10.0);
7    let row = lp.add_row(vec![1.0, 1.0], 1.0, 5.0);
8    assert_eq!(lp.num_cols(), 2);
9    assert_eq!(lp.num_rows(), 1);
10
11    let lp = lp.optimize();
12    let result = lp.status();
13    assert_eq!(result, Status::Optimal);
14    assert!((lp.obj_val() - 5.0).abs() < 1e-6);
15    let dual_sol = lp.dual_solution();
16    assert_eq!(dual_sol.len(), 1);
17    assert!((dual_sol[0] - 1.0).abs() < 1e-6);
18
19    let mut lp = Model::from(lp);
20    lp.remove_row(row);
21    assert_eq!(lp.num_rows(), 0);
22    let lp = lp.optimize();
23    let new_result = lp.status();
24    assert_eq!(new_result, Status::Optimal);
25    assert!((lp.obj_val() - 15.0).abs() < 1e-6);
26    let primal_sol = lp.primal_solution();
27    assert_eq!(primal_sol.len(), 2);
28    assert!((primal_sol[0] - 5.0).abs() < 1e-6);
29    assert!((primal_sol[1] - 10.0).abs() < 1e-6);
30
31    let mut lp = Model::from(lp);
32    lp.remove_col(col1);
33    assert_eq!(lp.num_cols(), 1);
34    let lp = lp.optimize();
35    let new_result = lp.status();
36    assert_eq!(new_result, Status::Optimal);
37    assert!((lp.obj_val() - 10.0).abs() < 1e-6);
38
39    assert!(lp.solving_time() >= 0.0);
40}
Source

pub fn dual_solution(&self) -> Vec<f64>

Returns the dual solution of the model.

Examples found in repository?
examples/simple_model.rs (line 15)
3fn main() {
4    let mut lp = Model::new();
5    let col1 = lp.add_col(vec![], 1.0, 0.0, 5.0);
6    let _col2 = lp.add_col(vec![], 1.0, 0.0, 10.0);
7    let row = lp.add_row(vec![1.0, 1.0], 1.0, 5.0);
8    assert_eq!(lp.num_cols(), 2);
9    assert_eq!(lp.num_rows(), 1);
10
11    let lp = lp.optimize();
12    let result = lp.status();
13    assert_eq!(result, Status::Optimal);
14    assert!((lp.obj_val() - 5.0).abs() < 1e-6);
15    let dual_sol = lp.dual_solution();
16    assert_eq!(dual_sol.len(), 1);
17    assert!((dual_sol[0] - 1.0).abs() < 1e-6);
18
19    let mut lp = Model::from(lp);
20    lp.remove_row(row);
21    assert_eq!(lp.num_rows(), 0);
22    let lp = lp.optimize();
23    let new_result = lp.status();
24    assert_eq!(new_result, Status::Optimal);
25    assert!((lp.obj_val() - 15.0).abs() < 1e-6);
26    let primal_sol = lp.primal_solution();
27    assert_eq!(primal_sol.len(), 2);
28    assert!((primal_sol[0] - 5.0).abs() < 1e-6);
29    assert!((primal_sol[1] - 10.0).abs() < 1e-6);
30
31    let mut lp = Model::from(lp);
32    lp.remove_col(col1);
33    assert_eq!(lp.num_cols(), 1);
34    let lp = lp.optimize();
35    let new_result = lp.status();
36    assert_eq!(new_result, Status::Optimal);
37    assert!((lp.obj_val() - 10.0).abs() < 1e-6);
38
39    assert!(lp.solving_time() >= 0.0);
40}
Source

pub fn solving_time(&self) -> f64

Returns the solving time of the model in seconds.

Examples found in repository?
examples/simple_model.rs (line 39)
3fn main() {
4    let mut lp = Model::new();
5    let col1 = lp.add_col(vec![], 1.0, 0.0, 5.0);
6    let _col2 = lp.add_col(vec![], 1.0, 0.0, 10.0);
7    let row = lp.add_row(vec![1.0, 1.0], 1.0, 5.0);
8    assert_eq!(lp.num_cols(), 2);
9    assert_eq!(lp.num_rows(), 1);
10
11    let lp = lp.optimize();
12    let result = lp.status();
13    assert_eq!(result, Status::Optimal);
14    assert!((lp.obj_val() - 5.0).abs() < 1e-6);
15    let dual_sol = lp.dual_solution();
16    assert_eq!(dual_sol.len(), 1);
17    assert!((dual_sol[0] - 1.0).abs() < 1e-6);
18
19    let mut lp = Model::from(lp);
20    lp.remove_row(row);
21    assert_eq!(lp.num_rows(), 0);
22    let lp = lp.optimize();
23    let new_result = lp.status();
24    assert_eq!(new_result, Status::Optimal);
25    assert!((lp.obj_val() - 15.0).abs() < 1e-6);
26    let primal_sol = lp.primal_solution();
27    assert_eq!(primal_sol.len(), 2);
28    assert!((primal_sol[0] - 5.0).abs() < 1e-6);
29    assert!((primal_sol[1] - 10.0).abs() < 1e-6);
30
31    let mut lp = Model::from(lp);
32    lp.remove_col(col1);
33    assert_eq!(lp.num_cols(), 1);
34    let lp = lp.optimize();
35    let new_result = lp.status();
36    assert_eq!(new_result, Status::Optimal);
37    assert!((lp.obj_val() - 10.0).abs() < 1e-6);
38
39    assert!(lp.solving_time() >= 0.0);
40}
Source

pub fn reduced_costs(&self) -> Vec<f64>

Returns the reduced costs of the model.

Source

pub fn num_iterations(&self) -> i32

Returns the number of iterations it took to solve the model.

Source

pub fn col_basis_status(&self, col_id: ColId) -> ColBasisStatus

Returns the basis status of a column.

§Arguments
  • col_id - The ColId of the column.
§Returns

The BasisStatus of the column.

Source

pub fn row_basis_status(&self, row_id: RowId) -> RowBasisStatus

Returns the basis status of a row.

§Arguments
  • row_id - The RowId of the row.
§Returns

The BasisStatus of the row.

Trait Implementations§

Source§

impl From<SolvedModel> for Model

Source§

fn from(solved_model: SolvedModel) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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 = 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 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.