Skip to content

Commit

Permalink
Method to get obj sense of the model & implement basic traits for enums
Browse files Browse the repository at this point in the history
  • Loading branch information
mmghannam committed Jul 20, 2024
1 parent da38a08 commit 06a3ef1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ impl Model {
ffi::SoPlex_changeObjReal(*self.inner, objvals.as_mut_ptr(), objvals.len() as i32);
}
}

/// Gets the objective sense of the model.
pub fn obj_sense(&self) -> ObjSense {
unsafe { ffi::SoPlex_getIntParam(*self.inner, OBJSENSE_PARAM_ID) }.into()
}
}

/// A solved linear programming model.
Expand Down Expand Up @@ -732,4 +737,10 @@ mod tests {
let mut lp = Model::new();
lp.read_file("tests/data/simple.txt");
}

#[test]
fn obj_sense() {
let lp = Model::new();
assert_eq!(lp.obj_sense(), ObjSense::Maximize);
}
}
33 changes: 33 additions & 0 deletions src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub(crate) const DECOMP_VERBOSITY_PARAM_ID: i32 = 27;
pub(crate) const STAT_TIMER_PARAM_ID: i32 = 29;

/// Enum representing the objective sense for optimization.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ObjSense {
/// Minimize the objective function.
Minimize = -1,
Expand All @@ -83,6 +84,7 @@ pub enum ObjSense {
}

/// Enum representing the type of representation.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Representation {
/// Automatically determine the representation type.
Auto = 0,
Expand All @@ -93,6 +95,7 @@ pub enum Representation {
}

/// Enum representing the type of algorithm used.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Algorithm {
/// Primal algorithm.
Primal = 0,
Expand All @@ -101,6 +104,7 @@ pub enum Algorithm {
}

/// Enum representing the factor update type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FactorUpdateType {
/// ETA update type.
Eta = 0,
Expand All @@ -109,6 +113,7 @@ pub enum FactorUpdateType {
}

/// Enum representing verbosity levels.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Verbosity {
/// Only show errors.
Error = 0,
Expand All @@ -125,6 +130,7 @@ pub enum Verbosity {
}

/// Enum representing the simplifier type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Simplifier {
/// Simplification is turned off.
Off = 0,
Expand All @@ -137,6 +143,7 @@ pub enum Simplifier {
}

/// Enum representing the scalar type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Scalar {
/// Scalar operation is turned off.
Off = 0,
Expand All @@ -155,6 +162,7 @@ pub enum Scalar {
}

/// Enum representing the starter type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Starter {
/// Starter is turned off.
Off = 0,
Expand All @@ -167,6 +175,7 @@ pub enum Starter {
}

/// Enum representing the pricer type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Pricer {
/// Automatically choose the pricer.
Auto = 0,
Expand All @@ -183,6 +192,7 @@ pub enum Pricer {
}

/// Enum representing the ratio tester type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RatioTester {
/// Use textbook ratio test.
Textbook = 0,
Expand All @@ -195,6 +205,8 @@ pub enum RatioTester {
}

/// Enum representing the synchronization mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum SyncMode {
/// Only sync real values.
Onlyreal = 0,
Expand All @@ -205,6 +217,7 @@ pub enum SyncMode {
}

/// Enum representing the read mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ReadMode {
/// Read real values.
Real = 0,
Expand All @@ -213,6 +226,8 @@ pub enum ReadMode {
}

/// Enum representing the solve mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum SolveMode {
/// Solve with real values.
Real = 0,
Expand All @@ -223,6 +238,8 @@ pub enum SolveMode {
}

/// Enum representing the check mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum CheckMode {
/// Check real values.
Real = 0,
Expand All @@ -233,6 +250,8 @@ pub enum CheckMode {
}

/// Enum representing the timer type.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum Timer {
/// Timer is turned off.
Off = 0,
Expand All @@ -243,6 +262,8 @@ pub enum Timer {
}

/// Enum representing the hyperpricing mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum HyperPricing {
/// Hyperpricing is turned off.
Off = 0,
Expand All @@ -253,6 +274,8 @@ pub enum HyperPricing {
}

/// Enum representing the solution polishing mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

pub enum SolutionPolishing {
/// Solution polishing is turned off.
Off = 0,
Expand Down Expand Up @@ -358,6 +381,16 @@ macro_rules! impl_from_int_param {
};
}

impl From<i32> for ObjSense {
fn from(value: i32) -> Self {
match value {
-1 => ObjSense::Minimize,
1 => ObjSense::Maximize,
_ => panic!("Invalid value for ObjSense: {}", value),
}
}
}

impl_from_int_param!(
BoolParam,
IntParam,
Expand Down

0 comments on commit 06a3ef1

Please sign in to comment.