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;
4use std::sync::Arc;
5
6#[must_use]
7pub fn problem_matches_solution(bpp: &BPProblem, sol: &BPSolution) -> bool {
8 let BPSolution {
9 layout_snapshots,
10 layout_bins,
11 time_stamp: _,
12 } = sol;
13
14 assert!((bpp.density() - sol.density()).abs() <= f32::EPSILON);
15 assert_eq!(bpp.layouts.len(), layout_snapshots.len());
16
17 assert_eq!(bpp.bin_cost(), sol.cost(&bpp.instance));
19 assert!(bpp.layouts.iter().all(|(key, layout)| {
20 layout_snapshots.iter().any(|(saved_key, snapshot)| {
21 bpp.layout_bins[key] == layout_bins[saved_key]
22 && snapshot_matches_layout(layout, snapshot)
23 })
24 }));
25
26 true
27}
28
29#[must_use]
30pub fn instance_item_bin_ids_correct(items: &[(Arc<Item>, usize)], bins: &[Bin]) -> bool {
31 items.iter().enumerate().all(|(i, (item, _))| item.idx == i)
32 && bins.iter().enumerate().all(|(i, bin)| bin.idx == i)
33}