This is called 2D Strip Packing, and he worked on Martello. If you are doing a Google search for your paper, their algorithm should be fairly easy to implement. One way to do this is to solve your problem using a branch and a border. First figure out the greedy solution to get the maximum height required by your packaging.
Then your algorithm should first find a set of x-coordinates, which is promising, and then find the y-coordinates for your rectangles. In other words, for each rectangle, answer all possible x coordinates that you can assign. At any time, you can save the sum of the total height occupying any particular x coordinate (this is called the cumulative constraint), and crop if the height exceeds the maximum maximum height. For each complete x-coordinate solution where all the x-coordinates of the rectangles are assigned, now you can try to find the real y-coordinates. You can do this in the same way, branching out each possible y-coordinate for each rectangle, cropping when you know that the two rectangles overlap. At the bottom of the tree you will find the x and y coordinates for your rectangles, at this point you can calculate the required height and update the maximum upper bound.
If you saved the current solution when you updated your upper bound, then when your algorithm completes, you will get the optimal solution.
source share