Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added set_obj_integral Method #101

Merged
merged 5 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ 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) -> Result<Self, Retcode> {
CodingTil marked this conversation as resolved.
Show resolved Hide resolved
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.
///
Expand Down Expand Up @@ -1068,6 +1074,24 @@ 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()
.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()
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
Loading