I have multiple rectangular frames, with different fixed heights. The width should be minimized and there is a maximum width. Then there are many different smaller rectangles. These should be packed into these frames. It doesn't matter in which frame the rectangles are as long as the total used area can be reduced, which is also the main goal: to use the smallest possible area.
It is not necessarily the case that all the frames have to be used if the area can be reduced in this way. Additionally, if one frame is completely filled it will just add another frame with the same height.
I would like to solve this problem with an algorithm in Java. Does anyone of you have a suitable approach?
After some research, https://www.codeproject.com/Articles/210979/Fast-optimizing-rectangle-packing-algorithm-for-bu sounds good to me so far, but you would have to somehow extend it to use not only one enclosing rectangle, but a few different ones.