Tuesday, February 10, 2015

MD1 Queue.java in program



MD1Queue.java
public class MD1Queue
 {

    public static void main(String[] args)
{
        double lambda = Double.parseDouble(args[0]);  
        double mu     = Double.parseDouble(args[1]);  

        Histogram hist = new Histogram(60 + 1);
        Queue queue = new Queue();
        StdDraw.setCanvasSize(700, 500);

        double nextArrival = StdRandom.exp(lambda);   
        double nextService = nextArrival + 1/mu;      
        while (true)
{

           
            while (nextArrival < nextService)
           {
                queue.enqueue(nextArrival);
                nextArrival += StdRandom.exp(lambda);
            }

            double arrival = queue.dequeue();
            double wait = nextService - arrival;

            StdDraw.clear();
            hist.addDataPoint(Math.min(60,  (int) (Math.round(wait))));
            hist.draw();
            StdDraw.show(20);

            if (queue.isEmpty())
             nextService = nextArrival + 1/mu;
            else                
            nextService = nextService + 1/mu;
        }
    }
}

No comments:

Post a Comment