2D Strip Packing is a classic optimization problem in computer science and operations research. The goal is to pack a set of rectangles (items) into a strip of fixed width (WIDTH) such that the total height of the packed rectangles is minimized.
The SKYLINE algorithm is a heuristic method designed to efficiently solve the 2D Strip Packing problem. The key idea is to define a struct space
to represent potential areas where rectangles can be placed. By evaluating the fitness of each space
, the algorithm selects the most suitable position to insert each rectangle.
For more details, please refer to the paper:
An efficient skyline heuristic for the 2D Strip Packing Problem
-
Input:
- An integer
n
, representing the number of rectangles (items). - An integer
WIDTH
, representing the fixed width of the strip's base. n
integers, representing the widths of the rectangles.n
integers, representing the heights of the rectangles.
- An integer
-
Output:
- A single integer, representing the minimum height required to pack all rectangles into the strip.
To assist in understanding and debugging the algorithm, a DEBUG
mode has been implemented:
- Uncomment the macro definition
#define DEBUG
in the code to enable DEBUG mode. - In DEBUG mode, the program will print detailed information about each step of the process and intermediate results to the console.
- In this implementation, I used C++ STL's
vector
to record thespaces
andRectangles
. Whilevector
is a flexible and easy-to-use data structure, using other specialized data structures such as heaps, balanced trees, or priority queues may speed up the algorithm.
Your feedback is highly appreciated! If you find any bugs or have suggestions for improvement, please let me know.