Computer Simulation A Foundational Approach Using Python Yahya Esmail Osais download
Computer Simulation A Foundational Approach Using Python Yahya Esmail Osais download
https://ebookbell.com/product/computer-simulation-a-foundational-
approach-using-python-yahya-esmail-osais-20668778
https://ebookbell.com/product/computer-simulation-a-foundational-
approach-using-python-yahya-esmail-osais-56234846
https://ebookbell.com/product/computer-simulations-in-condensed-
matter-systems-from-materials-to-chemical-biology-mauro-ferrario-
giovanni-ciccotti-k-binder-ettore-majorana-foundation-and-centre-for-
scientific-culture-4099310
https://ebookbell.com/product/the-phenomena-of-argyll-stone-rows-
revealed-through-3d-computer-simulation-david-a-fisher-49984346
https://ebookbell.com/product/the-process-of-question-answering-a-
computer-simulation-of-cognition-wendy-g-lehnert-50448848
Handbook Of Computer Simulation In Radio Engineering Communications
And Radar 1st Sergey A Leonov
https://ebookbell.com/product/handbook-of-computer-simulation-in-
radio-engineering-communications-and-radar-1st-sergey-a-leonov-5479170
https://ebookbell.com/product/simulating-nature-a-philosophical-study-
of-computersimulation-uncertainties-and-their-role-in-climate-science-
and-policy-advice-2nd-arthur-c-petersen-4422206
https://ebookbell.com/product/simulating-nature-a-philosophical-study-
of-computersimulation-uncertainties-and-their-role-in-climate-science-
and-policy-advice-second-edition-2nd-edition-arthur-c-petersen-4748638
https://ebookbell.com/product/reliable-methods-for-computer-
simulation-error-control-and-a-posteriori-estimates-p-neittaanmki-and-
s-repin-eds-4425476
https://ebookbell.com/product/magneticallycontrolled-shunt-reactors-
historical-overview-operating-principles-computer-simulation-and-
return-of-experience-ga-evdokunin-50252346
Computer Simulation
A Foundational Approach Using Python
CHAPMAN & HALL/CRC
COMPUTER and INFORMATION SCIENCE SERIES
Series Editor: Sartaj Sahni
PUBLISHED TITLES
Yahya E. Osais
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
© 2018 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business
This book contains information obtained from authentic and highly regarded sources. Reasonable
efforts have been made to publish reliable data and information, but the author and publisher cannot
assume responsibility for the validity of all materials or the consequences of their use. The authors and
publishers have attempted to trace the copyright holders of all material reproduced in this publication
and apologize to copyright holders if permission to publish in this form has not been obtained. If any
copyright material has not been acknowledged please write and let us know so we may rectify in any
future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information
storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access
www.copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc.
(CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization
that provides licenses and registration for a variety of users. For organizations that have been granted
a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and
are used only for identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
To my wife, Asmahan,
and my daughters, Renad, Retal, and Remas.
Contents
List of Programs xv
Preface xxxi
Symbols xxxvii
Chapter 1 Introduction 3
1.1 THE PILLARS OF SCIENCE AND ENGINEERING 3
1.2 STUDYING THE QUEUEING PHENOMENON 4
1.3 WHAT IS SIMULATION? 5
1.4 LIFECYCLE OF A SIMULATION STUDY 6
1.5 ADVANTAGES AND LIMITATIONS OF SIMULATION 9
1.6 OVERVIEW OF THE BOOK 10
1.7 SUMMARY 11
ix
x Contents
2.2.2 Attributes 15
2.2.3 State Variables 16
2.2.4 Events 17
2.2.5 Activities 17
2.3 THE SINGLE-SERVER QUEUEING SYSTEM 18
2.4 STATE DIAGRAMS 22
2.5 ACTUAL TIME VERSUS SIMULATED TIME 23
2.6 SUMMARY 24
2.7 EXERCISES 24
Bibliography 271
Index 273
List of Programs
xv
xvi Contents
12.2 Computing unreliability for the graph in Figure 12.2 using crude
Monte Carlo simulation. 213
12.3 Computing unreliability for the graph in Figure 12.2 using strat-
ified sampling. 214
12.4 Computing unreliability for the graph in Figure 12.2 using an-
tithetic sampling. 215
12.5 Computing unreliability for the graph in Figure 12.2 using dag-
ger sampling. The number of samples is significantly less. 216
12.6 Python implementation of the event graph in Figure 12.4 220
12.7 Python implementation of the event graph of the simple stop-
and-wait ARQ protocol in Figure 12.8. 228
A.1.1 Starting a new Python interactive session. 235
A.1.2 Running a Python program from the command line. 236
A.1.3 A Python source file. It can also be referred to as a Python script. 236
A.2.1 Input and output functions. 237
A.3.1 Binary operations on integer numbers. 238
A.3.2 Handling unsigned binary numbers. 239
A.4.1 Lists and some of their operations. 239
A.5.1 Transposing a matrix using the zip function. Matrix is first un-
packed using the start (*) operator. 240
A.6.1 Importing the random module and calling some of the functions
inside it. 241
A.7.1 Implementing the event list using the queue module. 242
A.7.2 Implementing the event list using the hqueue module. 243
A.7.3 Implementing the event list by sorting a list. 243
A.8.1 The name of the function can be stored in a list and then used
to call the function. 244
A.8.2 The name of the function can be passed as an argument to
another function. 244
A.9.1 A tuple can be used as a record that represents an item in the
event list. 245
A.10.1 Code for generating Figure 4.12(b). 245
A.10.2 Code for generating Figure 10.6(a). 247
A.10.3 Code for generating Figure 10.6(b). 248
B.1 Event. 251
B.2 Simulation Entity. 252
B.3 Event list and scheduler. 252
B.4 Example 1. 254
xviii Contents
2.1 A mental image of the system and its behavior must be devel-
oped before a conceptual model can be constructed. 14
2.2 Different mental images can be developed for the same system.
They include different levels of details. Complexity increases as
you add more details. 14
2.3 A continuous state variable takes values from a continuous set
(e.g., [0, 5] in (a)). A discrete state variable, on the other hand,
takes values from a discrete set (e.g., {0, 1, 2, 3, 4, 5} in (b)). 16
2.4 Events are used to move dynamic entities through a system.
A packet is moved from a source to a destination through two
routers using eight events. 17
2.5 An activity is delimited by two events and lasts for a random
duration of time. 18
2.6 A queueing phenomenon emerges whenever there is a shared
resource and multiple users. 19
2.7 Conceptual model of the queueing situation in Figure 2.6. 20
2.8 A sample path of the state variable Q which represents the
number of persons in the single-server queueing system. Note
the difference in the time between every two consecutive arrival
events. 20
2.9 Four activities occur inside the single-server queueing system:
(a) Generation, (b) Waiting, (c) Service, and (d) Delay. The
length of each activity is a random variable of time. 21
xix
xx LIST OF FIGURES
2.10 A simple electrical circuit and its state diagram. Only the switch
and lamp are modeled. Events are generated by the switch to
change the state of the lamp. 22
2.11 State diagrams of the state variables associated with the queue
and server in the single-server queueing system in Figure 2.7. A
portion of the state space of the system is shown in (c). 23
4.1 Sample space for the random experiment of throwing two dice.
The outcome of the experiment is a random variable X ∈
{2, 3, ..., 12}. 40
4.2 The PMF of a discrete random variable representing the out-
come of the random experiment of throwing two dice. 41
4.3 The cumulative distribution function of a discrete random vari-
able representing the outcome of the random experiment of
throwing two dice. 42
4.4 Probability density function of a continuous random variable. 43
4.5 Elements of a histogram. Bins can be of different widths. Length
of a bar could represent frequency or relative frequency. 45
4.6 Histogram for an exponential data set. This figure is generated
using Listing 4.1. 46
4.7 The situation of observing four successes in a sequence of seven
Bernoulli trials can be modeled as a binomial random variable. 48
4.8 The PMF of the Poisson random variable for λ = 10. Notice
that P (x) approaches zero as x increases. 49
4.9 Probability distribution functions for the uniform random vari-
able where a = 3 and b = 10. 50
4.10 Probability distribution functions of the exponential random
variable where µ = 1.5. 53
LIST OF FIGURES xxi
7.8 Event graph for the single-server queueing system with reneging. 116
7.9 Event graph for the single-server queueing system with balking. 116
7.10 A template for synthesizing simulation programs from event
graphs. 121
7.11 Two parallel single-server queueing systems with one shared
traffic source. 122
7.12 A simple network setup where a user communicates with a server
in a data center over a communication channel created inside a
network. Propagation delay (Pd ) and rate (R) are two important
characteristics of a channel. 122
7.1 Event table for the event graph in Figure 7.4. 118
12.1 Sample space of the system in Figure 12.2 along with the status
of the network for each possible system state. 211
12.2 Restructuring the sample space of the system in Figure 12.2
along with the probability of each stratum. The first row indi-
cates the number of UP links. 212
12.3 State variables of the event graph in Figure 12.4. 219
xxvii
Foreword
xxix
Preface
xxxi
xxxii Preface
To the Reader
While writing this book, I had assumed that nothing is obvious. Hence, all
the necessary details that you may need are included in the book. However,
you can always skip ahead and return to what you skip if something is not
clear. Also, note that throughout this book, “he” is used to to refer to both
genders. I find the use of “he or she” disruptive and awkward. Finally, the
source code is deliberately inefficient and serves only as an illustration of the
mathematical calculation. Use it at your own risk.
Website
The author maintains a website for the book. The address is http:
//faculty.kfupm.edu.sa/coe/yosais/simbook. Presentations, pro-
grams, and other materials can be downloaded from this website. A code
repository is also available on Github at https://github.com/yosais/
Computer-Simulation-Book.
Acknowledgments
I would like to thank all the graduate students who took the course with
me while developing the material of the book between 2012 and 2017. Their
understanding and enthusiasm were very helpful.
I would also like to thank King Fahd University of Petroleum and Minerals
(KFUPM) for financially supporting the writing of this book through project
number BW151001.
Last but not least, I would like to thank my wife for her understanding
and extra patience.
Yahya Osais
Dhahran, Saudi Arabia
2017
About the Author
xxxiii
Abbreviations
RV Random Variable
CDF Cumulative Distribution Function
iCDF Inverse CDF
PDF Probability Distribution Function
PMF Probability Mass Function
BD Birth-Death
LFSR Linear Feedback Shift Registers
RNG Random Number Generator
RVG Random Variate Generator
REG Random Event Generator
IID Independent and Identically Distributed
xxxv
Symbols
Variable that are used only in specific chapters are explained directly at their
occurrence and are not mentioned here.
µ Population Mean
σ2 Population Variance
σ Population Standard Deviation
x̄ Sample Mean
s2 Sample Variance
s Sample Standard Deviation
xxxvii
I
The Fundamentals
CHAPTER 1
Introduction
3
4 Computer Simulation: A Foundational Approach Using Python
E
O C
Figure 1.1
The three pillars of science and engineering: Observation (O), Experimenta-
tion (E), and Computation (C). By analogy, the table needs the three legs to
stay up.
Figure 1.2
A queue at a checkout counter in a supermarket. A phenomenon arising when-
ever there is a shared resource (i.e., the cashier) and multiple users (i.e., the
shoppers).
Mathematical Theoretical
Model Data
Simulation
Simulation
(Synthetic)
Model
Data
Measurements
Physical Model
(Actual Data)
Figure 1.3
Types of models and the data generated from them.
1 2 3
Formal
Problem System Model Description
6 5 4
Performance Statistical Computer
Summary Analysis Program
Figure 1.4
Phases of a simulation study.
the elements of a simulation study. More about this will be said in the next
section.
The model is a conceptual representation of the system. It represents a
modeler’s understanding of the system and how it works. A computer is used
to execute the model. Therefore, the model must first be translated into a
computer program using a programming language like Python.2 The execution
of the computer program results in the raw data.
The raw data is also referred to as simulation data. It is synthetic because it
is not actual data. Actual data is collected from a physical model of the system.
There is another type of data called theoretical data which is generated from
a mathematical model of the system. Figure 1.3 shows these types of models
and the types of data generated from them.
Table 1.1
Description of the phases of a simulation study of the system in Figure 1.2.
1. There is no need to build the physical system under study and then
observe it. Thus, knowledge about the behavior of the system can be
acquired with a minimum cost.
2. Critical scenarios can be investigated through simulation with less cost
and no risk.
1.7 SUMMARY
Simulation is a tool that can be used for performing scientific studies. It may
not be the first choice. But, it is definitely the last resort if a physical or
mathematical model of the system under study cannot be constructed. The
main challenge in simulation is developing a sound model of the system and
translating this model to an efficient computer program. In this book, you will
learn the skills that will help you to overcome this challenge.
Other documents randomly have
different content
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com