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

Remove use of Rc for Variable and Constraint & Add parameter getters #190

Merged
merged 6 commits into from
Jan 15, 2025
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
18 changes: 3 additions & 15 deletions examples/create_and_solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,8 @@ fn main() {
let x2 = model.add_var(0., f64::INFINITY, 4., "x2", VarType::Integer);

// Add constraints
model.add_cons(
vec![x1.clone(), x2.clone()],
&[2., 1.],
-f64::INFINITY,
100.,
"c1",
);
model.add_cons(
vec![x1.clone(), x2.clone()],
&[1., 2.],
-f64::INFINITY,
80.,
"c2",
);
model.add_cons(vec![&x1, &x2], &[2., 1.], -f64::INFINITY, 100., "c1");
model.add_cons(vec![&x1, &x2], &[1., 2.], -f64::INFINITY, 80., "c2");

let solved_model = model.solve();

Expand All @@ -40,6 +28,6 @@ fn main() {
let vars = solved_model.vars();

for var in vars {
println!("{} = {}", &var.name(), sol.val(var));
println!("{} = {}", var.name(), sol.val(&var));
}
}
4 changes: 2 additions & 2 deletions src/col.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ mod tests {
let mut model = minimal_model();
let x = model.add_var(0.0, 1.0, 1.0, "x", VarType::Binary);

let cons = model.add_cons(vec![x], &[1.0], 1.0, 1.0, "cons1");
model.set_cons_modifiable(cons, true);
let cons = model.add_cons(vec![&x], &[1.0], 1.0, 1.0, "cons1");
model.set_cons_modifiable(&cons, true);

let eventhdlr = Box::new(ColTesterEventHandler);
model = model.include_eventhdlr("ColTesterEventHandler", "", eventhdlr);
Expand Down
4 changes: 2 additions & 2 deletions src/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{ffi, Row};
use std::rc::Rc;

/// A constraint in an optimization problem.
#[derive(Debug)]
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct Constraint {
/// A pointer to the underlying `SCIP_CONS` C struct.
Expand Down Expand Up @@ -54,7 +54,7 @@ mod tests {
.set_obj_sense(ObjSense::Maximize);

let x1 = model.add_var(0., f64::INFINITY, 3., "x1", VarType::Integer);
let cons = model.add_cons(vec![x1], &[1.], 4., 4., "cons");
let cons = model.add_cons(vec![&x1], &[1.], 4., 4., "cons");
drop(model);

assert_eq!(cons.name(), "cons");
Expand Down
2 changes: 1 addition & 1 deletion src/heuristic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ mod tests {
) -> HeurResult {
let sol = model.create_sol();
for var in model.vars() {
sol.set_val(var, 1.0);
sol.set_val(&var, 1.0);
}
assert_eq!(sol.obj_val(), 7.0);
assert_eq!(model.add_sol(sol), Ok(()));
Expand Down
Loading
Loading