From 86be4fa34ced49b468c0481d4655186c20eb7a0c Mon Sep 17 00:00:00 2001 From: CodingTil <36734749+CodingTil@users.noreply.github.com> Date: Fri, 11 Aug 2023 22:58:03 +0200 Subject: [PATCH 1/5] Added set_obj_integral() function --- src/model.rs | 6 ++++++ src/scip.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/model.rs b/src/model.rs index d5b2982..fe1d232 100644 --- a/src/model.rs +++ b/src/model.rs @@ -102,6 +102,12 @@ impl Model { Ok(self) } + /// Informs the SCIP instance that the objective value is always integral and returns the same `Model` instance. + pub fn set_obj_integral(mut self) -> Result { + self.scip.set_obj_integral()?; + Ok(self) + } + /// Sets the presolving parameter of the SCIP instance and returns the same `Model` instance. pub fn set_presolving(mut self, presolving: ParamSetting) -> Self { self.scip 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 } } From a81b20e37bb242377901cabb22d5830587914d92 Mon Sep 17 00:00:00 2001 From: CodingTil <36734749+CodingTil@users.noreply.github.com> Date: Fri, 11 Aug 2023 23:08:39 +0200 Subject: [PATCH 2/5] Added test for set_obj_integral --- src/model.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/model.rs b/src/model.rs index fe1d232..3296edf 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1074,6 +1074,24 @@ mod tests { assert_eq!(sol.obj_val(), model.obj_val()); } + #[test] + fn set_obj_integral() { + let model = Model::new() + .hide_output() + .set_obj_integral() + .unwrap() + .include_default_plugins() + .read_prob("data/test/simple.lp") + .unwrap() + .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() From 35e60d2e0b4285bc2be08ce41dc6bfb8d0bc0b52 Mon Sep 17 00:00:00 2001 From: CodingTil <36734749+CodingTil@users.noreply.github.com> Date: Fri, 11 Aug 2023 23:35:13 +0200 Subject: [PATCH 3/5] Moved new method to Model --- src/model.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/model.rs b/src/model.rs index 3296edf..7ac18a9 100644 --- a/src/model.rs +++ b/src/model.rs @@ -102,12 +102,6 @@ impl Model { Ok(self) } - /// Informs the SCIP instance that the objective value is always integral and returns the same `Model` instance. - pub fn set_obj_integral(mut self) -> Result { - self.scip.set_obj_integral()?; - Ok(self) - } - /// Sets the presolving parameter of the SCIP instance and returns the same `Model` instance. pub fn set_presolving(mut self, presolving: ParamSetting) -> Self { self.scip @@ -212,6 +206,12 @@ 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) -> Result { + self.scip.set_obj_integral()?; + Ok(self) + } /// Adds a new variable to the model with the given lower bound, upper bound, objective coefficient, name, and type. /// @@ -1078,11 +1078,11 @@ mod tests { fn set_obj_integral() { let model = Model::new() .hide_output() - .set_obj_integral() - .unwrap() .include_default_plugins() .read_prob("data/test/simple.lp") .unwrap() + .set_obj_integral() + .unwrap() .solve(); let status = model.status(); assert_eq!(status, Status::Optimal); From f244bf2474af3b5683971a6153de95b208cdc70e Mon Sep 17 00:00:00 2001 From: CodingTil <36734749+CodingTil@users.noreply.github.com> Date: Sat, 12 Aug 2023 07:44:42 +0200 Subject: [PATCH 4/5] Update method signature to always return Self --- src/model.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/model.rs b/src/model.rs index 7ac18a9..589535a 100644 --- a/src/model.rs +++ b/src/model.rs @@ -208,9 +208,11 @@ impl Model { } /// Informs the SCIP instance that the objective value is always integral and returns the same `Model` instance. - pub fn set_obj_integral(mut self) -> Result { - self.scip.set_obj_integral()?; - Ok(self) + 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. @@ -1082,7 +1084,6 @@ mod tests { .read_prob("data/test/simple.lp") .unwrap() .set_obj_integral() - .unwrap() .solve(); let status = model.status(); assert_eq!(status, Status::Optimal); From 093957e69d28345052042e58616af275e680d0ea Mon Sep 17 00:00:00 2001 From: CodingTil <36734749+CodingTil@users.noreply.github.com> Date: Sat, 12 Aug 2023 11:04:05 +0200 Subject: [PATCH 5/5] Updated CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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