Skip to content

Commit 06a3ef1

Browse files
committed
Method to get obj sense of the model & implement basic traits for enums
1 parent da38a08 commit 06a3ef1

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/model.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,11 @@ impl Model {
433433
ffi::SoPlex_changeObjReal(*self.inner, objvals.as_mut_ptr(), objvals.len() as i32);
434434
}
435435
}
436+
437+
/// Gets the objective sense of the model.
438+
pub fn obj_sense(&self) -> ObjSense {
439+
unsafe { ffi::SoPlex_getIntParam(*self.inner, OBJSENSE_PARAM_ID) }.into()
440+
}
436441
}
437442

438443
/// A solved linear programming model.
@@ -732,4 +737,10 @@ mod tests {
732737
let mut lp = Model::new();
733738
lp.read_file("tests/data/simple.txt");
734739
}
740+
741+
#[test]
742+
fn obj_sense() {
743+
let lp = Model::new();
744+
assert_eq!(lp.obj_sense(), ObjSense::Maximize);
745+
}
735746
}

src/param.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub(crate) const DECOMP_VERBOSITY_PARAM_ID: i32 = 27;
7575
pub(crate) const STAT_TIMER_PARAM_ID: i32 = 29;
7676

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

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

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

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

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

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

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

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

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

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

197207
/// Enum representing the synchronization mode.
208+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
209+
198210
pub enum SyncMode {
199211
/// Only sync real values.
200212
Onlyreal = 0,
@@ -205,6 +217,7 @@ pub enum SyncMode {
205217
}
206218

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

215228
/// Enum representing the solve mode.
229+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
230+
216231
pub enum SolveMode {
217232
/// Solve with real values.
218233
Real = 0,
@@ -223,6 +238,8 @@ pub enum SolveMode {
223238
}
224239

225240
/// Enum representing the check mode.
241+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
242+
226243
pub enum CheckMode {
227244
/// Check real values.
228245
Real = 0,
@@ -233,6 +250,8 @@ pub enum CheckMode {
233250
}
234251

235252
/// Enum representing the timer type.
253+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
254+
236255
pub enum Timer {
237256
/// Timer is turned off.
238257
Off = 0,
@@ -243,6 +262,8 @@ pub enum Timer {
243262
}
244263

245264
/// Enum representing the hyperpricing mode.
265+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
266+
246267
pub enum HyperPricing {
247268
/// Hyperpricing is turned off.
248269
Off = 0,
@@ -253,6 +274,8 @@ pub enum HyperPricing {
253274
}
254275

255276
/// Enum representing the solution polishing mode.
277+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
278+
256279
pub enum SolutionPolishing {
257280
/// Solution polishing is turned off.
258281
Off = 0,
@@ -358,6 +381,16 @@ macro_rules! impl_from_int_param {
358381
};
359382
}
360383

384+
impl From<i32> for ObjSense {
385+
fn from(value: i32) -> Self {
386+
match value {
387+
-1 => ObjSense::Minimize,
388+
1 => ObjSense::Maximize,
389+
_ => panic!("Invalid value for ObjSense: {}", value),
390+
}
391+
}
392+
}
393+
361394
impl_from_int_param!(
362395
BoolParam,
363396
IntParam,

0 commit comments

Comments
 (0)