You are on page 1of 4

Subject: Modeling & Simulation Assignment 1 Question 1 The elevator program is a simple program but certain necessary information

is missing such as the time of inputs and scenarios where other inputs from the users might be entered. The program searches through the incalls and finds the floor that is going downwards. The action of going down is chosen as the timing of the input is unknown. Thus, once that is done, the Excalls_down is searched and then the variable having this info is sorted in descending order so that the floors with the biggest number is reached first. Then once all the floors are reached, then the Excalls_up is searched, thus searching for floors going up. This action is repeated in the reverse order as Incalls, Excalls_up,Excalls_Down to keep on moving. Everytime the search is done, the current floor is kept in mind. This helps so that we know which floors are up and down in comparison to the current floors. The coding is present at the bottom and the flow of the elevator is presented as results. Results Currently in floor: 2 Currently in floor: 1 Currently in floor: 0 Currently in floor: 1 Currently in floor: 4 Currently in floor: 5 Currently in floor: 4

Coding
% Subject: Modelling & Simulation % Date: 13-Mar-2013 % Question: Create an Elevator's action with given inputs L=[0,1,2,3,4,5]; %Level Current_L=3; Incalls=[1,5]; Ex_up=[0,1,4]; Ex_dn=[2,4]; UP_DOWN=[1,-1]; %1== UP; -1==DOWN for j=1:2 Incalls_i=size(Incalls,2); Ex_up_i=size(Ex_up,2); Ex_dn_i=size(Ex_dn,2); New_L=[];k=[]; %Elevator Goes Down for i=1:Incalls_i if Current_L>Incalls(i) New_L=[New_L,Incalls(i)]; k=[k,i]; % Incalls(i)=[]; end end Incalls(k)=[]; k=[]; for i=1:Ex_dn_i if Current_L>Ex_dn(i) New_L=[New_L,Ex_dn(i)]; k=[k,i]; % Incalls(i)=[]; end end Ex_dn(k)=[]; k=[]; New_L=sort(New_L,'descend'); if (size(New_L,2)~=0) Current_L=move(New_L); end %Elevator moving New_L=[]; for i=1:Ex_up_i if Current_L>Ex_up(i) New_L=[New_L,Ex_up(i)]; k=[k,i]; % Incalls(i)=[]; end

end Ex_up(k)=[]; k=[]; if (size(New_L,2)~=0) Current_L=move(New_L); end New_L=[]; Incalls_i=size(Incalls,2); Ex_up_i=size(Ex_up,2); Ex_dn_i=size(Ex_dn,2); %Time to go up for i=1:Incalls_i if Current_L<Incalls(i) New_L=[New_L,Incalls(i)]; k=[k,i]; % Incalls(i)=[]; end end Incalls(k)=[]; k=[]; for i=1:Ex_up_i if Current_L<Ex_up(i) New_L=[New_L,Ex_up(i)]; k=[k,i]; % Incalls(i)=[]; end end Ex_up(k)=[]; k=[]; New_L=sort(New_L,'ascend'); if (size(New_L,2)~=0) Current_L=move(New_L); end %Elevator moving New_L=[]; for i=1:Ex_dn_i if Current_L<Ex_dn(i) New_L=[New_L,Ex_dn(i)]; k=[]; % Incalls(i)=[]; end end Ex_dn(k)=[]; k=[]; end

%%%%%%%%%%%%%%%%
function [Current_L] = move(New_L) for i=1:size(New_L,2) %Can be turned into a function Current_L=New_L(i); disp(['Currently in floor: ', num2str(Current_L)]); pause(0.5); %elevat0r moving; end

You might also like