From ea247af8112a33a1ef3c0283739be581480a2e17 Mon Sep 17 00:00:00 2001 From: Mohammed Ghannam Date: Sat, 20 Jul 2024 16:38:14 +0200 Subject: [PATCH] Cargo fmt --- examples/simple_model.rs | 2 +- src/basis_status.rs | 3 +- src/lib.rs | 6 +-- src/model.rs | 100 ++++++++++++++++++++++++++------------- src/param.rs | 6 --- src/soplex_ptr.rs | 5 +- src/status.rs | 1 - 7 files changed, 75 insertions(+), 48 deletions(-) diff --git a/examples/simple_model.rs b/examples/simple_model.rs index 0b1d821..94524ba 100644 --- a/examples/simple_model.rs +++ b/examples/simple_model.rs @@ -37,4 +37,4 @@ fn main() { assert!((lp.obj_val() - 10.0).abs() < 1e-6); assert!(lp.solving_time() >= 0.0); -} \ No newline at end of file +} diff --git a/src/basis_status.rs b/src/basis_status.rs index 628b3fc..813d382 100644 --- a/src/basis_status.rs +++ b/src/basis_status.rs @@ -15,7 +15,6 @@ pub enum ColBasisStatus { Unknown = 5, } - /// Row basis status #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RowBasisStatus { @@ -56,4 +55,4 @@ impl From for RowBasisStatus { _ => panic!("Invalid value for BasisStatus"), } } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index f341c26..22a56d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,12 +44,12 @@ pub mod ffi { pub use soplex_sys::*; } +mod basis_status; mod model; -mod soplex_ptr; mod param; -mod basis_status; +mod soplex_ptr; pub use basis_status::*; pub use param::*; -pub use model::*; \ No newline at end of file +pub use model::*; diff --git a/src/model.rs b/src/model.rs index 0b23ebe..88edeaf 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,7 +1,7 @@ -use crate::{BoolParam, ColBasisStatus, ffi, IntParam, ObjSense, RealParam, RowBasisStatus}; use crate::param::{ALGORITHM_PARAM_ID, OBJSENSE_PARAM_ID, REPR_PARAM_ID}; use crate::soplex_ptr::SoplexPtr; use crate::status::Status; +use crate::{ffi, BoolParam, ColBasisStatus, IntParam, ObjSense, RealParam, RowBasisStatus}; /// A linear programming model. pub struct Model { @@ -17,7 +17,9 @@ pub struct ColId(usize); impl Model { /// Creates a new linear programming model. pub fn new() -> Self { - Self { inner: SoplexPtr::new() } + Self { + inner: SoplexPtr::new(), + } } /// Adds a column to the model. @@ -32,16 +34,26 @@ impl Model { /// # Returns /// /// The `ColId` of the added column. - pub fn add_col(&mut self, mut colentries: [f64; N], objval: f64, lb: f64, ub: f64) -> ColId { + pub fn add_col( + &mut self, + mut colentries: [f64; N], + objval: f64, + lb: f64, + ub: f64, + ) -> ColId { let nnonzeros = colentries.iter().filter(|&&x| x != 0.0).count(); let colsize = colentries.len(); unsafe { - ffi::SoPlex_addColReal(*self.inner, - colentries.as_mut_ptr(), - colsize as i32, - nnonzeros as i32, - objval, lb, ub); + ffi::SoPlex_addColReal( + *self.inner, + colentries.as_mut_ptr(), + colsize as i32, + nnonzeros as i32, + objval, + lb, + ub, + ); } ColId(self.num_cols() - 1) @@ -58,16 +70,24 @@ impl Model { /// # Returns /// /// The `RowId` of the added row. - pub fn add_row(&mut self, mut rowentries: [f64; N], lhs: f64, rhs: f64) -> RowId { + pub fn add_row( + &mut self, + mut rowentries: [f64; N], + lhs: f64, + rhs: f64, + ) -> RowId { let nnonzeros = rowentries.iter().filter(|&&x| x != 0.0).count(); let rowsize = rowentries.len(); unsafe { - ffi::SoPlex_addRowReal(*self.inner, - rowentries.as_mut_ptr(), - rowsize as i32, - nnonzeros as i32, - lhs, rhs); + ffi::SoPlex_addRowReal( + *self.inner, + rowentries.as_mut_ptr(), + rowsize as i32, + nnonzeros as i32, + lhs, + rhs, + ); } RowId(self.num_rows() - 1) @@ -94,7 +114,6 @@ impl Model { unsafe { ffi::SoPlex_removeColReal(*self.inner, col_id.0 as i32) }; } - /// Remove a row from the model. pub fn remove_row(&mut self, row_id: RowId) { unsafe { ffi::SoPlex_removeRowReal(*self.inner, row_id.0 as i32) }; @@ -155,7 +174,6 @@ impl Model { } } - /// Change the bounds of a column. /// /// # Arguments @@ -220,14 +238,17 @@ impl Model { } } - /// Sets the factor update type. /// /// # Arguments /// * `factor_update_type` - The factor update type. pub fn set_factor_update_type(&mut self, factor_update_type: crate::FactorUpdateType) { unsafe { - ffi::SoPlex_setIntParam(*self.inner, crate::FACTOR_UPDATE_TYPE_PARAM_ID, factor_update_type.into()); + ffi::SoPlex_setIntParam( + *self.inner, + crate::FACTOR_UPDATE_TYPE_PARAM_ID, + factor_update_type.into(), + ); } } @@ -237,7 +258,11 @@ impl Model { /// * `simplifier_type` - The simplifier type. pub fn set_simplifier_type(&mut self, simplifier_type: crate::Simplifier) { unsafe { - ffi::SoPlex_setIntParam(*self.inner, crate::SIMPLIFIER_PARAM_ID, simplifier_type.into()); + ffi::SoPlex_setIntParam( + *self.inner, + crate::SIMPLIFIER_PARAM_ID, + simplifier_type.into(), + ); } } @@ -267,7 +292,11 @@ impl Model { /// * `ratio_tester_type` - The ratio tester type. pub fn set_ratio_tester_type(&mut self, ratio_tester_type: crate::RatioTester) { unsafe { - ffi::SoPlex_setIntParam(*self.inner, crate::RATIO_TESTER_PARAM_ID, ratio_tester_type.into()); + ffi::SoPlex_setIntParam( + *self.inner, + crate::RATIO_TESTER_PARAM_ID, + ratio_tester_type.into(), + ); } } @@ -281,7 +310,6 @@ impl Model { } } - /// Sets the read mode. /// /// # Arguments @@ -328,7 +356,11 @@ impl Model { /// * `hyper_pricing` - The hyper pricing parameter. pub fn set_hyper_pricing(&mut self, hyper_pricing: crate::HyperPricing) { unsafe { - ffi::SoPlex_setIntParam(*self.inner, crate::HYPER_PRICING_PARAM_ID, hyper_pricing.into()); + ffi::SoPlex_setIntParam( + *self.inner, + crate::HYPER_PRICING_PARAM_ID, + hyper_pricing.into(), + ); } } @@ -338,7 +370,11 @@ impl Model { /// * `solution_polishing` - The solution polishing type. pub fn set_solution_polishing(&mut self, solution_polishing: crate::SolutionPolishing) { unsafe { - ffi::SoPlex_setIntParam(*self.inner, crate::SOLUTION_POLISHING_PARAM_ID, solution_polishing.into()); + ffi::SoPlex_setIntParam( + *self.inner, + crate::SOLUTION_POLISHING_PARAM_ID, + solution_polishing.into(), + ); } } @@ -348,7 +384,11 @@ impl Model { /// * `decomp_verbosity` - The decomposition verbosity. pub fn set_decomp_verbosity(&mut self, decomp_verbosity: crate::Verbosity) { unsafe { - ffi::SoPlex_setIntParam(*self.inner, crate::DECOMP_VERBOSITY_PARAM_ID, decomp_verbosity.into()); + ffi::SoPlex_setIntParam( + *self.inner, + crate::DECOMP_VERBOSITY_PARAM_ID, + decomp_verbosity.into(), + ); } } @@ -399,7 +439,6 @@ impl SolvedModel { unsafe { ffi::SoPlex_objValueReal(*self.inner) } } - /// Returns the primal solution of the model. pub fn primal_solution(&self) -> Vec { let mut primal = vec![0.0; self.num_cols()]; @@ -462,15 +501,16 @@ impl SolvedModel { impl From for Model { fn from(solved_model: SolvedModel) -> Self { - Self { inner: solved_model.inner } + Self { + inner: solved_model.inner, + } } } - #[cfg(test)] mod tests { - use crate::Algorithm; use super::*; + use crate::Algorithm; #[test] fn simple_problem() { @@ -522,7 +562,6 @@ mod tests { assert!((lp.obj_val() - -27.66666666).abs() < 1e-6); } - #[test] fn num_iterations() { let mut lp = Model::new(); @@ -558,7 +597,6 @@ mod tests { assert_eq!(lp.status(), Status::AbortTime); } - #[test] fn set_bool_param() { // TODO: think of a better test, @@ -598,7 +636,6 @@ mod tests { assert_eq!(result, Status::Infeasible); } - #[test] fn basis_status() { let mut lp = Model::new(); @@ -612,7 +649,6 @@ mod tests { assert_eq!(row_basis_status, RowBasisStatus::AtUpper); } - #[test] fn set_obj_sense() { let mut lp = Model::new(); diff --git a/src/param.rs b/src/param.rs index 020e552..c3bf8fd 100644 --- a/src/param.rs +++ b/src/param.rs @@ -54,7 +54,6 @@ pub enum BoolParam { SimplifierDominatedCols = 24, } - pub(crate) const OBJSENSE_PARAM_ID: i32 = 0; pub(crate) const REPR_PARAM_ID: i32 = 1; pub(crate) const ALGORITHM_PARAM_ID: i32 = 2; @@ -347,8 +346,6 @@ pub enum RealParam { SimplifierModifyRowFac = 25, } - - macro_rules! impl_from_int_param { ($($param:ident),*) => { $( @@ -383,6 +380,3 @@ impl_from_int_param!( SolutionPolishing, ReadMode ); - - - diff --git a/src/soplex_ptr.rs b/src/soplex_ptr.rs index 08a52e7..e074360 100644 --- a/src/soplex_ptr.rs +++ b/src/soplex_ptr.rs @@ -1,6 +1,6 @@ +use crate::ffi; use std::ffi::c_void; use std::ops::Deref; -use crate::ffi; pub(crate) struct SoplexPtr { ptr: *mut c_void, @@ -14,7 +14,6 @@ impl SoplexPtr { } } - impl Default for SoplexPtr { fn default() -> Self { SoplexPtr::new() @@ -35,4 +34,4 @@ impl Drop for SoplexPtr { ffi::SoPlex_free(self.ptr); } } -} \ No newline at end of file +} diff --git a/src/status.rs b/src/status.rs index 1623bfb..e170937 100644 --- a/src/status.rs +++ b/src/status.rs @@ -1,6 +1,5 @@ use std::convert::From; - /// Status of the solver #[derive(Debug, PartialEq, Clone)] pub enum Status {