0

Given a set of axis-aligned rectangles (rotatable by 90 degrees) and a rectilinear polygon, I'd like to determine whether or not the rectangles can all be packed into this polygon, and if possible, find an arbitrary packing.

Is this NP Hard? Would any assumptions make this question solveable? (e.g. restricting the polygon to be orthogonally convex) Any kind of reference would be nice?

Rufus
  • 5,111
  • 4
  • 28
  • 45
  • Yes it is NP hard even if the container polygon is itself a rectangle (see [Korf 2003](http://www.aaai.org/Papers/ICAPS/2003/ICAPS03-029.pdf)). A large variety of approximate algorithms exist, just google "rectangle packing". – n. m. could be an AI Mar 01 '17 at 11:49
  • @n.m. this was useful, i'd upvote if your comment was turned into an answer, even more helpful if you quoted the section about turning rectangle packing into pin packing to prove NP-hardness, thanks! – Rufus Mar 02 '17 at 06:18
  • I don't quite understand the proof myself, don't have much time to work my way through it. – n. m. could be an AI Mar 02 '17 at 07:42

2 Answers2

2

Yes it is NP hard even if the container polygon is itself a rectangle (see Korf 2003).

A large variety of approximate algorithms exist, just google "rectangle packing".

Given an instance of bin packing, we can generate a corresponding instance of rectangle packing as follows. For each number in the bin-packing problem, we generate a rectangle of unit height whose width is the value of the number. Thus each number generates a strip of that width and unit height. We also generate an enclosing rectangle whose height is the number of bins, and whose width is the capacity of the bins. Thus each bin corresponds to a horizontal strip of the enclosing rectangle. In the resulting rectangle-packing problem, each strip must be assigned to a row (bin) of the enclosing rectangle, such that the sum of the widths (numbers) of the strips assigned to each row (bin) doesn’t exceed the width (bin capacity) of the enclosing rectangle. Note that the strips are oriented and cannot be rotated. Thus, this rectanglepacking problem is equivalent to the original bin-packing problem. If we can solve any rectangle-packing problem in polynomial time, then we can solve any bin-packing problem in polynomial time. Thus, rectangle packing is NP-hard, and since it is also in NP, it is NP-complete.

Rufus
  • 5,111
  • 4
  • 28
  • 45
n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
0

There is similar task on usaco about packing rectangles. I only solved it by backtracking. Here is explanation of solution

oybek
  • 630
  • 4
  • 14