算法需要在一个相当优化的方式包装的矩形 [英] Algorithm needed for packing rectangles in a fairly optimal way

查看:187
本文介绍了算法需要在一个相当优化的方式包装的矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ive得到了一堆,我需要打包成尽可能小的空间(这个空间的大小应该是两个大国)。

Ive got a bunch of rectangular objects which I need to pack into the smallest space possible (the dimensions of this space should be powers of two).

我知道的各种包装算法将包中的项目,以及可能在给定的空间,但是在这种情况下,我所需要的算法来解决如何大,以致空间应该以及

I'm aware of various packing algorithms that will pack the items as well as possible into a given space, however in this case I need the algorithm to work out how large that space should be as well.

例如说,香港专业教育学院得到了下面的矩形

Eg say Ive got the following rectangles

  • 128 * 32
  • 128 * 64
  • 在64 * 32
  • 在64 * 32

它们可以被包装成一个128×128空间

They can be packed into a 128*128 space


 _________________
|128*32          |
|________________|
|128*64          |
|                |
|                |
|________________|
|64*32  |64*32   |
|_______|________|

然而,如果也有一个160 * 32和64 * 64之一,它需要一个256 * 128的空间

However if there was also a 160*32 and a 64*64 one it would need a 256*128 space


 ________________________________
|128*32          |64*64  |64*32  |
|________________|       |_______|
|128*64          |       |64*32  |
|                |_______|_______|
|                |               |
|________________|___            |
|160*32              |           |
|____________________|___________|

什么算法是有那些能够收拾一堆矩形,并确定为容器所需的大小(以2的幂,并且在每个维给定的最大大小)?

What algorithms are there that are able to pack a bunch of rectangles and determine the required size for the container (to a power of 2, and within a given maximum size for each dimension)?

推荐答案

快速和肮脏第一遍解决方案始终是一个伟大的,开始时,好像没有别的。一个比较

The quick and dirty first pass solution is always a great one to start with, as a comparison if nothing else.

从大至小贪心的位置。

把剩下的到你的打包地区最大的矩形。如果它不适合的任何地方,将其放置在扩展包区域尽可能少的地方。重复,直到你完成用最小的矩形。

Put the largest rectangle remaining into your packed area. If it can't fit anywhere, place it in a place that extends the pack region as little as possible. Repeat until you finish with the smallest rectangle.

这不是完美的,但在所有它很容易和一个不错的基础。它仍然会收拾你的原来的例子很好,给你第二同等的回答也是如此。

It's not perfect at all but it's easy and a nice baseline. It would still pack your original example perfectly, and give you an equivalent answer for the second as well.

这篇关于算法需要在一个相当优化的方式包装的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆