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.

  • Thanks for your response @candied_orange. Asking to find something other than an approach wasn't the intention here. And the problem is to find a resource-friendly approach instead of just doing hundreds and thousands of iterations. – Wombosvideo Jul 4 at 8:02
  • Thank you for your edit. Welcome to the site. – candied_orange Jul 4 at 8:03
  • Maybe I've played to much tetris, but fixed heights and minimized width really thru me off because I expect packing to go from bottom to top not side to side. – candied_orange Jul 4 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.