当前位置:首页 > 代码 > 正文

排队论仿真matlab代码(排队问题matlab)

admin 发布:2022-12-19 18:43 157


今天给各位分享排队论仿真matlab代码的知识,其中也会对排队问题matlab进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

本科基于matlab的仿真排队系统毕业设计的要求有哪些

排队论即通过对服务对象到来及服务时间的统计研究,得出某些数量指标的统计规律,并更让据这些规律来改进服务系统。

二.排队论模型

1.基本构成

输入过程:描述顾客按照怎样的规律到达排队系统

排队规则:顾客按照怎样的规定次序接受服务

服务机构:服务台的数量;服务时间服从的分布

2.数量指标

队长,等待队长,等待时间,逗留时间,忙期(连续保持服务的时长),闲期

运用MATLAB编程排队论中M/M/C模型多服务台的模型仿真程序(参考下列仿真程序改成多服务台的)

非常完整的文档 就是带进公式计算了 你根据里面的几个例子看看你是哪一个的

急!请教matlab 排队论

M/M/m排队系统性能仿真代码matlab

function r=randexp(lambda) r = -lambda*log(rand);

说明同上

%mmm simulation in matlab

clc;clear;

ST_Idle=0;

ST_Busy=1;

EV_NULL=0;

EV_Arrive=1;

EV_Depart=2;

EV_LEN=3;

Q_LIMIT=1000;

% next_event_type=[];

% next_depart=[]

% num_custs_delayed=[];

% num_delays_required=[];

% num_events=[];

% num_in_q=[];

% server_status=[];

% area_num_in_q=[];

% area_server_status=[];

% mean_interarrival=[];

% mean_service=[];

% sim_time=[];

% time_last_event=[];

% total_of_delays=[];

%

time_arrival=[]; %到达时刻

time_next_event=zeros(1,EV_LEN);

%仿真参数

num_events=EV_LEN-1;

num_server=3; %M/M/m m=2

mean_interarrival=1;

mean_service=.5;

num_delays_required=2000; %

outfile=fopen('MM m.txt','w');

fprintf(outfile, 'Multiple-server queueing system\n\n');

fprintf(outfile, 'Mean interarrival time%11.3f minutes\n\n',mean_interarrival);

fprintf(outfile, 'Mean service time%16.3f minutes\n\n', mean_service);

fprintf(outfile, 'Number of servers%20d\n\n', num_server);

fprintf(outfile, 'Number of customers%14d\n\n', num_delays_required);

%part1 initialize

sim_time=0.0;

%/* Initialize the state variables. */

server_status =zeros(1,num_server); %idle

num_in_q = 0;

time_last_event = 0.0;

%/* Initialize the statistical counters. */

num_custs_delayed = 0;

total_of_delays = 0.0;

total_of_time = 0.0;

area_num_in_q = 0.0;

area_server_status = 0.0;

%/* Initialize event list. Since no customers are present, the departure

%(service completion) event is eliminated from consideration. */

time_next_event(EV_Arrive) = sim_time + randexp(mean_interarrival);

time_next_event(EV_Depart) = 1.0e+230;

time_depart=zeros(1,num_server);

next_depart=0;

%part2

while (num_custs_delayed num_delays_required)

%Run the simulation while more delays are still needed.

%/* Determine the next event. */

min_time_next_event = 1.0e+290;

next_event_type = 0;

% Determine m depart event

min_time_depart=1e290;

next_depart=-1;

for i=1:num_server

if(server_status(i)==1 time_depart(i)min_time_depart)

min_time_depart=time_depart(i);

next_depart=i;

end

end

time_next_event(2)=min_time_depart;

%

%/* Determine the event type of the next event to occur. */

for i = 1: num_events

if (time_next_event(i) min_time_next_event)

min_time_next_event = time_next_event(i);

next_event_type = i;

end

end

%/* Check to see whether the event list is empty. */

if (next_event_type == 0)

%/* The event list is empty, so stop the simulation. */

fprintf(outfile, '\nEvent list empty at time %f', sim_time);

exit(1);

end

%/* The event list is not empty, so advance the simulation clock. */

sim_time = min_time_next_event;

%/* Update time-average statistical accumulators. */

double time_since_last_event;

%/* Compute time since last event, and update last-event-time marker. */

time_since_last_event = sim_time - time_last_event;

time_last_event = sim_time;

%/* Update area under number-in-queue function. */

area_num_in_q=area_num_in_q + num_in_q * time_since_last_event;

%/* Update area under server-busy indicator function. */

for i=1:num_server

area_server_status =area_server_status + server_status(i) * time_since_last_event;

end

%/* Invoke the appropriate event function. */

%arrival

if(next_event_type==EV_Arrive)

double delay;

%/* Schedule next arrival. */

time_next_event(1) = sim_time + randexp(mean_interarrival);

%/* Check to see whether server is busy. */

s_idle=-1;

for i=1:num_server

if (server_status(i) == ST_Idle)

s_idle=i;

break;

end

end

%/* all Server is busy, so increment number of customers in queue. */

if(s_idle== -1 )

num_in_q=1+num_in_q;

%/* Check to see whether an overflow condition exists. */

if (num_in_q Q_LIMIT)

%/* The queue has overflowed, so stop the simulation. */

fprintf(outfile, '\nOverflow of the array time_arrival at');

fprintf(outfile, ' time %f', sim_time);

exit(2);

end

%/* There is still room in the queue, so store the time of arrival of the arriving customer at the (new) end of time_arrival. */

time_arrival(length(time_arrival)+1)=sim_time;

else

%/* Server is idle, so arriving customer has a delay of zero. (The following two statements are for program clarity

%and do not affect the results of the simulation.) */

delay = 0.0;

total_of_delays =total_of_delays + delay;

%/* Increment the number of customers delayed, and make server busy. */

num_custs_delayed = 1 + num_custs_delayed;

server_status(s_idle) = ST_Busy;

%/* Schedule a departure (service completion). */

time_depart(s_idle) = sim_time + randexp(mean_service);

end % if (server_status == ST_Busy)

%depart

else

double delay;

%/* Check to see whether the queue is empty. */

if (num_in_q == 0)

% /* The queue is empty so make the server idle and eliminate the departure (service completion) event from consideration. */

server_status(next_depart) = ST_Idle;

time_depart(next_depart) = 1.0e+230;

%check_depart()

min_time_dapart=1e290;

next_depart=-1;

for i=1:num_server

if(server_status(i)==1 time_depart(i)min_time_depart)

min_time_depart=time_depart(i);

next_depart=i;

end

end

time_next_event(2)=min_time_depart;

else

%/* The queue is nonempty, so decrement the number of customers in queue. */

num_in_q=num_in_q-1;

%/* Compute the delay of the customer who is beginning service and update the total delay accumulator. */

delay = sim_time - time_arrival(1);

total_of_delays =total_of_delays + delay;

%/* Increment the number of customers delayed, and schedule departure. */

num_custs_delayed = 1 + num_custs_delayed;

serv_time=randexp(mean_service);

time_depart(next_depart) = sim_time + serv_time;

total_of_time = total_of_time + delay + serv_time;

%check_depart()

min_time_dapart=1e290;

next_depart=-1;

for i=1:num_server

if(server_status(i)==1 time_depart(i)min_time_depart)

min_time_depart=time_depart(i);

next_depart=i;

end

end

time_next_event(2)=min_time_depart;

%/* Move each customer in queue (if any) up one place. */

tempForPop=time_arrival(2:length(time_arrival));

time_arrival=tempForPop;

end %if (num_in_q == 0)

end %if(next_event_type==EV_Arrive)

end %while

%%%%%%%%%% part 3

%/* Invoke the report generator and end the simulation. */

fprintf(outfile, '\n\nAverage delay in queue%11.3f minutes\n\n',total_of_delays / num_custs_delayed);

fprintf(outfile, '\n\nAverage delay in system%11.3f minutes\n\n',total_of_time / num_custs_delayed);

fprintf(outfile, 'Average number in queue%10.3f\n\n',area_num_in_q / sim_time);

fprintf(outfile, 'Server utilization%15.3f\n\n',area_server_status / sim_time);

fprintf(outfile, 'Time simulation ended%12.3f minutes', sim_time);

fclose(outfile);

MATLAB的排队模型。。

1.问题分析:本实验采用蒙特卡洛(Monte Carlo)模拟方法,蒙特卡洛是一种应用随机数来进行计算机模拟的方法.此方法对研究的系统进行随机观察抽样,通过对样本值的观察统计,求得所研究系统的某些参数.在MATLAB中发生指数分布的随机数命令为exprnd(),产生均匀分布随机数命令为unifrnd()。

符号说明:

:第i个顾客到来的时刻

:第i个顾个接受服务后离开的时间

:第i个顾客和第i-1个顾客到来的间隔时间

:第i个顾客需要服务的时间

:第i个顾客的等待时间

考察第i个顾客和第i-1个顾客排队并将接受服务的情形,有以下两种情况:

(1)图这里只能省略)

(2)作出程序流程图

顾客到来的时间间隔和所需服务时间可分别由MATLAB随机数发生器exprnd()和unifrnd()产生,根据第一步的分析,通过迭代即可模拟每个工作日的该服务员接待顾客和顾客排队的情形,时间以分钟为单位,程序流程图为:

模拟100个工作日(for i=1:100)

构造单个工作日的排队系列while (sTj=480)

通过指数分布随机数发生器

构造顾客间隔时间序列(TjM)

通过均匀分布随机数发生器构造顾客所需服务时间序列(TfM)

模拟该工作日内服务员接待顾客(for i=1:n-1)

计算第i个顾客离开时的时刻t

计算第i+1个顾客的等待时间s

如果s0则令s=0

如果时刻t480,记录i值,跳出循环

记录第i+1个顾客等待时间s值,和第i个顾客离开时刻t

记算该工作日顾客平均等待时间sMean值

记录每个工作日顾客平均等待时间序列sMeanM,和服务员接待顾客数目序列sIM

记算平均每日完成服务的个数和每日顾客的平均等待时间

(3)编写MATLAB程序

clear,clc;

sMeanM=[];sIM=[];

for i=1:100

TjM=[];TfM=[];sTj=0;

while (sTj=480)

Tjp=exprnd(10);

Tfp=unifrnd(4,15);

TjM=[TjM;Tjp];

TfM=[TfM;Tfp];

sTj=sTj+Tjp;

end

n=length(TjM);

s=0;sM=[];T=[];

for i=1:n-1

t=sum(TjM(1:i,1))+s+TfM(i);

s=(t-sum(TjM(1:(i+1),1)))*((t-sum(TjM(1:(i+1),1)))0);

if t480

sI=i;break

else

T=[T;t];

sM=[sM;s];

end

end

sMean=mean([0;sM]);

sMeanM=[sMeanM;sMean];

sIM=[sIM;sI];

end

MrecH=mean(sIM)

MwaiH=mean(sMeanM)

(4)结果分析

将以上程序运行十次,100个工作日平均每日完成服务的个数(MrecH)及每日顾客的平均等待时间(MwaiH)(分钟)如下表

次数

1

2

3

4

5

6

7

8

9

10

MrecH

43.54

44.36

43.79

44.28

44.38

44.09

43.62

44.68

44.45

43.95

MwaiH

25.286

24.514

25.349

26.857

23.487

24.589

23.428

23.620

25.618

27.318

100个工作日的模拟情况告诉我们,该服务员平均每天需要接待顾客44人左右,顾客平均需要等待25分钟左右。

应该是这样!

排队论仿真matlab代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于排队问题matlab、排队论仿真matlab代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/18212.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载