Hello. Question on the algorithm.

There is a database of orders, it contains the address of the recipient and the number of desired cards. Example of record from the base: st. Lenin dom1, 100 cards. The person who makes the order wants to receive various (!) Cards. That is, from one person there was only one postcard. If he ordered 100 cards, he wants to get 100 different (!) Cards.

There are people who send cards, they are shown these same orders. One postman (we will call them that) shows one order from one person (so that all the postcards that come in are different).

The question now is how to issue these orders? So that customers get their postcards as soon as possible?

There are a lot of postmen, orders too. There are less mailmen than orders, it happens the other way around. An example of a database (the list is sorted in descending order by date. That is, below those who ordered earlier. Above those who ordered recently.)

st. Lenin dom1, 100 cards.

st. Petrova dom14, 10 postcards.

st. Lomonosov house 20, 300 cards.

st. Ivanov house 187, 50 postcards.

Options:

  1. Take turns. That is, who ordered earlier, the first order and issue. And all the postmen fulfill the first order first. The disadvantage of this approach is that the top order will start to be executed only when the previous ones are completed, that is, the top one will wait for the postcard for a long time.

  2. Issued by common queue. That is, for example, we have 4 orders and 4 postmen. The first order takes the first postman, the second order takes the second postman, and so on. Something like multitasking. Are there any cons?

For the sender 1 order can be processed 1 time. If he sent a card for this order, no more need to show this order to him! Otherwise, the recipient will receive another card from this sender. And he wants to receive postcards from different senders.

How best to organize the issue, so that customers receive their cards as soon as possible?

Thank.

  • one
    Full feeling that the problem is not enough conditions. From the point of view of sound logic, of course the second option, but somehow very simple. - SilverIce
  • And what is the resource of the postman? those. on one order can come one postman? Well, and so on. There is a queue of recipients, a queue of manufacturers and a delivery queue. How is the queue of manufacturers? - Chad
  • Resource? Well, until he gets tired of sending :) The postman works out and leaves. At this time others come. But there is always a certain number of working postmen. The number of working postmen can vary (as they like, they will start sending). The postman works out one order (1 card) goes on to another order, etc., until he gets bored. For each order he will send 1 postcard. Senders (postmen) are not exactly a queue. This is a group of people currently working. Control this count will not work. Those. will want to send, no so no. - beatmaker pm
  • Those. the postman can only send one postcard to the customer? - Chad
  • Yes. The customer wants cards from different senders. That is, if he ordered 500 cards, then he wants to receive them from 500 different postmen. - beatmaker

0