Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的Cargo算法_Php_Algorithm - Fatal编程技术网

PHP中的Cargo算法

PHP中的Cargo算法,php,algorithm,Php,Algorithm,老实说,我有一个测试,可以计算出一个给定尺寸和重量容量的容器需要多少来包装特定的货物。但我在算法方面真的很差,所以我把这篇文章贴在这里,希望你们能给我一些提示。任何帮助都将不胜感激。谢谢你们 我有三种容器尺寸,其容量如下: 容器尺寸:大 最大容积(m3):76 最大重量(kg):29600 容器尺寸:中等 最大容积(m3):67.3 最大重量(kg):27397 容器尺寸:小 最大容积(m3):33 最大重量(kg):22100 给定一批货物的总重量和体积,算法必须输出最有效的集装箱组合来包装货

老实说,我有一个测试,可以计算出一个给定尺寸和重量容量的容器需要多少来包装特定的货物。但我在算法方面真的很差,所以我把这篇文章贴在这里,希望你们能给我一些提示。任何帮助都将不胜感激。谢谢你们

我有三种容器尺寸,其容量如下:

容器尺寸:大
最大容积(m3):76
最大重量(kg):29600

容器尺寸:中等
最大容积(m3):67.3 最大重量(kg):27397

容器尺寸:小
最大容积(m3):33 最大重量(kg):22100

给定一批货物的总重量和体积,算法必须输出最有效的集装箱组合来包装货物。系统应尽可能使用更大的容器,但应尽量减少空置空间

对于体积为213m3、重量为22421kg的输入,预期输出为:

array(  
‘L’ => array(   
‘quantity’ => 2,   
‘volume’   => 152,   
‘weight’ => 16000  
),  
‘M’ => array(   
‘quantity’ => 1,   
‘volume’   => 61,   
‘weight’ => 6421  
),  
 ‘S’ => array(   
‘quantity’ => 0,   
‘volume’   => 0,   
‘weight’ => 0  
), 
) 
array(  
‘L’ => array(   
‘quantity’ => 2,   
‘volume’   => 152,   
‘weight’ => 16000  
),  
‘M’ => array(   
‘quantity’ => 0,   
‘volume’   => 0,   
‘weight’ => 0  
),  
‘S’ => array(   
‘quantity’ => 1,   
‘volume’   => 30,   
‘weight’ => 3158  
), 
) 
对于体积为182m3、重量为19158kg的输入,预期输出为:

array(  
‘L’ => array(   
‘quantity’ => 2,   
‘volume’   => 152,   
‘weight’ => 16000  
),  
‘M’ => array(   
‘quantity’ => 1,   
‘volume’   => 61,   
‘weight’ => 6421  
),  
 ‘S’ => array(   
‘quantity’ => 0,   
‘volume’   => 0,   
‘weight’ => 0  
), 
) 
array(  
‘L’ => array(   
‘quantity’ => 2,   
‘volume’   => 152,   
‘weight’ => 16000  
),  
‘M’ => array(   
‘quantity’ => 0,   
‘volume’   => 0,   
‘weight’ => 0  
),  
‘S’ => array(   
‘quantity’ => 1,   
‘volume’   => 30,   
‘weight’ => 3158  
), 
) 
我不明白它是怎么工作的

所以请提示我


多谢各位

您要解决的问题是一个众所周知的NP完全问题,称为背包问题。维基百科链接是否描述了该问题:-

最好的推荐方法是某种启发式方法。本文描述了一些有用的启发式算法来解决背包问题

编辑:-进一步解释一下,NP完全问题是一类已知的问题,不存在有效的解决方案。i、 例如,没有既快速又正确的算法。因此,您必须使用某种启发式近似算法来解决它,这些算法既快速又合理正确

什么样的启发式算法最适合您的问题可能超出了stackoverflow的范围。我已经给了你一些资源,你可以在这个研究得很好的问题上搜索更多