Exemple #1
0
 /**
  * Runs the simulation.
  *
  * @param integer $timeLimit The amount of simulation time to be simulated.
  */
 public function run($timeLimit)
 {
     $serverBusy = false;
     $numberInQueue = 0;
     $serviceTime = new ExponentialRV(100.0);
     $interArrivalTime = new ExponentialRV(100.0);
     $this->eventList->enqueue(new Simulation_Event(self::ARRIVAL, 0));
     while (!$this->eventList->isEmpty()) {
         $event = $this->eventList->dequeueMin();
         $t = $event->getTime();
         if ($t > $timeLimit) {
             $this->eventList->purge();
             break;
         }
         //[
         printf("%s\n", str($event));
         //]
         switch ($event->getType()) {
             case self::ARRIVAL:
                 if (!$serverBusy) {
                     $serverBusy = true;
                     $this->eventList->enqueue(new Simulation_Event(self::DEPARTURE, $t + $serviceTime->next()));
                 } else {
                     ++$numberInQueue;
                 }
                 $this->eventList->enqueue(new Simulation_Event(self::ARRIVAL, $t + $interArrivalTime->next()));
                 break;
             case self::DEPARTURE:
                 if ($numberInQueue == 0) {
                     $serverBusy = false;
                 } else {
                     --$numberInQueue;
                     $this->eventList->enqueue(new Simulation_Event(self::DEPARTURE, $t + $serviceTime->next()));
                 }
                 break;
         }
     }
 }