计算运输箱尺寸的粗略估算 [英] Calculate a rough estimate for shipping box size

查看:62
本文介绍了计算运输箱尺寸的粗略估算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到计算运输所需盒子尺寸的最佳方法.

I'm trying to find the best way to calculate the box size needed for shipping.

我有3个不同大小的运输集装箱.我在数据库中定义了产品的宽度,长度,深度和质量.

I have 3 shipping containers with different sizes. I have the product's width, length, depth, and mass defined in the database.

我想知道如何找到要运送的最少数量的箱子,以及在购物车中有多少物品的情况下,找到这些箱子的最小尺寸.

I would like to know how to find the smallest amount of boxes needed to ship, and also the smallest dimensions of those boxes given the number of items in the cart.

我当前的想法"是找到整个产品数组的最大宽度,根据它选择一个框,然后根据需要拆分订单……这似乎行不通.

My current 'idea' is to find the maximum width of the entire products array, the select a box according to it, and then split the order as needed... this doesn't seem like it would work.

我的盒子尺寸是: -8 x 6 x 6 = 228立方英寸 -10 x 8 x 8 = 640立方英寸 -12.5 x 12.5 x 12.5 = 1953.125立方英寸

My Box sizes are: - 8 x 6 x 6 = 228 cubic inches - 10 x 8 x 8 = 640 cubic inches - 12.5 x 12.5 x 12.5 = 1953.125 cubic inches

产品定义如下:

 [Product] => Array
                (
                    [STOCK_CODE] => 010003
                    [Product_Slug] => GABA_010003
                    [ItemName] => GABA
                    [WHOLESALE_PRICE] => 17.47
                    [RETAIL_PRICE] => 24.95
                    [Brand] => 
                    [ProductLine] => 
                    [image_name] => 705077000440
                    [MASS] => 0.313
                    [Height] => 4.625
                    [Width] => 2.375
                    [Depth] => 2.375
                    [cubic_inches] => 26.087890625
                )

我调查了背包问题,包装问题等,但找不到解决方法.任何帮助都会很棒.

I've looked into knapsack problem, packing problem, etc and can't find a way to do this. Any help would be GREAT.

function shipping(){

        $this->CartProduct->unbindModel(
            array('belongsTo' => array('User'))
        );

        //find all cart products by current logged in user
        $cartItems = $this->CartProduct->find('all', array('conditions' => array('CartProduct.user_id' => $this->Auth->user('id'))));

        $i = 0;

        //get the max width, height, depth
        $maxHeight = 0;
        $maxWidth = 0;
        $maxDepth = 0;
        foreach($cartItems as $c){
            $cartItems[$i]['Product']['cubic_inches'] = $c['Product']['Height'] * $c['Product']['Width'] * $c['Product']['Depth'];
            $cartItems[$i]['CartProduct']['total_cubic_inches'] = ($c['Product']['Height'] * $c['Product']['Width'] * $c['Product']['Depth']) * $c['CartProduct']['qty'];

            if($c['Product']['Height'] > $maxHeight)
            {
                $maxHeight = $c['Product']['Height'];
            }

            if($c['Product']['Width'] > $maxWidth)
            {
                $maxWidth = $c['Product']['Width'];
            }
            if($c['Product']['Depth'] > $maxDepth)
            {
                $maxDepth = $c['Product']['Depth'];
            }
            $i++;
        }

        //possible containers 
        //8 x 6 x 6 = 228 ci
        //10 x 8 x 8 = 640 ci
        //12.5 x 12.5 x 12.5 = 1953.125

        $possibleContainers = array(
            1 => array(
                'Height' => 8,
                'Width' => 6,
                'Depth' => 6,
                'Cubic' => 228),
            2 => array(
                'Height' => 10,
                'Width' => 8,
                'Depth' => 8,
                'Cubic' => 640),
            3 => array(
                'Height' => 12.5,
                'Width' => 12.5,
                'Depth' => 12.5,
                'Cubic' => 1953.125)
        );



        $max = array(
            'Height' => $maxHeight, 
            'Width' => $maxWidth, 
            'Depth' => $maxDepth, 
        );

        pr($cartItems);
        pr($possibleContainers);
        die();  
    }

推荐答案

要获得最佳答案,那就是NP-Hard ... http://en.wikipedia.org/wiki/Bin_packing_problem

As for getting a optimal answer, that's NP-Hard... http://en.wikipedia.org/wiki/Bin_packing_problem

维基百科上显示的贪婪算法虽然可能相差很远,但实际上可能适合您的情况.

The greedy algorithm shown on Wikipedia, while it can be quite far off, might actually do for your case.

不过,作为估算,您可以将项目的数量相加,然后应用效率系数,然后使用可以使用的最小包装盒.

However as an estimate you could just sum up the volumes of the items and then apply a inefficiency factor and then use the smallest box(s) you can.

或者,您可以按减小的体积分类物品,然后查看可以放入当前盒子中的物品的数量,并在无法容纳物品的情况下创建一个新盒子.不确定如何处理不同大小的盒子尽管.您可能还会遇到一种情况,即它更改了框的大小,而不是创建一个新的框.

Alternately you could sort the items into decreasing volume and then see how much you can get into the current set of boxes, creating a new box when you can't fit the item in. Not sure how you would handle different box sizes though. You could also have a case where it changes the box size rather than creating a new box.

值得深思的东西.

这篇关于计算运输箱尺寸的粗略估算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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