MM1 simulation in Matlab

Topics: Customer service, Customer, Average Pages: 6 (884 words) Published: February 12, 2014
mm1 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=1000000;

% next_event _type=[];
% num_custs _delayed=[];
% num_delays _count=[];
% num_events=[];
% num_in _queue=[];
% server_status=[];
% area_num _in _queue=[];
% area_server _status=[];
% mean_interarrival=[];
% mean_service=[];
% clock=[];
% time_last _event=[];
% total_of _delays=[];

time_arrival=[];

time_next _event=zeros(1,EV_LEN);

num_events=EV_LEN-1;
mean_interarrival=0.25;
mean_service=0.2;
num_delays _counts=10000;

outfile=fopen('mm1.txt','w');
fprintf(outfile, 'Single-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 customers %14 d \n \n', num_delays _counts);

%% part1

clock=0.0;
% Initialize the state variables.
server_status = 0; % idle
num_in _queue = 0;
time_last _event = 0.0;

% Initialize the statistical counters.
num_custs_delayed = 0;
total_of _delays = 0.0;
area_num _in _queue = 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) = clock + exprnd(mean_interarrival); time_next _event(EV_Depart) = 1.0e+230;

%% part2
while (num_custs _delayed < num_delays _counts)
% Run the simulation while more customer service counts are still needed. %Determine the next event.
min_time_next _event = 1.0e+290;
next_event _type = 0;

% 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, '\n Event list empty at time % f', clock); exit(1);
end

% The event list is not empty, so advance the simulation clock. clock = 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 = clock - time_last _event;
time_last _event = clock;

% Update area under number-in-queue function.
area_num_in _queue = area_num _in _queue + num_in _queue * time_since _last _event;

% Update area under server-busy indicator function.
area_server_status = area_server _status + server_status * time_since _last _event;
% Invoke the appropriate event function.

% For arrival event:
if(next_event _type == EV_Arrive)
double delay;

% Schedule next arrival.
time_next_event(1) = clock + exprnd(mean_interarrival);

% Check to see whether server is busy.
if (server_status == ST_Busy)

% If server is busy, increment number of customers in queue. num_in_queue = 1 + num_in _queue;

% Check to see whether an overflow condition exists.
if (num_in _queue > Q_LIMIT)

% The queue has overflowed, so stop the simulation.
fprintf(outfile, '\n Overflow of the array time_arrival at'); fprintf(outfile, ' time % f', clock);
exit(2);
end

% If there is still room in the queue, store the time of arrival of the arriving customer at the (new) end of time_arrival. time_arrival(length(time_arrival)+1)=clock;

else
% When server is idle, the arriving customer...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Simulation Example with Matlab Essay
  • Matlab Essay
  • Simulation Report Essay
  • System Simulation in Matlab/Simulink Essay
  • Essay about simulation
  • simulation Essay
  • Matlab Essay
  • MATLAB Essay

Become a StudyMode Member

Sign Up - It's Free