jagua_rs/probs/bpp/entities/
solution.rs1use crate::Instant;
2use crate::entities::LayoutSnapshot;
3use crate::probs::bpp::entities::{BPInstance, LayKey};
4use slotmap::SecondaryMap;
5
6#[derive(Debug, Clone)]
9pub struct BPSolution {
10 pub(crate) layout_snapshots: SecondaryMap<LayKey, LayoutSnapshot>,
12 pub(crate) layout_bins: SecondaryMap<LayKey, usize>,
14 pub time_stamp: Instant,
16}
17
18impl BPSolution {
19 #[must_use]
20 pub fn layout_snapshots(&self) -> &SecondaryMap<LayKey, LayoutSnapshot> {
21 &self.layout_snapshots
22 }
23
24 #[must_use]
25 pub fn layout_bins(&self) -> &SecondaryMap<LayKey, usize> {
26 &self.layout_bins
27 }
28
29 #[must_use]
30 pub fn density(&self) -> f32 {
31 let total_bin_area = self
32 .layout_snapshots
33 .values()
34 .map(|ls| ls.container.area())
35 .sum::<f32>();
36
37 let total_item_area = self
38 .layout_snapshots
39 .values()
40 .map(LayoutSnapshot::placed_item_area)
41 .sum::<f32>();
42
43 total_item_area / total_bin_area
44 }
45
46 #[must_use]
47 pub fn cost(&self, instance: &BPInstance) -> u64 {
48 self.layout_bins
49 .values()
50 .map(|idx| instance.bins[*idx].cost)
51 .sum()
52 }
53}