Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2007

Tip: Looking for answers? Try searching our database.

queuing simulation

Thread view: 
justplain.kzn@gmail.com - 03 May 2007 22:50 GMT
Hi,

I am new to java and I am trying to implement a simple queuing system
using the poission spread for arrivals. To keep things simple I am
initially trying to populate the queue and print.

Below is a snippet of my code - my values seem out of wack and I have
since gotten my knickers in a knot. Any assistance/pointers with a
simple and straightforward implementation will greatly appreciated.

Thanks in advance

args[0]=0.2
args[1]=0.1

public class MM1Queue {

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

       Queue<Double> q = new Queue<Double>();            // arrival
times of customers
       double nextArrival   = Math.exp(lambda);     // time of next
arrival
       double nextDeparture = Double.POSITIVE_INFINITY;  // time of
next departure
//        double nextDeparture = 0.2;  // time of next departure
System.out.println ("nd " + nextDeparture);
System.out.println ("na " + nextArrival);
//System.exit(0);

// simulate an M/M/1 queue
               int counter=0;
       while (true) {
                       counter++;

           // it's an arrival
           if (nextArrival <= nextDeparture) {
               if (q.isEmpty()) nextDeparture = nextArrival +
Math.exp(mu);
               q.enqueue(nextArrival);
               System.out.printf("Queue = %6.2f\n", nextArrival);
               System.out.println ("Size = " + q.size());
               nextArrival += Math.exp(lambda);
           }

           // it's a departure
           else {
               double wait = nextDeparture - q.dequeue();
               System.out.printf("Wait = %6.2f\n", wait);
               if (q.isEmpty()) nextDeparture =
Double.POSITIVE_INFINITY;
               else             nextDeparture += Math.exp(mu);

           }
           if (counter>100) break;

       } // while loop
   }
Andrew Thompson - 04 May 2007 02:24 GMT
On May 4, 7:50 am, justplain....@gmail.com wrote:
> Hi,

Lo.  Please refrain from multi-posting, in future.
<http://www.physci.org/codes/javafaq.html#xpost>

(X-post to c.l.j.p./h., w/ f-u to c.l.j.h. only)

Andrew T.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.