Today I will ask a technical question about the priority warehouse selection of goods, delivery addresses and delivery warehouses.
As in the title:
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;
The shipping address is X;
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?
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.