dongwen7380 2014-12-12 19:46
浏览 28

PHP中的货物算法

Honestly, i have a testing calculate how many containers of a given size and weight capacity it takes to pack the specified goods. But i'm really bad at algorithm, so i post this to looking some hint from you guys. Any help is appreciate. Thank you guys !

I have three container sizes and their capacities like this :

Container Size : Large
Maximum Volume (m3) : 76
Maximum Weight (kg) : 29,600

Container Size : Medium
Maximum Volume (m3) : 67.3 Maximum Weight (kg) : 27,397

Container Size : Small
Maximum Volume (m3) : 33 Maximum Weight (kg) : 22,100

Given a total weight and volume for goods in a shipment, the algorithm must output the most efficient combination of containers to pack the goods in. The system should use larger containers where possible, but empty space should be minimised.

For input of volume 213m3 and weight 22,421kg, the expected output is:

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  
), 
) 

For input of volume 182m3 and weight 19,158kg, the expected output is:

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  
), 
) 

I can't understand how it work ....

So please hint me.

Thank you.

  • 写回答

1条回答 默认 最新

  • douhunbei0166 2014-12-12 20:08
    关注

    The problem you are looking to solve is a well known NP-complete problem called as the knapsack problem. Here is the wikipedia link describing that problem :-

    The best recommended way would be some sort of heuristics. Here's a paper that describes some useful heuristics to solve the knapsack problem.

    Edit :- To explain a bit further, NP-complete problems are a known category of problems for which no efficient solution exists. i.e., there is no algorithm that is both fast and correct. Hence you have to use some kind of heuristic approximation algorithms to solve it that are both fast and reasonably correct.

    What kind of heuristic would be best suited for your problem is probably out of the scope of stackoverflow. I've given you some resources and you can search more on this rather well studied problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目