From b260e19fa4f93ad6380cbdf435671bfe5c72c3ec Mon Sep 17 00:00:00 2001 From: CodingTil <36734749+CodingTil@users.noreply.github.com> Date: Sat, 12 Aug 2023 11:46:26 +0200 Subject: [PATCH] Added `set_obj_integral` Method (#101) * Added set_obj_integral() function * Added test for set_obj_integral * Moved new method to Model * Update method signature to always return Self * Updated CHANGELOG.md --- CHANGELOG.md | 1 + src/model.rs | 25 +++++++++++++++++++++++++ src/scip.rs | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f15612e..b1e7000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## unreleased ### Added + - Added method `set_obj_integral` to allow specifying that the objective value is always integral. ### Fixed ### Changed ### Removed diff --git a/src/model.rs b/src/model.rs index d5b2982..589535a 100644 --- a/src/model.rs +++ b/src/model.rs @@ -206,6 +206,14 @@ impl Model { .set_cons_modifiable(cons, modifiable) .expect("Failed to set constraint modifiable"); } + + /// Informs the SCIP instance that the objective value is always integral and returns the same `Model` instance. + pub fn set_obj_integral(mut self) -> Self { + self.scip + .set_obj_integral() + .expect("Failed to set the objective value as integral"); + self + } /// Adds a new variable to the model with the given lower bound, upper bound, objective coefficient, name, and type. /// @@ -1068,6 +1076,23 @@ mod tests { assert_eq!(sol.obj_val(), model.obj_val()); } + #[test] + fn set_obj_integral() { + let model = Model::new() + .hide_output() + .include_default_plugins() + .read_prob("data/test/simple.lp") + .unwrap() + .set_obj_integral() + .solve(); + let status = model.status(); + assert_eq!(status, Status::Optimal); + + //test objective value + let obj_value = model.obj_val(); + assert_eq!(obj_value, 200.); + } + #[test] fn set_time_limit() { let model = Model::new() diff --git a/src/scip.rs b/src/scip.rs index 35ab9cb..6fca671 100644 --- a/src/scip.rs +++ b/src/scip.rs @@ -97,6 +97,11 @@ impl ScipPtr { Ok(()) } + pub(crate) fn set_obj_integral(&mut self) -> Result<(), Retcode> { + scip_call!(ffi::SCIPsetObjIntegral(self.raw)); + Ok(()) + } + pub(crate) fn n_vars(&self) -> usize { unsafe { ffi::SCIPgetNVars(self.raw) as usize } }