[英]Algorithm to determine (x,y) coordinates for rectangles so the area of the surrounding rectangle is minimal?
I hope my title makes sense, but here is what I a trying to do: 我希望我的标题有意义,但这是我想要做的:
I have n
rectangles, each with widths of W n and heights of H n that I need to arrange so on a two dimensional (x,y) plane the rectangle that they all fit in takes up the least area. 我有n
矩形,每个都有宽度为W n ,高度为H n我需要在二维(x,y)平面上排列,它们都适合的矩形占据的面积最小。 I also need to be able to establish what (x,y) corresponds to what rectangle. 我还需要能够确定(x,y)对应于什么矩形。
I would prefer something in psuedo-code, but can work with many languages. 我更喜欢psuedo-code中的某些东西,但可以使用多种语言。
Thanks for helping. 谢谢你的帮助。
This is a difficult problem to be solved optimally, however there are some solutions that are not too hard to implement and that represent a good approximations for many uses (eg for textures). 这是一个要以最佳方式解决的难题,但是有一些解决方案并不太难实现,并且代表了许多用途(例如纹理)的良好近似。 Try googling for "rect(angle) packing" ... you will find a lot of code that solves the problem. 尝试谷歌搜索“矩形(角度)包装”...你会发现很多代码解决了这个问题。
Sounds NP-complete to me. 对我来说听起来很完整。 Kinda like the knapsack problem. 有点像背包问题。 Which means there is no real solution. 这意味着没有真正的解决方案。 Only good approximations. 只有很好的近似值。
It's a variant on 2D bin packing. 它是2D纸盒包装的变种。 The fact that your container is flexible, allows for more optimization as well making it more challenging (as in difficult). 您的容器灵活,允许更多优化,使其更具挑战性(如困难)。 Drools Planner (open source java) can handle this. Drools Planner (开源java)可以处理这个问题。 At least one implementation (see user mailing list) with Drools Planner exists (not open source). 存在至少一个带有Drools Planner的实现(请参阅用户邮件列表)(非开源)。 If you need an open source example to start from, probably the cloud balance in drools-planner-examples is a good example to start from. 如果您需要一个开源示例,那么drools-planner-examples中的云平衡可能就是一个很好的例子。
For an overview of the algorithms you can use, see my answer on a similar question . 有关可以使用的算法的概述,请参阅我对类似问题的回答 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.