Esempio n. 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;
         }
     }
 }
Esempio n. 2
0
    {
        parent::__destruct();
    }
    /**
     * Returns the next random number.
     *
     * @return float The next random number.
     */
    public function next()
    {
        return -$this->mu * log(RandomNumberGenerator::next());
    }
    //}>a
    /**
     * Main program.
     *
     * @param array $args Command-line arguments.
     * @return integer Zero on success; non-zero on failure.
     */
    public static function main($args)
    {
        printf("ExponentialRV main program.\n");
        $status = 0;
        $rv = new ExponentialRV(100.0);
        AbstractRandomVariable::test($rv);
        return $status;
    }
}
if (realpath($argv[0]) == realpath(__FILE__)) {
    exit(ExponentialRV::main(array_slice($argv, 1)));
}