Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenGar committed Sep 2, 2024
1 parent 7d55102 commit c7f1ecb
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions jagua-rs/src/entities/placing_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ use crate::geometry::d_transformation::DTransformation;
/// Encapsulates all required information to place an `Item` in a `Problem`
pub struct PlacingOption {
/// Which layout to place the item in
pub layout_index: LayoutIndex,
pub layout_idx: LayoutIndex,
/// The id of the item to be placed
pub item_id: usize,
/// The decomposition of the transformation
pub d_transf: DTransformation,
}

impl PlacingOption {
pub fn from_placed_item(layout_index: LayoutIndex, placed_item: &PlacedItem) -> Self {
pub fn from_placed_item(layout_idx: LayoutIndex, placed_item: &PlacedItem) -> Self {
PlacingOption {
layout_index,
layout_idx,
item_id: placed_item.item_id,
d_transf: placed_item.d_transf,
}
Expand Down
2 changes: 1 addition & 1 deletion jagua-rs/src/entities/problems/bin_packing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl BPProblem {

impl ProblemGeneric for BPProblem {
fn place_item(&mut self, p_opt: PlacingOption) -> (LayoutIndex, PItemKey) {
let layout_index = match &p_opt.layout_index {
let layout_index = match &p_opt.layout_idx {
LayoutIndex::Real(i) => LayoutIndex::Real(*i),
LayoutIndex::Template(i) => {
//Layout is empty, clone it and add it to `layouts`
Expand Down
4 changes: 2 additions & 2 deletions jagua-rs/src/entities/problems/strip_packing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl SPProblem {
let cde = self.layout.cde();
if !cde.poly_collides(&transformed_shape, entities_to_ignore.as_ref()) {
let insert_opt = PlacingOption {
layout_index: STRIP_LAYOUT_IDX,
layout_idx: STRIP_LAYOUT_IDX,
item_id,
d_transf,
};
Expand Down Expand Up @@ -167,7 +167,7 @@ impl SPProblem {
impl ProblemGeneric for SPProblem {
fn place_item(&mut self, p_opt: PlacingOption) -> (LayoutIndex, PItemKey) {
assert_eq!(
p_opt.layout_index, STRIP_LAYOUT_IDX,
p_opt.layout_idx, STRIP_LAYOUT_IDX,
"Strip packing problems only have a single layout"
);
let item_id = p_opt.item_id;
Expand Down
8 changes: 4 additions & 4 deletions jagua-rs/src/io/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub fn build_strip_packing_solution(
let d_transf = transform.decompose();

let placing_opt = PlacingOption {
layout_index: STRIP_LAYOUT_IDX,
layout_idx: STRIP_LAYOUT_IDX,
item_id: item.id,
d_transf,
};
Expand Down Expand Up @@ -362,11 +362,11 @@ pub fn build_bin_packing_solution(instance: &BPInstance, json_layouts: &[JsonLay
let d_transf = transform.decompose();

let initial_insert_opt = PlacingOption {
layout_index: LayoutIndex::Template(template_index),
layout_idx: LayoutIndex::Template(template_index),
item_id: first_item.id,
d_transf,
};
let (layout_index, _) = problem.place_item(initial_insert_opt);
let (layout_idx, _) = problem.place_item(initial_insert_opt);
problem.flush_changes();

//Insert the rest of the items
Expand All @@ -385,7 +385,7 @@ pub fn build_bin_packing_solution(instance: &BPInstance, json_layouts: &[JsonLay
let d_transf = transform.decompose();

let insert_opt = PlacingOption {
layout_index,
layout_idx,
item_id: item.id,
d_transf,
};
Expand Down
6 changes: 3 additions & 3 deletions lbf/benches/hpg_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn hpg_query_bench(c: &mut Criterion) {
.placed_items()
.values()
.map(|pi| PlacingOption {
layout_index: LayoutIndex::Real(0),
layout_idx: LayoutIndex::Real(0),
item_id: pi.item_id,
d_transf: pi.d_transf,
})
Expand Down Expand Up @@ -133,7 +133,7 @@ fn hpg_update_bench(c: &mut Criterion) {
.placed_items()
.values()
.map(|pi| PlacingOption {
layout_index: LayoutIndex::Real(0),
layout_idx: LayoutIndex::Real(0),
item_id: pi.item_id,
d_transf: pi.d_transf,
})
Expand Down Expand Up @@ -195,7 +195,7 @@ fn hpg_update_bench(c: &mut Criterion) {
if !layout.cde().poly_collides(&buffer_shape, &[]) {
let d_transf = transf.decompose();
valid_placements.push(PlacingOption {
layout_index: LayoutIndex::Real(0),
layout_idx: LayoutIndex::Real(0),
item_id: SELECTED_ITEM_ID,
d_transf,
});
Expand Down
16 changes: 8 additions & 8 deletions lbf/benches/quadtree_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ fn quadtree_update_bench(c: &mut Criterion) {
);
let (mut problem, _) = util::create_blf_problem(instance.clone(), config, 0);

let layout_index = LayoutIndex::Real(0);
let layout_idx = LayoutIndex::Real(0);
let mut rng = SmallRng::seed_from_u64(0);

group.bench_function(BenchmarkId::from_parameter(depth), |b| {
b.iter(|| {
// Remove an item from the layout
let (pik, pi) = problem
.get_layout(&layout_index)
.get_layout(&layout_idx)
.placed_items()
.iter()
.choose(&mut rng)
.expect("No items in layout");

let p_opt = PlacingOption {
layout_index,
layout_idx,
item_id: pi.item_id,
d_transf: pi.d_transf,
};

//println!("Removing item with id: {}\n", pi_uid.item_id);
problem.remove_item(layout_index, pik, true);
problem.remove_item(layout_idx, pik, true);

problem.flush_changes();

Expand Down Expand Up @@ -178,24 +178,24 @@ fn quadtree_query_update_1000_1(c: &mut Criterion) {

let mut sample_cycler = samples.chunks(N_SAMPLES_PER_ITER).cycle();

let layout_index = LayoutIndex::Real(0);
let layout_idx = LayoutIndex::Real(0);

group.bench_function(BenchmarkId::from_parameter(depth), |b| {
b.iter(|| {
let (pik, pi) = problem
.get_layout(layout_index)
.get_layout(layout_idx)
.placed_items()
.iter()
.choose(&mut rng)
.expect("No items in layout");

let p_opt = PlacingOption {
layout_index,
layout_idx,
item_id: pi.item_id,
d_transf: pi.d_transf,
};

problem.remove_item(layout_index, pik, true);
problem.remove_item(layout_idx, pik, true);
problem.flush_changes();

let item_id = p_opt.item_id;
Expand Down
2 changes: 1 addition & 1 deletion lbf/benches/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn create_blf_problem(
.map(|k| {
let pi = &problem.layout.placed_items()[*k];
PlacingOption {
layout_index: STRIP_LAYOUT_IDX,
layout_idx: STRIP_LAYOUT_IDX,
item_id: pi.item_id,
d_transf: pi.d_transf,
}
Expand Down
8 changes: 4 additions & 4 deletions lbf/src/lbf_optimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ pub fn find_lbf_placement(

pub fn sample_layout(
problem: &Problem,
layout_index: LayoutIndex,
layout_idx: LayoutIndex,
item: &Item,
config: &LBFConfig,
rng: &mut impl Rng,
sample_counter: &mut usize,
) -> Option<PlacingOption> {
let layout: &Layout = problem.get_layout(&layout_index);
let layout: &Layout = problem.get_layout(&layout_idx);
let cde = layout.cde();
let irrel_hazards = match item.hazard_filter.as_ref() {
None => vec![],
Expand Down Expand Up @@ -213,7 +213,7 @@ pub fn sample_layout(
if worth_testing && !cde.poly_collides(&buffer, &irrel_hazards) {
//sample is valid and improves on the current best
let p_opt = PlacingOption {
layout_index,
layout_idx,
item_id: item.id,
d_transf: transform.decompose(),
};
Expand Down Expand Up @@ -254,7 +254,7 @@ pub fn sample_layout(
if worth_testing && !cde.poly_collides(&buffer, &irrel_hazards) {
//sample is valid and improves on the current best
let p_opt = PlacingOption {
layout_index,
layout_idx,
item_id: item.id,
d_transf,
};
Expand Down

0 comments on commit c7f1ecb

Please sign in to comment.