Question
Two queues with two servers Your job is to simulate two queues with two servers. A client standing in line may change queues, by leaving
Two queues with two servers
Your job is to simulate two queues with two servers. A client standing in line may change queues, by leaving its place in line and going to the end of the other line. Does it get served faster?
More detailed description:
The simulation loop is
for each tick {
remove customer(s) who have had service completed;
update any measurements of those in queue;
compute number of arrivals and insert to queue;
assign customer(s) to idle server(s);
}
At each iteration of the simulation loop, you will need to update relevant numbers, such as incrementing customer wait time.
Customers arrive according to a Poisson distribution. At each tick of time, the Poisson generator will compute the number of arrivals. The mean of a Poisson distribution is the average number of customers arriving per tick. So, a mean of 0.2 indicates 0.2 customers per tick, or 1 customer every 5 ticks; a mean of 3.0 indicates an average of 3 customers per tick.
private static int getPoissonRandom(double mean) {
Random r = new Random();
double L = Math.exp(-mean);
int k = 0;
double p = 1.0;
do {
p = p * r.nextDouble();
k++;
} while (p > L);
return k - 1;
}
Designing the experiment:
There will be two queues, each with its own server.
Each queue uses a Poisson generator with the same mean.
A customer in the first queue can, at random, decide to leave the queue and join the end of the second queue. NOTE: this will violate the definition of queue (enter at tail and exit at head), so you will have to include that operation.
Customers cannot leave the second queue, except through being serviced.
All entering customers do so through a normal queue insert.
The customer obtaining service can be left at the head of the queue, or you can remove it after it is assigned to the server (before service starts).
When a customer is being serviced, its wait time is not incremented.
More than one customer can switch queue at one tick.
To answer the question (should a customer switch queue to get better service?) youll need to keep track of how long a customer is actually in queue and, for those who switched, how long they would have waited if they hadnt switched.
To get the first measurement, update the wait time for each customer while in queue.
To get the second measurement, notice that a customer stops waiting when the customer immediately before it has service completed.
A customer in queue 1 will have the opportunity to switch queues after any new customers have been inserted to queue 2. If three customers arrive to queue 1, each of the three new arrivals, will, in turn, be given the opportunity to switch to queue 2.
Probabilities:
Each customer needs some number of service ticks: uniformly distributed between 1 and 5 ticks inclusive, i.e., [1, 6).
Mean arrival rate for the Poisson distribution is 0.25 customers/tick for each queue.
A customer will change queues (from first queue to second queue only not from second to first) if:
1. it is at the end of the queue, and
2. the decision to switch is 50/50.
Note, a customer may decide to switch queues even though the second queue is longer than the first.
For debugging and demonstration purposes:
Assign each customer a unique id.
The output for a customer (in queue or being serviced) is:
customer id,
current wait time
original queue
current queue
The output for a tick of the simulation occurs at the end of the body of the loop:
tick #
queue 1: server busy/idle
queue 1: number in queue
queue 1: list of customers in queue (use customer output given above)
queue 2: server busy/idle
queue 2: number in queue
queue 2: list of customers in queue (use customer output given above)
The output for tracing server activity is:
When starting service: tick # server x start service on customer y
x: is 1 or 2
y is customer id
When ending service: tick # server x end service on customer y
x is 1 or 2
y is customer id.
You may add output information as desired (and useful).
COMMENT: You can run this as one long simulation including all switching customers. Or you can run it as 5 simulations, each simulating ending as soon as the switched customer starts service.
Constraints:
- Run experiments until at least 5 customers have switch queues and completed service. You will need to output the time it would have taken if it had not switched queues and the time it did take if it did switch queues for each switching customer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started