# Queue simulation of two parallel servers

4 views (last 30 days)
Panagiotis Artemiou on 24 May 2023
Commented: Raymond Norris on 24 May 2023
I've got a problem where I need to simulate o production line which consists of 3 stations having 1 machine each. Each machine serving time follows a specific distribution. The products pass one station after the other in series, and the code I wrote is the below.
hours_day = 8;
days_year = 220;
arrival_rate = 4; %per hour
arrival_rate_m = 4/60; %per minute
minutes_year = 60 * hours_day * days_year;
for y=1:10000
inter_arrival_times(y) = exprnd(1/arrival_rate_m);
arrival_times(y) = sum(inter_arrival_times(1:end)); % generate the arrival times of products for a year
if arrival_times(y)>minutes_year
break
end
end
m1_start = arrival_times(1); % first product arriving at station 1
for i=1:length(arrival_times)-1
m1_serve_time(i) = unifrnd(m1_min,m1_max); % machine in station 1 serve time
m1_finish(i) = m1_start(i) + m1_serve_time(i); % machine in station 1 finish processing
m1_start(i+1) = max(arrival_times(i+1),m1_finish(i)); % machine in station 1 start processing of next
end
m2_start(1) = m1_finish(1); % first product arriving at station 2 (the first to finish from station 1)
for j=1:length(arrival_times)-2
m2_serve_time(j) = unifrnd(m2_min,m2_max); % machine in station 2 serve time
m2_finish(j) = m2_start(j) + m2_serve_time(j); % machine in station 2 finish processing
m2_start(j+1) = max(m1_finish(j+1),m2_finish(j)); % machine in station 2 start processing of next
end
m3_start(1) = m2_finish(1); % first product arriving at station 3 (the first to finish from station 2)
for k=1:length(arrival_times)-3
m3_serve_time(k) = normrnd(m3_mean,m3_std); % machine in station 3 serve time
m3_finish(k) = m3_start(k) + m3_serve_time(k); % machine in station 3 finish processing
m3_start(k+1) = max(m2_finish(k+1),m3_finish(k)); % machine in station 3 start processing of next
end
This is like an MM1 simulation but with 3 "servers" in series.
Now I want to simulate what would happen if we add a second machine in station 1 that has the same servning characteristics as the other one (same distribution and parameters), and so they can process products in parallel.
Is it possible to do that in the way I developed the code until now, and if so how can this be done?
Any helpful idea is really welcome.
Thank you in advance!

Raymond Norris on 24 May 2023
If I'm reading this right, I think this code
for y=1:10000
inter_arrival_times(y) = exprnd(1/arrival_rate_m);
arrival_times(y) = sum(inter_arrival_times(1:end)); % generate the arrival times of products for a year
if arrival_times(y)>minutes_year
break
end
end
can be rewritten as follows (and should save a bit of time).
% Get all of the random numbers upfront
inter_arrival_times = exprnd(1/arrival_rate_m,1,10000);
% Calculate the cumulative sumation at each point
arrival_times = cumsum(inter_arrival_times);
% Trim arrival times that exceed the number of minutes in a year
arrival_times(arrival_times>minutes_year) = [];
Regarding how to add a second machine to station 1, can you sketch out what the code might look like? I'm gathering it's not as simple as adding a fourth for-loop (i.e., m1b_serve_time(i) = ...) Does the code then need to lie within for 1st for-loop?
Also, do you have the Parallel Computing Toolbox? If so, all 3 of your for-loops could be run in parallel.
Raymond Norris on 24 May 2023
The video lays out the algorithm pretty well. Just need to initialize Machine 1 and Machine 2 properly before entering the for-loop.

### Categories

Find more on Time Series Events in Help Center and File Exchange

R2020b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!