J
justplain.kzn
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
}
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
}