**A. Appendix A. Source Code in MATLAB**


1.Generate Passenger Origin Destination Pairs Randomly

Author: Lutfi Al-Sharif Date: 27th April 2020 version: 1.0

% this MATLAB script generates passenger origin–destination pairs randomly % based on three main parameters:

% the floor populations

% the entrance floors bias ratios

% the mix of traffic.

2. Set the Parameters

This building has 10 floors The floor index runs from 1 to 10. floors 1, 2 and 10 are entrance floors floor 10 is probably a restaurant.

```
% set the entrance bias
EB = [0.3 0.3 00000000.4];
% set the population on each floor
U=[0160160160100100100100100 20];
% set the traffic mix as percentages adding up to 1
% [i/c o/g i/f i/e]
% incoming: outgloing: interfloor: interentrance
Traffic = [0.45 0.45 0.1 0];
```
% set the number of required passengers P = 12;

3. shuffle the seed to set it to a specific value

% in order to get the same sequence every run, set the seed to a specific % value (e.g., 0 in this case). sd = 0; % value of the seed rng(sd)

% in order to get a different sequence everytime the programme runs, shuffle the seed rng('shuffle');

4.Create the PDF (probability density function)

call Create\_PDF to create the PDF array.

PDF = Create\_PDF(EB, U, Traffic).

PDF =

Columns 1 through 7


Columns 8 through 10


5.Convert the PDF to a CDF

CDF: Cumulative Distribution Function The CDF is ideal to use for the random sampling in order to randomly generate passenger origin–destination pairs.

*A Universal Methodology for Generating Elevator Passenger Origin-Destination Pairs… DOI: http://dx.doi.org/10.5772/intechopen.93332*

CDF = PDF2CDF(PDF).

CDF =

Columns 1 through 7

0 0.0229 0.0458 0.0686 0.0829 0.0972 0.1115 .1659 0.1659 0.1917 0.2175 0.2337 0.2498 0.2659 .3548 0.3806 0.3806 0.3836 0.3854 0.3872 0.3891 .4465 0.4723 0.4752 0.4752 0.4771 0.4789 0.4807 .5296 0.5457 0.5475 0.5494 0.5494 0.5505 0.5517 .5875 0.6037 0.6055 0.6073 0.6085 0.6085 0.6096 .6455 0.6617 0.6635 0.6653 0.6665 0.6676 0.6676 .7035 0.7196 0.7215 0.7233 0.7245 0.7256 0.7267 .7615 0.7776 0.7795 0.7813 0.7824 0.7836 0.7847 .8080 0.8418 0.8726 0.9035 0.9228 0.9421 0.9614

Columns 8 through 10


6.Generate P passenger origin destination pairs using the CDF

call GenPass to generate P passenger origin–destination pairs usnig the CDF.

POD = GenPass(P,CDF)

% The resultant array POD is a two dimensional array that has dimensions of % 2 rows by P columns. The first row contains the passenger origin floor;

% the second row contains the passenger destination floors.

% each column pertains to one passenger (a passenger origin–destination % pair).

% the floor indexing runs from 1 to N.

% End.

POD =

1 10 1 10 4716 2210 4 78 4 382910 3 8 9 2.

Create\_PDF.m.

Background Theory and References....................................................................... 1 extract the total number of floors and traffic mix from the variable Traffic.......2

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.


function [PDF] = Create\_PDF(EB, U, Traffic).

%This module, Create\_PDF compiles the probability density function (PDF) %for generating passenger origin–destination pairs.

% Author: Lutfi Al-Sharif % Date: 27th April 2020% this function creates a square array that is referred to as a PDF % PDF stands for probability density function (PDF). % it is a square array that has dimensions of N rows by N columns % where N is the total number of floors in the building.

% it is used in order to generate random passneger origin–destination-pairs. % it depends on two important parameters: the relative percentages of the % floor populations of the occupant floors, the relative entrance bias of % entrance floors; and the mix of traffic (the percentage incoming traffic, % outgoing traffic, interfloor traffic and interentrance traffic).

1.Background Theory and References

the methodology presented here in this function is based on a method of producing the origin destination matrix in the following papers.

% Al-Sharif L and Abu Alqumsan A M. An Integrated Framework for Elevator % Traffic Design under General Traffic Conditions Using Origin Destination % Matrices, Virtual Interval and the Monte Carlo Simulation Method. % Building Services Engineering Research and Technology 2015; 36(6): % 728–750.

%Al-Sharif L and Abu Alqumsan A M. Generating the Elevator % Origin–Destination Matrix from the User Requirements Specification under % General Traffic Conditions. Elevator Technology 2016; 21: 1–13. % Proceedings of Elevcon 2016. Madrid/Spain: The International Association % of Elevator Engineers.

%Al-Sharif L. Building the Origin–Destination % Matrix under General Traffic Conditions and Using it to Generate % Passenger Origin–Destination Pairs (METE XII). Lift Report 2016; % 42(3):24–33.

% This paper introduces the methodology by which any floor could % simultaneously be an entrance floor and an occupant floor

% Al-Sharif L. The Universal Origin–Destination-Matrix with Dual % Designation Floors as Entrances and Occupant Floors. Lift Report 2018; % 44(2):36–45.

*A Universal Methodology for Generating Elevator Passenger Origin-Destination Pairs… DOI: http://dx.doi.org/10.5772/intechopen.93332*

2.extract the total number of floors and traffic mix from the variable Traffic

N = length(U);

% The variable Traffic is a one dimensional array, of size 1x4% the four variables inside Traffic represent the ratio of incoming, % outgoing, interfloor and interentrance respectively. % they should all be less than or equal to 1% the sum of the four values must add up to 1% % the first element is the incoming traffic % extract it and assign it to the variable i\_c i\_c = Traffic(1); % the second element is the outgoing traffic % extract it and assign it to the variable o\_g o\_g = Traffic(2); % the third element variable is the interfloor traffic % extract it and assign it to the variable i\_f i\_f = Traffic(3); % the fourth element in the Traffic Array element variable is the interfloor traffic % extract it and assign it to the variable i\_f i\_e = Traffic(4); Error using Create\_PDF (line 49) Not enough input arguments.

3.Generate the PDF

the next step is to prepare the probability density function (PDF) square array.

% find the total population U which is the sum of the individual floor % populations Utotal = sum(U); % normalise it by dividing each element of the array by the total % population. % this will result in an array that has a total sum of 1 Unor = U/Utotal;

4.produce the first draft arrays for the four traffic modes

```
% the transpose of an array A is A'
% the tanspose is used here in order to produce a square array
% by multiplying the transpose of a row vector by another row vector of the
% same size.
% A square array is produced.
```
i\_c\_array = (EB'\*Unor); o\_g\_array = (Unor'\*EB); i\_f\_array = (Unor'\*Unor); i\_e\_array = (EB'\*EB);

5.process them to make them ready for the final PDF

% zero the diagonals

% this assumes rational passenger behaviour whereby a passenger cannot % travel from a floor back to the same floor.

for i = 1:N i\_c\_array(i,i) = 0; o\_g\_array(i,i) = 0; i\_f\_array(i,i) = 0; i\_e\_array(i,i) = 0; end

% re-adjust to compensate for the loss of the value of the diagonal elements

% find the adjusting factors for all four arrays (which are the current sum % of all the elements in the array (expected to be smaller than 1 due to % teh fact that the diagonal was zeroed.

Mi\_c = sum(sum(i\_c\_array)); % sum up all the elements of ic Mo\_g = sum(sum(o\_g\_array)); % sum up all the elements in og Mi\_f = sum(sum(i\_f\_array)); % sum up all the elements in if Mi\_e = sum(sum(i\_e\_array)); % sum up all the elements in ie

```
% then divide the array by the adjusting factor in order to restore the sum
% of its elements to 1
```

```
if Mi_c  = 0
i_c_array = i_c_array/Mi_c;
end
```
if Mo\_g = 0 o\_g\_array = o\_g\_array/Mo\_g; end

if Mi\_f = 0 i\_f\_array = i\_f\_array/Mi\_f; end

if Mi\_e = 0 i\_e\_array = i\_e\_array/Mi\_e; end

% Each of the four arrays now must sum up to 1. % this can be checked by using the instruction sum(sum(A))

6. find the value of the PDF as the weighted sum of all the four traffic mode arrays

% now find the value fo the final PDF by doing a weight sum of the four % arrays, multiplying each by its strength from the traffic array.

PDF = i\_c\*i\_c\_array+ o\_g\*o\_g\_array + i\_f\*i\_f\_array + i\_e\*i\_e\_array;

% the sum of all the element of the final PDF should also sum up to 1. end

*A Universal Methodology for Generating Elevator Passenger Origin-Destination Pairs… DOI: http://dx.doi.org/10.5772/intechopen.93332*

PDF2CDF.m.


\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

function [CDFfromPDF] = PDF2CDF(PDF). %This function converts the PDF to a CDF % Author: Lutfi Al-Sharif % Date: 27th April 2020

1.Extract the number of floors from the dimensions of the input argument, PDF and set to N

N=size(PDF,1); % as this is a square matrix, it does not matter if we take the number of rows or the number of columns.

Error using PDF2CDF (line 7) Not enough input arguments.

2.Convert the PDF to a CDF

the pdf is the probability density function. The cdf is the cumulative distribution function by integrating the PDF we can obtain the CDF.

CDFtemp = 0; % initialise a temporary variable that is hold a temporary value during the conversion process.

CDF(N, N) = 0; % initialise all the values in the CDF to zero

for i = 1:N % run through the array one row at a time, so finish a complete row then move to the next row and complete it.

% (i.e., rather than one column at a time).

for j = 1:N % move through column entres in the row being processed CDFtemp = CDFtemp+PDF(i,j); % keep track of the running sum in CDFtemp CDF(i,j) = CDFtemp;

end

end

% note that this CDF will always end with a 1, but might not start with a % zero.

% it is important to be aware of this when carrying out random sampling on % this CDF matrix.

CDFfromPDF=CDF; end

GenPass.m.

Generate Passenger origin–destination pairs for P passengers ............................. 1 Set up a Counter and apply it to the CDF to find the origin–destination pair..... 1

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

function [ POD ] = GenPass(P,CDF)

1.Generate Passenger origin–destination pairs for P passengers

Author: Lutfi Al-Sharif Date: 27th April 2020

% this function will generate a number of passenger origin–destination % pairs.

% The number of passengers is passed as a parameter P

% and the CDF (cumulative distribution function) is also passed to the % function.

% it applies the principle of random sampling in order to find the % origin–destination pair for a certain passenger.

% A random number that is uniformly distributed between 0 and 1 is % generated using the function rand()

% this random number is then checked to see where it falls within the CDF % array. Its position within the array decides the origin (the row) and % the destination (the column) in the array.

% the output set of origin–destination pairs is compiled in the array % called POD. it has dimensions of 2 x P.

% the first row contains the origins of the P passengers.

% the second row contains the correspinding destinations for these % passengers.

2. Set up a Counter and apply it to the CDF to find the origin–destination pair

% the results will be placed in the POD with is a 2 by P array that % contains all the passenger origins (in the first row) and their % destinations (in the second row). POD = 0; % zero the POD array.

% first set up a counter for the P passengers, using k as an index for k = 1:P

% the ODfound is a Boolean variable that indicates that the value of

% the random variables has been matched to its position inside the CDF % matrix.

% initialise it to false so that it can be set to true one found.

ODfound = false; % the origin destination for this passenger has not been found yet.

tempCDF = 0; % tempCDF will hold that las indexed value of the elements in the CDF.

temp = rand();

%now run through the rows of the CDF one row at a time

for i = 1:length(CDF)

%now run through the elements of the row one column at a time

for j = 1:length(CDF)

% check if the random number is between two consecutive elements % of the CDF array.

if ((temp>tempCDF) && (temp<=CDF(i,j)) && (ODfound == false))

ODfound = true; % if found, then set temporary flag to indicate this

POD(1,k) = i; % the row index is the origin for this kth passenger.

POD(2,k) = j; % the column index is the destination for this kth

passenger

% the found origin and destination are placed in the kth column

% of the POD array. The origin in the first row and the

% destination in the second row.

*A Universal Methodology for Generating Elevator Passenger Origin-Destination Pairs… DOI: http://dx.doi.org/10.5772/intechopen.93332*

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_.

end end end end.

Error using GenPass (line 33) Not enough input arguments.

end
