Page 214 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 214

Unit 10: Heaps





              {                                                                                 Notes
                  boolean serverBusy = false;
                  int numberInQueue = 0;
                  RandomVariable serviceTime = new ExponentialRV (100.);
                  RandomVariable interArrivalTime =
                     new ExponentialRV (100.);
                  eventList. enqueue (new Event.arrival, 0));
                  while (!eventList. isEmpty ())
                  {
                     Event event = (Event) eventList.dequeueMin ();
                     double t = event.getTime ();
                     if (t > timeLimit)
                         {eventList.purge (); break; }
                     switch (event.getType ())
                     {
                     case Event.arrival:
                         if (!severBusy)
                         {
                            serverBusy = true;
                            eventList.enqueue (new Event(Event.departure,
                                t + serviceTime.nextdouble ()));
                         }
                         else
                            ++numberInQueue;
                         eventList.enqueue (new Event (Event.arrival,
                            t + interArrivalTime.nextDouble ()));
                         break;
                     case Event.departure:
                         if (numberInQueue == 0)
                            serverBusy = false;
                         else
                         {
                            --numberInQueue;
                            eventList.enqueue (new Event(Event.departure,
                                t + serviceTime.nextDouble ()));
                         }
                         break;
                     }
                  }
                }
              // ...
          }

                      Program 10.6: Application of Priority Queues – discrete Event Simulation



                                           LOVELY PROFESSIONAL UNIVERSITY                                   209
   209   210   211   212   213   214   215   216   217   218   219