我有不同尺寸的小矩形(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
所以给出了外部矩形的大小,并且想要最小化中间的白色区域? –
使它变硬的条件是矩形只能放在边缘/边上。它们不能堆叠 –
没有给出外部矩形的大小。只给出小矩形纪念。外部矩形的尺寸将随着位置变化而改变。但是我想要在边缘上放置最佳的小矩形,这样可以提供最小的外矩形区域。 –