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
3
votes
2 answers

Bin Packing: Set amount on bins, want to minimize the max bin weight

Given n bins of infinite capacity, I want to pack m items into them (each with a specific weight), whilst minimizing the weight of the heaviest bin. This isn't a traditional bin packing / knapsack problem where a bin has a finite capacity and you…
user593062
  • 1,373
  • 4
  • 14
  • 23
3
votes
3 answers

2D bin packing on a grid

I have an n × m grid and a collection of polyominos. I would like to know if it is possible to pack them into the grid: no overlapping or rotation is allowed. I expect that like most packing problems this version is NP-hard and difficult to…
3
votes
4 answers

Algorithm to determine (x,y) coordinates for rectangles so the area of the surrounding rectangle is minimal?

I hope my title makes sense, but here is what I a trying to do: I have n rectangles, each with widths of Wn and heights of Hn that I need to arrange so on a two dimensional (x,y) plane the rectangle that they all fit in takes up the least area. I…
Tom
  • 6,567
  • 7
  • 44
  • 72
3
votes
1 answer

Toy box challenge - E-commerce Shipment / Container splitting

Edit: I'm looking for an efficient Ruby, JavaScript, Java or Python implementation of 3D bin-packing with the constraints below I'm looking for an efficient algorithm for correctly identifying the number of containers required to store a list of…
Alex Norcliffe
  • 2,309
  • 1
  • 16
  • 20
3
votes
5 answers

Creating groups of equal sum in R

I am trying to group a column of my data.frame/data.table into three groups, all with equal sums. The data is first ordered from smallest to largest, such that group one would be made up of a large number of rows with small values, and group three…
Chris
  • 6,047
  • 1
  • 27
  • 49
3
votes
1 answer

An approach to implement rectangular bin packing

I'm trying to implement 2D bin packing using the Maximal rectangles algorithms as in the following paper. http://clb.demon.fi/files/RectangleBinPack.pdf In order to implement this, what type of a data structure will be most appropriate? After…
maheshakya
  • 2,148
  • 6
  • 24
  • 40
3
votes
2 answers

2D Bin Packing: Why are my images overlapping?

I ported this 2D bin-packing algorithm from JavaScript to PHP and I'm using it to lay out some images in a sprite map. It works for regularly shaped images (e.g., all squares) but it's producing slightly broken results for larger, more complex data…
mpen
  • 237,624
  • 230
  • 766
  • 1,119
2
votes
1 answer

Rectangle packing with static rectangles

I've implemented a rectangle packing class similar to the one mentioned here. My ultimately goal is to pack a number of smaller sprites into a large spritesheet. The difficulty I'm experiencing is figuring out a way to expand that algorithm to allow…
ndg
  • 2,458
  • 2
  • 30
  • 51
2
votes
3 answers

Dynamic Programming Problem.. Array Partitioning..

The question says, That given an array of size n, we have to output/partition the array into subsets which sum to N. For E,g, I/p arr{2,4,5,7}, n=4, N(sum) = 7(given) O/p = {2,5}, {7} I saw similar kind of problem/explanation in the url…
AlgoGeek
  • 91
  • 2
  • 8
2
votes
3 answers

How to divide a list of negative and positive numbers into the largest number of subsets whose sum is 0?

I am trying to solve this problem but I can't manage to figure out how. Let's suppose I have a list of positive and negative numbers whose sum is guaranteed to be 0. [-10, 1, 2, 20, 5, -100, -80, 10, 15, 15, 60, 100, -20, -18] I…
2
votes
2 answers

Bin Packing Js implementation using box rotation for best fit

I have used the bin packing js implementation here https://github.com/jakesgordon/bin-packing When I specify the frame size as 800x600 and Blocks size as 150x700,150x700 it would say that, it cant accommodate However, there is ample space. The same…
Code Guy
  • 2,205
  • 21
  • 49
2
votes
0 answers

AWS Binpack placement strategy resulting in issues during instance autoscaling

Here is the scenario: We are running Docker containers in an AWS ECS cluster. Previously, we were not using any placement strategy for containers. For minimizing the number of instances within the cluster, we tried introducing binpack placement…
2
votes
2 answers

3D BPP algorithm in Python

I'm working on an algorithm to optimize the packing of items in boxes. I can have up to 20 items which I need to pack in as few boxes as possible (6 possible box sizes), while minimizing the wasted volume within the boxes. I thought of implementing…
Louis Dussart
  • 31
  • 1
  • 3
2
votes
2 answers

Measurement for intersection of 2 irregular shaped 3d object

I am trying to implement an objective function that minimize the overlap of 2 irregular shaped 3d objects. While the most accurate measurement of the overlap is the intersection volume, it's too computationally expensive as I am dealing with complex…
Susie
  • 315
  • 1
  • 11
2
votes
1 answer

Time complexity of a genetic algorithm for bin packing

I am trying to explore genetic algorithms (GA) for the bin packing problem, and compare it to classical Any-Fit algorithms. However the time complexity for GA is never mentioned in any of the scholarly articles. Is this because the time complexity…
user1340852
  • 665
  • 2
  • 6
  • 22
1 2
3
14 15