function varargout = functiongui(varargin)
% FUNCTIONGUI MATLAB code for functiongui.fig
% FUNCTIONGUI, by itself, creates a new FUNCTIONGUI or raises the existing
% singleton*.
%
% H = FUNCTIONGUI returns the handle to a new FUNCTIONGUI or the handle to
% the existing singleton*.
%
% FUNCTIONGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FUNCTIONGUI.M with the given input arguments.
%
% FUNCTIONGUI('Property','Value',...) creates a new FUNCTIONGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before functiongui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to functiongui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help functiongui
% Last Modified by GUIDE v2.5 12-Jun-2016 18:10:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @functiongui_OpeningFcn, ...
'gui_OutputFcn', @functiongui_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 functiongui is made visible.
function functiongui_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 functiongui (see VARARGIN)
% Choose default command line output for functiongui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
set(handles.customer_num,'String',1000);
set(handles.test_num,'String',10);
set(handles.arrive_parameter,'String',4);
set(handles.service_parameter,'String',5);
set(handles.belt,'String',0.3);
set(handles.alpha,'String',0.1);
% UIWAIT makes functiongui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = functiongui_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 customer_num_Callback(hObject, eventdata, handles)
% hObject handle to customer_num (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of customer_num as text
% str2double(get(hObject,'String')) returns contents of customer_num as a double
% --- Executes during object creation, after setting all properties.
function customer_num_CreateFcn(hObject, eventdata, handles)
% hObject handle to customer_num (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function test_num_Callback(hObject, eventdata, handles)
% hObject handle to test_num (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of test_num as text
% str2double(get(hObject,'String')) returns contents of test_num as a double
% --- Executes during object creation, after setting all properties.
function test_num_CreateFcn(hObject, eventdata, handles)
% hObject handle to test_num (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in begin.
function begin_Callback(hObject, eventdata, handles)
Cus_allnum = str2double(get(handles.customer_num,'String'));
Arrive_parameter =str2double(get(handles.arrive_parameter,'String'));
Service_parameter = str2double(get(handles.service_parameter,'String'));
Test_count = str2double(get(handles.test_num,'String'));
Belt = str2double(get(handles.belt,'String'));
Alpha = str2double(get(handles.alpha,'String'));
%%%必须是有效值
if(isnan(Cus_allnum)||isnan(Arrive_parameter)||isnan(Service_parameter)||isnan(Test_count)||isnan(Belt)||isnan(Alpha))
exit(1);
end
Simulate_count = Test_count;%重复运行次数
belt = 0.0;%%%%%%%%%%%%%%%%%%最终的绝对精度
Table_data = [];%%%%%%%%%%%%%存储每次运行的结果矩阵
n = Simulate_count;%%%%%%%%%% 最终运行次数n
while(Simulate_count>0)
Ser_counter_leisure = 0;%%%%服务台的状态,0:空闲,1:繁忙
Ser_counter_busy = 1;%%%%%%%服务台的状态,0:空闲,1:繁忙
Event_arrive = 1;%%%%%%%%%%%到达事件
Event_leave = 2;%%%%%%%%%%%%离开事件
Time_arrive = [];%%%%%%%%%%%每个顾客到达的时刻
Time_servered = [];%%%%%%%%%每个顾客被服务的时刻
Time_leave = [];%%%%%%%%%%%%每个顾客离开的时刻
Queue_arrive_time = [];%%%%%进入队列时刻
Num_events = 2;%%%%%%%%%%%%%事件数
Num_ser_counter = 2;%%%%%%%服务台数
Num_customers = Cus_allnum;%顾客总数
Num_serd_customers = 0;%%%%%已经被服务的顾客数
Num_arrived_customers = 0;%%已经到达的顾客数
Num_inqueue = 0;%%%%%%%%%%%%队列中顾客数
Duration_time = 0;%%%%%%%%%%事件持续时间30
MU_a = Arrive_parameter;%%%%%到达模式的参数
MU_s = Service_parameter;%%%%服务模式的参数
%1.初始化
Simulate_time = 0.0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%仿真推进时钟
State_ser_counter = zeros(1,Num_ser_counter);%%%%%%%%%%%%服务台状态
Next_event_time = zeros(1,Num_events+1);%%%%%%%%%%%%%%%%%时间事件表下一个事件到达时间
Arrive_interval_time = exprnd(MU_a);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%初始化到达间隔时间
Service_time = exprnd(MU_s);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%初始化被服务时间
Next_event_time(Event_arrive) = Simulate_time + exprnd(Arrive_interval_time);%%%%%%%%%%%下一到达事件时间
Next_event_time(Event_leave) = 1.0e+230;%%%%%%%%%%%%%%%%时间事件表下一离开事件时间初始化为无穷大
Ser_customerdepart_time = zeros(1,Num_ser_counter);%%%%%%记录每个服务台顾客离开的时刻
Ordinal_serveCounter_depart = 0;%%%%%%%%%%%%%%%%%%%%%%%%%顾客最先离开的服务台编号
Last_event_time = 0.0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%上一个事件的时刻
Cus_inqueue_time = 0.0;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%顾客在时间区间上排队人数与时间区间长度之积
%2.仿真
while(Num_serd_customers<Num_customers)
next_event_time = 1.0e+300;%%%%%%%%%%%%%%%%%%%%%%%下一个事件发生的时间
next_leave_event_time = 1.0e+300;%%%%%%%%%%%%%%%%%%下一个离开服务台的时间
Ordinal_serveCounter_depart = 0;
%%%找到最先有顾客离开的服务台
for i=1:Num_ser_counter
if(State_ser_counter(i)==Ser_counter_busy && Ser_customerdepart_time(i)<next_leave_event_time)
next_leave_event_time = Ser_customerdepart_time(i);
Ordinal_serveC