Algorithm Sedgewick Fourth Edition-1th Chapter Foundation -024-M/M/1 Queue

Source: Internet
Author: User

1 /******************************************************************************2 * Compilation:javac Mm1queue.java3 * Execution:java mm1queue Lambda mu4 * Dependencies:Queue.java Histogram.java5  *6 * Simulate an M/M/1 queue where arrivals and departures is Poisson7 * Processes with arrival rate lambda and service rate mu.8  *9 *% java mm1queue.Ten  * One *% java mm1queue. A  * - *% java mm1queue. -  * the  * - * Remarks -  *  ------- - *-We assume the interrarrival and service times are independent. +  *  -  * +  ******************************************************************************/ A  at  Public classMm1queue { -  -      Public Static voidMain (string[] args) { -         DoubleLambda = double.parsedouble (args[0]);//Arrival Rate -         Doublemu = double.parsedouble (args[1]);//Service Rate -  inqueue<double> q =NewQueue<double> ();//arrival Times of customers -         DoubleNextarrival = Stdrandom.exp (lambda);//Time of next arrival to         DoubleNextdeparture = double.positive_infinity;//Time of next departure +  -         //Histogram Object theHistogram hist =NewHistogram (60); *  $         //simulate an M/M/1 queuePanax Notoginseng          while(true) { -  the             //it ' s an arrival +             if(Nextarrival <=nextdeparture) { A                 if(Q.isempty ()) Nextdeparture = Nextarrival +stdrandom.exp (MU); the Q.enqueue (nextarrival); +Nextarrival + =stdrandom.exp (lambda); -             } $  $             //it ' s a departure -             Else { -                 Doublewait = nextdeparture-q.dequeue (); thestdout.printf ("Wait =%6.2f, Queue size =%d\n", Wait, q.size ()); -Hist.adddatapoint (Math.min (60, (int) (Math.Round (Wait) ));Wuyi Hist.draw (); the                 if(Q.isempty ()) Nextdeparture =double.positive_infinity; -                 ElseNextdeparture + =stdrandom.exp (MU); Wu                  -             } About         } $  -     } -  -}

Algorithm Sedgewick Fourth Edition-1th Chapter Foundation -024-M/M/1 Queue

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.