Questions tagged [bin-packing]

In the bin packing problem, objects of different volumes must be packed into a finite number of bins or containers each of volume V in a way that minimizes the number of bins used. In computational complexity theory, it is a combinatorial NP-hard problem.

From wikipedia

In the bin packing problem, objects of different volumes must be packed into a finite number of bins or containers each of volume V in a way that minimizes the number of bins used. In computational complexity theory, it is a combinatorial NP-hard problem.

There are many variations of this problem, such as 2D packing, linear packing, packing by weight, packing by cost, and so on. They have many applications, such as filling up containers, loading trucks with weight capacity constraints, creating file backups in removable media and technology mapping in Field-programmable gate array semiconductor chip design. The bin packing problem can also be seen as a special case of the cutting stock problem. When the number of bins is restricted to 1 and each item is characterised by both a volume and a value, the problem of maximising the value of items that can fit in the bin is known as the knapsack problem.

Despite the fact that the bin packing problem has an NP-hard computational complexity, optimal solutions to very large instances of the problem can be produced with sophisticated algorithms. In addition, many heuristics have been developed: for example, the first fit algorithm provides a fast but often non-optimal solution, involving placing each item into the first bin in which it will fit. It requires Θ(n log n) time, where n is the number of elements to be packed. The algorithm can be made much more effective by first sorting the list of elements into decreasing order (sometimes known as the first-fit decreasing algorithm), although this still does not guarantee an optimal solution, and for longer lists may increase the running time of the algorithm. It is known, however, that there always exists at least one ordering of items that allows first-fit to produce an optimal solution.1

An interesting variant of bin packing that occurs in practice is when items can share space when packed into a bin. Specifically, a set of items could occupy less space when packed together than the sum of their individual sizes. This variant is known as VM packing[2] since when virtual machines (VMs) are packed in a server, their total memory requirement could decrease due to pages shared by the VMs that need only be stored once. If items can share space in arbitrary ways, the bin packing problem is hard to even approximate. However, if the space sharing fits into a hierarchy, as is the case with memory sharing in virtual machines, the bin packing problem can be efficiently approximated.

  1. Lewis, R. (2009), "A General-Purpose Hill-Climbing Method for Order Independent Minimum Grouping Problems: A Case Study in Graph Colouring and Bin Packing", Computers and Operations Research 36 (7): 2295–2310, doi:10.1016/j.cor.2008.09.004
  2. Sindelar, Michael; Sitaraman, Ramesh; Shenoy, Prashant (2011), "Sharing-Aware Algorithms for Virtual Machine Colocation", Proceedings of 23rd ACM Symposium on Parallelism in Algorithms and Architectures (SPAA), San Jose, CA, June 2011: 367–378
225 questions
49
votes
8 answers

How can I programmatically determine how to fit smaller boxes into a larger package?

Does anyone know of existing software or algorithms to calculate a package size for shipping multiple items? I have a bunch of items in our inventory database with length, width and height dimesions defined. Given these dimensions I need to…
polara
  • 4,722
  • 5
  • 21
  • 19
42
votes
1 answer

How is 2D bin packing achieved programmatically?

There are a few similar questions on stackoverflow, but none of them seem to provide a tangible answer that someone without a solid understanding of NP-hard problems and algorithms can understand. How does one perform 2D bin packing of rectangular…
FrozenFire
  • 873
  • 1
  • 6
  • 15
38
votes
6 answers

3 dimensional bin packing algorithms

I'm faced with a 3 dimensional bin packing problem and am currently conducting some preliminary research as to which algorithms/heuristics are currently yielding the best results. Since the problem is NP hard I do not expect to find the optimal…
18
votes
2 answers

Horizontal ordered bin packing of svg elements

Trying to figure out the best way of bin packing/ distributing a bunch of known width svg images in a horizontal row, where they can be stacked on top of each other if the width of the container is too tight. Height of container should optimally be…
hampusohlsson
  • 9,346
  • 5
  • 30
  • 46
17
votes
3 answers

Algorithm for fitting objects in a space

I have a collection of different sized squares and rectangles that I want to fit together using PHP into one large square/rectangle. The squares are usually images that I want to make into a montage - but sometimes they are simply math objects. Are…
Xeoncross
  • 50,836
  • 73
  • 238
  • 351
14
votes
1 answer

Variation of the backpack ... in python

I have a conceptual problem where I have several packages, each package contains a number of elements inside. Elements are of type A or type B. I want to distribute the packages in a finite number of bins in such a way that the distribution between…
Bas Jansen
  • 3,010
  • 4
  • 26
  • 60
12
votes
2 answers

Block layout algorithm

I'm looking for help with improving an algorithm for placing blocks of odd shapes. My problem domain is odd, but the best analogy for my blocks is Tetris pieces, except that they can have more than four pieces. The blocks still are composed of only…
Tesserex
  • 16,418
  • 5
  • 61
  • 101
11
votes
3 answers

3d bin packing algorithm

I am looking for a deterministic implementation for any 3d bin packing algorithm, i.e. for packing many small and different cuboids inside one or many bigger ones. The solution could vary from the optimal one. It should be written in C, C++, Java,…
Mouk
  • 1,737
  • 2
  • 14
  • 26
10
votes
4 answers

Fitting rectangles together in optimal fashion

I was wondering if anyone knows of any algorithms suited to fitting together N number of rectangles of unknown size into the smallest possible containing rectangle. By optimal I mean with reducing the amount of white space left over in the…
madcapnmckay
  • 15,293
  • 6
  • 58
  • 77
9
votes
1 answer

Optimized data structure for 2d spatial search and Javascript implementation?

I'm working on a Tetris-type HTML5 game and need to beef up a space optimization algorithm. Rectangular blocks of varying size need to be added to the canvas in the most space efficient way. I know how much space the block takes, I need to find…
RSG
  • 6,555
  • 6
  • 31
  • 50
8
votes
2 answers

Is there a c++ source/lib to solve 2D Bin Packing with a rectangular bin (not square) and rotation?

As the title already says I need C/C++ sourcecode or a library that I can use to solve the Bin Packing problem with 2D rectangular shapes where the bin is also rectangular and the rectangles are also being rotated by 90° angles to fit better. I…
HardCoder
  • 2,956
  • 5
  • 29
  • 49
8
votes
1 answer

Where can I find open source 2d bin packing algorithms?

I'm looking for open source (preferably c++) algorithms for 2d bin packing of rectangular and or irregular shapes. I've found several papers on the subject but no code.
Tom M
  • 153
  • 1
  • 2
  • 9
7
votes
3 answers

Solving task scheduling or bin-packing optimizations in R

I have an optimisation issue. It's about a product that contains 20 parts (the order of producing doesn't matter). I've got 3 similar machine that can produce all 20 parts. I've got the 20 parts represented in minutes (ie. it takes 3min to produce…
S12000
  • 2,861
  • 10
  • 31
  • 45
6
votes
4 answers

Fair product distribution algorithm

Here is my problem: There are n companies distributing products. All products should be distributed in k days Distributing products of company Ci should be consecutive - it means that it can be distributed on days 2,3,4,5 but not 2,3,6,7 number of…
dfens
  • 5,135
  • 4
  • 29
  • 48
6
votes
2 answers

c# 3D Bin Packing for shipping

I try to implement optimisation for shipping product from my e-commerce website. I don't use plugin for e-commerce, only asp.net mvc 5. I ask FeDex API for shipping rate for all items in cart. So if the user have 3 item in cart it will calculate it…
Benoit
  • 949
  • 9
  • 26
1
2 3
14 15