Preface :
A simulation creates a model of a real-world situation so that we can better understand it. The simulation uses computer objects with methods that model real-world objects and their behaviors. One very popular type of simulation is an event-driven simulation that uses a minimum priority queue to process events that occur over time. The priority queue consists of different types of event objects that are time-stamped to indicate when they are to occur. The simulation identifies an event, notes its time and circumstances, and adds it to the priority queue. Often, the occurrence of an event triggers other related and subsequent events which are added to the queue. The simulation runs by repeated removing and analyzing the next (earliest time) event from the priority queue until the queue is empty of a specified length of time elapses. The simulation provides a progression of discrete events that highlight the key activities in the real world situation.
In the following sections, we will present design principles for all event-driven simulations and use a bank simulation as the example. Code segments that declare variables and implement key methods will aid our discussion.
A Bank Simulation :
In this section, we will describe a bank simulation that looks at the flow of customers through a bank as they are served by a group of tellers. In the process, we will measure the efficiency of service by computing the average waiting time of each customer and the percentage of time each teller is busy. Instead of collecting actual customer data, we introduce probabilistic values that describe different expected arrival rates for customers and different expected service times for a teller to handle a customer. We use a random number generator to mirror the arrival and departure of customers during a bank day. The simulation allows us to introduce new parameters and thus measure the relative effect on service if we change customer or teller behavior. For instance, suppose the bank estimates that a gift promotion would increase customer traffic by 20%. A simulation study would increase the expected arrival rate and measure the effect on waiting times and teller utilization. The result may indicate that customers experience unacceptable wait times, creating dissatisfaction that would diminish the effect of the promotion. The bank could repeat the simulation with additional tellers until reasonable wait times are established.
The bank simulation produces arrival, service and departure events for each customer. Associated variables maintain an ongoing record of service time that each teller is committed to provide customers that are already in the bank. When a customer enters, the simulation creates an arrival event(A) that marks the time. This event spawns a service event(S) indicating when the customer reaches a teller. The time for the service event depends on prior teller commitments. If a teller is free, service begins immediately. Otherwise, the simulation must evaluate the backlogged service times for each teller and select the minimal value. In effect, the value represents the first time a teller is free. The interval between arrival time and service time denotes waiting time for the customer. The service event spawns a departure event that takes into account the time required by the teller to handle the customer. The service time becomes a further commitment for the teller and is used to update the backlogged service time for the teller, which could affect waiting times for subsequent customers.
Below figure looks at four customers who enter a bank that employs two tellers. A time line lays out times for events from the start of the simulation, measured in minutes. The line segments above the timeline detail the events for each customer. The line segments below the timeline track service provided by each teller.
Simulation Design Pattern :
The key components of a simulation are events. These objects are instances of different types of activities and behaviors that occur in the simulation. The object type for the different events are part of an inheritance hierarchy that defines Event as a superclass. The Event class includes a single integer time, which denotes when the event occurs. An abstract method doEvent() is included for polymorphism. The method is overwritten in each subclass to carry out our tasks each time a specific event occurs. The Event superclass implements the Comparable interface by having compareTo() compare the relative times when two events occur. This allows the simulation to store events in a minimum priority queue. The simulation runs by extracting events from the priority queue in order of their times. The simulation is thus like a compressed video recording of a day's activities in which successive frames in the video are the events :
In our example, the inheritance hierarchy includes the Event superclass and subclasses for ArrivalEvent, ServiceEvent and DepartureEvent.
The actual running of the simulation is handled by an EventDrivenSimulation class, which provides a priority queue of Event references. The class features the method pushEvent(), which inserts a new event in the priority queue and the method run() which proceeds to empty the queue in a progressive time sequence of events. Each event that is popped from the queue is processed using doEvent().
BankSimulation Class :
The BankSimulation class drives the bank simulation. By extending EventDrivenSimulation, it has access to the priority queue and the method run() in the superclass that processes events in a time sequence. BankSimulation defines user-supplied parameters that specify the length of the simulation, the number of tellers and the range (high-low) for expected arrival times and service times. The class defines variables that are updated during execution; for instance, number of customers and total wait time. It also supplies supporting variables such as a random number generator and an array of Teller objects. The method startSimulation() inputs parameters for the simulation and creates and stores events in the priority queue(Here is hard code). It then calls run() to execute the simulation and concludes by displaying a summary of the results :
For whole source code, please refer to attachment(Including three event class). The execution result just like below :
This is a blog to track what I had learned and share knowledge with all who can take advantage of them
標籤
- [ 英文學習 ]
- [ 計算機概論 ]
- [ 深入雲計算 ]
- [ 雜七雜八 ]
- [ Algorithm in Java ]
- [ Data Structures with Java ]
- [ IR Class ]
- [ Java 文章收集 ]
- [ Java 代碼範本 ]
- [ Java 套件 ]
- [ JVM 應用 ]
- [ LFD Note ]
- [ MangoDB ]
- [ Math CC ]
- [ MongoDB ]
- [ MySQL 小學堂 ]
- [ Python 考題 ]
- [ Python 常見問題 ]
- [ Python 範例代碼 ]
- [心得扎記]
- [網路教學]
- [C 常見考題]
- [C 範例代碼]
- [C/C++ 範例代碼]
- [Intro Alg]
- [Java 代碼範本]
- [Java 套件]
- [Linux 小技巧]
- [Linux 小學堂]
- [Linux 命令]
- [ML In Action]
- [ML]
- [MLP]
- [Postgres]
- [Python 學習筆記]
- [Quick Python]
- [Software Engineering]
- [The python tutorial]
- 工具收集
- 設計模式
- 資料結構
- ActiveMQ In Action
- AI
- Algorithm
- Android
- Ansible
- AWS
- Big Data 研究
- C/C++
- C++
- CCDH
- CI/CD
- Coursera
- Database
- DB
- Design Pattern
- Device Driver Programming
- Docker
- Docker 工具
- Docker Practice
- Eclipse
- English Writing
- ExtJS 3.x
- FP
- Fraud Prevention
- FreeBSD
- GCC
- Git
- Git Pro
- GNU
- Golang
- Gradle
- Groovy
- Hadoop
- Hadoop. Hadoop Ecosystem
- Java
- Java Framework
- Java UI
- JavaIDE
- JavaScript
- Jenkins
- JFreeChart
- Kaggle
- Kali/Metasploit
- Keras
- KVM
- Learn Spark
- LeetCode
- Linux
- Lucene
- Math
- ML
- ML Udemy
- Mockito
- MPI
- Nachos
- Network
- NLP
- node js
- OO
- OpenCL
- OpenMP
- OSC
- OSGi
- Pandas
- Perl
- PostgreSQL
- Py DS
- Python
- Python 自製工具
- Python Std Library
- Python tools
- QEMU
- R
- Real Python
- RIA
- RTC
- Ruby
- Ruby Packages
- Scala
- ScalaIA
- SQLAlchemy
- TensorFlow
- Tools
- UML
- Unix
- Verilog
- Vmware
- Windows 技巧
- wxPython
訂閱:
張貼留言 (Atom)
[Git 常見問題] error: The following untracked working tree files would be overwritten by merge
Source From Here 方案1: // x -----删除忽略文件已经对 git 来说不识别的文件 // d -----删除未被添加到 git 的路径中的文件 // f -----强制运行 # git clean -d -fx 方案2: 今天在服务器上 gi...
-
前言 : 為什麼程序管理這麼重要呢?這是因為: * 首先,本章一開始就談到的,我們在操作系統時的各項工作其實都是經過某個 PID 來達成的 (包括你的 bash 環境), 因此,能不能進行某項工作,就與該程序的權限有關了。 * 再來,如果您的 Linux 系統是個...
-
屬性 : 系統相關 - 檔案與目錄 語法 : du [參數] [檔案] 參數 | 功能 -a | 顯示目錄中個別檔案的大小 -b | 以bytes為單位顯示 -c | 顯示個別檔案大小與總和 -D | 顯示符號鏈結的來源檔大小 -h | Hum...
-
來源自 這裡 說明 : split 是 Perl 中非常有用的函式之一,它可以將一個字串分割並將之置於陣列中。若無特別的指定,該函式亦使用 RE 與 $_ 變數 語法 : * split /PATTERN/,EXPR,LIMIT * split /...
作者已經移除這則留言。
回覆刪除作者已經移除這則留言。
回覆刪除