二维矩形原料的简易求解(上)

需求:

包装工厂接到不同规格纸箱的订单,按订单批次进料(原纸),原纸的宽度(width)有多种规格(20多种)但长度(long)不限,原料价格按长度梯度有优惠。为简化求解,先将纸箱(产品)展开转化为矩形(矩形),然后按长(l)、宽(w),分别求解不同宽度原纸的长度,从而计算出价格;找出相对最优解。

同种矩形,从原纸的宽度先排列(原纸横排)

1 矩形竖排(单个),用矩形的宽度w,求解不同宽度原纸的长度,计算出价格

        long = w*size ; price = long * 梯度优惠

2 矩形横排(单个),用矩形的长度,求解不同宽度原纸的长度,计算出价格

        long = l*size;price = long * 梯度优惠

3 矩形竖排(n个),用矩形的宽度w,求解不同宽度原纸的长度,计算出价格

        n=width/w

        long = w*((size-1)/n +1) ; price = long * 梯度优惠

4 矩形横排(n个),用矩形的长度,求解不同宽度原纸的长度,计算出价格

        n=width/l

        long = l*((size-1)/n +1) ; price = long * 梯度优惠

5 矩形横竖排(n个),便于工业操作,竖排的一直竖排,横排的一直横排,求解不同宽度原纸的长度,计算出价格

不同种矩形(先按两种矩形),从原纸的宽度先排列(原纸横排)

在二维矩形最优解有很多算法,但都是学术研究的解法,太过于理想不适合工业生产,特别是小型企业,存在生产限制条件的企业;大型企业都有固定的产品规格,供应原料商会提供相对规格的原料,根本不会用到二维矩形最优解来解决下料问题。我们所熟知的就是那些为小众公司带来方便的技术应用。

深圳逆时针

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
二维矩形装箱问题是一个经典的优化问题,其目标是将一组不同大小的矩形尽可能紧密地放入一个矩形容器中,以最小化容器的面积或者最大化利用率。这个问题在物流、制造业和计算机图形学等领域都有广泛的应用。 在Python中,可以使用不同的算法来解决二维矩形装箱问题。其中一种常见的算法是基于贪心策略的最佳适应算法。该算法的基本思想是按照矩形的面积从大到小的顺序依次将矩形放入容器中,每次选择一个最合适的位置进行放置。 以下是一个简单的Python代码示例,演示了如何使用最佳适应算法解决二维矩形装箱问题: ```python class Rectangle: def __init__(self, width, height): self.width = width self.height = height def pack_rectangles(rectangles, container_width, container_height): container = [[0, 0, container_width, container_height]] # 初始容器 packed_rectangles = [] for rectangle in rectangles: best_index = -1 best_fit = float('inf') for i, (x, y, width, height) in enumerate(container): if rectangle.width <= width and rectangle.height <= height: fit = max(width - rectangle.width, height - rectangle.height) if fit < best_fit: best_fit = fit best_index = i if best_index == -1: # 创建新的容器 container.append([0, 0, container_width, container_height]) best_index = len(container) - 1 x, y, width, height = container[best_index] packed_rectangles.append((rectangle, x, y)) # 更新容器 if rectangle.width == width and rectangle.height == height: del container[best_index] elif rectangle.width == width: container[best_index] = [x, y + rectangle.height, width, height - rectangle.height] elif rectangle.height == height: container[best_index] = [x + rectangle.width, y, width - rectangle.width, height] else: container.append([x + rectangle.width, y, width - rectangle.width, rectangle.height]) container[best_index] = [x, y + rectangle.height, width, height - rectangle.height] return packed_rectangles # 示例用法 rectangles = [Rectangle(4, 5), Rectangle(3, 6), Rectangle(2, 7), Rectangle(3, 4)] container_width = 10 container_height = 10 packed_rectangles = pack_rectangles(rectangles, container_width, container_height) for rectangle, x, y in packed_rectangles: print(f"Rectangle ({rectangle.width}, {rectangle.height}) is placed at ({x}, {y})") ``` 这段代码使用了一个`Rectangle`类来表示矩形,`pack_rectangles`函数接受一个矩形列表、容器的宽度和高度作为输入,并返回一个包含每个矩形及其在容器中位置的列表。在示例用法中,我们创建了一个矩形列表,并将其放入一个10x10的容器中,然后打印出每个矩形的位置信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值