Skip to content

Commit

Permalink
benches
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenGar committed Feb 2, 2024
1 parent 9351a6a commit d8522b0
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 114 deletions.
3 changes: 2 additions & 1 deletion jaguars/src/collision_detection/cd_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ impl CDEngine {
}

pub fn flush_changes(&mut self) {
self.haz_prox_grid.as_mut().map(|hpg| hpg.flush_deregisters(self.dynamic_hazards.iter()));
self.haz_prox_grid.as_mut()
.map(|hpg| hpg.flush_deregisters(self.dynamic_hazards.iter()));
}

pub fn has_uncommitted_deregisters(&self) -> bool {
Expand Down
43 changes: 27 additions & 16 deletions jaguars/src/entities/problems/bp_problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::entities::problems::problem::private::ProblemPrivate;
use crate::entities::solution::Solution;
use crate::util::assertions;

#[derive(Clone)]
pub struct BPProblem {
instance: Arc<Instance>,
layouts: Vec<Layout>,
Expand Down Expand Up @@ -57,7 +58,7 @@ impl BPProblem {
}
}

pub fn remove_layout(&mut self, layout_index: usize) {
pub fn remove_layout(&mut self, layout_index: LayoutIndex) {
self.unregister_layout(layout_index);
}

Expand All @@ -71,13 +72,18 @@ impl BPProblem {
self.layouts.push(layout);
}

pub fn unregister_layout(&mut self, layout_index: usize) {
let layout = self.layouts.remove(layout_index);
self.layout_has_changed(layout.id());
self.unregister_bin(layout.bin().id());
layout.placed_items().iter().for_each(
|v| { self.unregister_included_item(v.item_id()) });
self.uncommitted_removed_layouts.push(layout);
pub fn unregister_layout(&mut self, layout_index: LayoutIndex) {
match layout_index {
LayoutIndex::Existing(i) => {
let layout = self.layouts.remove(i);
self.layout_has_changed(layout.id());
self.unregister_bin(layout.bin().id());
layout.placed_items().iter().for_each(
|v| { self.unregister_included_item(v.item_id()) });
self.uncommitted_removed_layouts.push(layout);
}
LayoutIndex::Empty(_) => unreachable!("cannot remove empty layout")
}
}

fn next_layout_id(&mut self) -> usize {
Expand Down Expand Up @@ -130,15 +136,20 @@ impl Problem for BPProblem {
self.layout_has_changed(layout_id);
}

fn remove_item(&mut self, layout_index: usize, pi_uid: &PlacedItemUID) {
self.layout_has_changed(self.layouts[layout_index].id());
let layout = &mut self.layouts[layout_index];
layout.remove_item(pi_uid, false);
if layout.is_empty() {
//if layout is empty, remove it
self.unregister_layout(layout_index);
fn remove_item(&mut self, layout_index: LayoutIndex, pi_uid: &PlacedItemUID) {
match layout_index {
LayoutIndex::Existing(i) => {
self.layout_has_changed(self.layouts[i].id());
let layout = &mut self.layouts[i];
layout.remove_item(pi_uid, false);
if layout.is_empty() {
//if layout is empty, remove it
self.unregister_layout(layout_index);
}
self.unregister_included_item(pi_uid.item_id);
}
LayoutIndex::Empty(_) => unreachable!("cannot remove item from empty layout")
}
self.unregister_included_item(pi_uid.item_id);
}

fn create_solution(&mut self, old_solution: &Option<Solution>) -> Solution {
Expand Down
5 changes: 3 additions & 2 deletions jaguars/src/entities/problems/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::entities::problems::sp_problem::SPProblem;
use crate::entities::solution::Solution;

#[enum_dispatch]
#[derive(Clone)]
pub enum ProblemEnum {
BPProblem, //Bin Packing Problem
SPProblem, //Strip Packing Problem
Expand All @@ -22,7 +23,7 @@ pub enum ProblemEnum {
pub trait Problem: ProblemPrivate {
fn insert_item(&mut self, i_opt: &PlacingOption);

fn remove_item(&mut self, layout_index: usize, pi_uid: &PlacedItemUID);
fn remove_item(&mut self, layout_index: LayoutIndex, pi_uid: &PlacedItemUID);

fn create_solution(&mut self, old_solution: &Option<Solution>) -> Solution;

Expand Down Expand Up @@ -92,7 +93,7 @@ pub(super) mod private {
use crate::entities::problems::problem::ProblemEnum;

#[enum_dispatch(ProblemEnum)]
pub trait ProblemPrivate {
pub trait ProblemPrivate : Clone {
fn next_solution_id(&mut self) -> usize;

fn missing_item_qtys_mut(&mut self) -> &mut [isize];
Expand Down
5 changes: 3 additions & 2 deletions jaguars/src/entities/problems/sp_problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::geometry::geo_traits::{Shape, Transformable};
use crate::util::assertions;
use crate::util::config::CDEConfig;

#[derive(Clone)]
pub struct SPProblem {
instance: Arc<Instance>,
layout: Layout,
Expand Down Expand Up @@ -111,8 +112,8 @@ impl Problem for SPProblem {
self.register_included_item(item_id);
}

fn remove_item(&mut self, layout_index: usize, pi_uid: &PlacedItemUID) {
assert_eq!(layout_index, 0, "strip packing problems only have a single layout");
fn remove_item(&mut self, layout_index: LayoutIndex, pi_uid: &PlacedItemUID) {
assert_eq!(layout_index, LayoutIndex::Existing(0), "strip packing problems only have a single layout");
self.layout.remove_item(pi_uid, false);
self.unregister_included_item(pi_uid.item_id);
}
Expand Down
2 changes: 1 addition & 1 deletion lbf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mimalloc = "0.1.39"
criterion = "0.5.1"

[[bench]]
name = "cde_bench"
name = "quadtree_bench"
harness = false

[profile.release]
Expand Down
75 changes: 0 additions & 75 deletions lbf/benches/cde_bench.rs

This file was deleted.

Empty file added lbf/benches/fast_fail_bench.rs
Empty file.
Empty file.
Loading

0 comments on commit d8522b0

Please sign in to comment.