【发布时间】:2016-04-28 16:10:05
【问题描述】:
我有不同尺寸的小矩形(1cm x 2xm、2cmx3cm、4cm*6cm 等)。不同类型矩形的数量可能因情况而异。每种类型的不同矩形可能有不同的计数。
我需要用所有这些小矩形创建一个大矩形,这些小矩形只能放在边缘上。 没有轮换。理想情况下,最终的外部矩形应该类似于正方形。 X~Y。并非所有边缘都需要填充。较小的矩形之间可能存在间隙。图片示例:
http://i.stack.imgur.com/GqI5z.png
我正在尝试编写一个代码来找出可以形成的最小可能区域。
我有一个算法可以遍历所有可能的位置以找出可能的最小区域。但是随着不同类型矩形的数量和矩形数量的增加,这需要很长时间。即 2 种矩形,每个有 100 + 矩形。 8个for循环。那将是 ~100^8 次迭代
关于计算最小可能面积的更好更快的算法有什么想法吗?代码是python,但任何算法概念都可以。
for rectange_1_top_count in (range(0,all_rectangles[1]["count"]+1)):
for rectange_1_bottom_count in range(0,all_rectangles[1]["count"]-rectange_1_top_count+1):
for rectange_1_left_count in (range(0,all_rectangles[1]["count"]-rectange_1_top_count-rectange_1_bottom_count+1)):
for rectange_1_right_count in ([all_rectangles[1]["count"]-rectange_1_top_count-rectange_1_bottom_count-rectange_1_left_count]):
for rectange_2_top_count in (range(0,all_rectangles[2]["count"]+1)):
for rectange_2_bottom_count in (range(0,all_rectangles[2]["count"]-rectange_2_top_count+1)):
for rectange_2_left_count in (range(0,all_rectangles[2]["count"]-rectange_2_bottom_count-rectange_2_top_count+1)):
for rectange_2_right_count in [(all_rectangles[2]["count"]-rectange_2_bottom_count-rectange_2_left_count-rectange_2_top_count)]:
area=calculate_minimum_area()
if area< minimum_area:
minimum_area=area
【问题讨论】:
-
那么外矩形的大小给定了,你想最小化中间的白色区域吗?
-
很难的条件是矩形,只能放在边缘/边上。它们不能堆叠
-
没有给出外矩形的大小。只给出了小的矩形尺寸。外部矩形的尺寸会随着位置的变化而变化。但我希望边缘上的最佳小矩形放置将提供最小的外部矩形区域。
-
好的,谢谢。你必须使用所有的瓷砖吗?
-
是否要求边的每一段都与矩形相邻,还是可以有间隙?显然,角落中的矩形是两条边的一部分。但是一个大矩形也可以是底部和顶部边缘的一部分吗?
标签: algorithm geometry rectangles minimization placement