Skip to content

Commit

Permalink
Merge pull request #2 from Specy/branch&bound
Browse files Browse the repository at this point in the history
Branch&bound, fixes #1
  • Loading branch information
Specy authored Nov 6, 2024
2 parents 4dc2acc + 04e34de commit 00ed76a
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 90 deletions.
2 changes: 1 addition & 1 deletion examples/tsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ fn find_min_cut(size: usize, weights: &mut [f64]) -> (f64, Vec<bool>) {
}

assert!(best_cut_weight.is_finite());
return (best_cut_weight, best_cut);
(best_cut_weight, best_cut)
}

#[cfg(test)]
Expand Down
32 changes: 32 additions & 0 deletions src/broken_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
mod broken_tests {
use crate::{ComparisonOp, OptimizationDirection, Problem};

#[test]
#[should_panic]
fn broken_test_1() {
let mut problem = Problem::new(OptimizationDirection::Maximize);

// Define variables with their objective coefficients
let x = problem.add_var(50.0, (2.0, f64::INFINITY));
let y = problem.add_var(40.0, (0.0, 7.0));

//TODO this fails to find optimal solution with f64::MAX
let z = problem.add_var(45.0, (0.0, f64::MAX));


problem.add_constraint(&[(x, 3.0), (y, 2.0), (z, 1.0)], ComparisonOp::Le, 20.0);
problem.add_constraint(&[(x, 2.0), (y, 1.0), (z, 3.0)], ComparisonOp::Le, 15.0);

let sol = problem.solve().unwrap();

assert_eq!(
[
*sol.var_value(x),
*sol.var_value(y),
*sol.var_value(z)
],
[2.0, 6.2, 1.6]
);
assert_eq!(sol.objective(), 420.0);
}
}
Loading

0 comments on commit 00ed76a

Please sign in to comment.