You are on page 1of 71

THE DESIGN AND IMPLEMENTATION OF GENERIC

QUEUEING SYSTEMS SIMULATION

Written by:
Yosfik Alqadri, S.T.

92312066

GRADUATE PROGRAM

GUNADARMA UNIVERSITY

JAKARTA
2014
THE DESIGN AND IMPLEMENTATION OF GENERIC
QUEUEING SYSTEMS SIMULATION

Written by:
Yosfik Alqadri, S.T.

THESIS

Submitted as a partial fulfillment


of the Requirements for Magister Degree of Information System

Management

Concentrating on Information System Software

Gunadarma University

GRADUATE DEGREE

GUNADARMA UNIVERSITY

JAKARTA
2014
PAGE OF APPROVAL

Title : The Design and Implementation of


Generic Queueing Systems Simulation
Name : Yosfik Alqadri, S.T.
NIM : 92312066

Date of graduation :

Approved by:

Board of Advisors

. . . . . . . . . . . . . . . . . . .

Dr. Ernastuti, S.Si., M.Kom.

(Chair Person)

. . . . . . . . . . . . . . . . . . .

Prof. Dr. Yuhara Sukra., M.Sc.

(Coordinator)

. . . . . . . . . . . . . . . . . . .
Dr. Tb. Maulana Kusuma, S.Kom., MEngSc.
(Director)

ii
ABSTRACT

Yosfik Alqadri (92312066)


TITLE: The Design and Implementation of Generic Queueing Systems
Simulation)
Master Thesis. Magister Degree of Information System Management. 2014
Keywords : Queue, Simulation, Python.

(xii + 49 + 6)

Waiting in queue is part of our daily life. We, as the customer do not need

the waiting. The service providers also do not want the customer to wait, because

too much waiting may lose them the business. Computer-based simulation is one
solution to find the optimum service rate for queueing systems. Queueing systems

simulation is a scenario-based simulation, where users provide parameters for the

scenario, such as mean arrival time and mean service time.

A Generic Queueing Systems Simulation is developed in this thesis. The

generic queueing model used as the basis of the simulation is chosen from the ex-
isting queueing models. The simulation makes use of the pseudo-random generator.
The generic queueing systems simulation is designed as a function in Python pro-

gramming language, which can then be called from another program to generate the
simulation results.
In this thesis, it is concluded that the best model for the generic queueing
simulation is the multi channel single phase model. The simulation makes use a
kind of multiplicative pseudo-random number generator, called Lehmer’s random
number generator, to substitute the built-in random number generator in Python.

iii
The performance of the simulation is of class O(n) = n, where n is the number of
server in the queueing systems.

Bibliography (1967-2014)

iv
CURRICULUM VITAE

Yosfik Alqadri, was born in Padang on April 26th , 1989. The educational
background started from SDN 44 Padang Elementary School from 1994 until 2000.
He continued his education to SMPN 18 Padang Junior High School and gradu-
ated in 2003. From then, he continued to SMAN 10 Padang Senior High School
and graduated in 2006. In 2009, he continued to Gundarma University majoring

in Informatics Engineering. In 2009, he got Sarmag (Sarjana Magister) Scholarship


Program from Gunadarma University majoring in Informatics Engineering and fin-

ished the Undergraduate Degree on 2013. Currently, he is completing the master’s

program majoring in Information Systems Management.

v
ACKNOWLEDGEMENTS

Praise be to God for all the blessing, for which without, this work could not
be completed. This work was done to complete the requirement to finish the study
at Information Systems Management Master’s Program, Gunadarma University.
Author wishes to thank everyone who has given their support, kindness, and

patience in making this work completed. It is not possible to name them all here.
However, author would like to dedicate acknowledgements to:

1. Prof. Dr. E. S. Margianti, S.E., MM, as Rector of Gunadarma University.

2. Prof. Suryadi Harmanto, S.Si., MMSI, as 2nd Vice Rector of Gunadarma

University.

3. Prof. Dr. Yuhara Sukra., M.Sc., as Coordinator of Postgraduate Program.

4. Dr. Tb. Maulana Kusuma, S.Kom., MEngSc., as Director of Postgraduate

Program.

5. Dr. Yuhilza Hanum, S.Si., M.Eng., as Head of Magister of Information System

Management.

6. Drs. Haryanto, MMSI, as Director of SarMag (Sarjana Magister) Program.

7. Dr. Ernastuti, S.Si., M.Kom., as supervisor of this work, for her excellent
supervision.

8. Mr. Remi Senjaya, ST., MMSI who sincerely take care of us (SarMag students)
and give us all information and needs in SarMag Program.

9. My beloved family, for the never-ending love, support, and kindness.

vi
10. All of SarMag lecturers, for support and knowledge given to author.

11. All SarMag staffs in Simatupang and Salemba Campus, for the supports.

12. All my friends, especially in SarMag, for a lot of supports, sharings, jokes, and
joys. Thank you for such happiness.

13. And a special thanks to Citra Bunga Putri, for all the talks and chats, a relief
from all the pressure from this work.

Last but not least, Author is looking forward to get suggestions and critics

from anyone to help improving this work in the future. Hopefully, readers would

gain knowledge and learn new things from this work.

Jakarta, February 2014

Yosfik Alqadri, S.T.

vii
Contents

COVER . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
PAGE OF APPROVAL . . . . . . . . . . . . . . . . . . . . . . . . . . ii
ABSTRACT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii

CURRICULUM VITAE . . . . . . . . . . . . . . . . . . . . . . . . . . v
ACKNOWLEDGEMENTS . . . . . . . . . . . . . . . . . . . . . . . . vi
Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii

List of Figure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi

List of Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii


Chapter I : INTRODUCTION . . . . . . . . . . . . . . . . . . . . . 1

1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

1.2 Problem Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

1.3 Scope of the Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

1.4 Objective of the Work . . . . . . . . . . . . . . . . . . . . . . . . . . 3


1.5 Working Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . 4

1.6 Structure of the Work . . . . . . . . . . . . . . . . . . . . . . . . . . 4


Chapter II : LITERATURE REVIEW . . . . . . . . . . . . . . . . 6
2.1 Components of Queue . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Characteristics of Queue . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.1 Source of Arrival . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.2 Pattern of Arrival . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2.3 Poisson’s Pattern of Arrival [5] . . . . . . . . . . . . . . . . . 8
2.2.4 Exponential Distribution [12] . . . . . . . . . . . . . . . . . . 9
2.2.5 Length of Queue . . . . . . . . . . . . . . . . . . . . . . . . . 9

viii
2.2.6 Queueing Discipline [4] . . . . . . . . . . . . . . . . . . . . . . 10
2.2.7 Service Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2.3 Queueing Models [6] . . . . . . . . . . . . . . . . . . . . . . . . . . . 10


2.4 Performance of a Queueing System . . . . . . . . . . . . . . . . . . . 13
2.5 Single Channel Queueing Process Formulation . . . . . . . . . . . . . 13
2.6 Random Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2.6.1 Pseudo-random Number . . . . . . . . . . . . . . . . . . . . . 14

2.6.2 Pseudo-random Number Generator [11] . . . . . . . . . . . . . 15


2.7 Simulation Technique . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.8 Python Programming Language [1] . . . . . . . . . . . . . . . . . . . 16

Chapter III : ANALYSIS AND DESIGN . . . . . . . . . . . . . . . 19

3.1 Generic Queueing Model Selection . . . . . . . . . . . . . . . . . . . . 19

3.2 Simulation Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.3 Simulation Components Specification . . . . . . . . . . . . . . . . . . 24


3.3.1 Input Process . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.3.2 Simulation Data Keeping Mechanism . . . . . . . . . . . . . . 24

3.3.3 Pseudo-random Number Generator . . . . . . . . . . . . . . . 25

3.3.4 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Chapter IV : IMPLEMENTATION AND TESTING . . . . . . . . 28

4.1 Development Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28


4.2 Simulation Implementation . . . . . . . . . . . . . . . . . . . . . . . . 28
4.3 Simulation Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.3.1 Running the Simulation . . . . . . . . . . . . . . . . . . . . . 37
4.3.2 Performance Testing . . . . . . . . . . . . . . . . . . . . . . . 39
4.4 Example of Simulation Application . . . . . . . . . . . . . . . . . . . 41

ix
4.4.1 Queueing Problem in Mainframe Computer [6] . . . . . . . . . 41
4.4.2 Queueing Problem in Logistics . . . . . . . . . . . . . . . . . . 45

Chapter V : CONCLUSION . . . . . . . . . . . . . . . . . . . . . . 50
5.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
5.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
BIBLIOGRAPHY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

x
List of Figures

1.1 Traffic jam at toll booths in Jakarta . . . . . . . . . . . . . . . . . . . 2

2.1 A queueing process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6


2.2 Single Channel Single Phase . . . . . . . . . . . . . . . . . . . . . . . 11

2.3 Multi Channel Single Phase . . . . . . . . . . . . . . . . . . . . . . . 12

2.4 Single Channel Multi Phase . . . . . . . . . . . . . . . . . . . . . . . 12


2.5 Multi Channel Multi Phase . . . . . . . . . . . . . . . . . . . . . . . 12

2.6 Position of simulation in problem solving . . . . . . . . . . . . . . . . 17

3.1 Proposed Simulation Procedure . . . . . . . . . . . . . . . . . . . . . 22

4.1 An example displaying the result of simulation . . . . . . . . . . . . . 38

4.2 An example displaying the content of simulation data file . . . . . . . 39

4.3 The growth of runtime is linear to the growth of number of server . . 41

4.4 Output of the mainframe simulation . . . . . . . . . . . . . . . . . . 43


4.5 Mean error for 10,000 executions of the simulation . . . . . . . . . . . 45

4.6 Output of the logistic cost simulation . . . . . . . . . . . . . . . . . . 49

xi
List of Tables

3.1 Sample output file format . . . . . . . . . . . . . . . . . . . . . . . . 26

4.1 Result of runtime testing in milliseconds . . . . . . . . . . . . . . . . 41

xii
Chapter I
INTRODUCTION

1.1 Background

Waiting in queue is part of our daily life. We wait in queue at supermarket


to checkout. We wait in queue at fast-food restaurants and banks. We wait in our
vehicles in traffic jams and toll booths. We, as the customer do not need the waiting.

We only need the service. And the service providers also do not want the customer

to wait, because too much waiting may lose them the business.

Queue is formed when the number of demand for service is greater than the

number of service available. This happened because of limited resources, such as


the number available servers, available service space, or available service time. It

is economically infeasible for the service providers to overcome the limitation of

resources. Therefore, they have to find the optimum service rate, based on the equi-

librium from the cost for providing the resources and the customers’ waiting time.
Queueing processes can generally be classified into four models. They are: Single

Channel Single Phase model, Multi Channel Single Phase model, Single Channel
Multi Phase model, and Multi Channel Multi Phase model [6].

Computer-based simulation is one solution to find the optimum service rate


for queueing systems. Queueing systems simulation is a scenario-based simulation,
where users provide parameters for the scenario, such as mean arrival time and mean
service time. Results from the simulation can then be used as the basis for decision
for the service provider to plan the service systems. Queueing systems simulation
have achieved success in many fields and is heavily used in industries.
Meanwhile in Jakarta, the capital city of Indonesia, there have been com-

1
2

plaints going on about the poor service of several public services, with the most
frequently encountered being the traffic jam and the long wait in the toll booths
(figure 1.1). The public service systems is not carefully planned, which results in
low service rate. The use of queueing systems simulation in the planning stages
should improve this service rate problem.

Figure 1.1: Traffic jam at toll booths in Jakarta

1.2 Problem Statement

Problems in this work are:

1. In order to be usable in most domain, what kind of queueing model is adequate


to be taken as the generic model?

2. What are the components needed and how to integrate them into a simulation
software?

3. How is the performance of the simulation software?


3

4. How can the software be applied to solve real-world queueing problems?

1.3 Scope of the Work

This work concerns on developing a generic queueing systems software simu-


lation that is capable of performing most frequently encountered queueing systems
scenario in daily life. The model chosen for the simulation software is taken from
existing models from queueing theory, not a new one. The chosen model is the most

adequate to be taken as a generic model.

Also concerned in this work is about the pseudo-random number genera-


tor. Most programming languages have built-in random pseudo-number generator.

However, for some reasons (such as security concerns), the algorithm of the built-in

pseudo-random number generator is far too complex. The complexity is unnecessary

for the simulation software. A less complex but faster algorithm is chosen for the

pseudo-random number generator, to substitute the built-in one.

1.4 Objective of the Work

The goals of this work are:

1. Select adequate model to be taken as the generic model.

2. Develop components necessary for the simulation model, and implement the
model.

3. Measure the performance of the developed simulation software.

4. Apply the software to solve some example of real-world queueing problems.


4

1.5 Working Methodology

In conducting this work, author takes the following steps:

1. Literature Review. At this step, studies of topics related to queueing models


and simulation is done. This includes reviewing queueing components, queue-
ing characteristics, queueing models, queueing systems performance, single-

channel queueing formulation, pseudo-random number generators, and simu-


lation technique.

2. System Analysis. After studies of related topics, an analysis is done to

compare and then choose the best model and the best pseudo-random number

generator to be implemented.

3. System Design. This phase carries out the process of designing the simula-
tion components needed and how to integrate them.

4. Implementation and Testing. After the design is complete, the simulation

software is then implemented in the programming language of choice (in this

work, Python). After implementation is complete, testing is carried out to


measure the performance of the completed simulation software.

1.6 Structure of the Work

Chapter 1 is Introduction. This chapter explains the background, problem


statements, scope, objective of the thesis, and method. The structures of the work
will be also explained briefly in this chapter. Chapter 2 is Literature Review. This
chapter explains the relevant theories that are used in this work. Chapter 3 is
System Analysis and Design. This chapter comprised of the analysis done to choose
5

the best model and algorithm, and then design the components needed for the
software. Chapter 4 is Implementation and Testing. This chapter will describe the
implementation and testing of the completed simulation software. The last chapter
is Conclusion.
Chapter II
LITERATURE REVIEW

2.1 Components of Queue

Agner Krarup Erlang, a Danish engineer who worked for the Copenhagen
Telephone Exchange, published the first paper on what would now be called queueing
theory in 1909 [3]. He modeled the number of telephone calls arriving at an exchange

by a Poisson process [7]. A queueing process can be very simple, but sometimes can

also very complex. The main components are arrival of customer and service. These

components can be seen on figure 2.1.

Figure 2.1: A queueing process

Every queueing problems involve the arrival of customer. A customer can be


in the form of people, vehicle, or phone call waiting to be processed. This component
is often considered as the input. The input process involves source of arrival, usually
called Calling Population. The event of arrival happens in a random manner.
The formation of a queue depends on the arrival characteristics and the ser-
vice process. The procedure of how to handle the queue is usually called the queueing
discipline. Queue discipline may be First Come First Served (FCFS), Last Come
First Served (LCFS), priority-based or arbitrary. If no queue is formed, some facil-

6
7

ities are idle, which might indicate that they are beyond the real need.
Service facility can be of a single or multiple server. For example, there are
multiple toll booth at the toll road, while a theater might only have a single ticket
booth.

2.2 Characteristics of Queue

2.2.1 Source of Arrival

The number of arriving customers can be finite or infinite. If there is no limit

set on the number of waiting customers, it is called an infinite queue. Otherwise, it


is called a finite queue.

2.2.2 Pattern of Arrival

The most common way to describe the pattern of arrival is through the

use of inter-arrival time. Inter-arrival time is defined as the interval between two

consecutive event of customer arrival. If arrival time stochastically change over time,

a probability function of inter-arrival time is needed.


The relationship between inter-arrival time, Ta , and arrival rate, λ is given
by

1
λ= (2.1)
Ta

The distribution of arrival, A0 (t), is the probability of inter-arrival time being


greater than t. Because it is defined that F (t) is the probability of inter-arrival time
being less than t, we have the following relationship
8

A0 (t) = 1 − F (t) (2.2)

2.2.3 Poisson’s Pattern of Arrival [5]

The event of customer arrival happens in a random manner. It can happen


at any time. The next arrival time of customer is independent from the previous,

within an interval ∆t. If λ is defined as the mean of the number of arrival over a
certain amount of time, then the probability of a customer arrival within ∆t is λ∆t.

The distribution function of inter-arrival time is given by

f (t) = λe−λt with (t > 0) (2.3)

and the distribution of arrival is given by

A0 (t) = e−λt (2.4)

λ is the mean of the number of arrival over a certain amount of time. The

number of arrival at any point in time is a random number. This is described by

the following relationship, where the probability of a number of arrival, r, within a


period of t, is given by

(λt)r e−λt
P (r) = with (r = 0, 1, 2, . . . ) (2.5)
r!

This is called the Poisson’s distribution, and is a discrete distribution. On


the other hand, equation 2.3 is called exponential distribution, and is a continuous
distribution. The random manner of inter-arrival time is usually called Poisson’s
arrival pattern.
9

2.2.4 Exponential Distribution [12]

By giving definition of F (t) = y, integrating equation 2.3 yields a cumulative


distribution function

∫ t
y= λe−λt dt = 1 − e−λt (2.6)
0

and when inversed, yields

λt = −ln(1 − y) (2.7)

Because y is a cumulative function, the value of 1 − y will be between 0 and

1. Within this range, the natural logarithm yields negative value. The minus sign

at the front will convert it to positive.


By using equation 2.7 and substituting y with a sequence of uniformly dis-

tributed random number between 0 and 1, we will get a sequence of exponentially

distributed random numbers. If y is uniformly distributed, then so is 1 − y. There-

fore, a simpler equation then can be derived

−ln(y)
t= = Ta ln(y) (2.8)
λ

2.2.5 Length of Queue

In queueing theory, a queue begin with the assumption that its length, to-
gether with the source of arrival, to be infinite.
10

2.2.6 Queueing Discipline [4]

Queueing discipline is a set of rule or procedure to handle which customer


from the queue is to be served. It is usually assumed that the customer will be
served according to the First Come First Served (FCFS) principle.

2.2.7 Service Pattern

Service time in a queueing process can also be in the form of probability


distribution. The usual assumption used for the service time is negative exponential
distribution, which is given by

F (t) = µe−µt (2.9)

where µ is the mean service rate.

By giving F (t) = y, integrating equation 2.9 yields

∫ t
y= µe−µt dt = 1 − e−µt (2.10)
0

By applying previous technique from equation 2.6, a simpler equation then

can be derived to produce a sequence of exponentially distributed random numbers

−ln(y)
t= = Ts ln(y) (2.11)
µ

with Ts being the mean service time.

2.3 Queueing Models [6]

Queueing processes can generally be classified into four models.


11

1. Single Channel Single Phase Single Channel Single Phase is the simplest
queueing model. It has only one waiting line, and only one server. Example
of this model is the queueing process at a ticket booth at a theater.

2. Multi Channel Single Phase Multi Channel Single Phase is a queueing


model that has multiple waiting line, and multiple server with only one stage
of service. Example of this model is the queueing process at a barber shop.

3. Single Channel Multi Phase Single Channel Multi Phase is a queueing


model that has only one waiting line, and multiple server with more than

one stage of service. Example of this model is the queueing process of a

registration.

4. Multi Channel Multi Phase Multi Channel Multi Phase is a queueing

model that has multiple waiting line, and multiple server with more than one

stage of service. Example of this model is the queueing process of patients


waiting to be served by a group of nurse.

Figures 2.2, 2.3, 2.4, and 2.5 illustrate these four models.

Figure 2.2: Single Channel Single Phase


12

Figure 2.3: Multi Channel Single Phase

Figure 2.4: Single Channel Multi Phase

Figure 2.5: Multi Channel Multi Phase


13

2.4 Performance of a Queueing System

Performance of a queueing system can be measured by the following

1. Wq , mean waiting time per customer

2. W , mean time in system per customer

3. Lq , mean number of waiting customer in queue

4. L, mean number of waiting customer in the system

5. Pw , utilization of the queueing system

These measures are essential as the basis for making decisions about the

design of the service facilities.

2.5 Single Channel Queueing Process Formulation

A simple queueing model has the following characteristics

1. Arrival time pattern conforms to Poisson’s distribution

2. Service time pattern conforms to exponential distribution

3. Single phase service

4. Queueing discipline is First Come First Served (FCFS)

Assumption on a single channel queue is that λ < µ. Mean service rate, µ


should exceed mean arrival time rate, λ. If otherwise, the queue length will grow
longer over time, and optimum solution cannot be achieved.
14

The performance of a single channel queue is described by the following equa-


tions

λ
Wq = (2.12)
µ(µ − λ)

1
W = (2.13)
µ−λ

λ2
Lq = (2.14)
µ(µ − λ)

λ
L= (2.15)
µ−λ

λ
Pw = (2.16)
µ

2.6 Random Number

2.6.1 Pseudo-random Number

One foundation of the study of simulation is the ability to produce a sequence

of random numbers. A sequence of random numbers is uniformly distributed be-


tween 0 and 1. Formerly, sequence of random numbers is produced in manual or
mechanical fashion, such as shuffling dice or card. Modern approach uses computers
to produce the random number sequence, by using selected algorithm.
Sequence of random numbers produced by the algorithm is not true random
numbers by nature. Somehow, the sequence can still be predicted (even though it
is very hard or nearly impossible), since the next number depends on the previ-
15

ous numbers on the sequence. Because of this untrue nature, the random number
produced by the algorithms is called pseudo-random numbers.

2.6.2 Pseudo-random Number Generator [11]

Pseudo-random number generator is an algorithm to produce a sequence of


random numbers. The sequence produced should be uniformly distributed. The

current result of executing the algorithm, can then be used to produce another
random number in the next execution.

Uniform distribution means that the chance of every number (within a certain

or desired range) to be picked up is equal.

Below are some well known approach for pseudo-random number generators

1. Additive Pseudo-random Number Generator. Zi+1 = (a.Zi + c) with

a, c, m ∈ Z+ . A random number, Ui , is achieved by Ui = Zi /m, while Z0 is


the seed.

2. Multiplicative Pseudo-random Number Generator. Zi+1 = (a.Zi ) mod


m with a, m ∈ Z+ . A random number, Ui , is achieved by Ui = Zi /m, while

Z0 is the seed.

Almost any programming language is equipped with a built-in pseudo-random

number generator. However, the algorithms chosen are usually the complex one, such
as the Marsenne Twister, which is the built-in pseudo-random number generator for
Python. The complex ones are usually chosen because of security concern, thus
sacrificing running time to produce more unpredictable random number sequence.
16

2.7 Simulation Technique

A mathematical models are used to solve problems analytically. If analytical


solution is infeasible for the problem, then numerical computation approach is used
to solve it. Analytical approach produce general solutions, while numerical compu-
tation approach produce local solutions for current iteration and will cover wider
(and more complete) range as iterations take place.
According to Shannon, simulation is the process of designing a model repre-
senting a real-world system, and the experimental execution of this model is con-

ducted to better understand the system’s behavior and planning a better strategy

based on that behavior.

Position of simulation in problem solving is illustrated in figure 2.6. For static

models, there is no difference between analytical and numerical computation. For


dynamic models, some of them can be solved analytically, but some other cannot.

For dynamic models that cannot be solved analytically, numerical computation ap-

proach is used. Simulation is the name of the name of this special technique in

numerical approach to solve the equations of the models in iterative manner.

2.8 Python Programming Language [1]

Python is a remarkably powerful dynamic programming language that is used


in a wide variety of application domains. Python is often compared to Tcl, Perl,
Ruby, Scheme or Java. Some of its key distinguishing features include: very clear
and readable syntax, strong introspection capabilities, intuitive object orientation,
natural expression of procedural code, full modularity, exception-based error han-
dling, very high level dynamic data types, extensive standard libraries and third
17

Figure 2.6: Position of simulation in problem solving

party modules, and embeddable within applications as a scripting interface.

Since 2008, Python has consistently ranked in the top eight most popular pro-
gramming languages as measured by the TIOBE Programming Community Index.
It is the third most popular language whose grammatical syntax is not predomi-
nantly based on C, e.g. C++, C#, Objective-C, Java. Python does borrow heavily,
however, from the expression and statement syntax of C, making it easier for pro-
grammers to transition between languages.
An empirical study found that, for a programming problem involving string
18

manipulation and search in a dictionary, scripting languages such as Python were


more productive than conventional languages such as C and Java. Memory con-
sumption was often "better than Java and not much worse than C or C++". Large
organizations that make use of Python include Google, Yahoo!, CERN, NASA, and
some smaller ones like ILM, and ITA.
Libraries like NumPy, SciPy and Matplotlib allow Python to be used effec-

tively in scientific computing, with specialized libraries such as BioPython and As-

tropy providing domain-specific functionality. Sage is a mathematical software with


a "notebook" programmable in Python: its library covers many aspects of math-
ematics, including algebra, combinatorics, numerical mathematics, number theory,

and calculus.

Python has been successfully embedded in a number of software products as

a scripting language, including in finite element method software such as Abaqus,

3D animation packages such as 3ds Max, Blender, Cinema 4D, Lightwave, Houdini,
Maya, modo, MotionBuilder, Softimage, the visual effects compositor Nuke, and

2D imaging programs like GIMP, Inkscape, Scribus and Paint Shop Pro. GNU

Debugger uses Python as a pretty printer to show complex structures such as C++

containers. Esri is now promoting Python as the best choice for writing scripts in
ArcGIS. It has even been used in several video games, and has been adopted as

first of the three available programming languages in Google App Engine, the other
two being Java and Go. Python has also been used in artificial intelligence tasks.
Thanks to being a scripting language with module architecture, syntax simplicity
and rich text processing tools, Python is often used for natural language processing
tasks.
Chapter III
ANALYSIS AND DESIGN

3.1 Generic Queueing Model Selection

In order for the simulation software to be usable for most cases, a generic
queueing model must be decided first. Based on the previous chapter, there are
four queueing models: single channel single phase, multi channel single phase, single

channel multi phase, and multi channel multi phase.

Regarding the channel, a multiple one should handle all the case. The multi

channel is flexible, with customers having the tendency to choose the shortest line

at each arrival and also to change line if some of the server become idle (available
for service). This makes more sense rather than a strict multi channel with the

prohibition of customer changing lines.

Now, if we look closely, the single phase service should suffice for most cases.

The single phase service can also be seen as the accumulation of multi phase service.
By taking into account the waiting time for each phase of service, and carefully

adding it to the total service time for each phase of service, we can still get the
mean time in system for each customer. In short, the desired performance parameter

of a multi phase service simulation can still be achieved via single phase service
simulation.
By following arguments above, the multi channel single phase model is
selected as the most adequate generic model for the simulation software. Now, how
about the number of the server? The number of the server is arbitrary. The user will
provide the number of server for the simulation. If the number is zero or negative,
the simulation will not run, and will produce empty output.

19
20

3.2 Simulation Design

After selecting the model, detailed steps for the simulation procedure is de-
veloped. The output of the simulation is to measure the following performance
parameters.

1. Mean waiting time per customer

2. Mean time in system per customer

3. Mean number of waiting customer in queue

4. Mean number of waiting customer in the system

5. Utilization of the queueing system

In order for the simulation to be carried out, the following simulation vari-

ables is used. The name inside the bracket will be the actual name in the software

implementation.

1. Number of server (jumlahP elayan)

2. Mean inter-arrival time per customer (lamda)

3. Mean service time per customer (mu)

4. Number of unit time for duration of the simulation (waktuSimulasi)

5. Current time of simulation (t)

6. List of customers (daf tarP elanggan)

7. List of servers (daf tarP elayan)


21

8. A random number (angkaAcak)

9. Server selected by currently arrived customer (pelayan)

10. Arrival time of a customer (waktuDatang)

11. Start time of service for a customer (waktuM ulai)

12. Service time of a customer (lamaP elayanan)

13. End time of service for a customer (waktuSelesai)

14. Waiting time of a customer before being processed (lamaT unggu)

15. Finishing time of the last customer (waktuBerakhir)

16. Result mean waiting time per customer (rerataLamaT unggu)

17. Result number of waiting customer in queue(rerataP anjangAntrian)

18. Result mean time in system per customer (rerataLamaSistem)

19. Result mean number of waiting customer in the system (rerataP anjangSistem)

20. Utilization of the queueing system (utilisasi)

After defining the simulation variables, the simulation procedure is developed

to produce desired results. The procedure is illustrated by figure 3.1. A more


detailed description of the steps in the procedure is as follows.

1. Set current time, t, to zero.

2. Input the value for variables jumlahP elayan, lamda, mu, and waktuSimulasi,
which are the number of server, mean inter-arrival time, mean service time,
and duration of simulation, respectively.
22

Figure 3.1: Proposed Simulation Procedure


23

3. Compute a random number for variable angkaAcak.

4. Select the idle server. If all server is busy, select the one closest to finishing
the job. Store the selected server in variable pelayan.

5. If the currently arriving customer is the first customer in system, the value
of arrival time variable, waktuDatang, is the exponentially distributed inter-

arrival time, lamda, computed by

−ln(angkaAcak)
waktuDatang = (3.1)
lamda

If it is not the first customer in system, the value of waktuDatang is its old
value added with the result of equation 3.1.

6. If the currently arriving customer is the first customer in system, the value of

service start time variable, waktuM ulai, is equal to waktuDatang. If it is not

the first customer in system, the value of waktuM ulai is the maximum value

between waktuDatang and the finishing time of pelayan.

7. Service time for currently arriving customer, lamaP elayanan is the exponen-
tially distributed service time, mu, computed by

−ln(angkaAcak)
lamaP elayanan = (3.2)
mu

8. End time of service for currently arriving customer, waktuSelesai, is waktuM ulai
added with lamaP elayanan.

9. Waiting time of a customer before being processed, lamaT unggu, is the dif-
ference between waktuM ulai and waktuDatang.
24

10. Append the list of customers, daf tarP elanggan, with the currently arriving
customer.

11. Update the finishing time of the selected server, pelayan, with the value of
waktuM ulai added with lamaP elayanan.

12. Update t with waktuDatang. If the new t is less than waktuSimulasi, repeat

step 3. Otherwise, stop the simulation.

3.3 Simulation Components Specification

Based on the procedure in previous section, a more detailed and technically

oriented specification for the simulation software is developed. The components

concerned here are the input process, simulation data keeping mechanism, pseudo-
random number generator, and the output process.

3.3.1 Input Process

As stated before, the simulation software is intended to be generic. And

as the generic model, single channel single phase, is chosen, the user will supply
the value for the number of server (jumlahP elayan), mean inter-arrival time per
customer (lamda), mean service time per customer (mu), and number of unit time

for duration of the simulation (waktuSimulasi).

3.3.2 Simulation Data Keeping Mechanism

Simulation data can be viewed as record stored in a table. In procedural


programming languages, there are convenient way to implement this. For exam-
ple, the record data structure in Pascal, or struct in C/C++. For object oriented
25

programming languages, there are even more convenient way to do this, by using
object. Instead of viewing data for each customer as a separate record, each cus-
tomer can be viewed as objects with properties attached to each of them. To create
customer’s object, there will be a class called P elanggan with properties including:
server selected by currently arrived customer (pelayan), arrival time of a customer
(waktuDatang), start time of service for a customer (waktuM ulai), service time of

a customer (lamaP elayanan), end time of service for a customer (waktuSelesai),

and waiting time of a customer before being processed (lamaT unggu).

3.3.3 Pseudo-random Number Generator

Because security concern is not taken into account for random numbers in

the simulation, a fast and easy to implement algorithm is chosen. For this purpose,
Lehmer random number generator, or commonly known as MINSTD, is chosen.

Lehmer random number generator is a multiplicative random number generator,

following the equation [10]

Xk+1 = (g.Xk ) mod n (3.3)

This algorithm is still in use today, noticeably in C++ 2011 standard spec-
ification (C++11). Its first version, suggested by Park and Miller in 1988, uses
parameters n = 23 1 − 1 = 2, 147, 483, 647 along with g = 75 = 16, 807 [8]. Later,
in 1993, Park and Miller revised the parameter g = 48, 271 [9]. The later version is
the one used in C++11’s minstd_rand random number generator [2].
A pseudo random number generator needs a first arbitrary number in order
to generate the sequence. This first arbitrary number is commonly known as the
seed, represented by X0 . If the seed is an input from user, it will be inconvenient
26

because it should not have been taken into consideration by him/her. The software
will take care of that. If the arbitrary number is hard-coded into the source code,
then it is no longer arbitrary. Also, the sequence produced will be constant, as
the seed is also constant. The simulation will produce identical result for the same
input.
In order to solve this, the software will take the Operating System’s time.

The time will then be converted to long integer and then multiplied by 256. This

method is used in Python’s random module in order to get the seed. This method
will produce non identical seed for several consecutive simulation run.

3.3.4 Output

The summary of the simulation will be displayed right after a simulation run
ended. However, if a user want to view the simulation data used in the run, an

output file is needed. For this purpose, a comma separated values (CSV) file should

suffice. This kind of file can be opened in a text editor, and is supported by most

spreadsheet application (e.g. Microsoft Excel, OpenOffice Calc). If a user want to

process the data further, he/she can then open it in the spreadsheet and do the
analysis. Format of the simulation data on the CSV file is illustrated by table 3.1.

Table 3.1: Sample output file format


Pelanggan Waktu Lama Pelayan Waktu Lama Waktu
datang tunggu mulai pelayanan selesai
1 1 0 1 1 1 2
2 3 0 2 3 2 5
3 5 0 3 5 2 7
4 6 0 4 6 1 7
5 10 0 1 10 2 12

In this example, customer #1 arrived at the first unit of time. Because the
27

simulation had just started, there is no customer waiting in the queue, which means
that waiting time is zero. Therefore, customer #1 proceeded to server #1. The
service lasted for 1 unit of time, and customer #1 finished at the second unit of
time. The same thing went for customers #2, #3, and #4, each of which arrived
at the third, fifth, and sixth unit of time. Because of the server selection algorithm
in the simulation program, each customer proceeded to servers #2, #3, and #4

respectively. Customers #2, #3, and #4 were served for 2, 2, and 1 units of time,

and finished at the fifth, seventh, and seventh unit of time respectively. When
customer #5 arrived at the tenth unit of time, server #1 was already in idle state
and served customer #5 directly, which means zero waiting time. The service lasted

for 2 units of time, and customer #5 finished at the twelfth unit of time.
Chapter IV
IMPLEMENTATION AND TESTING

4.1 Development Tools

The programming language used for development of the simulation software


is Python 3.3.3. Python 3.3.3 is the latest Python distribution at the time of the
writing. However, Python 2.x is still used widely, and the library support availability

is better than Python 3.x. The reason of choosing Python 3.x as the language for

development is that it is the future implementation of Python. Python 2.7 will

be the last Python 2.x implementation, and then it will be discontinued. For this

reason, Python 3.x is used, in order for the software to be usable for a longer period
of time.

4.2 Simulation Implementation

The simulation makes use of some built-in functionality from Python library.
The simulation data will be exported as a CSV file, so csv module is needed. For

computing random numbers, natural logarithm and ceiling functions (log() and

ceil()) from math module are also needed. And to get current system time from
the operating system, the time() function from time module is needed. Below is
the code to import the necessary modules.

import csv
import math
import time

28
29

As stated in the previous chapter, simulation data keeping mechanism is


done by creating customer object from a class named Pelanggan. Properties at-
tached to class Pelanggan include: server selected by currently arrived customer
(pelayan), arrival time of a customer (waktuDatang), start time of service for a
customer (waktuMulai), service time of a customer (lamaPelayanan), end time of
service for a customer (waktuSelesai), and waiting time of a customer before being

processed (lamaTunggu). In Python, a special method named __init__() is used

as the constructor to create the object of the class. Below is how the code looks like.

class Pelanggan:

def __init__(self, pelayan, waktuDatang, waktuMulai,


lamaPelayanan):

self.pelayan = pelayan

self.waktuDatang = waktuDatang

self.waktuMulai = waktuMulai
self.lamaPelayanan = lamaPelayanan

self.waktuSelesai = self.waktuMulai + self.lamaPelayanan

self.lamaTunggu = self.waktuMulai - self.waktuDatang

To compute a random number, a function named acak() is called. This

function accept no parameter at all, but instead a global variable named angkaAcak
which is also defined in function mulaiSimulasi. All the values used inside this
function follows the later version of Lehmer random number generator, revised by
Park and Miller in 1993. To map the random number into a range between 0 and
1, it is divided by the range before returning it as the final value. Below is how the
code looks like.
30

def acak():
global angkaAcak
a = 48271
m = (2 ** 31) - 1
angkaAcak = (a * angkaAcak) % m
return float(angkaAcak) / m

To produce an exponentially distributed number, acakEksponensial() is


called. This function accept one parameter, lamda, which is the mean inter-arrival

time per customer. This function follows the formula to compute an exponentially

distributed number, as described in chapter 2. Function log() is a built in function


that comes from module math. Below is how the code looks like.

def acakEksponensial(lamda):

return -math.log(acak()) / lamda

User will start the simulation by calling the main function, simulasi(). The

supplied parameters will be the number of server (jumlahPelayan), mean inter-

arrival time per customer (lamda), mean service time per customer (mu), and number
of unit time for duration of the simulation (waktuSimulasi). The simulation will

proceed if all the following conditions are satisfied:

• jumlahPelayan is an integer

• jumlahPelayan is equal or greater than 1

• lamda is not zero (to avoid "division-by-zero" error)

• mu is not zero (to avoid "division-by-zero" error)


31

• waktuSimulasi is greater than zero.

If all the conditions are satisfied, the real simulation process will start, by
calling function mulaiSimulasi(). If one or more conditions are not satisfied,
an error message will be printed. Also defined in the function, is the five vari-
ables for performance parameters to be measured by the simulation. They are:
rerataPanjangAntrian, rerataPanjangSistem, rerataLamaTunggu, rerataLamaSistem,
and utilisasi, each defined as a global variable. The five variables will be return

as the result every time function simulasi() is called. Below is how the code looks

like.

def simulasi(jumlahPelayan, lamda, mu, waktuSimulasi):

global rerataPanjangAntrian, rerataPanjangSistem,


rerataLamaTunggu, rerataLamaSistem, utilisasi

if isinstance(jumlahPelayan, int) and

jumlahPelayan >= 1 and

lamda != 0 and
mu != 0 and
waktuSimulasi > 0:
mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi)
return (rerataPanjangAntrian, rerataPanjangSistem,
rerataLamaTunggu, rerataLamaSistem, utilisasi)
else:
print(’Salah satu atau lebih parameter simulasi tidak valid.’)

The body of function mulaiSimulasi begins with initialization of some local


and global variables. The local variables include current time of simulation (t), list of
32

customers (daftarPelanggan), and list of servers (daftarPelayan). t is initialized


with value of zero, daftarPelanggan as an empty list, and daftarPelayan as list
of n zeros, where n is the value of jumlahPelayan. The global variable includes
the random number variable, angkaAcak. The seed of angkaAcak is achieved by
getting current system time from the operating system, by calling function time()
from module time, then multiply it by 256. It is convenient to convert it to integer

before further computation. Below is how the code looks like.

def mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi):


t = 0

daftarPelanggan = []

daftarPelayan = [0] * jumlahPelayan

global angkaAcak

angkaAcak = int(time.time() * 256)

...

The simulation will run as long as variable t is less than waktuSimulasi.

First, an idle or closest-to-finish server is chosen, by looking at the minimum finish-


ing time stored in list daftarPelayan. After getting the minimum value, the index
of that value is achieved by calling method index(), attached to daftarPelayan.
The index is then stored to variable pelayan. If the first customer is encountered
(by checking whether the length of list daftarPelanggan equals zero), the value
waktuDatang is the rounded up (ceil()) result of calling acakEksponensial()
with parameter lamda, and the value of waktuMulai is the same with waktuDatang
. If it is not the first customer, then the value of waktuDatang is its previous
value added with the rounded up (ceil()) result of calling acakEksponensial()
33

with parameter lamda, and the value of waktuMulai is the maximum between
waktuDatang and the finishing time of the chosen server (value of daftarPelayan
at index pelayan). The value of lamaPelayanan is the rounded up (ceil()) re-
sult of calling acakEksponensial() with parameter mu. After all that steps, a new
customer object is created by calling the constructor of class Pelanggan, and then
store the object to list daftarPelanggan. Before the next iteration, value of fin-

ishing time in list daftarPelayan and value of t are updated with the new one.

Below is how the code looks like.

def mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi):

...
while t < waktuSimulasi:

pelayan = daftarPelayan.index(min(daftarPelayan))

if len(daftarPelanggan) == 0:

waktuDatang = int(math.ceil(acakEksponensial(lamda)))
waktuMulai = waktuDatang

else:

waktuDatang += int(math.ceil(acakEksponensial(lamda)))
waktuMulai = max(waktuDatang, daftarPelayan[pelayan])
lamaPelayanan = int(math.ceil(acakEksponensial(mu)))
daftarPelanggan.append(Pelanggan(pelayan+1, waktuDatang,
waktuMulai, lamaPelayanan))
daftarPelayan[pelayan] = waktuMulai + lamaPelayanan
t = waktuDatang
...
34

After the iteration ended, next step is to compute the result. All the five
return value for function simulasi() is computed in the following steps. Below is
how the code looks like.

def mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi):


...
waktuBerakhir = daftarPelanggan[-1].waktuSelesai

daftarLamaTunggu = [pelanggan.lamaTunggu for

pelanggan in daftarPelanggan]

rerataLamaTunggu = sum(daftarLamaTunggu) /
len(daftarLamaTunggu)

rerataPanjangAntrian = sum(daftarLamaTunggu) /

waktuBerakhir

daftarLamaTotal = [pelanggan.lamaTunggu +

pelanggan.lamaPelayanan for

pelanggan in daftarPelanggan]

rerataLamaTotal = sum(daftarLamaTotal) /
len(daftarLamaTotal)
rerataPanjangSistem = sum(daftarLamaSistem) /
waktuBerakhir

daftarLamaPelayanan = [pelanggan.lamaPelayanan for


pelanggan in daftarPelanggan]
utilisasi = sum(daftarLamaPelayanan) / waktuBerakhir
35

...

After getting all the results needed, the next step is to print them out. Below
is how the code looks like.

def mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi):


...

print(’Hasil simulasi:’)
print()
print(’ Jumlah pelayan:’, jumlahPelayan)
print(’ Rerata panjang antrian:’, rerataPanjangAntrian)

print(’Rerata antrian dalam sistem:’, rerataPanjangSistem)

print(’ Rerata lama tunggu:’, rerataLamaTunggu)

print(’ Rerata lama dalam sistem:’, rerataLamaSistem)


print(’ Utilisasi sistem:’, utilisasi)

print()

...

The next step is to store the simulation data generated during the simulation,
into a CSV file. The data can then be opened in a spreadsheet application for further
processing, if desired by the user. Below is how the data stored to a CSV file in

Python 3.x (the method is slightly different in Python 2.x).

def mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi):


...
namaFile = ’simulasi(%s,%s,%s,%s).csv’ %
(jumlahPelayan, lamda, mu, waktuSimulasi)
with open(namaFile, ’w’, newline=’’) as fileKeluaran:
36

keluaran = csv.writer(fileKeluaran)
keluaran.writerow([’Pelanggan’, ’Waktu datang’, ’Lama tunggu’,
’Pelayan’, ’Waktu mulai’, ’Lama pelayanan’,
’Waktu selesai’])
i = 0
for pelanggan in daftarPelanggan:

i += 1

baris = []
baris.append(i)
baris.append(pelanggan.waktuDatang)

baris.append(pelanggan.lamaTunggu)

baris.append(pelanggan.pelayan)

baris.append(pelanggan.waktuMulai)

baris.append(pelanggan.lamaPelayanan)
baris.append(pelanggan.waktuSelesai)

keluaran.writerow(baris)

fileKeluaran.close()

...

After the storing process is complete, a message about the name of the file is
displayed so that user can find it. Below is how the code looks like.

def mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi):


...
print(’Data simulasi tersedia dalam file:’, namaFile)
...
37

4.3 Simulation Testing

4.3.1 Running the Simulation

The simulation source file is named antrian.py. To run the simulation, first
user should go to the directory of the source file in a console application. After that,
user should run the python interpreter in that location, by typing python. Below is

an example of how to do these steps in Microsoft Windows.

D:\>cd Python

D:\Python>python

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40)

[MSC v.1600 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more


information.

>>>

The triple > sign prompt indicates that user are inside Python interpreter
environment at the moment. Next step is to load the source into the interpreter, by

typing import antrian. To start the simulation and supply the parameters, type
antrian.simulasi(a,b,c,d), where:

• a is number of server

• b is mean inter-arrival time per customer

• c is mean service time per customer

• d is number of unit time for duration of the simulation


38

1
Below is an example of how to run the simulation with 4 servers, 4
mean
1
inter-arrival time, 3
mean service time, and 500 unit time of duration.

Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40)


[MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import antrian
>>> antrian.simulasi(4, 1/4, 1/3, 500)

Figure 4.1 shows the result from the execution of the call to antrian.simulasi(4,

1/4, 1/3, 500) above. At the bottom of the result, a message about the name of

the file containing the simulation data is displayed. The file is located in the same
directory as the source file. Figure 4.2 shows the content of the file, opened with

Microsoft Excel application.

Figure 4.1: An example displaying the result of simulation


39

Figure 4.2: An example displaying the content of simulation data file

4.3.2 Performance Testing

The simulation procedure developed for this work, makes use of function

min() to find the minimum value of server’s finish time from the list daftarPelayan.

To find the minimum value of a list, all values need to be checked. This means that
the complexity of the algorithm is linear to n, the length of the list. In other words,
it has a complexity of class O(n) = n.
The performance being measured here is the runtime of the simulation, de-

pending on the number of server. The goal of the testing is to make sure that the
growth of runtime is linear to the number of server, supplied by the user as one of
the parameter to run the simulation.
To run the performance testing, two new lines of code are added to function
simulasi(). The first is to take the system time, right before the call to function
mulaiSimulasi(). The second is to take the system time, right after the call, and
40

then compute the difference, convert it to milliseconds, and print the result. Below
is how the code looks like, after modification.

def simulasi(jumlahPelayan, lamda, mu, waktuSimulasi):

if isinstance(jumlahPelayan, int) and


jumlahPelayan >= 1 and
lamda != 0 and
mu != 0 and

waktuSimulasi > 0:

waktuMulai = time.time()

mulaiSimulasi(jumlahPelayan, lamda, mu, waktuSimulasi)


print(’Simulasi selesai dalam’, int(round((time.time() -

waktuMulai) * 1000)), ’milidetik’)

else:

print(’Salah satu atau lebih parameter simulasi tidak valid.’)

The range of value for the number of server is from 500 up to 5000, increased
by 500 in each step. One step of testing consist of five run, and the result is the

average runtime from the five runs. The other parameters are kept constant, which
1 1
are 4
mean inter-arrival time, 3
mean service time, and 100000 unit time of duration.
Table 4.1 shows the result of the test.
Figure 4.3 shows the plot of the test result. From this plot, it can be seen that
the growth of runtime is linear to the growth of the number of server. This result is
just as expected, given that the function min() used in the simulation procedure,
is of complexity O(n) = n.
41

Table 4.1: Result of runtime testing in milliseconds


No. of Run #1 Run #2 Run #3 Run #4 Run #5 Average
server (ms) (ms) (ms) (ms) (ms) (ms)
500 967 967 967 952 967 964
1000 1544 1544 1544 1544 1560 1547
1500 2075 2075 2090 2090 2090 2081
2000 2652 2636 2683 2668 2668 2661
2500 3229 3214 3214 3198 3214 3214
3000 3791 3775 3760 3775 3791 3778
3500 4352 4337 4290 4290 4259 4306
4000 4852 4898 4883 4789 4914 4867
4500 5444 5398 5398 5429 5429 5420
5000 5912 5959 5912 5897 5850 5906

Figure 4.3: The growth of runtime is linear to the growth of number of server

4.4 Example of Simulation Application

4.4.1 Queueing Problem in Mainframe Computer [6]

A mainframe computer is capable of processing 60 programs in 1,5 minutes.


Meanwhile, there are 60 programs coming to the mainframe within 2 minutes, wait-
ing to be processed. We are about to determine:
42

1. Utilization of the mainframe (Pw )

2. Mean time of program in the system (W )

3. Mean waiting time for each program (Wq )

The expected performance measurements of the system can be computed by formula

2.12-2.16 in chapter 2, subsection 2.5. After getting the results, the expected perfor-
mance measurements is then compared to the performance measurements computed
by the simulation by calling function simulasi() in module antrian. Below is the

code that computes the expected and simulated performance measurements of the

mainframe queueing problems above.

import antrian

def ekspektasi(lamda, mu):

W_q = lamda / (mu * (mu - lamda))

W = 1 / (mu - lamda)

L_q = (lamda ** 2) / (mu * (mu - lamda))


L = lamda / (mu - lamda)
P_w = lamda / mu
print(’Ekspektasi sistem:’)
print()
print(’ Rerata panjang antrian:’, L_q)
print(’ Rerata panjang antrian dalam sistem:’, L)
print(’ Rerata lama tunggu:’, W_q)
print(’ Rerata lama dalam sistem:’, W)
print(’ Utilisasi sistem:’, P_w)
43

print()
return (L_q, L, W_q, W, P_w)

lamda = 60/120
mu = 60/90
ekspektasi(lamda, mu)

antrian.simulasi(1, lamda, mu, 5000)

Result of the mainframe queueing problem simulation can be seen in figure


4.4. The expected Pw is 0.75, and the simulated one is 0.81 (error: 8%). The

expected W is 6 seconds, and the simulated one is 6.1 seconds (error: 1.67%). The
expected Wq is 4.5, and the simulated one is 4.07 (error: 9.55%).

Figure 4.4: Output of the mainframe simulation

By extending the code to iterate the execution of simulation 10,000 times,


mean error for Pw , W , and Wq can be obtained. Below are the modifications to the
code.
44

lamda = 60/120
mu = 60/90
L_q, L, W_q, W, P_w = ekspektasi(lamda, mu)

total_run = 10000
iterasi = 0

p_w_error = 0

w_error = 0
w_q_error = 0

while iterasi <= total_run:

l_q,l,w_q,w,p_w = antrian.simulasi(1,lamda,mu,5000)

p_w_error += abs(P_w - p_w)

w_error += abs(W - w)
w_q_error += abs(W_q - w_q)

iterasi += 1

p_w_error_avg = (p_w_error / total_run) / P_w


w_error_avg = (w_error / total_run) / W
w_q_error_avg = (w_q_error / total_run) / W_q

print(’Rerata error Pw :’, p_w_error_avg*100, ’%’)


print(’Rerata error W :’, w_error_avg*100, ’%’)
print(’Rerata error Wq :’, w_q_error_avg*100, ’%’)
45

The mean error for 10,000 executions of the simulation is 7.69% for Pw ,
12.76% for W , and 15.87% for Wq . An example of the result from the extended test
can be seen in figure 4.5.

Figure 4.5: Mean error for 10,000 executions of the simulation

4.4.2 Queueing Problem in Logistics

A furniture rental company owns a warehouse with a machine for loading and

unloading, operated by a group of 3 employee. From historical data, it is known


that 4 logistic trucks arrive in one hour, and the service facility can handle 6 trucks
in one hour. The head of the company is planning to increase the number of the
machine operator group. We are about to determine the number of group to be
added to achieve the lowest cost. The rent for a truck is US$20 per hour, and the
fee for an employee is US$6 per hour. It is assumed that if the company employs
2 groups, the service will be able to handle 12 trucks in one hour. If the company
employs 3 groups, then it is assumed that the service will be able to handle 18 trucks
46

in one hour.
As with the previous subsection, the expected and simulated cost will be
computed. The expected performance measurement is still computed by formula
2.12-2.16 in chapter 2, subsection 2.5. Below is the code that computes the expected
and simulated cost of the furniture rental company above.

import antrian
import numpy as np
import matplotlib.pyplot as plt

def ekspektasi(lamda, mu):


W_q = lamda / (mu * (mu - lamda))

W = 1 / (mu - lamda)

L_q = (lamda ** 2) / (mu * (mu - lamda))

L = lamda / (mu - lamda)


P_w = lamda / mu

return (L_q, L, W_q, W, P_w)

def autolabel(rects):

for rect in rects:


height = rect.get_height()
ax.text(rect.get_x()+rect.get_width()/2., 1.05*height,
’%d’%int(height), ha=’center’, va=’bottom’)

kelompok = 3
jamKerja = 8
47

biayaTruk = 20
biayaPekerja = 6
lamda = 4/60
mu = 6/60
L_ekspektasi = []
L_simulasi = []

for i in range(1, 4):

L_q, L, W_q, W, P_w = ekspektasi(lamda, i*mu)


L_ekspektasi.append(L)
L_q, L, W_q, W, P_w = antrian.simulasi(i, lamda,

i*mu, 5000)

L_simulasi.append(L)

biaya_ekspektasi = []

biaya_simulasi = []
for i in range(1, 4):

biaya = L_ekspektasi[i-1]*jamKerja*biayaTruk +

i*kelompok*biayaPekerja*jamKerja

biaya_ekspektasi.append(biaya)
biaya = L_simulasi[i-1]*jamKerja*biayaTruk +

i*kelompok*biayaPekerja*jamKerja
biaya_simulasi.append(biaya)

N = 3
b_eks = tuple(biaya_ekspektasi)
ind = np.arange(N)
48

width = 0.35
fig, ax = plt.subplots()
rects1 = ax.bar(ind, b_eks, width, color=’c’)
b_sim = tuple(biaya_simulasi)
rects2 = ax.bar(ind+width, b_sim, width, color=’b’)
ax.set_xlabel(’Jumlah kelompok’)

ax.set_ylabel(’Biaya (US$)’)

ax.set_title(’Perkiraan biaya: ekspektasi & hasil simulasi’)


ax.set_xticks(ind+width)
ax.set_xticklabels( (’1’, ’2’, ’3’) )

ax.legend( (rects1[0], rects2[0]),

(’Ekspektasi’, ’Simulasi’) )

autolabel(rects1)

autolabel(rects2)
plt.show()

Result of the logistic cost simulation can be seen in figure 4.6. For 1 group,

the expected cost is US$463, and the simulated one is US$545. For 2 groups, the
expected cost is US$368, and the simulated one is US$347. For 3 groups, the ex-
pected cost is US$477, and the simulated one is US$476. Based on the results, the
lowest cost is achieved by adding one more group of employee.
49

Figure 4.6: Output of the logistic cost simulation


Chapter V
CONCLUSION

5.1 Conclusion

A generic queueing systems simulation has been designed and implemented


in this work. The first step of the work is to decide what model suit the best
to be generic model. In this work, a multi channel single phase model is chosen

as the generic model, because of its ability in representing most of the problems

encountered in daily life.

The design phase begin with establishing what performance parameters are

going to be measured. For this generic queueing systems simulation, they are: mean
waiting time per customer, mean time in system per customer, mean number of

waiting customer in queue, mean number of waiting customer in the system, and

utilization of the queueing system.

After the performance parameters had been established, the design phase
continues with developing the simulation procedure. There are a total of 20 variables

used in the simulation procedure. The procedure itself rely on the common min()
function, to decide which server is chosen by the customer. By doing so, the customer

will always choose the idle or the closest-to-finish server. This is an optimal strategy
for the simulation.
Because security concern of random number is not taken into account for
the simulation, a simple and fast algorithm is chosen for this work. The chosen
algorithm is Lehmer random number generator, which is a kind of multiplicative
random number generator. The values for the variables used in Lehmer random
number generator, follows the one suggested by Park and Miller in 1988, and later

50
51

revised in 1993.
The simulation software is implemented using Python programming language.
The implementation follows the specification stated in chapter 3, about the input
process, simulation data-keeping mechanism, pseudo-random number generator, and
the output. Simulation data is stored to a CSV file, as convenient way for the user
to explore it at a later time.

Since the simulation procedure rely heavily on the min() function, it is hy-

pothesized that the runtime of the simulation depends on the length of the queue.
To confirm this, a performance test is done to see whether the growth of runtime is
linear to the growth of queue length. The test result confirmed this, and show that

the complexity of the algorithm is of class O(n) = n.

The simulation makes use of random numbers. It yields different result on

each run of simulation. The mean error for 10,000 executions of the simulation are

still large (> 5%). Therefore, there is still room for improvement to reduce the error
rate of the simulation.

5.2 Future Work

In the future, experiments by modifying the algorithm will be done to further


reduce the large error rate of the simulation. Also, a single and integrated simula-
tion environment based on the generic simulation system is to be developed. This
simulation environment can be used for solving various kind of queueing problems.
This single environment will may also have a graphical user interface to make it
easier to use, especially for the decision makers.
Bibliography

[1] January 2014, http://python.org/about/.

[2] January 2014, http://www.cplusplus.com/reference/random/minstd_rand/.

[3] S. Asmussen and O. Boxma, “Editorial introduction,” Queueing Systems,

vol. 63, no. 1-4, pp. 1–2, 2009.

[4] D. Gross, J. Shortle, J. Thompson, and C. Harris, Fundamentals of Queueing

Theory, 4th ed. John Wiley & Sons, 2008.

[5] F. Haight, Handbook of the Poisson Distribution. John Wiley & Sons, 1967.

[6] T. Kakiay, Dasar Teori Antrian untuk Kehidupan Nyata. Penerbit Andi, 2004.

[7] J. Kingman, “The first erlang century and the next,” Queueing Systems, vol. 63,
no. 1-4, pp. 1–2, 2009.

[8] S. Park and K. Miller, “Random number generators: Good ones are hard to
find,” Communications of the ACM, vol. 31, pp. 1192–1201, 1988.

[9] S. Park, K. Miller, and P. Stockmeyer, “Technical correspondence,” Communi-


cations of the ACM, vol. 36, pp. 105–110, 1993.

[10] W. Payne, J. Rabung, and T. Bogyo, “Coding the lehmer pseudo-random num-
ber generator,” Communications of the ACM, vol. 12, pp. 85–86, 1969.

[11] W. Press, S. Teukolsky, W. Vetterling, and B. Flannery, Numerical Recipes:


The Art of Scientific Computing, 3rd ed. Cambridge University Press, 2007.

[12] B. Sridadi, Pemodelan dan Simulasi Sistem. Penerbit Informatika, 2009.

52
APPENDIX

Code Listings
Listing 5.1: program/antrian.py

1 import csv
2 import math
3 import time
4
5 class Pelanggan :
6 def __init__ ( self , pelayan , waktuDatang , waktuMulai ,
lamaPelayanan ) :
7 self . pelayan = pelayan
8 self . waktuDatang = waktuDatang
9 self . waktuMulai = waktuMulai
10 self . lamaPelayanan = lamaPelayanan
11 self . waktuSelesai = self . waktuMulai + self . lamaPelayanan
12 self . lamaTunggu = self . waktuMulai - self . waktuDatang
13
14 def acak () :
15 global angkaAcak
16 a = 48271
17 m = (2 ** 31) - 1
18 angkaAcak = ( a * angkaAcak ) % m
19 return float ( angkaAcak ) / m
20
21 def acakEksponensial ( lamda ) :
22 return - math . log ( acak () ) / lamda
23
24 def mulaiSimulasi ( jumlahPelayan , lamda , mu , waktuSimulasi ) :
25 t = 0
26 daftarPelanggan = []
27 daftarPelayan = [0] * jumlahPelayan
28
29 global angkaAcak , rerataPanjangAntrian , rerataPanjangSistem ,
rerataLamaTunggu , rerataLamaSistem , utilisasi
30
31 try :
32 fileMasukan = open ( " input . txt " , " r " )
33 angkaAcak = int ( fileMasukan . readline () )
34 except IOError :
35 fileMasukan = open ( " input . txt " , " w " )
36 angkaAcak = int ( time . time () * 256)
37 fileMasukan . write ( str ( angkaAcak ) )
38 finally :
39 fileMasukan . close ()
40
41 while t < waktuSimulasi :

53
42 pelayan = daftarPelayan . index ( min ( daftarPelayan ) )
43 if len ( daftarPelanggan ) == 0:
44 waktuDatang = int ( math . ceil ( acakEksponensial ( lamda ) ) )
45 waktuMulai = waktuDatang
46 else :
47 waktuDatang += int ( math . ceil ( acakEksponensial ( lamda ) ) )
48 waktuMulai = max ( waktuDatang , daftarPelayan [ pelayan ])
49 lamaPelayanan = int ( math . ceil ( acakEksponensial ( mu ) ) )
50 daftarPelanggan . append ( Pelanggan ( pelayan +1 , waktuDatang ,
waktuMulai , lamaPelayanan ) )
51 daftarPelayan [ pelayan ] = waktuMulai + lamaPelayanan
52 t = waktuDatang
53
54 fileMasukan = open ( " input . txt " , " w " )
55 fileMasukan . truncate ()
56 fileMasukan . write ( str ( angkaAcak ) )
57 fileMasukan . close ()
58
59 waktuBerakhir = daftarPelanggan [ -1]. waktuSelesai
60
61 daftarLamaTunggu = [ pelanggan . lamaTunggu for pelanggan in
daftarPelanggan ]
62 rerataLamaTunggu = sum ( daftarLamaTunggu ) / len ( daftarLamaTunggu )
63 r er a t a P a n j a n g Antrian = sum ( daftarLamaTunggu ) / waktuBerakhir
64
65 daftarLamaSistem = [ pelanggan . lamaTunggu + pelanggan .
lamaPelayanan for pelanggan in daftarPelanggan ]
66 rerataLamaSistem = sum ( daftarLamaSistem ) / len ( daftarLamaSistem )
67 r erat a Pa n j an g S istem = sum ( daftarLamaSistem ) / waktuBerakhir
68
69 d afta r La m a Pe l a yanan = [ pelanggan . lamaPelayanan for pelanggan in
daftarPelanggan ]
70 utilisasi = sum ( daftarL amaP el ayan a n ) / waktuBerakhir
71
72 print ( ’ Hasil simulasi : ’)
73 print ()
74 print ( ’ Jumlah pelayan : ’ , jumlahPelayan )
75 print ( ’ Rerata panjang antrian : ’ ,
re r a t a P a n j a ngAntrian )
76 print ( ’ Rerata panjang antrian dalam sistem : ’ ,
r er a ta P a nj angSistem )
77 print ( ’ Rerata lama tunggu : ’ , rerataLamaTunggu )
78 print ( ’ Rerata lama dalam sistem : ’ , rerataLamaSistem )
79 print ( ’ Utilisasi sistem : ’ , utilisasi )
80 print ()
81
82 namaFile = ’ simulasi (% s ,% s ,% s ,% s ) . csv ’ % ( jumlahPelayan , lamda ,
mu , waktuSimulasi )
83 with open ( namaFile , ’w ’ , newline = ’ ’) as fileKeluaran :
84 keluaran = csv . writer ( fileKeluaran )

54
85 keluaran . writerow ([ ’ Pelanggan ’ , ’ Waktu datang ’ , ’ Lama tunggu ’ ,
’ Pelayan ’ , ’ Waktu mulai ’ , ’ Lama pelayanan ’ , ’ Waktu selesai ’
])
86 i = 0
87 for pelanggan in daftarPelanggan :
88 i += 1
89 baris = []
90 baris . append ( i )
91 baris . append ( pelanggan . waktuDatang )
92 baris . append ( pelanggan . lamaTunggu )
93 baris . append ( pelanggan . pelayan )
94 baris . append ( pelanggan . waktuMulai )
95 baris . append ( pelanggan . lamaPelayanan )
96 baris . append ( pelanggan . waktuSelesai )
97 keluaran . writerow ( baris )
98 fileKeluaran . close ()
99
100 print ( ’ Data simulasi tersedia dalam file : ’ , namaFile )
101
102 def simulasi ( jumlahPelayan , lamda , mu , waktuSimulasi ) :
103 global rerataPanjangAntrian , rerataPanjangSistem ,
rerataLamaTunggu , rerataLamaSistem , utilisasi
104 if isinstance ( jumlahPelayan , int ) and jumlahPelayan >= 1 and
lamda != 0 and mu != 0 and waktuSimulasi > 0:
105 waktuMulai = time . time ()
106 mulaiSimulasi ( jumlahPelayan , lamda , mu , waktuSimulasi )
107 print ( ’ Simulasi selesai dalam ’ , int ( round (( time . time () -
waktuMulai ) * 1000) ) , ’ milidetik \ n ’)
108 return ( rerataPanjangAntrian , rerataPanjangSistem ,
rerataLamaTunggu , rerataLamaSistem , utilisasi )
109 else :
110 print ( ’ Salah satu atau lebih parameter simulasi tidak valid . ’)
111 return

55
Listing 5.2: program/mainframe.py

1 import antrian
2
3 def ekspektasi ( lamda , mu ) :
4 W_q = lamda / ( mu * ( mu - lamda ) )
5 W = 1 / ( mu - lamda )
6 L_q = ( lamda ** 2) / ( mu * ( mu - lamda ) )
7 L = lamda / ( mu - lamda )
8 P_w = lamda / mu
9 print ( ’ Ekspektasi sistem : ’)
10 print ()
11 print ( ’ Rerata panjang antrian : ’ , L_q )
12 print ( ’ Rerata panjang antrian dalam sistem : ’ , L)
13 print ( ’ Rerata lama tunggu : ’ , W_q )
14 print ( ’ Rerata lama dalam sistem : ’ , W)
15 print ( ’ Utilisasi sistem : ’ , P_w )
16 print ()
17 return ( L_q , L , W_q , W , P_w )
18
19 lamda = 60/120
20 mu = 60/90
21 ekspektasi ( lamda , mu )
22 antrian . simulasi (1 , lamda , mu , 5000)

56
Listing 5.3: program/logistik.py

1 import antrian
2 import numpy as np
3 import matplotlib . pyplot as plt
4
5 def ekspektasi ( lamda , mu ) :
6 W_q = lamda / ( mu * ( mu - lamda ) )
7 W = 1 / ( mu - lamda )
8 L_q = ( lamda ** 2) / ( mu * ( mu - lamda ) )
9 L = lamda / ( mu - lamda )
10 P_w = lamda / mu
11 return ( L_q , L , W_q , W , P_w )
12
13 def autolabel ( rects ) :
14 for rect in rects :
15 height = rect . get_height ()
16 ax . text ( rect . get_x () + rect . get_width () /2. , 1.05* height , ’% d ’% int
( height ) , ha = ’ center ’ , va = ’ bottom ’)
17
18 kelompok = 3
19 jamKerja = 8
20 biayaTruk = 20
21 biayaPekerja = 6
22 lamda = 4/60
23 mu = 6/60
24 L_ekspektasi = []
25 L_simulasi = []
26 for i in range (1 , 4) :
27 L_q , L , W_q , W , P_w = ekspektasi ( lamda , i * mu )
28 L_ekspektasi . append ( L )
29 L_q , L , W_q , W , P_w = antrian . simulasi (i , lamda , i * mu , 5000)
30 L_simulasi . append ( L )
31 biaya_ekspektasi = []
32 biaya_simulasi = []
33 for i in range (1 , 4) :
34 biaya = L_ekspektasi [i -1]* jamKerja * biayaTruk + i * kelompok *
biayaPekerja * jamKerja
35 biaya_ekspektasi . append ( biaya )
36 biaya = L_simulasi [i -1]* jamKerja * biayaTruk + i * kelompok *
biayaPekerja * jamKerja
37 biaya_simulasi . append ( biaya )
38
39 N = 3
40 b_eks = tuple ( biaya_ekspektasi )
41 ind = np . arange ( N )
42 width = 0.35
43 fig , ax = plt . subplots ()
44 rects1 = ax . bar ( ind , b_eks , width , color = ’c ’)
45 b_sim = tuple ( biaya_simulasi )

57
46 rects2 = ax . bar ( ind + width , b_sim , width , color = ’b ’)
47 ax . set_xlabel ( ’ Jumlah kelompok ’)
48 ax . set_ylabel ( ’ Biaya ( US$ ) ’)
49 ax . set_title ( ’ Perkiraan biaya : ekspektasi & hasil simulasi ’)
50 ax . set_xticks ( ind + width )
51 ax . set_xticklabels ( ( ’1 ’ , ’2 ’ , ’3 ’) )
52 ax . legend ( ( rects1 [0] , rects2 [0]) , ( ’ Ekspektasi ’ , ’ Simulasi ’) )
53 autolabel ( rects1 )
54 autolabel ( rects2 )
55 plt . show ()

58

You might also like