jagua_rs/probs/bpp/util/
assertions.rs

1use crate::entities::Item;
2use crate::probs::bpp::entities::{BPProblem, BPSolution, Bin};
3use crate::util::assertions::snapshot_matches_layout;
4
5pub fn problem_matches_solution(bpp: &BPProblem, sol: &BPSolution) -> bool {
6    let BPSolution {
7        layout_snapshots,
8        time_stamp: _,
9    } = sol;
10
11    assert_eq!(bpp.density(), sol.density(&bpp.instance));
12    assert_eq!(bpp.layouts.len(), layout_snapshots.len());
13
14    // Check that each layout in the problem has a matching snapshot in the solution
15    bpp.layouts.iter().all(|(_, l)| {
16        layout_snapshots
17            .iter()
18            .any(|(_, ls)| snapshot_matches_layout(l, ls))
19    });
20
21    true
22}
23
24pub fn instance_item_bin_ids_correct(items: &[(Item, usize)], bins: &[Bin]) -> bool {
25    items.iter().enumerate().all(|(i, (item, _))| item.id == i)
26        && bins.iter().enumerate().all(|(i, bin)| bin.id == i)
27}