Velocity Reviews > Java > queuing simulation

# queuing simulation

justplain.kzn@gmail.com
Guest
Posts: n/a

 05-03-2007
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.

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
Guest
Posts: n/a

 05-04-2007
On May 4, 7:50 am, (E-Mail Removed) 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.

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post jasperng VHDL 0 11-27-2008 06:23 AM Silverstrand Front Page News 0 04-17-2006 05:49 PM Vicky Cisco 0 05-09-2004 07:07 AM J Anderia Cisco 1 04-06-2004 07:28 AM Martin Bilgrav Cisco 8 11-03-2003 09:08 PM