ruby - How to implement priority warehouse selection of receiving address and shipping warehouse in PHP
怪我咯
怪我咯 2017-06-27 09:18:02
0
1
794

Today I will ask a technical question about the priority warehouse selection of goods, delivery addresses and delivery warehouses.

As in the title:

  1. The user purchased three products: A, B, and C (it can be considered that the user purchased n SKU products, and each SKU has a corresponding quantity). We use capital letters for product SKU: A, B, C;

  2. The shipping address is X;

  3. Each product has multiple warehouses, and the warehouse delivery selects the most recent and optimal one (the priority is configured according to the delivery address). For example, the warehouses are: a, b, c, d (warehouses are represented by lowercase letters) )etc;

Priority logic:

The user purchases the goods and chooses warehouse delivery. The fewer the number of packages, the better (primary), and the closer the package is, the better (secondary);

The delivery address is X, the priority list of warehouses corresponding to X address:

X => a,b,c,d

Example:

Example 1. The user purchased 1 sku (the quantity is 3) and sent it to the corresponding address X:


A: 3

The inventory and quantity corresponding to this product A: The order corresponding to the X address is: a, b, c, d

A corresponding warehouse and inventory list:

a: 1 b: 3 c: 4 d: 5

According to the principle of minimum package to the nearest warehouse, the result will be deducted from warehouse b inventory (3 items of A product) to ship 1 package.


Example 2. The user purchased 2 skus and sent them to the corresponding address X:

A: 3 B: 2

The inventory and quantity corresponding to these products A and B: (The order corresponding to the X address is: a, b, c, d)

A corresponding warehouse and inventory list:

a: 1 b: 3 c: 4 d: 5

B corresponding warehouse and inventory list:

a: 1 b: 2 c: 1 d: 5

According to the principle of the minimum package to the nearest warehouse, the result should also be deducted from warehouse b (3 products A, 2 products B) storing and shipping 1 package.


Example 3. The user purchased 2 skus and sent them to the corresponding address X:

A: 3 B: 2

The inventory and quantity corresponding to these products A and B: (The order corresponding to the X address is: a, b, c, d)

A corresponding warehouse and inventory list:

a: 3 b: 3 c: 1 d: 5

B corresponding warehouse and inventory list:

a: 1 b: 1 c: 2 d: 1

According to the minimum package nearest warehouse principle, the result should also deduct warehouse a (3 items of product A, 1 item of product B), add warehouse b (1 item of product B), and deliver a total of 2 packages (warehouse a and 1 item of product B). b (one for each warehouse) (here we also follow the principle of having the best few packages and the closest warehouse).


Example 4, the user purchased 2 skus and sent them to the corresponding address X:

A: 3 B: 5

The inventory and quantity corresponding to these products A and B: (The order corresponding to the X address is: a, b, c, d)

A corresponding warehouse and inventory list:

a: 2 b: 3 c: 4 d: 5

B corresponding warehouse and inventory list:

a: 1 b: 1 c: 2 d: 5

According to the principle of the minimum number of packages to the nearest warehouse, the result should also be deducted from warehouse d (3 items of product A, 5 items of product B), and a total of 1 package (one in warehouse d) should be shipped. The principle of the minimum number of packages is achieved here.


I dare to ask, how can some experts break this algorithm?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all (1)
学习ing

This is what I think, first sort the sku array in descending order, for example, 3 pieces of sku, array(8,4,1);
Get the optimal package plan of 8 pieces, 4 pieces, and 3 pieces respectively,
then put By combining the warehouse conditions of these three plans and removing duplications, you can get the optimal plan.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!