Struct Model

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

A linear programming model.

Implementations§

Source§

impl Model

Source

pub fn new() -> Self

Creates a new linear programming model.

Examples found in repository?
examples/simple_model.rs (line 4)
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 add_col( &mut self, colentries: Vec<f64>, objval: f64, lb: f64, ub: f64, ) -> ColId

Adds a column to the model.

§Arguments
  • colentries - An array of f64 representing the column entries.
  • objval - The objective value of the column.
  • lb - The lower bound of the column.
  • ub - The upper bound of the column.
§Returns

The ColId of the added column.

Examples found in repository?
examples/simple_model.rs (line 5)
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 add_row(&mut self, rowentries: Vec<f64>, lhs: f64, rhs: f64) -> RowId

Adds a row to the model.

§Arguments
  • rowentries - An array of f64 representing the row entries.
  • lhs - The left-hand side of the row.
  • rhs - The right-hand side of the row.
§Returns

The RowId of the added row.

Examples found in repository?
examples/simple_model.rs (line 7)
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 optimize(self) -> SolvedModel

Optimizes the model and returns the solved model.

Examples found in repository?
examples/simple_model.rs (line 11)
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 num_cols(&self) -> usize

Returns the number of columns in the model.

Examples found in repository?
examples/simple_model.rs (line 8)
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 num_rows(&self) -> usize

Returns the number of rows in the model.

Examples found in repository?
examples/simple_model.rs (line 9)
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 remove_col(&mut self, col_id: ColId)

Remove a column from the model.

Examples found in repository?
examples/simple_model.rs (line 32)
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 remove_row(&mut self, row_id: RowId)

Remove a row from the model.

Examples found in repository?
examples/simple_model.rs (line 20)
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 read_file(&mut self, filename: &str)

Read instance from lp/mps file.

§Arguments
  • filename - The name of the lp/mps file to read from.
§Panics

if the file does not exist or the file is not in the correct format.

Source

pub fn set_bool_param(&mut self, param: BoolParam, value: bool)

Sets boolean parameter.

§Arguments
  • param - which BoolParam to set.
  • value - The value of the parameter.
Source

pub fn set_int_param(&mut self, param: IntParam, value: i32)

Sets integer parameter.

§Arguments
  • param - which IntParam to set.
  • value - The value of the parameter.
Source

pub fn set_real_param(&mut self, param: RealParam, value: f64)

Sets real parameter.

§Arguments
  • param - which RealParam to set.
  • value - The value of the parameter.
Source

pub fn change_col_bounds(&mut self, col_id: ColId, lb: f64, ub: f64)

Change the bounds of a column.

§Arguments
  • col_id - The ColId of the column to change.
  • lb - The new lower bound of the column.
  • ub - The new upper bound of the column.
Source

pub fn change_row_range(&mut self, row_id: RowId, lhs: f64, rhs: f64)

Change the range (bounds) of a row.

§Arguments
  • row_id - The RowId of the row to change.
  • lhs - The new left-hand side of the row.
  • rhs - The new right-hand side of the row.
Source

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

Sets the objective sense of the model.

§Arguments
  • sense - The objective sense of the model.
Source

pub fn set_algorithm(&mut self, algorithm: Algorithm)

Sets the algorithm to use.

§Arguments
  • algorithm - The Algorithm to use.
Source

pub fn set_representation(&mut self, representation: Representation)

Sets the representation of the model.

§Arguments
  • representation - The Representation of the model.
Source

pub fn set_verbosity(&mut self, verbosity: Verbosity)

Sets the verbosity level.

§Arguments
  • verbosity - The verbosity level.
Source

pub fn set_factor_update_type(&mut self, factor_update_type: FactorUpdateType)

Sets the factor update type.

§Arguments
  • factor_update_type - The factor update type.
Source

pub fn set_simplifier_type(&mut self, simplifier_type: Simplifier)

Sets the simplifier type.

§Arguments
  • simplifier_type - The simplifier type.
Source

pub fn set_starter_type(&mut self, starter_type: Starter)

Sets the starter type.

§Arguments
  • starter_type - The starter type.
Source

pub fn set_pricer_type(&mut self, pricer_type: Pricer)

Sets the pricer type.

§Arguments
  • pricer_type - The pricer type.
Source

pub fn set_ratio_tester_type(&mut self, ratio_tester_type: RatioTester)

Sets the ratio tester type.

§Arguments
  • ratio_tester_type - The ratio tester type.
Source

pub fn set_sync_mode(&mut self, sync_mode: SyncMode)

Sets the sync mode.

§Arguments
  • sync_mode - The sync mode.
Source

pub fn set_read_mode(&mut self, read_mode: ReadMode)

Sets the read mode.

§Arguments
  • read_mode - The read mode.
Source

pub fn set_solve_mode(&mut self, solve_mode: SolveMode)

Sets the solve mode.

§Arguments
  • solve_mode - The solve mode.
Source

pub fn set_check_mode(&mut self, check_mode: CheckMode)

Sets the check mode.

§Arguments
  • check_mode - The check mode.
Source

pub fn set_timer_mode(&mut self, timer_mode: Timer)

Sets the timer mode.

§Arguments
  • timer_mode - The timer mode.
Source

pub fn set_hyper_pricing(&mut self, hyper_pricing: HyperPricing)

Sets the hyper pricing parameter.

§Arguments
  • hyper_pricing - The hyper pricing parameter.
Source

pub fn set_solution_polishing(&mut self, solution_polishing: SolutionPolishing)

Sets the solution polishing type.

§Arguments
  • solution_polishing - The solution polishing type.
Source

pub fn set_decomp_verbosity(&mut self, decomp_verbosity: Verbosity)

Sets the decomposition verbosity.

§Arguments
  • decomp_verbosity - The decomposition verbosity.
Source

pub fn set_stat_timer(&mut self, stat_timer: Timer)

Sets the statistics timer parameter.

§Arguments
  • stat_timer - The statistics timer parameter.
Source

pub fn set_scalar_type(&mut self, scalar_type: Scalar)

Sets the scalar type.

§Arguments
  • scalar_type - The scalar type.
Source

pub fn set_obj_vals(&mut self, objvals: &mut [f64])

Sets the objective function vector.

§Arguments
  • objvals - The objective function vector.
Source

pub fn obj_sense(&self) -> ObjSense

Gets the objective sense of the model.

Trait Implementations§

Source§

impl Default for Model

Source§

fn default() -> Self

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

impl From<SolvedModel> for Model

Source§

fn from(solved_model: SolvedModel) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Model

§

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