diff --git a/src/solvers/scip.rs b/src/solvers/scip.rs index df6c040..226aaac 100644 --- a/src/solvers/scip.rs +++ b/src/solvers/scip.rs @@ -185,6 +185,7 @@ impl Solution for SCIPSolved { mod tests { use crate::{ constraint, variable, variables, CardinalityConstraintSolver, Solution, SolverModel, + WithInitialSolution, }; use super::scip; @@ -203,6 +204,35 @@ mod tests { assert_eq!((solution.value(x), solution.value(y)), (0.5, 3.)) } + #[test] + fn can_solve_with_initial_solution() { + // Solve problem initially + let mut vars = variables!(); + let x = vars.add(variable().clamp(0, 2)); + let y = vars.add(variable().clamp(1, 3)); + let solution = vars + .maximise(x + y) + .using(scip) + .with((2 * x + y) << 4) + .solve() + .unwrap(); + // Recreate same problem with initial values slightly off + let initial_x = solution.value(x) - 0.1; + let initial_y = solution.value(x) - 1.0; + let mut vars = variables!(); + let x = vars.add(variable().clamp(0, 2)); + let y = vars.add(variable().clamp(1, 3)); + let solution = vars + .maximise(x + y) + .using(scip) + .with((2 * x + y) << 4) + .with_initial_solution([(x, initial_x), (y, initial_y)]) + .solve() + .unwrap(); + + assert_eq!((solution.value(x), solution.value(y)), (0.5, 3.)) + } + #[test] fn can_solve_with_equality() { let mut vars = variables!();