From d77571c298efb67cf9d47006c2a53bd627242a40 Mon Sep 17 00:00:00 2001 From: Mohammed Ghannam Date: Thu, 9 Jan 2025 14:47:54 +0100 Subject: [PATCH] Cargo fmt --- src/col.rs | 5 +++- src/eventhdlr.rs | 24 +++++++++++++++----- src/pricer.rs | 59 +++++++++++++++++++++++++++++++++--------------- src/row.rs | 9 ++++++-- src/scip.rs | 18 +++++++-------- 5 files changed, 78 insertions(+), 37 deletions(-) diff --git a/src/col.rs b/src/col.rs index f04cd3f..bb6f6ce 100644 --- a/src/col.rs +++ b/src/col.rs @@ -192,7 +192,10 @@ impl PartialEq for Col { #[cfg(test)] mod tests { - use crate::{minimal_model, BasisStatus, Event, EventMask, Eventhdlr, Model, ModelWithProblem, ProblemOrSolving, SCIPEventhdlr, Solving, VarType}; + use crate::{ + minimal_model, BasisStatus, Event, EventMask, Eventhdlr, Model, ModelWithProblem, + ProblemOrSolving, SCIPEventhdlr, Solving, VarType, + }; struct ColTesterEventHandler; diff --git a/src/eventhdlr.rs b/src/eventhdlr.rs index 789be8e..b5b9bff 100644 --- a/src/eventhdlr.rs +++ b/src/eventhdlr.rs @@ -16,8 +16,7 @@ pub trait Eventhdlr { } /// The EventMask represents different states or actions within an optimization problem. -#[derive(Debug, Copy, Clone)] -#[derive(PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq)] pub struct EventMask(u64); impl EventMask { @@ -224,7 +223,12 @@ mod tests { EventMask::LP_EVENT | EventMask::NODE_EVENT } - fn execute(&mut self, _model: Model, _eventhdlr: crate::SCIPEventhdlr, _event: Event) { + fn execute( + &mut self, + _model: Model, + _eventhdlr: crate::SCIPEventhdlr, + _event: Event, + ) { *self.counter.borrow_mut() += 1; } } @@ -247,7 +251,6 @@ mod tests { assert!(*counter.borrow() > 1); } - struct InternalSCIPEventHdlrTester; impl Eventhdlr for InternalSCIPEventHdlrTester { @@ -255,7 +258,12 @@ mod tests { EventMask::LP_EVENT | EventMask::NODE_EVENT } - fn execute(&mut self, _model: Model, eventhdlr: crate::SCIPEventhdlr, event: Event) { + fn execute( + &mut self, + _model: Model, + eventhdlr: crate::SCIPEventhdlr, + event: Event, + ) { assert!(self.get_type().matches(event.event_type())); assert_eq!(eventhdlr.name(), "InternalSCIPEventHdlrTester"); } @@ -268,7 +276,11 @@ mod tests { .include_default_plugins() .read_prob("data/test/simple.lp") .unwrap() - .include_eventhdlr("InternalSCIPEventHdlrTester", "", Box::new(InternalSCIPEventHdlrTester)) + .include_eventhdlr( + "InternalSCIPEventHdlrTester", + "", + Box::new(InternalSCIPEventHdlrTester), + ) .solve(); } } diff --git a/src/pricer.rs b/src/pricer.rs index 3ebdb7c..f176130 100644 --- a/src/pricer.rs +++ b/src/pricer.rs @@ -7,9 +7,14 @@ pub trait Pricer { /// /// # Arguments /// * `model`: the current model of the SCIP instance in `Solving` stage. - /// * `pricer`: the internal pricer object. + /// * `pricer`: the internal pricer object. /// * `farkas`: If true, the pricer should generate columns to repair feasibility of LP. - fn generate_columns(&mut self, model: Model, pricer: SCIPPricer, farkas: bool) -> PricerResult; + fn generate_columns( + &mut self, + model: Model, + pricer: SCIPPricer, + farkas: bool, + ) -> PricerResult; } /// An enum representing the possible states of a `PricerResult`. @@ -45,7 +50,6 @@ impl From for SCIP_Result { } } - /// A wrapper around a SCIP pricer object. pub struct SCIPPricer { pub(crate) raw: *mut ffi::SCIP_PRICER, @@ -74,23 +78,17 @@ impl SCIPPricer { /// Returns the priority of the pricer. pub fn priority(&self) -> i32 { - unsafe { - ffi::SCIPpricerGetPriority(self.raw) - } + unsafe { ffi::SCIPpricerGetPriority(self.raw) } } /// Returns the delay of the pricer. pub fn is_delayed(&self) -> bool { - unsafe { - ffi::SCIPpricerIsDelayed(self.raw) != 0 - } + unsafe { ffi::SCIPpricerIsDelayed(self.raw) != 0 } } /// Returns whether the pricer is active. pub fn is_active(&self) -> bool { - unsafe { - ffi::SCIPpricerIsActive(self.raw) != 0 - } + unsafe { ffi::SCIPpricerIsActive(self.raw) != 0 } } } @@ -105,7 +103,12 @@ mod tests { struct LyingPricer; impl Pricer for LyingPricer { - fn generate_columns(&mut self, _model: Model, _pricer: SCIPPricer, _farkas: bool) -> PricerResult { + fn generate_columns( + &mut self, + _model: Model, + _pricer: SCIPPricer, + _farkas: bool, + ) -> PricerResult { PricerResult { state: PricerResultState::FoundColumns, lower_bound: None, @@ -131,7 +134,12 @@ mod tests { struct EarlyStoppingPricer; impl Pricer for EarlyStoppingPricer { - fn generate_columns(&mut self, _model: Model, _pricer: SCIPPricer, _farkas: bool) -> PricerResult { + fn generate_columns( + &mut self, + _model: Model, + _pricer: SCIPPricer, + _farkas: bool, + ) -> PricerResult { PricerResult { state: PricerResultState::StopEarly, lower_bound: None, @@ -158,7 +166,12 @@ mod tests { struct OptimalPricer; impl Pricer for OptimalPricer { - fn generate_columns(&mut self, _model: Model, _pricer: SCIPPricer, _farkas: bool) -> PricerResult { + fn generate_columns( + &mut self, + _model: Model, + _pricer: SCIPPricer, + _farkas: bool, + ) -> PricerResult { PricerResult { state: PricerResultState::NoColumns, lower_bound: None, @@ -194,7 +207,12 @@ mod tests { } impl Pricer for AddSameColumnPricer { - fn generate_columns(&mut self, mut model: Model, _pricer: SCIPPricer, _farkas: bool) -> PricerResult { + fn generate_columns( + &mut self, + mut model: Model, + _pricer: SCIPPricer, + _farkas: bool, + ) -> PricerResult { assert_eq!(self.data.a, (0..1000).collect::>()); if self.added { PricerResult { @@ -250,7 +268,12 @@ mod tests { struct InternalSCIPPricerTester; impl Pricer for InternalSCIPPricerTester { - fn generate_columns(&mut self, _model: Model, pricer: SCIPPricer, _farkas: bool) -> PricerResult { + fn generate_columns( + &mut self, + _model: Model, + pricer: SCIPPricer, + _farkas: bool, + ) -> PricerResult { assert_eq!(pricer.name(), "internal"); assert_eq!(pricer.desc(), "internal pricer"); assert_eq!(pricer.priority(), 100); @@ -262,7 +285,7 @@ mod tests { } } } - + #[test] fn internal_pricer() { let pricer = InternalSCIPPricerTester {}; diff --git a/src/row.rs b/src/row.rs index 76288b6..cb0c660 100644 --- a/src/row.rs +++ b/src/row.rs @@ -226,7 +226,7 @@ impl From for RowOrigin { #[cfg(test)] mod tests { use crate::Event; -use crate::{ + use crate::{ minimal_model, EventMask, Eventhdlr, HasScipPtr, Model, ModelWithProblem, ProblemOrSolving, Solving, VarType, }; @@ -238,7 +238,12 @@ use crate::{ EventMask::FIRST_LP_SOLVED } - fn execute(&mut self, model: Model, _eventhdlr: crate::SCIPEventhdlr, _event: Event) { + fn execute( + &mut self, + model: Model, + _eventhdlr: crate::SCIPEventhdlr, + _event: Event, + ) { let first_cons = model.conss()[0].clone(); let row = first_cons.row().unwrap(); assert_eq!(row.n_non_zeroes(), 1); diff --git a/src/scip.rs b/src/scip.rs index 375976f..0301a04 100644 --- a/src/scip.rs +++ b/src/scip.rs @@ -1,6 +1,10 @@ use crate::branchrule::{BranchRule, BranchingCandidate}; use crate::pricer::{Pricer, PricerResultState}; -use crate::{ffi, scip_call_panic, BranchingResult, Constraint, Event, Eventhdlr, HeurResult, Model, Node, ObjSense, ParamSetting, Retcode, SCIPEventhdlr, SCIPPricer, SCIPSeparator, Separator, Solution, Solving, Status, VarType, Variable}; +use crate::{ + ffi, scip_call_panic, BranchingResult, Constraint, Event, Eventhdlr, HeurResult, Model, Node, + ObjSense, ParamSetting, Retcode, SCIPEventhdlr, SCIPPricer, SCIPSeparator, Separator, Solution, + Solving, Status, VarType, Variable, +}; use crate::{scip_call, HeurTiming, Heuristic}; use core::panic; use scip_sys::{SCIP_Cons, SCIP_Var, Scip, SCIP_SOL}; @@ -600,12 +604,8 @@ impl ScipPtr { scip: Rc::new(scip_ptr), state: Solving, }; - let eventhdlr = SCIPEventhdlr { - raw: eventhdlr, - }; - let event = Event { - raw: event, - }; + let eventhdlr = SCIPEventhdlr { raw: eventhdlr }; + let event = Event { raw: event }; unsafe { (*eventhdlr_ptr).execute(model, eventhdlr, event) }; Retcode::Okay.into() } @@ -785,9 +785,7 @@ impl ScipPtr { state: Solving, }; - let pricer = SCIPPricer { - raw: pricer, - }; + let pricer = SCIPPricer { raw: pricer }; let pricing_res = unsafe { (*pricer_ptr).generate_columns(model, pricer, farkas) }; if !farkas {