Git Product home page Git Product logo

binpackingjs's Introduction

binpackingjs

Build Status npm version MIT license

binpackingjs is 2D, 3D, 4D well tested JavaScript Bin Packing library.

  • 3D Bin Packing Code is porting from golang package bp3d which is based on this paper.
  • 2D Bin Packing Code is porting from ruby package bin_packing which is based on this paper.

Install

yarn add binpackingjs

2D Bin Packing

2D Bin Packing Demo

2D Bin Packing

const BinPacking2D = require('binpackingjs').BP2D;
const { Bin, Box, Packer } = BinPacking2D;

let bin_1 = new Bin(100, 50);
let bin_2 = new Bin(50, 50);
let boxes = [
  new Box(15, 10), // Should be added last (smaller)
  new Box(50, 45), // Fits in bin_2 better than in bin_1
  new Box(40, 40),
  new Box(200, 200), // Too large to fit
];
let packer = new Packer([bin_1, bin_2]);
let packed_boxes = packer.pack(boxes);

packed_boxes.length
=> 3
bin_1.boxes.length
=> 2
bin_1.boxes[0].label
=> '40x40 at [0x0]'
bin_1.boxes[0].label
=> '40x40 at [0x0]'
bin_1.boxes[1].label
=> '15x10 at [0x40]'
bin_2.boxes.length
=> 1
bin_2.boxes[0].label
=> '50x45 at [0x0]'
boxes[3].packed
=> false

3D Bin Packing

const BinPacking3D = require('binpackingjs').BP3D;

const { Item, Bin, Packer } = BinPacking3D;

let bin1 = new Bin("Le petite box", 296, 296, 8, 1000);
let item1 = new Item("Item 1", 250, 250, 2, 200);
let item2 = new Item("Item 2", 250, 250, 2, 200);
let item3 = new Item("Item 3", 250, 250, 2, 200);
let packer = new Packer();

packer.addBin(bin1);
packer.addItem(item1);
packer.addItem(item2);
packer.addItem(item3);

// pack items into bin1
packer.pack();

// item1, item2, item3
console.log(bin1.items);

// items will be empty, all items was packed
console.log(packer.items);

// unfitItems will be empty, all items fit into bin1
console.log(packer.unfitItems)

License

MIT

binpackingjs's People

Contributors

dechov avatar dependabot[bot] avatar greattichonizuka avatar jeffstieler avatar mafricalucas avatar olragon avatar seanonthenet avatar superdav42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

binpackingjs's Issues

The algorithm does not seem to behave correctly with boxes that are more rectangular than square.

Hi Long,

I would like to thank you for this amazing repository. I'm using using it to calculate the amount of needed material sheets for cnc machining. The code iterates over a set of predefined bin sizes to find out the optimal amount. So far so good it works perfectly but after trying and trying I 've found that with some box sizes behaves strangely. Especially with boxes that are rectangular. I have attached 2 images to illustrate the issue.

Any help will be more than welcome. or if you can point me where in the source code the issue may be.

img1
img2
.

[Feature] Disable multiple bin packing

Really nice work on implementing this. I am trying to disable multiple bin packing, rather I want to use a single bin for packing all the items.
Is there any undocumented way for the library to support single bin packing for 3D packing instead of multiple bin packing? @olragon
If not, do you have any idea how to tweak this setting?

3D bin packing won't fit

Test case:

const BinPacking3D = require('binpackingjs').BP3D;
const { Item, Bin, Packer } = BinPacking3D;

let bin1 = new Bin("Le petite box", 292, 220, 46, 1000);
let item1 = new Item("Item 1", 210, 80, 46, 200);
let item2 = new Item("Item 1", 210, 80, 46, 200);
let item3 = new Item("Item 1", 210, 80, 8, 200);
let item4 = new Item("Item 3", 220, 110, 20, 200);
let packer = new Packer();

packer.addBin(bin1);
packer.addItem(item1);
packer.addItem(item2);
packer.addItem(item3);
packer.addItem(item4);

packer.pack();
console.log(bin1.items); // only 2 out of 4 are packed
console.log(packer.items);
console.log(packer.unfitItems); // 2 items

Expected result is that all items will fit into the bin1

Question on 3D intersect function

Hello, I am trying to understand the 3D BinPacking code but I am stuck in intersect function. Could you please explain to me what is this function for? And how do you do that check?
Thank you!

Determine smallest possible size bin to use

I have 11,875 possible bin combinations (from 6x6x2" to 30x20x20") and a list of items that need to be shipped. Is it possible to figure out the smallest (most effective shipping cost wise) bin to pack items in?

3D packing depth issue?

If I run this:

'use strict'

const {BP3D: { Item, Bin, Packer}} = require('binpackingjs')

const item = [18.75, 7.25, 4, 1]
const binOfFour = ['bin_of_4', 18.75 * 2, 7.25 * 2, 4 * 1, 10000]
const binOfEight = ['bin_of_8', 18.75 * 2, 7.25 * 2, 4 * 2, 10000]

const packIt = (itemProps, itemCount, binProps) => {
    const packer = new Packer()

    const bin = new Bin(...binProps)
    packer.addBin(bin)

    for (let i = -1; ++i < itemCount; ) {
        packer.addItem(new Item(`item_${i + 1}`, ...itemProps))
    }

    packer.pack()
    return {
        ...bin,
        items: bin.items.length,
    }
}

console.log(JSON.stringify(packIt(item, 20, binOfFour), null, 4))
console.log(JSON.stringify(packIt(item, 20, binOfEight), null, 4))

the result is this:

{
    "name": "bin_of_4",
    "width": 3750000,
    "height": 1450000,
    "depth": 400000,
    "maxWeight": 1000000000,
    "items": 4
}
{
    "name": "bin_of_8",
    "width": 3750000,
    "height": 1450000,
    "depth": 800000,
    "maxWeight": 1000000000,
    "items": 6
}

correct me if I'm wrong, but for bin_of_8 if i have a bin that's 2 times the width, 2 times the height and 2 times the depth of the items it holds, then 8 items should fit in the bin

Would it be possible to make it optimize between boxes?

I have several boxes of the same size. The contents to be packed are boxes of various dimensions, and I want to find the optimal way to pack as many of these content boxes as possible into as few containing boxes as possible. Is there a way or could the feature be added to make it optimize for several containing boxes please?

Minimum bin size by volume

Hi there.

Is this able to return a minimum 3D bin size by volume given a set of supplied items?

Example use case: a custom box will be made up for the items for each shipment.

Thanks
Sean

Paper link for 2d packing is broken

It is going to some site that has nothing to do with the algorithm. (I might be wrong, google translate was helping me out on the Finnish site). Is there any other source on the algorithm?

Centered bin packing

Hi!

Really nice job on this bin packing method!
I'm trying to tweak your code to get the packing centered around a point instead of [0px,0 px], and not

Do you have an idea on how to make it ?

Thanks :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.