Queue length simulation problem

9 ビュー (過去 30 日間)
Henri Södergård
Henri Södergård 2019 年 4 月 20 日
コメント済み: husam mahdi 2021 年 10 月 19 日
I have created a code to simulate the length of a queue at a drive-in, which should be somewhat correctly made (at least as my assignment explains the problem). The problem I have, is that I need to minimize the waiting time in the queue, while also minimizing the amount of service stations used during the simulation. In other words, the amount of service stations needs to change as a function of the queue length. I really don't know how I should approach this optimization problem. I've attached the code I've written until now below.
function [] = queue_simulation2()
% This function simulates the length of a queue
% that is Poisson-distributed
%% Initializations
lambda=40/(60*60); % Arriving cars, cars/second
mu=4*60; % Average service time, seconds/customer
s=2; % Amount of service stations
time=1; % Time to observe, seconds
t_span=8*60*60; % One working day, seconds
%% Function loops and plotting
% Create a figure window
figure('Name','Queue simulation')
hold on
% For-loop to consider 10 simulations
for k = 1:1:10
% Reset the parameters
t=1;
arrived=zeros(1+t_span,1);
left=zeros(1+t_span,1);
queue=zeros(1+t_span,1);
% While-loop for one simulation
while t <= t_span
% People arrive in the queue
arrived(t+1)=poisson_time(lambda,time);
% Calculating mu_j depending on the queue length
Ej=queue(t);
j=Ej+arrived(t+1);
if j <= s
mu_j=mu/j; % If Ej=0, then mu_j=inf
else
mu_j=mu/s;
end
% Calculating how many people receive their orders in
% the given time.
% Note that the amount of people getting their service depends
% on the queue length at the end of the loop before + the
% people that arrive during the time period.
if j == 0
% Since, if there are no people in the queue, then there
% are no people to serve
left(t+1)=0;
else
left(t+1)=poisson_time(1/mu_j,time);
end
% Queue length at time t+1
queue(t+1)=Ej+arrived(t+1)-left(t+1);
% Correct the queue length so that it cannot be negative
if queue(t+1) <= 0
queue(t+1)=0;
else
queue(t+1)=queue(t+1);
end
% Update the time
t=t+time;
end
% Plot the simulation
stairs(0:1:t_span,queue)
end
% Add title and labels to the plot
title('Queue length simulation')
xlabel('Time, [s]'); ylabel('Queue length')
grid on; grid minor; axis tight
end
function n = poisson_time(lambda,time)
% This function counts the Poisson events in a fixed time
%% Initializations
t=0.0; % Time in the beginning
n=0; % Events in the beginning
%% Function
while t < time
dt=-log(1-rand(1,1))/lambda;
t=t+dt;
n=n+1;
end
n=n-1;
return;
end
  1 件のコメント
husam mahdi
husam mahdi 2021 年 10 月 19 日
Hello, did you find a solution for this problem? i have the same issue.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeProblem-Based Optimization Setup についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by