Skip to content

Commit

Permalink
Added set_obj_integral Method (#101)
Browse files Browse the repository at this point in the history
* Added set_obj_integral() function

* Added test for set_obj_integral

* Moved new method to Model<ProblemCreated>

* Update method signature to always return Self

* Updated CHANGELOG.md
  • Loading branch information
CodingTil authored Aug 12, 2023
1 parent 1ffb0d1 commit b260e19
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## unreleased
### Added
- Added method `set_obj_integral` to allow specifying that the objective value is always integral.
### Fixed
### Changed
### Removed
Expand Down
25 changes: 25 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ impl Model<ProblemCreated> {
.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.
///
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/scip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down

0 comments on commit b260e19

Please sign in to comment.