pub struct Model { /* private fields */ }Expand description
A linear programming model.
Implementations§
Source§impl Model
impl Model
Sourcepub fn new() -> Self
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}Sourcepub fn add_col(
&mut self,
colentries: Vec<f64>,
objval: f64,
lb: f64,
ub: f64,
) -> ColId
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}Sourcepub fn add_row(&mut self, rowentries: Vec<f64>, lhs: f64, rhs: f64) -> RowId
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}Sourcepub fn optimize(self) -> SolvedModel
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}Sourcepub fn num_cols(&self) -> usize
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}Sourcepub fn num_rows(&self) -> usize
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}Sourcepub fn remove_col(&mut self, col_id: ColId)
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}Sourcepub fn remove_row(&mut self, row_id: RowId)
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}Sourcepub fn set_bool_param(&mut self, param: BoolParam, value: bool)
pub fn set_bool_param(&mut self, param: BoolParam, value: bool)
Sets boolean parameter.
§Arguments
param- whichBoolParamto set.value- The value of the parameter.
Sourcepub fn set_int_param(&mut self, param: IntParam, value: i32)
pub fn set_int_param(&mut self, param: IntParam, value: i32)
Sets integer parameter.
§Arguments
param- whichIntParamto set.value- The value of the parameter.
Sourcepub fn set_real_param(&mut self, param: RealParam, value: f64)
pub fn set_real_param(&mut self, param: RealParam, value: f64)
Sourcepub fn change_col_bounds(&mut self, col_id: ColId, lb: f64, ub: f64)
pub fn change_col_bounds(&mut self, col_id: ColId, lb: f64, ub: f64)
Change the bounds of a column.
§Arguments
col_id- TheColIdof the column to change.lb- The new lower bound of the column.ub- The new upper bound of the column.
Sourcepub fn change_row_range(&mut self, row_id: RowId, lhs: f64, rhs: f64)
pub fn change_row_range(&mut self, row_id: RowId, lhs: f64, rhs: f64)
Change the range (bounds) of a row.
§Arguments
row_id- TheRowIdof the row to change.lhs- The new left-hand side of the row.rhs- The new right-hand side of the row.
Sourcepub fn set_obj_sense(&mut self, sense: ObjSense)
pub fn set_obj_sense(&mut self, sense: ObjSense)
Sourcepub fn set_algorithm(&mut self, algorithm: Algorithm)
pub fn set_algorithm(&mut self, algorithm: Algorithm)
Sourcepub fn set_representation(&mut self, representation: Representation)
pub fn set_representation(&mut self, representation: Representation)
Sourcepub fn set_verbosity(&mut self, verbosity: Verbosity)
pub fn set_verbosity(&mut self, verbosity: Verbosity)
Sourcepub fn set_factor_update_type(&mut self, factor_update_type: FactorUpdateType)
pub fn set_factor_update_type(&mut self, factor_update_type: FactorUpdateType)
Sourcepub fn set_simplifier_type(&mut self, simplifier_type: Simplifier)
pub fn set_simplifier_type(&mut self, simplifier_type: Simplifier)
Sourcepub fn set_starter_type(&mut self, starter_type: Starter)
pub fn set_starter_type(&mut self, starter_type: Starter)
Sourcepub fn set_pricer_type(&mut self, pricer_type: Pricer)
pub fn set_pricer_type(&mut self, pricer_type: Pricer)
Sourcepub fn set_ratio_tester_type(&mut self, ratio_tester_type: RatioTester)
pub fn set_ratio_tester_type(&mut self, ratio_tester_type: RatioTester)
Sourcepub fn set_sync_mode(&mut self, sync_mode: SyncMode)
pub fn set_sync_mode(&mut self, sync_mode: SyncMode)
Sourcepub fn set_read_mode(&mut self, read_mode: ReadMode)
pub fn set_read_mode(&mut self, read_mode: ReadMode)
Sourcepub fn set_solve_mode(&mut self, solve_mode: SolveMode)
pub fn set_solve_mode(&mut self, solve_mode: SolveMode)
Sourcepub fn set_check_mode(&mut self, check_mode: CheckMode)
pub fn set_check_mode(&mut self, check_mode: CheckMode)
Sourcepub fn set_timer_mode(&mut self, timer_mode: Timer)
pub fn set_timer_mode(&mut self, timer_mode: Timer)
Sourcepub fn set_hyper_pricing(&mut self, hyper_pricing: HyperPricing)
pub fn set_hyper_pricing(&mut self, hyper_pricing: HyperPricing)
Sourcepub fn set_solution_polishing(&mut self, solution_polishing: SolutionPolishing)
pub fn set_solution_polishing(&mut self, solution_polishing: SolutionPolishing)
Sourcepub fn set_decomp_verbosity(&mut self, decomp_verbosity: Verbosity)
pub fn set_decomp_verbosity(&mut self, decomp_verbosity: Verbosity)
Sourcepub fn set_stat_timer(&mut self, stat_timer: Timer)
pub fn set_stat_timer(&mut self, stat_timer: Timer)
Sourcepub fn set_scalar_type(&mut self, scalar_type: Scalar)
pub fn set_scalar_type(&mut self, scalar_type: Scalar)
Sourcepub fn set_obj_vals(&mut self, objvals: &mut [f64])
pub fn set_obj_vals(&mut self, objvals: &mut [f64])
Trait Implementations§
Source§impl From<SolvedModel> for Model
impl From<SolvedModel> for Model
Source§fn from(solved_model: SolvedModel) -> Self
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more