jagua_rs/probs/bpp/util/
assertions.rs1use crate::entities::Item;
2use crate::probs::bpp::entities::{BPProblem, BPSolution, Bin};
3use crate::util::assertions::snapshot_matches_layout;
4
5#[must_use]
6pub fn problem_matches_solution(bpp: &BPProblem, sol: &BPSolution) -> bool {
7 let BPSolution {
8 layout_snapshots,
9 time_stamp: _,
10 } = sol;
11
12 assert!((bpp.density() - sol.density(&bpp.instance)).abs() <= f32::EPSILON);
13 assert_eq!(bpp.layouts.len(), layout_snapshots.len());
14
15 bpp.layouts.iter().all(|(_, l)| {
17 layout_snapshots
18 .iter()
19 .any(|(_, ls)| snapshot_matches_layout(l, ls))
20 });
21
22 true
23}
24
25#[must_use]
26pub fn instance_item_bin_ids_correct(items: &[(Item, usize)], bins: &[Bin]) -> bool {
27 items.iter().enumerate().all(|(i, (item, _))| item.id == i)
28 && bins.iter().enumerate().all(|(i, bin)| bin.id == i)
29}