# System simulation: Simulation Implementation of elevator system

#### 1, Experimental background

according to the time distribution of the first operation, the elevator simulation system is realized to test the time cost performance of students arriving at the first floor in different scenarios. Elevator system is a discrete system, which is driven by events. The state changes at discrete time points and operates in the mode of call first service.

#### 2, Known conditions

1. Arrival time is the start time = wake-up time distribution + washing time distribution. The distribution of wake-up time is N ( 7.633 , 0.7822 ) N(7.633,0.7822) N(7.633,0.7822), the distribution of washing time is N ( 0.17689 , 0.00235 ) N(0.17689,0.00235) N(0.17689,0.00235) .
2. The running speed of the elevator is 1.58s/floor.
3. Residence time of each floor U ( 10 , 60 ) U(10,60) U(10,60) seconds.
4. Elevator operation strategy: call first, service first + operation direction floor sequencing strategy

#### 3, Implementation process

the elevator has three states: idle, running under full load (number of people < 10), running and full load (number of people = 10). Set Event_queue is the sequence of events. The first behavior is the start time and consumption time. The second behavior is the current state. 1 is arrival, 0 is in the elevator, and - 1 determines whether to reach the first floor or out of the elevator. Let queue be the waiting sequence, and each line represents missing multiplication. The first digit is the number of people, and the second digit and later are the ID number
Set queue_ in_ The ID that the elevator records in the elevator.
There are three situations for elevator operation:

1. Students arrive to call the elevator ① yes and open door ③ whether it is full ② whether it is on the first floor.
2. When the elevator is running, arrive at the call floor, judge whether there is a queue below the call floor in turn, and if so, join the elevator queue when the elevator is running downward under the condition that the elevator is not full.
3. The elevator closes and waits for a call.

Case 1 type=1 Figure 1 student arrival flow chart

Case 2 type=0 Figure 2 flow chart of elevator movement process

Case 3 type = -1 Fig. 3 flow chart of elevator door closing waiting process

#### 4, Effect test

Operation process: ...... Figure 4 operation process Figure 5 broken line diagram of time consumption

Scene group comparison
① There are 20 students on each floor

Table 1 (5,9) average consumption schedule under the floor
 Number of floors 5 6 7 8 9 Total number 100 120 140 160 180 Average consumption time 1 43.511s 41.365 67.589 52.908 65.652 2 44.179s 48.702 53.102 61.904 86.502 3 41.515 53.731 60.289 59.374 64.415 4 41.056 49.858 60.929 53.575 71.541 5 38.552 67.702 40.739 64.393 74.349 Total average 41.762 52.271 56.5296 58.4308 72.4918 Figure 5 Comparison of average consumption time of different floors
② According to the actual data of the author's dormitory building, the average service time of 64 people on each floor is 261.192s
Table 2 average consumption schedule of 64 people on the 9th floor

 1 2 3 4 5 average 376.576 196.35 267.617 266.11 199.309 261.192s

#### 5, Conclusion

Compared with the average time performance, the average time cost increases with the increase of the number of floors and the total number of people.

#### Appendix:

Main.m

```clc;clear;
close all;
%***********************
Event_queue= [];%Event queue
N=6;%Number of floors
student_num = 20*N;
queue = zeros(N,20);
elevator_loc = 1;%Elevator floor
elevator_num_threshold = 10;%Maximum number of elevators
num_in_elevator = 0;%Number of people in the elevator
time_every_floor = 0.0004388; %2.1361/3600s
elevator_dst = 0;
queue_in_elevator = [];
elevator_door = 0;%Status of elevator door

wakeup_time=normrnd(7.633,0.7822,1,student_num);
wash_time=normrnd(0.17689,0.00235,1,student_num);
t=wakeup_time+wash_time;
time=sort(t);

for t=1:student_num
s(t)=student;
s(t).id = t;
s(t).StartTime = time(t);
s(t).floor = unidrnd(N); %floor=1 2 3 4 5 6 7 8 9
s(t).left_elevator = 0;%Time to leave the elevator
if s(t).floor == 1
s(t).left_elevator = s(t).StartTime;
else
Event_queue = insert_Event_queue(Event_queue, s(t).StartTime, 1,s(t).id);
end
end
t_floor = []; %Print and generate the corresponding floor of students
for i = 1:student_num
t_floor = [t_floor s(i).floor];
end
t_floor;
t_start=[]; %Print and generate the corresponding start time of students entering the elevator system
for i =1:student_num
t_start = [t_start s(i).StartTime];
end
t_start;

t=0;
mid = 0;
while(~isempty(Event_queue))

[t,type,id,Event_queue]=pop_Event_queue(Event_queue);
%**********************************************************************************************
if type == -1 %Elevator door closing
elevator_door = 0;
if elevator_loc == 1
for i = N:-1:1
if queue(i,1) ~= 0
elevator_dst = i;
break;
end
end
if i == 1
elevator_dst = 0;
else
Event_queue = insert_Event_queue(Event_queue,t+time_every_floor*(elevator_dst-1), 0, elevator_dst);
end
else
time_arrive_next_floor = t + time_every_floor;%Go to the next floor
Event_queue = insert_Event_queue(Event_queue,time_arrive_next_floor, 0, elevator_loc-1);%insert change event
end
%**********************************************************************************************
elseif type == 0 %Elevator operation
elevator_loc = id;%Elevator floor
elevator_door = 1;
if elevator_loc == 1%Get out of the elevator
while(num_in_elevator ~= 0)
temp_id = queue_in_elevator(1);
s(temp_id).left_elevator = t;%Record the time
queue_in_elevator = queue_in_elevator(2:length(queue_in_elevator));
num_in_elevator = num_in_elevator - 1;
end
%            queue_in_elevator = [];
elevator_dst = 0;
time_elevator_close = t + (10 + 50 * rand())/3600;
Event_queue = insert_Event_queue(Event_queue,time_elevator_close, -1, elevator_loc);%insert close event
elseif elevator_loc == elevator_dst
elevator_dst = 1;
time_elevator_close = t + (10 + 50 * rand())/3600;
Event_queue = insert_Event_queue(Event_queue,time_elevator_close, -1, elevator_loc);%insert close event
if queue(elevator_loc,1) ~= 0
[queue, pop_id] = pop_queue(queue,elevator_loc,elevator_num_threshold-num_in_elevator);
while(~isempty(pop_id))
temp_id = pop_id(1);
queue_in_elevator = [queue_in_elevator temp_id];%ID Put it in the elevator
num_in_elevator = num_in_elevator + 1;
pop_id = pop_id(2:length(pop_id));
end
end
elseif elevator_dst == 1
if queue(elevator_loc,1) ~= 0 && num_in_elevator < elevator_num_threshold%Determine whether someone
[queue, pop_id] = pop_queue(queue,elevator_loc,elevator_num_threshold-num_in_elevator);
while(~isempty(pop_id))%Layer by layer judgment
temp_id = pop_id(1);
queue_in_elevator = [queue_in_elevator temp_id];
num_in_elevator = num_in_elevator + 1;
pop_id = pop_id(2:length(pop_id));
end
time_elevator_close = t + (10 + 50 * rand())/3600;
Event_queue = insert_Event_queue(Event_queue,time_elevator_close, -1, elevator_loc);%insert close event
else
Event_queue = insert_Event_queue(Event_queue,t+time_every_floor, 0, elevator_loc-1);%insert change event
end
end
%**********************************************************************************************
elseif type == 1% Elevator.
if elevator_loc == s(id).floor && elevator_door == 1%The elevator is just in and the door is open
queue_in_elevator = [queue_in_elevator id];
num_in_elevator = num_in_elevator + 1;
elseif queue(s(id).floor,1) == 0 %Judge whether the current floor queue is empty
temp_num_in_queue = queue(s(id).floor,1);%Number of people on this floor
queue(s(id).floor,temp_num_in_queue+2) = id;
queue(s(id).floor,1) = queue(s(id).floor,1) + 1;
if elevator_loc == 1 && elevator_dst == 0 %At first, the elevator was on the first floor
for i = N:-1:1
if queue(i,1) ~= 0
elevator_dst = i;
break;
end
end
Event_queue = insert_Event_queue(Event_queue,t+time_every_floor*(elevator_dst-1), 0, elevator_dst);%hold id Changed to the floor
end
else %else, join the queue
temp_num_in_queue = queue(s(id).floor,1);
queue(s(id).floor,temp_num_in_queue+2) = id;
queue(s(id).floor,1) = queue(s(id).floor,1) + 1;
end
end

end
% Graphical visualization of results
t_cost=[];
t_left=[];
for i =1:student_num
t_cost = [t_cost (s(i).left_elevator-s(i).StartTime)*3600];
end
for i =1:student_num
t_left = [t_left s(i).left_elevator];
end

x=(1:student_num);
figure
plot(x,t_cost,'LineWidth',1.5);
xlabel('ID');
ylabel('Time consuming(Unit: Second)');
grid on;

%Result value output
fprintf('Number of floors: %d  Total number of students:%d\n',N,student_num);
fprintf('-----------------------------------------------------------\n')
t_start_hour=floor(t_start);
t_start_middle = (t_start-floor(t_start))*60;
t_start_min=floor(t_start_middle);
t_start_second=(t_start_middle-floor(t_start_middle))*60;

t_left_hour=floor(t_left);
t_left_middle = (t_left-floor(t_left))*60;
t_left_min=floor(t_left_middle);
t_left_second=(t_left_middle-floor(t_left_middle))*60;

for k=1:student_num
fprintf('ID be entitled as %d My students are in the second grade %d The departure time on the first floor is %d:%d:%0.1f,Departure time is %d:%d:%0.1f,time consuming%0.1fs\n',s(k).id,s(k).floor,t_start_hour(k),t_start_min(k),t_start_second(k),t_left_hour(k),t_left_min(k),t_left_second(k),t_cost(k));
end
fprintf('-----------------------------------------------------------\n')
fprintf('The average length of time students spend taking the elevator= %f second\n',mean(t_cost));

```

pop_queuw.m

```function [ queue, pop_id ] = pop_queue( queue, index ,num_to_pop )
pop_id = [];
num_pop = 0;
if queue(index,1) <= num_to_pop %The number of students who want to withdraw is less than the number of queuing on the current floor
num_pop = queue(index,1); %Everyone in line took it out
for i = 2:(num_pop+1)
pop_id = [pop_id queue(index,i)];
if queue(index,i) == 0
bb = 1;
end
end
queue(index,:) = 0;
else %The number of students you want to withdraw is more than the number of people in the queue on the current floor
num_pop = num_to_pop;
queue(index,1) = queue(index,1) - num_pop;
for i = 2:(num_pop +1)
pop_id = [pop_id queue(index,i)];
if queue(index,i) == 0
bb = 1;
end
queue(index,i) = 0; %Dispose of the removed student position 0
end
for i = 2:(queue(index,1)+1)
queue(index,i) = queue(index,i+num_pop); %Line up the students who are not taken out from the back and move forward
queue(index,i+num_pop) = 0; %The student position moved forward is disposed of 0
end

end
end
```

insert_Event_queue.m

```function event_queue=insert_Event_queue(event_queue,time, type,id)

if isempty(event_queue)
event_queue = [time type id]';
else
s = size(event_queue);
%check the start and end
if event_queue(1,1) >= time
event_queue = [[time type id]' event_queue(:,1:s(2))];
elseif event_queue(1,s(2)) <= time
event_queue = [event_queue(:,1:s(2)) [time type id]'];
else
for n = 1:s(2) %go through the event queue and find the right place to insert
if event_queue(1,n)<time
%insert the time and type
event_queue = [event_queue(:,1:n) [time type id]' event_queue(:,n+1:s(2))];
break;
end
end
end
end
```

pop_Event_queue.m

```function [time, type, id, event_queue]=pop_Event_queue(event_queue)
time= event_queue(1,1);% move the timer
type = event_queue(2,1);
id = event_queue(3,1);
s = size(event_queue);
if s == [3 1]% only one event existed
event_queue = [];
else %more than one event existed
%push the fisrt event out.
event_queue=event_queue(:,2:s(2));%Remove the previous one
end
```

reference resources
. Liuss Shengsheng cabin

Tags: MATLAB

Posted by konrados on Fri, 15 Apr 2022 12:12:26 +0930