Algorithm to Minimize Number of Shipments from Multiple Warehouses

前端 未结 5 1684
伪装坚强ぢ
伪装坚强ぢ 2021-02-10 13:04

I have 10 warehouses across the US. Each of them may or may not have product A, B, C, D, E in stock. Someone orders all five items from my website.

I want to minimize th

5条回答
  •  清歌不尽
    2021-02-10 13:42

    How about the following:

    IF a warehouse has all items THEN pick that warehouse  
    ELSE  
       Find how many items each warehouse has e.g. NY (2) Boston(3) Chicago(2)  
       Sort them by items Boston(3) NY(2) Chicago (2)  
       Current Max is the warehouse with the most products i.e. (3)  
       Step 1: Start making shipments starting from the warehouse with the current max i.e. Boston.  
       Step 2:  As you go on check if you have all the packets and not e.g. NY has 2 and Chicago also has 2 but they are the same 2. Keep this tuple as potential.  
       Step 3: Once you finished with all warehouses, update current max to be the next highest number of products a warehouse has.  In this case (2)  
       IF no warehouse left you are done  
       ELSE go to Step 1
       Continue until you have shipments for all items
    

提交回复
热议问题