Skip to content

Commit b53baa0

Browse files
jk2997Joonho Kim
andauthored
Updated rust-lpsolve crate to 1.0.1 (#115)
Co-authored-by: Joonho Kim <[email protected]>
1 parent 8cf3cc3 commit b53baa0

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ minilp = [
3939
[dependencies]
4040
coin_cbc = { version = "0.1", optional = true, default-features = false }
4141
microlp = { version = "0.2.11", optional = true }
42-
lpsolve = { version = "0.1", optional = true }
42+
lpsolve = { version = "1.0.1", optional = true }
4343
highs = { version = "1.11.0", optional = true }
4444
russcip = { version = "0.8.2", optional = true }
4545
lp-solvers = { version = "1.0.0", features = ["cplex"], optional = true }

src/solvers/lpsolve.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ pub fn lp_solve(to_solve: UnsolvedProblem) -> LpSolveProblem {
4848

4949
let cols = to_c(variables.len());
5050
let mut model = Problem::new(0, cols).expect("Unable to create problem");
51-
let (obj_coefs, obj_idx, _const) = expr_to_scatter_vec(objective);
52-
assert!(model.scatter_objective_function(&obj_coefs, &obj_idx));
51+
let (mut obj_coefs, mut obj_idx, _const) = expr_to_scatter_vec(objective);
52+
model
53+
.scatter_objective_function(obj_coefs.as_mut_slice(), obj_idx.as_mut_slice())
54+
.unwrap();
5355
for (i, v) in variables.into_iter().enumerate() {
5456
let col = to_c(i + 1);
55-
assert!(model.set_integer(col, v.is_integer));
57+
model.set_integer(col, v.is_integer).unwrap();
5658
if v.min.is_finite() || v.max.is_finite() {
57-
assert!(model.set_bounds(col, v.min, v.max));
59+
model.set_bounds(col, v.min, v.max).unwrap();
5860
} else {
59-
assert!(model.set_unbounded(col));
61+
model.set_unbounded(col).unwrap();
6062
}
6163
}
6264
LpSolveProblem(model)
@@ -114,8 +116,10 @@ impl SolverModel for LpSolveProblem {
114116
} else {
115117
ConstraintType::Le
116118
};
117-
let success = self.0.add_constraint(&coeffs, target, constraint_type);
118-
assert!(success, "could not add constraint. memory error.");
119+
let success = self
120+
.0
121+
.add_constraint(coeffs.as_mut_slice(), target, constraint_type);
122+
assert!(success.is_ok(), "could not add constraint. memory error.");
119123
ConstraintReference { index }
120124
}
121125

@@ -135,8 +139,13 @@ impl ModelWithSOS1 for LpSolveProblem {
135139
variables.push(var.index().try_into().expect("too many vars"));
136140
}
137141
let name = CString::new("sos").unwrap();
138-
self.0
139-
.add_sos_constraint(&name, SOSType::Type1, 1, &weights, &variables);
142+
self.0.add_sos_constraint(
143+
&name,
144+
SOSType::Type1,
145+
1,
146+
weights.as_mut_slice(),
147+
variables.as_mut_slice(),
148+
);
140149
}
141150
}
142151

0 commit comments

Comments
 (0)