ArticleslgStudy

computer science

Rectangle packing

Rectangle packing is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Rectangle packing rather than just read about it. In short: Rectangle packing is a packing problem where the objective is to determine whether a given set of small rectangles can be placed inside a given large polygon, such that no two small rectangles overlap. Several variants of this problem have been studied.

Key takeaways

  • Rectangle packing belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Rectangle packing to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Rectangle packing from memory before moving on to harder problems.

Reference excerpt

Rectangle packing is a packing problem where the objective is to determine whether a given set of small rectangles can be placed inside a given large polygon, such that no two small rectangles overlap. Several variants of this problem have been studied.

Packing identical rectangles in a rectangle In this variant, there are multiple instances of a single rectangle of size (l,w), and a bigger rectangle of size (L,W). The goal is to pack as many small rectangles as possible into the big rectangle without overlap between any rectangles (small or large). Common constraints of the problem include limiting small rectangle rotation to 90° multiples and requiring that each small rectangle is orthogonal to the large rectangle. This problem has some applications such as loading of boxes on pallets and, specifically, woodpulp stowage. As an example result: it is possible to pack 147 small rectangles of size (137,95) in a big rectangle of size (1600,1230).

Packing identical squares in a rectilinear polygon Given a rectilinear polygon (whose sides meet at right angles) R in the plane, a set S of points in R, and a set of identical squares, the goal is to find the largest number of non-overlapping squares that can be packed in points of S. Suppose that, for each point p in S, we put a square centered at p. Let GS be the intersection graph of these squares. A square-packing is equivalent to an independent set in GS. Finding a largest square-packing is NP-hard; one may prove this by reducing from 3SAT.

Packing different rectangles in a given rectangle In this variant, the small rectangles can have varying lengths and widths, and they should be packed in a given large rectangle. The decision problem of whether such a packing exists is NP-hard. This can be proved by a reduction from 3-partition. Given an instance of 3-partition with 3m positive integers: a1, ..., a3m, with a total sum of m T, we construct 3m small rectangles, all with a width of 1, such that the length of rectangle i is ai + m. The big rectangle has width m and length T + 3m. Every solution to the 3-partition instance induces a packing of the rectangles into m subsets such that the total length in each subset is exactly T, so they exactly fit into the big rectangle. Conversely, in any packing of the big rectangle, there must be no "holes", so the rectangles must not be rotated. Therefore, the packing must involve exactly m rows where each row contains rectangles with a total length of exactly T. This corresponds to a solution of the 3-partition instance. When there is an additional restriction that the packing must be exact (with no wasted space), the small rectangles may be rotated only by multiples of 90°. In this case, the problem is in NP. Without this requirement, the small rectangles may be rotated in arbitrary angles. In this more general case, it is not clear if the problem is in NP, since it is much harder to verify a solution.

Packing different rectangles in a minimum-area rectangle In this variant, the small rectangles can have varying lengths and widths, and their orientation is fixed (they cannot be rotated). The goal is to pack them in an enclosing rectangle of minimum area, with no boundaries on the enclosing rectangle's width or height. This problem has an important application in combining images into a single larger image. A web page that loads a single larger image often renders faster in the browser than the same page loading multiple small images, due to the overhead involved in requesting each image from the web server. The problem is NP-complete in general, but there are fast algorithms for solving small instances.

Integer programming formulation One can model rectangle packing problem for fixed sizes and orientations as an integer linear program. Further, constraints and variables can be added to minimize the bounding-box-netlength. Given small rectangles R 1 , . . . R n {\displaystyle R_{1},...R_{n}}

with widths w 1 , . . . , w n {\displaystyle w_{1},...,w_{n}} , heights h 1 , . . . , h n {\displaystyle h_{1},...,h_{n}} and nets N 1 , . . . , N n {\displaystyle {\mathcal {N}}_{1},...,{\mathcal {N}}_{n}} as well as a larger rectangle with width W {\displaystyle W} and height H {\displaystyle H} , the integer program looks as follows:

Objective minimizing bounding-box-netlength

min ∑ N ∈ ∪ i = 1 n N i y N , t − y N , b + x N , r − x N , l {\displaystyle \min \sum _{N\in \cup _{i=1}^{n}{\mathcal {N}}_{i}}y_{N,t}-y_{N,b}+x_{N,r}-x_{N,l}}

Non-overlap constraints

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Rectangle packing

Start with the simplest possible case. Write down what Rectangle packing claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Rectangle packing before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Rectangle packing ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Rectangle packing

In research
Rectangle packing appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Rectangle packing in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Rectangle packing is common in secondary-school and first-year university syllabi. It links to neighbouring topics Geometric algorithms, NP-hard problems, Packing problems, so understanding it makes those chapters shorter.
In everyday life
Look for Rectangle packing outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Rectangle packing in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Rectangle packing means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Rectangle packing out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Rectangle packing in simple terms?

Rectangle packing is a packing problem where the objective is to determine whether a given set of small rectangles can be placed inside a given large polygon, such that no two small rectangles overlap. Several variants of this problem have been studied.

Why does Rectangle packing matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Rectangle packing?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Rectangle packing.

Tags

  • Geometric algorithms
  • NP-hard problems
  • Packing problems

Keep exploring