Home OR-Objects Tutorials Prev Next

Tutorial 3 - Elevator Simulation


In this tutorial you will learn to use the exponential and empirical distributions in OR-Objects to simulate passengers entering an elevator system. For simplicity, some of the applet details will be skipped. If you would like all the details then view the complete source.


Initialize Arrival Distributions

The method 'initArrivals' initializes the distributions that are used to generate passenger arrivals. The simulation uses an ExponentialDistribution to generate arriving passengers with a mean time between arrivals of five seconds. The passenger origin and destination floors are generated from two EmpiricalDistributions, one to determine the origin floor and the other to determine the destination floor. The distribution '_origDist', used to generate origin floors, will start twice as many passengers from floors zero and five than from the other floors. The distribution '_destDist', used to generate destination floors, will send twice as many passengers to floors zero and nine than to the other floors. Note that 'CPS' is a constant equal to the number of simulation clock ticks per second of simulated time..

    DistributionI _arrivalDist;
    DiscreteDistributionI _origDist;
    DiscreteDistributionI _destDist;
    .....
    public void
    initArrivals()
    {
        int[] floors =      {0,1,2,3,4,5,6,7,8,9,10,11};
        double[] origProb = {2,1,1,1,1,2,1,1,1,1, 1, 1};
        double[] destProb = {2,1,1,1,1,1,1,1,1,2, 1, 1};

        _arrivalDist = new ExponentialDistribution(5);
        _nextArrival = (int)(CPS * _arrivalDist.getRandomScaler());

        _origDist = new EmpiricalDistribution(floors, new DenseVector(origProb));
        _destDist = new EmpiricalDistribution(floors, new DenseVector(destProb));
    }


Generate Arriving Passengers

This method, 'checkArrivals', is called from the main simulation loop and generates the arriving passengers. If it isn't time for the next arrival the method simply returns. Otherwise; it sets up the time for the next arrival and adds the new passenger. The origin floor is obtained from '_origDist' and the destination is obtained from '_destDist'. The origin floor is used directly from the distribution, but the destination floor is checked to insure it is different from the origin floor. Destinations will be drawn until one is obtained that is different from the origin.
    public void
    checkArrivals(int time)
    {
        if(time < _nextArrival) return;
        _nextArrival = (int)(time + CPS * _arrivalDist.getRandomScaler());

        int orig = _origDist.getRandomInteger();
        int dest = _destDist.getRandomInteger();
        while(dest == orig) dest = _destDist.getRandomInteger();

        arrival(new Passenger(orig, dest));
    }
For the sake of expediency the assignment algorithm used in this tutorial is very simplistic. To make it otherwise would require a lot of work that would not significantly enhance the effectiveness of the tutorial.

In Association with Amazon.com

In Association with Amazon.com
Copyright (C) 1997-2000 by DRA Systems all rights reserved.