Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mmghannam committed Jan 9, 2025
1 parent b87a799 commit d77571c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 37 deletions.
5 changes: 4 additions & 1 deletion src/col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 18 additions & 6 deletions src/eventhdlr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -224,7 +223,12 @@ mod tests {
EventMask::LP_EVENT | EventMask::NODE_EVENT
}

fn execute(&mut self, _model: Model<Solving>, _eventhdlr: crate::SCIPEventhdlr, _event: Event) {
fn execute(
&mut self,
_model: Model<Solving>,
_eventhdlr: crate::SCIPEventhdlr,
_event: Event,
) {
*self.counter.borrow_mut() += 1;
}
}
Expand All @@ -247,15 +251,19 @@ mod tests {
assert!(*counter.borrow() > 1);
}


struct InternalSCIPEventHdlrTester;

impl Eventhdlr for InternalSCIPEventHdlrTester {
fn get_type(&self) -> EventMask {
EventMask::LP_EVENT | EventMask::NODE_EVENT
}

fn execute(&mut self, _model: Model<Solving>, eventhdlr: crate::SCIPEventhdlr, event: Event) {
fn execute(
&mut self,
_model: Model<Solving>,
eventhdlr: crate::SCIPEventhdlr,
event: Event,
) {
assert!(self.get_type().matches(event.event_type()));
assert_eq!(eventhdlr.name(), "InternalSCIPEventHdlrTester");
}
Expand All @@ -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();
}
}
59 changes: 41 additions & 18 deletions src/pricer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Solving>, pricer: SCIPPricer, farkas: bool) -> PricerResult;
fn generate_columns(
&mut self,
model: Model<Solving>,
pricer: SCIPPricer,
farkas: bool,
) -> PricerResult;
}

/// An enum representing the possible states of a `PricerResult`.
Expand Down Expand Up @@ -45,7 +50,6 @@ impl From<PricerResultState> for SCIP_Result {
}
}


/// A wrapper around a SCIP pricer object.
pub struct SCIPPricer {
pub(crate) raw: *mut ffi::SCIP_PRICER,
Expand Down Expand Up @@ -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 }
}
}

Expand All @@ -105,7 +103,12 @@ mod tests {
struct LyingPricer;

impl Pricer for LyingPricer {
fn generate_columns(&mut self, _model: Model<Solving>, _pricer: SCIPPricer, _farkas: bool) -> PricerResult {
fn generate_columns(
&mut self,
_model: Model<Solving>,
_pricer: SCIPPricer,
_farkas: bool,
) -> PricerResult {
PricerResult {
state: PricerResultState::FoundColumns,
lower_bound: None,
Expand All @@ -131,7 +134,12 @@ mod tests {
struct EarlyStoppingPricer;

impl Pricer for EarlyStoppingPricer {
fn generate_columns(&mut self, _model: Model<Solving>, _pricer: SCIPPricer, _farkas: bool) -> PricerResult {
fn generate_columns(
&mut self,
_model: Model<Solving>,
_pricer: SCIPPricer,
_farkas: bool,
) -> PricerResult {
PricerResult {
state: PricerResultState::StopEarly,
lower_bound: None,
Expand All @@ -158,7 +166,12 @@ mod tests {
struct OptimalPricer;

impl Pricer for OptimalPricer {
fn generate_columns(&mut self, _model: Model<Solving>, _pricer: SCIPPricer, _farkas: bool) -> PricerResult {
fn generate_columns(
&mut self,
_model: Model<Solving>,
_pricer: SCIPPricer,
_farkas: bool,
) -> PricerResult {
PricerResult {
state: PricerResultState::NoColumns,
lower_bound: None,
Expand Down Expand Up @@ -194,7 +207,12 @@ mod tests {
}

impl Pricer for AddSameColumnPricer {
fn generate_columns(&mut self, mut model: Model<Solving>, _pricer: SCIPPricer, _farkas: bool) -> PricerResult {
fn generate_columns(
&mut self,
mut model: Model<Solving>,
_pricer: SCIPPricer,
_farkas: bool,
) -> PricerResult {
assert_eq!(self.data.a, (0..1000).collect::<Vec<usize>>());
if self.added {
PricerResult {
Expand Down Expand Up @@ -250,7 +268,12 @@ mod tests {
struct InternalSCIPPricerTester;

impl Pricer for InternalSCIPPricerTester {
fn generate_columns(&mut self, _model: Model<Solving>, pricer: SCIPPricer, _farkas: bool) -> PricerResult {
fn generate_columns(
&mut self,
_model: Model<Solving>,
pricer: SCIPPricer,
_farkas: bool,
) -> PricerResult {
assert_eq!(pricer.name(), "internal");
assert_eq!(pricer.desc(), "internal pricer");
assert_eq!(pricer.priority(), 100);
Expand All @@ -262,7 +285,7 @@ mod tests {
}
}
}

#[test]
fn internal_pricer() {
let pricer = InternalSCIPPricerTester {};
Expand Down
9 changes: 7 additions & 2 deletions src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl From<ffi::SCIP_ROWORIGINTYPE> for RowOrigin {
#[cfg(test)]
mod tests {
use crate::Event;
use crate::{
use crate::{
minimal_model, EventMask, Eventhdlr, HasScipPtr, Model, ModelWithProblem, ProblemOrSolving,
Solving, VarType,
};
Expand All @@ -238,7 +238,12 @@ use crate::{
EventMask::FIRST_LP_SOLVED
}

fn execute(&mut self, model: Model<Solving>, _eventhdlr: crate::SCIPEventhdlr, _event: Event) {
fn execute(
&mut self,
model: Model<Solving>,
_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);
Expand Down
18 changes: 8 additions & 10 deletions src/scip.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d77571c

Please sign in to comment.