Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
GPSS
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Barber Shop === The following example, taken from ''Simulation using GPSS'',<ref>{{cite book|last=Schriber|first=Thomas|author-link=Thomas J. Schriber|title=Simulation using GPSS|year=1974|publisher=Wiley|isbn=978-0-471-76310-9}}</ref> is the "Hello world!" of GPSS and will illustrate the main concepts. The aim is to simulate one day of operation of a barber shop. Customers arrive in a random constant flow, enter the shop, queue if the barber is busy, get their hair cut on a first-come first-served basis, and then leave the shop. We wish to know the average and maximum waiting line, as well as the number of customers. <pre style="font-size:80%;">SIMULATE ; Define model * * Model segment 1 * GENERATE 18,6 ; Customer arrive every 18Β±6 mn QUEUE Chairs ; Enter the line SEIZE Joe ; Capture the barber DEPART Chairs ; Leave the line ADVANCE 16,4 ; Get a hair cut in 16Β±4 mn RELEASE Joe ; Free the barber TERMINATE ; Leave the shop * * Model segment 2 * GENERATE 480 ; Timer arrives at time = 480 mn TERMINATE 1 ; Shut off the run * * Control cards * START 1 ; Start one run END ; End model</pre> The "program" is comprised between the <code>SIMULATE</code> and <code>END</code> statements, and is divided into "model segments" and "control cards". The first segment models customers. The <code>GENERATE</code> block creates a flow of Transactions and schedules them to enter the model with an inter-arrival time uniformly distributed over the range 18Β±6. It is the programmer's responsibility to interpret these transaction as customers and to understand that the time is to be counted in minutes. The Transactions start their existence in the <code>GENERATE</code> block and progress from Block to Block, according to certain rules, until they reach a <code>TERMINATE</code> which remove them from the model. Normally transactions progress from one block to the next one, so the customer transactions will leave the <code>GENERATE</code> block to enter the <code>QUEUE Chairs</code> block. This block simulates a waiting line, and collects statistics accordingly. In the example, it materializes a line of chairs and, at the end of the simulation, we will know, among other things, the maximum queue size (how many chairs are needed) and the average waiting time. The <code>QUEUE</code> block requires the name of the queue as a parameter, because more than one queue may exist in the model. Each one is associated with a <code>DEPART</code> block, which is triggered when the transaction leaves the queue. GPSS remembers which transactions are in the queue, so that it is possible to know the average time spent, and to check that no buggy transaction is leaving a queue without previously entering in it. After the <code>QUEUE chairs</code> block, the transaction will try to proceed to the <code>SEIZE Joe</code> block, a block simulating the capture of the ''Facility'' named Joe. Facilities model single servers of capacity one. If the facility is busy, the <code>SEIZE</code> will deny the attempting transaction the right to enter. In the example, the customer will wait in the <code>QUEUE</code> block. If it is free, or as soon as it becomes available, the transaction will be allowed to capture the facility, mark it as busy to other transactions and start to count the service time and other statistics, until the same transaction reaches the corresponding <code>RELEASE Joe</code> block. The <code>SEIZE</code> / <code>RELEASE</code> pairs are linked by the facility name, because many independent facilities may exist in the model. They can model operators, like a barber, a repairman, an agent, but also pieces of equipment, like a crane, a gas station, an authorization document, etc., in fact anything with capacity one. To simulate multiple parallel servers, like a team of five barbers, or an oven with a capacity of 10, GPSS uses another entity named <code>STORAGE</code>. After a customer seizes Joe, it proceeds to the next statement which is <code>ADVANCE 16,4</CODE>, whose task is to freeze the entity for a prescribed length of time. Here, a random number between 16-4=12 and 16+4=20mn is picked. Other service time distributions are available through GPSS <code>FUNCTION</code>. During that time, other transactions will be allowed to move through the model, blocking some other facilities that may exist in the model, but not Joe because this facility is busy with the frozen customer. After the prescribed time, the customer will wake up, proceed to the next statement, which will free Joe, and <code>TERMINATE</code>. The following transaction on the previous block, which is a customer sitting on a chair, will be able to <code>SEIZE Joe</code>. To select the "next" transaction, GPSS uses the first-come first-served basis, with priority. Other selection policies can be programmed by direct manipulation of the ''future event chain'' entity. In parallel to this first segment, simulating the customer behavior, a second model segment simulates the end of the day. At time 480mn = 8h an entity is <code>GENERATE</code>d, which will <code>TERMINATE</code> on the next block. This time, the <code>TERMINATE</code> has parameter 1, meaning a special counter is decreased by 1. When that counter reaches 0, the program stops and the output is printed. This special counter is set up with the <code>START</code> statement. In the example, it is set to one, thus the simulation will finish after one run of 480 mn in simulated time. The output contains: <pre style="font-size:80%;"> FACILITY AVERAGE NUMBER AVERAGE SEIZING PREEMPTING UTILIZATION ENTRIES TIME/TRAN TRANS. NO. TRANS. NO. Joe .860 26 15.884 26 QUEUE MAXIMUM AVERAGE TOTAL ZERO PERCENT AVERAGE $AVERAGE TABLE CURRENT CONTENTS CONTENT ENTRIES ENTRIES ZEROS TIME/TRANS TIME/TRANS NUMBER CONTENTS Chairs 1 .160 27 12 44.4 2.851 5.133 1 $AVERAGE TIME/TRANS = AVERAGE TIME/TRANS EXCLUDING ZERO ENTITIES</pre> It indicates that Joe was busy 86.0% of the time, gave a hair cut to 26 customers and that hair cut took 15.88 minutes on the average. Incidentally, Joe was cutting the hair of customer number 26 when the simulation was closed. No programming provisions were taken for the barber to finish the hair cut before closing the shop. It indicates also that a maximum of 1 customer was observed waiting his turn, in fact the number of waiting customer was on the average 0.160. A total of 27 customers did enter the queue, so that customer number 27 was still sitting, waiting his turn, when Joe closed the shop. Out of these 27 customers, 12 were served without having to wait. In fact, the queue was empty 44.4% of the time. The average waiting time was 2.851 min, and the average waiting time for the 15=27-12 customers who did really wait was 5.133 min.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)