Reputation: 402
Suppose you have a warehouse that receives orders during the day. These order can either be withdrawals or additions of products to the warehouse. At the end of the day you get an inventory list of items still contained in the warehouse. Because the workforce is stretched quite thin it can happen that an order is not taken care of at the same day it is received in the ticket system of the warehouse. Therefore at the end of the day you have to match the issued orders against the inventory list of the warehouse to find out which ones have actually been executed and which orders are still open.
Codewise i've been solving this by several nested loops just aggregating and comparing the inventory positions trying to match the orders. Unfortunately this is not really efficient and with a large number of orders and positions the resulting problem takes quite some time to complete.
In order to improve that i want to identify the underlying problem. I.e. is it Set Cover, Knapsack or something else and based on the problem and whether it is in P or NP is there an efficient algorithm or at least an efficient heuristic to solve it?
Upvotes: 0
Views: 40
Reputation: 106126
As stated, we know you have the following sources of information:
One solution is to create hash sets from the current and previous days' inventory lists, then as you iterate "issued orders", compare the order quantity with the difference between the inventory sets.
The time for this is:
the time to create two sets from unsorted (as far as we know) lists (if there's reason to care, the set for today can be kept for re-use tomorrow, halving this cost) - this is O(n) in the hash set size, and
the time to iterate over the "issued orders" and do two O(1) look-ups in the inventory hash sets: that's O(n) where n is the number of orders
Sounds pretty fast to me.
Upvotes: 1