N
N
Nub_Ispuganniy2015-11-06 23:34:14
Programming
Nub_Ispuganniy, 2015-11-06 23:34:14

Claim Generator Algorithm for Modeling QS with Poisson Flow?

The appearances of clients in the hairdresser form a Poisson flow, the intensity of which is 10 people per hour.
part of the course work, it is necessary to draw up a model of a hairdressing salon in C ++ classes, and now I ran into a problem, I can’t understand exactly how this generator should work, tell me the algorithm in general terms, then I’ll try myself)))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2015-11-07
@Nub_Ispuganniy

class Event {  //  интерфейс
public:
  virtual double time() = 0;   // когда потребуется внимание со стороны менеджера событий
  virtual void process() = 0;  // команда обработать событие
  // virtual int type() = 0;      // можно пристроить, если по какой-то причине надо отличать кресло от генератора клиентов
};

class EventSink {  // интерфейс
  virtual void add(Event& x);
}

class Shop;

class Chair : protected Event {
private:
  double fTime;
  bool fIsOccupied;
public:
  Shop& shop;
  virtual double time() override { return fTime; }
  virtual void process() override;
  {
     что-то типа…
     если shop.nWaiting != 0 {
        --shop.nWaiting;
        occupy(time);
     } else {
         isOccupied = false;
     }
  }
  void occupy (double aTime) {
        time = aTime + время обслуживания клиента
        shop.manager.add(*this);
   }
   bool isOccupied() { return fIsOccupied; }
};

class CustomerGenerator : protected Event {
   // Устроен аналогично Chair, служит для генерации потока клиентов
public:
  virtual void process() override {
     если shop.nWaiting == 0 и кресло свободно {
        shop.chair.occupy(fTime);
     } else {
        ++shop.nWaiting;
     }
     fTime += экспоненциальное время ожидания;
     manager.add(*this);
  }
  void init() {
     fTime = 0;
     process();
  }
};

class Shop {
public:
   Chair chair;  // можно несколько кресел
   CustomerGenerator generator;
   int nWaiting;  // сколько человек в очереди
   EventSink& manager;
}

class Manager : public EventSink {
   Event* events[2];   // события отсортированы по времени
   int nEvents;

   void add(Event& x) override {
      // вставить двоичным поиском x в нашу очередь;  тут же можно сделать ограничение
      // «обработать 1000 клиентов» или «работать 8 часов».
   }

   И самое главное — «жизненный цикл».
   shop.generator.init();
   Пока очередь не пуста…
   • вытащить из неё событие
   • process его!
}

How does it work?
1. At the 5th minute, a visitor arrives. This means that the generator is added to the queue with a time of 5 minutes.
2. Select the generator from the queue. Since there is no queue at the hairdresser, he sits down in a chair (a chair with a time of 5 + 8 = 13 minutes is entered into the list), a generator is entered into the list with a time of 5 + 3 = 8 minutes.
3. From this pair, we select the generator (it has 8 minutes, against 13 minutes at the chair). He brings our friend into the queue (now there is only one in the queue), the generator is put into the queue with a time of 8 + 4 = 12 minutes.
4. The chair and the generator are back in line, and the minimum time is at the generator. Now two people are waiting in the barbershop, and we put the generator in the queue for 12 + 30 = 42 minutes.
5. Now the chair has minimum time, and it serves one more customer, queuing itself at (13 + 8 = 21 minutes.
6. Again, the chair has minimum time, it enters itself into the queue for 21 + 8 = 29 minutes.
7. It's 29 minutes, but there is no one to cut!There is one generator left in the manager's queue.. 8.
Selecting a generator from the queue, and so on... Do not forget that events are not added to the tail of the queue, but anywhere - after all, an event can, in turn, cascade other events
.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question