Crate pack_it_up

Source
Expand description

pack_it_up is a simple Rust library that implements various bin packing algorithms.

§Example

use pack_it_up::Pack;
use pack_it_up::offline::first_fit_decreasing::first_fit_decreasing;

#[derive(Debug, Eq, PartialEq)]
struct MyItem {
    some_content: i32,
    size: usize,
}

impl Pack for MyItem {
    fn size(&self) -> usize {
        self.size
    }
}

fn main() {
    let my_items = vec![
        MyItem { some_content: 1, size: 1, },
        MyItem { some_content: 2, size: 2, },
        MyItem { some_content: 3, size: 19, },
        MyItem { some_content: 4, size: 17, },
        MyItem { some_content: 5, size: 1, },
    ];

    let mut bins = first_fit_decreasing(20, my_items);

    // The above will result in 2 full bins
    assert_eq!(2, bins.len());

    let first_bin_contents = bins.remove(0).into_contents();
    assert_eq!(vec![MyItem{ some_content: 3, size: 19 }, MyItem { some_content: 1, size: 1 }], first_bin_contents);

    let second_bin_contents = bins.remove(0).into_contents();
    assert_eq!(vec![MyItem{ some_content: 4, size: 17 }, MyItem { some_content: 2, size: 2 }, MyItem { some_content: 5, size: 1 }], second_bin_contents);
}

Modules§

offline
online
wrapper

Structs§

Bin

Traits§

Pack
Allows the bin packing algorithm to know how big an item is, which can then be used to figure out in which bin it fits.