Skip to content

Commit

Permalink
test: cover initial solutions for SCIP
Browse files Browse the repository at this point in the history
  • Loading branch information
KnorpelSenf committed Dec 29, 2024
1 parent 3959eb0 commit cf7a1d1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/solvers/scip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl Solution for SCIPSolved {
mod tests {
use crate::{
constraint, variable, variables, CardinalityConstraintSolver, Solution, SolverModel,
WithInitialSolution,
};

use super::scip;
Expand All @@ -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!();
Expand Down

0 comments on commit cf7a1d1

Please sign in to comment.