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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵