Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

求一个PHP商品装箱最小化的算法,贪婪算法?

现有php订单商品列表数组如下:
$goods = [

20200702024 =>  [
    "name" => "LP-雨伞",    // 商品名称
    "bar_code" => "20200702024",// 条形码
    "quantity" => "3",            // 数量
    "scan_mode" => "5",            // 发货模式
    "volume" => "15.6",            // 体积
  ],

6970328080043 => [

    "name" => "压缩面膜",
    "bar_code" => "6970328080043",
    "quantity" => "1",
    "scan_mode" => "5",
    "volume" => "23",            

],
6922994301816 => [

    "name" => "洁面巾",
    "bar_code" => "6922994301816",
    "quantity" => "5",
    "scan_mode" => "3",
    "volume" => "20",

],

6922994300765 =>  [
    "name" => "鲜藻精华面膜",
    "bar_code" => "6922994300765",
    "quantity" => "11",
    "scan_mode" => "4",
    "volume" => "36",
],
6922994300192 =>  [
    "name" => "甘菊花露水",
    "bar_code" => "6922994300192",
    "quantity" => "8",
    "scan_mode" => "1",
    "volume" => "65",
],

];

现有包裹箱子体积固定为300,如何拆分订单商品。
拆分包裹条件:
1、最小化拆分包裹,不能浪费箱子
2、每个商品的体积是单个的,总体积= 商品数量 X 单个体积
3、商品可以随意搭配装箱,只要满足最后的条件,箱子最小化,不浪费一个箱子
4、比如:有些商品装3个就满了,但是它有8个,也要拆开放下一个箱子
5、使用PHP语言,这个算法应该如何写?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

无解。因为不知道长宽高。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...