Data structure / design for product and delivery information

I need to save some data on goods, stocks and shipping costs

For example, in my store there are several items, and different warehouses store them, although not all items are required. Then each warehouse may have different costs for the delivery of goods, depending on how close they are to their destination.

So, as an example

warehouse1 : item1, item3, item 5
warehouse2 : item1, item2
warehouse3 : item1, item3, item 4

so if the order consists of (item 1, item 2, item 3) 
it can be fulfilled by either warehouse1 + warehouse2, or warehouse3 + warehouse2. 
in this case it should choose whichever is cheaper

In this case, I want to minimize the number of warehouses that are used to complete the order, as well as minimize the cost. Orders can have several items of different types, but they will all be sent to the same destination.

I thought of storing a list of all products as something like

class Item{
   double price;
   List<Integer> warehouses; //id of all the warehouses that carry this item
}

. , , -, .

, . , . , , , , , -, ?

+4
2

, , - , ,

, , . , , NP- .

( , ).

+1

, , , .

, , - , , .

, , , , - .

Shipment, Map<Warehouse,List<Item>> .

, - Map<Cost,Shipment>.

Base-Case

№ 1. , , , , .

№ 2.

№ 3. , , # 2

# 4. №2 №3 , .

№ 5. , .

base_case .

, , , , , , .

, , , , (, ).

№ 3 , . , , / .

, , - , .

, , .

, !

+1

Source: https://habr.com/ru/post/1668901/


All Articles