Skip to content

Commit

Permalink
Merge pull request #148 from Andful/main
Browse files Browse the repository at this point in the history
Allow setting boolean parameters
  • Loading branch information
mmghannam authored Sep 13, 2024
2 parents 50dbb63 + 0ef2638 commit 530390a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,12 @@ impl<T> Model<T> {
Ok(self)
}

/// Sets a SCIP boolean parameter and returns a new `Model` instance with the parameter set.
pub fn set_bool_param(mut self, param: &str, value: bool) -> Result<Self, Retcode> {
self.scip.set_bool_param(param, value)?;
Ok(self)
}

/// Sets a SCIP integer parameter and returns a new `Model` instance with the parameter set.
pub fn set_int_param(mut self, param: &str, value: i32) -> Result<Self, Retcode> {
self.scip.set_int_param(param, value)?;
Expand Down Expand Up @@ -1715,6 +1721,14 @@ mod tests {
Model::new().print_version();
}

#[test]
fn set_bool_param() {
Model::new()
.hide_output()
.set_bool_param("display/allviols", true)
.unwrap();
}

#[test]
fn set_int_param() {
let res = Model::new()
Expand Down
6 changes: 6 additions & 0 deletions src/scip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ impl ScipPtr {
Ok(())
}

pub(crate) fn set_bool_param(&mut self, param: &str, value: bool) -> Result<(), Retcode> {
let param = CString::new(param).unwrap();
scip_call! { ffi::SCIPsetBoolParam(self.raw, param.as_ptr(), if value { 1u32 } else { 0u32 }) };
Ok(())
}

pub(crate) fn set_int_param(&mut self, param: &str, value: i32) -> Result<(), Retcode> {
let param = CString::new(param).unwrap();
scip_call! { ffi::SCIPsetIntParam(self.raw, param.as_ptr(), value) };
Expand Down

0 comments on commit 530390a

Please sign in to comment.