douyu0845 2012-04-15 22:36
浏览 61
已采纳

包裹打包的PHP / C ++空间计算

I am working on a shopping cart project which requires a 'postage calculator' based on items that the person has in their cart.

Obviously I will be storing the item's dimensions incl. weight and padding in a database and will also store the parcel (box) size and weight that the items will go in to, incl. box padding.

Figuring the weight of the parcels will be easy but I was wondering how to go about figuring how to pack the box via PHP, that is, I would like the code to 'play tetris' with the items to make sure they get the best possible fit, giving accurate postage costs.

Does anybody have any ideas on how best to achieve this or does anybody know of a PHP Class or function that can do this?

EDIT: When I said 'best possible fit' maybe I was being optimistic! Having the script try every possible combination of package distribution within the parcel would be over the top, however I could improve the speed by writing the algoritm in C++ and running the program in PHP when the user 'checks out', the return value being an array with the parcel size and weight (which are all that are needed to calculate postage costs)

  • 写回答

1条回答 默认 最新

  • dqwh26750 2012-04-15 22:44
    关注

    I don't believe anyone has already found the perfect algorithm to do this. All existing algorithms (which ususally are not public) try to get a near perfect approach, but there's just too much calculation needed to calculate each and every possibility within a reasonable amount of time.

    Those trucks need to leave at a certain point of time after all. :)

    Besides, calculating the ideal fit also means you must know the exact measurements of each parcel, and the person that loads the truck need to use a complex 'map' to put those parcels in exactly the way you calculated.

    No, in practice, the easiest approach is to calculate the total volume, use a certain factor (like 0.95, which you can finetune on the go) and use that as a guess to how many parcels will fit in your truck. And as long as its people who load your truck, this is the best approach too. Anything else will need robots to load the truck according to your specific calculated instructions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重