olragon / binpackingjs Goto Github PK
View Code? Open in Web Editor NEW2D, 3D, 4D Bin Packing JS Library
License: MIT License
2D, 3D, 4D Bin Packing JS Library
License: MIT License
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
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?
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 :)
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?
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
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!
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?
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?
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.
ReferenceError: window is not defined at Object.<anonymous> (node_modules/binpackingjs/dist/BinPacking.min.js:1:277)
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.