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

Allow setting parameters from all states #111

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changed
- Free sol after adding in `ScipPtr::add_sol()`.
- Allow adding a var in `Solving` mode.
- Allow setting parameters from all states.
### Removed

## 0.2.5
Expand Down
136 changes: 75 additions & 61 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,65 +66,6 @@
state: Unsolved {},
})
}

/// Includes all default plugins in the SCIP instance and returns a new `Model` instance with a `PluginsIncluded` state.
pub fn include_default_plugins(mut self) -> Model<PluginsIncluded> {
self.scip
.include_default_plugins()
.expect("Failed to include default plugins");
Model {
scip: self.scip,
state: PluginsIncluded {},
}
}

/// Sets a SCIP string parameter and returns a new `Model` instance with the parameter set.
pub fn set_str_param(mut self, param: &str, value: &str) -> Result<Self, Retcode> {
self.scip.set_str_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)?;
Ok(self)
}

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

/// Sets a SCIP real parameter and returns a new `Model` instance with the parameter set.
pub fn set_real_param(mut self, param: &str, value: f64) -> Result<Self, Retcode> {
self.scip.set_real_param(param, value)?;
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
.set_presolving(presolving)
.expect("Failed to set presolving with valid value");
self
}

/// Sets the separating parameter of the SCIP instance and returns the same `Model` instance.
pub fn set_separating(mut self, separating: ParamSetting) -> Self {
self.scip
.set_separating(separating)
.expect("Failed to set separating with valid value");
self
}

/// Sets the heuristics parameter of the SCIP instance and returns the same `Model` instance.
pub fn set_heuristics(mut self, heuristics: ParamSetting) -> Self {
self.scip
.set_heuristics(heuristics)
.expect("Failed to set heuristics with valid value");
self
}
}

impl Model<PluginsIncluded> {
Expand Down Expand Up @@ -206,7 +147,7 @@
.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
Expand Down Expand Up @@ -491,7 +432,7 @@
let var_id = var.index();
self.state.vars.borrow_mut().insert(var_id, var.clone());
var
}
}
}

impl Model<Solved> {
Expand Down Expand Up @@ -1111,6 +1052,66 @@
.expect("Failed to set time limit");
self
}


/// Includes all default plugins in the SCIP instance and returns a new `Model` instance with a `PluginsIncluded` state.
pub fn include_default_plugins(mut self) -> Model<PluginsIncluded> {
self.scip
.include_default_plugins()
.expect("Failed to include default plugins");
Model {
scip: self.scip,
state: PluginsIncluded {},

Check warning on line 1064 in src/model.rs

View check run for this annotation

Codecov / codecov/patch

src/model.rs#L1064

Added line #L1064 was not covered by tests
}
}

/// Sets a SCIP string parameter and returns a new `Model` instance with the parameter set.
pub fn set_str_param(mut self, param: &str, value: &str) -> Result<Self, Retcode> {
self.scip.set_str_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)?;
Ok(self)
}

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

/// Sets a SCIP real parameter and returns a new `Model` instance with the parameter set.
pub fn set_real_param(mut self, param: &str, value: f64) -> Result<Self, Retcode> {
self.scip.set_real_param(param, value)?;
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
.set_presolving(presolving)

Check warning on line 1095 in src/model.rs

View check run for this annotation

Codecov / codecov/patch

src/model.rs#L1095

Added line #L1095 was not covered by tests
.expect("Failed to set presolving with valid value");
self
}

/// Sets the separating parameter of the SCIP instance and returns the same `Model` instance.
pub fn set_separating(mut self, separating: ParamSetting) -> Self {
self.scip
.set_separating(separating)

Check warning on line 1103 in src/model.rs

View check run for this annotation

Codecov / codecov/patch

src/model.rs#L1103

Added line #L1103 was not covered by tests
.expect("Failed to set separating with valid value");
self
}

/// Sets the heuristics parameter of the SCIP instance and returns the same `Model` instance.
pub fn set_heuristics(mut self, heuristics: ParamSetting) -> Self {
self.scip
.set_heuristics(heuristics)

Check warning on line 1111 in src/model.rs

View check run for this annotation

Codecov / codecov/patch

src/model.rs#L1111

Added line #L1111 was not covered by tests
.expect("Failed to set heuristics with valid value");
self
}
}

/// The default implementation for a `Model` instance in the `ProblemCreated` state.
Expand Down Expand Up @@ -1606,4 +1607,17 @@

assert!(statuses.iter().all(|&s| s == Status::Optimal));
}

#[test]
fn set_param_all_states() {
Model::new()
.set_int_param("display/verblevel", 0).unwrap()
.include_default_plugins()
.set_int_param("display/verblevel", 0).unwrap()
.read_prob("data/test/simple.lp")
.unwrap()
.set_int_param("display/verblevel", 0).unwrap()
.solve()
.set_int_param("display/verblevel", 0).unwrap();
}
}
Loading