function varargout = ChaoShiXiTong(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ChaoShiXiTong_OpeningFcn, ...
'gui_OutputFcn', @ChaoShiXiTong_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ChaoShiXiTong is made visible.
function ChaoShiXiTong_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ChaoShiXiTong (see VARARGIN)
% Choose default command line output for ChaoShiXiTong
clc;
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ChaoShiXiTong wait for user response (see UIRESUME)
% uiwait(handles.gaotiepaiduixitong);
% --- Outputs from this function are returned to the command line.
function varargout = ChaoShiXiTong_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%-----------菜单部分的制作---------------------%
%------------帮助菜单-------------------------%
function help_Callback(hObject, eventdata, handles)
% 菜单多服务台系统仿真说明函数
function notice_Callback(hObject, eventdata, handles)
h = figure('MenuBar','none','Name','多服务台排队论模型说明','NumberTitle',...
'off','units','pixels','position',[500,400,400,200],'Windowstyle','modal');
uicontrol('style','text','units','pixels','position',[50 60 300 80],...
'string','本仿真系统是标准的M/M/N排队模型,各服务台平均服务时间相同;服务员中间没有休息、排队容量不受限制;采用下次事件时间推进机制和先到先服务FIFO排队规则;选择选排队最短的柜台',...
'BackgroundColor',get(h,'Color'),...
'fontsize',16,'foregroundcolor','b','fontname','宋体');
uicontrol('string','关闭','units','pixels','position',[160 30 70 40],...
'fontsize',16,'fontweight','bold','foregroundcolor','b','callback',...
'delete(gcf);');
% 菜单运行指南
function guide_Callback(hObject, eventdata, handles)
h = figure('MenuBar','none','Name','运行指南','NumberTitle',...
'off','units','pixels','position',[500,400,400,200],'Windowstyle','modal');
uicontrol('style','text','units','pixels','position',[50 60 300 80],...
'string','输入参数,点击运行,可输出模型结果',...
'BackgroundColor',get(h,'Color'),...
'fontsize',16,'foregroundcolor','r','fontname','黑体');
uicontrol('string','关闭','units','pixels','position',[160 30 70 40],...
'fontsize',16,'fontweight','bold','foregroundcolor','b','callback',...
'delete(gcf);');
% 退出菜单
function exit_Callback(hObject, eventdata, handles)
selection = questdlg(['关闭 ' get(handles.gaotiepaiduixitong,'Name') '?'],...
['关闭 ' get(handles.gaotiepaiduixitong,'Name') '...'],...
' 是 ',' 否 ',' 是 ');
if strcmp(selection,' 否 ')
return;
end
% delete(handles.gaotiepaiduixitong)
close(gcf);
%——————————————————————————————以下正文
%顾客平均等待时间编辑框
function wq_Callback(hObject, eventdata, handles)
function wq_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%服务员繁忙程度编辑框
function ps_Callback(hObject, eventdata, handles)
function ps_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%顾客平均排队长度按钮
function ls_Callback(hObject, eventdata, handles)
function ls_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%设备配置弹出框
function fwts_Callback(hObject, eventdata, handles)
global tai
h = get(hObject,'value');
tai = h;
function fwts_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%顾客平均到达强度编辑框
function ddl_Callback(hObject, eventdata, handles)
function ddl_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%服务强度编辑框
function fwl_Callback(hObject, eventdata, handles)
function fwl_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% 运行按钮
function calc_Callback(hObject, eventdata, handles)
global Lambda %顾客到达强度
global Lamda %顾客购物强度
global Minu %柜台服务强度
global tai %柜台数
handles=guihandles;
guidata(hObject,handles);%更新数据
%读取到达强度,转换为数字
lambda = str2double(get(handles.ddl,'string'));
%读取服务强度,转换为数字
minu = str2double(get(handles.fwl,'string'));
%判断仿真类型,服务台个数为1时,即是单服务台;大于1时,便是多服务台
ru = lambda/(minu*tai); %服务机构的平均利用率
if (ru > 0)&&(ru < 1) &&(lambda>0) && (minu>0) && (tai>0)
P0=0; %计算初始转移概率
for i=0:tai-1
P0=P0+(ru*tai)^i/factorial(i);
end
P0=P0+((ru*tai)^tai)/(tai*(1-ru)*factorial(tai));
P0=1/P0; %初始转移概率
Lq = ((tai*ru)^tai)*ru*P0/(factorial(tai)*(1-ru)^2); %平均排队长
Ls = Lq + lambda/minu; %平均队长
Wq = Lq/lambda; %平均等待时间
Ps = 1-P0; %服务利用率
p=lambda/((minu)*(tai)); %服务员繁忙程度
else
errordlg('请仔细检查,重新输入','错误');
return;
end
%显示顾客平均等待时间,顾客排队长度,服务员繁忙程度
set(handles.wq,'string',num2str(Wq));
set(handles.ls,'string',num2str(Ls));
set(handles.ps,'string',num2str(p));
clear P0,clear Lq %删除变量,释放内存
% 重置按钮
function reset_Callback(hObject, eventdata, handles)
set(handles.ddl,'String',0);
set(handles.fwl,'String',0);
set(handles.wq,'String','0');
set(handles.ls,'String','0');
set(handles.p,'String','0');
guidata(hObject, handles);
% --- Executes on button press in fangzhen.
function fangzhen_Callback(hObject, eventdata, handles)
global Lambda %顾客到达强度
global Lamda %顾客购物过强度
global Minu %服务员服务强度
global tai %柜台数
load halton
%% 生成随机到达时间间隔、购物时间及每个柜台结账服务时间
Arrin = -1/Lambda.*log(halton(1:1000,1)); %生成到达时间间隔
Carral = cumsum(Arrin); %到达时刻
Ncus = max(find(Carral<180)); %% 3个小时内到达的总顾客数
Shopping = -1/Lamda.*log(halton(1:1000,2)); %生成购物时间间隔
Service = -1/Minu.*log(halton(1:1000,3)); %生成服务时间间隔
ArriGui = Carral+ Shopping; %所有顾客到达服务台的到达时刻及顺序,记为ArrGui
%% 初始化每个柜台的状态1
for g = 1:N
Gui(g).Qu = [0,0]; % 按事件时间记录柜台g的排队,0时刻排队为0
Gui(g).Bu = [0,0];% 0表示空闲,1表示繁忙,0时刻空闲
Gui(g).Arrivaltime = []; %选择柜台g的顾客到达柜台的时间
Gui(g).startser=[]; %选择柜台g的顾客开始接受服务的时间
Gui(g).wait=[]; %选择柜台g的顾客排队等待的时间
Gui(g).servetime=[]; %选择柜台g的顾客接受服务的时间
Gui(g).Leavetime = []; %选择柜台g的顾客离开柜台的时间
Gui(g).cusnu = []; % 选择柜台g的顾客代码
Gui(g).staytime = []; %选择柜台g的顾客在服务台停留的时间
end
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
- 226.
- 227.
- 228.
- 229.
- 230.
- 231.