GPSS-WORLD fundamentals of simulation using live examples

  • Tutorial
Good Friday dear readers of Habr.
In this post, I invite you to quickly familiarize yourself with the possibility of creating a simulation model of processes in the GPSS-WORLD program. This post can not be considered a full-fledged tutorial, but I will share with you those grains that I know and it is quite possible that within half an hour after reading the article you will have the imagination to create your own simulation model. As the people say: "It is difficult to learn easily in battle."
And in some places, this “tutorial” adheres to the principle: “the beaten one isn’t lucky,” but I will still bring to you the knowledge that I have, but you yourself are free to decide whether to trust me or better to check. In any case, I will be happy to audit the code from GPSS-WORLD experts. All article materials posted on GItHub
We will learn the basics right away with live examples - accessible, understandable and close to the heart of many employees spending their legal 8 hours in offices.
We’ll move on from the specifics to the lyrics, Friday traditionally has crazy questions to ask, and this time my colleague DrZugrik and I asked ourselves: “How many support workers do you need to tell me how to screw in a light bulb?”
For details of this thought experiment, I ask under cat.

Writing this mini tutorial along with model development took 6 hours of pure time.
I would be grateful if the article reached potentially interested readers.


In order to avoid causing negative emotions, the original picture was replaced by a cat with a pipe and hidden under a spoiler.

initial illustration





First, we need GPSS-World itself .

We will use the free version for students.
Also, when learning a language of simulation, a textbook will be useful.
You can take this one .
In my opinion, not very affordable, but better than nothing.

So we stocked up the necessary tools, now it remains to connect the imagination and come up with the first model.
I can not be called the guru of simulation in general and GPSS-World in particular, the materials from this book served as a basis for the examples presented here . But I think that the compiled models have the right to life.
Let us first consider this case.
Given:
An office in which 10 employees work, Cooler at the end of the corridor to which "bark 4 minutes", employees who want to drink tea and make a trip to the cooler once an hour. The filling time for the bowl with a bag of life-giving moisture is approximately 2 minutes. The working day is 480 minutes (8 hours without a lunch break, so to speak)
Determine:
The coefficient of use of the cooler by the office staff.
Create a simulation model

	GENERATE	,,,10		; 1  Amount office staff
	ADVANCE	4,0.8		; 2  Time to reach the cooler	 
DRINK	QUEUE	STAND	       ; 3  Queue to the cooler. input	
	SEIZE	COOLER	       ; 4  Verification of employment cooler
	DEPART	STAND		; 5  Queue to the cooler. output
	ADVANCE	2,0.8		; 6  Filling the cup with boiling water
	RELEASE	COOLER		; 7  leave the cooler
	ADVANCE	60,10		; 8  Time for tea, time to work, time to get back to the cooler				
	TRANSFER	,DRINK		; 9  Go back to the cooler
	GENERATE	480		; 10 Working day (minutes)
	TERMINATE	1		; 11 Minus one minute
	START	1		; 12 Start from the first minute


Since I left comments in my broken English, I certainly see the point in detail telling about the functioning of the model.
Line 1 - GENERATE ,,, 10 - the GENERATE block itself sets us the number of incoming requirements (in this case, office employees), a record of operators of the form ,,, 10 tells us that the first three parameters are missing, and the fourth parameter indicates the maximum number of incoming requirements. GENERATE block. You can set with other parameters, but I will talk about this a little later.
As you guessed ";" - Separates the comment field. A little more about the design structure of the code, the code is read from left to right, there are several blocks that it is desirable to separate by tabs. The leftmost block is a label (similar to a label in other programming languages), then the block itself (for example generate) then its parameters usually go, then comments. Once upon a time we were taught to separate these blocks by tabulation, but this is more a matter of aesthetics. 1 space seems also enough that everything would start. By the way, where everything is written in BIG letters, it is better to write like that, otherwise an execution error may fly out.
Line 2 - ADVANCE 4.0.8; He is responsible for the temporal characteristics of the process, so that it is more understandable in this case, this means that the employee goes to the cooler for 4 minutes ± 0.4 minutes.
Thus, the first digit means the units of time (iteration) spent, the second digit means half the deviation up or down, the books say that the deviation value is generated randomly, maybe it is, but every restart the system gives the same values ​​(I don’t know maybe there is an analogue of randomize from the good old Pascal, but I did not find it). The ADVANCE block can also be set with other values, but more on that later.
Line 3 - DRINK QUEUE STAND; - here we meet our first label DRINK, followed by the QUEUE block, which creates a queue in this queue, we will get everyone who goes to the cooler to wet his throat. STAND - let's say the queue identifier.
Line 4 - SEIZE COOLER - the SEIZE block determines whether our device is free, in this case the device identifier is COOLER (well, or simply a cooler).
Line 5 DEPART STAND - if the last block gave us a positive result (cooler free), then the next DEPART block is triggered, which ensures that the person leaves the STAND queue.
Line 6 - ADVANCE 2.0.8 a person who has left the line will pour about 2 minutes of boiling water into his mug (well, plus he will have time to chat with people in line to the cooler)
Line 7 - RELEASE COOLER, having done his “wet” business, the person will free the device COOLER, for the next afflicted.
Line 8 - ADVANCE 60.10 - this block takes into account the time. Which a person who drank water will take the effort to gather strength and come to the cooler again (at least I hope that this is simulated).
Line 9 - TRANSFER, DRINK - “And everything will repeat as before,” A. Block would say if he were familiar with programming. This operator provides a transition to the DRINK label.
Line 10 - GENERATE 480 it would seem, from the programming point of view, after going to the label in the last block, everything that lies below does not make sense, but it’s not. (Why not, to be honest, I didn’t really go deep, but judging by the experience and the drop-down to errors, this piece is perceived a bit outside the context of the previous 8 blocks). The main thing is that this unit sets us the runtime of the entire model, namely 480 minutes (8 hours)
Line 11 - TERMINATE 1 - This side subtracts one from each iteration counter. Without this block, you can go into an endless loop.
Line 12 - START 1 - Tells the program where to start the cycle, we start from the first minute.

Uh, well, we are done with the description of the first model.
Who cares about the results, I ask for a spoiler. If you like to check everything yourself, then once again I will remind all the models posted on GItHub

Results Model 1 - cooler utilization


analyze the results
So we see that on average our cooler is loaded by 33%, that is, in our team of 10 employees it turns out approximately as if the Administrator Peter, Marya Vasilyevna from accounting and the Project manager Vasily Chufirkin constantly applied to it, well 0.33 people, or for example - a cat. In fact, this block of text does not carry a semantic load, I just really wanted to draw a cat and a cooler and Marya Vasilievna from accounting (everyone except the cat is a purely invented person)



Although damn it after I read this , I can safely say that the cooler could drink 12 cute cats =)



But back to the topic.



Let's look at the results of the issuance.

Facility is a list of all our working devices, in this case only a cooler.
Entries 79 - means the number of service approaches to the device, in this case the number of people with empty cups was 79 - for the entire shift.
Util is the utilization rate of the equipment. It tells us that the cooler was idle (1-0.33) * 100% = 67% of the whole time.
AVE TIME - average usage time of a cooler by 1 person 2.002 minutes
AVAIL. - The availability of the cooler, I don’t know what it means, apparently the unit says it is available
DELAY = 0 - it tells us that the number of people who just came up to the cooler, were upset and left empty-handed (a mug), is zero.

Now let's move to our queue (QUEUE)
As you can see, the name of the queue we created earlier is indicated here,
in which there were a maximum of 9 people, in which there were 79 entrances, and 48 zero entrances (most likely the entrances were without waiting in the queue), the average time spent by a person in the queue was 1.5 minutes. Cont. = 0 tells us that at the end of the simulation no one was in the queue.

Well, it seems that everything is not bad, but what will happen if we return to the full
year 2006 and hire 30 more employees to our office?

results Model 1 - cooler utilization rate for 40 employees




As you can see from the model, our cooler will almost stop idle, and the average time in the queue will be as much as 20 minutes, which suggests that either we need a second cooler, or that it is time to deprive everyone of the bonus for long tea parties.
Maybe this model is rustic, but even it, with the manifestation of some imagination, allows us to estimate the number of coolers that is needed on the floor.
But at the moment we are not yet able to develop multichannel service models. So let’s kill two birds with one stone, learn multi-channel service and at the same time answer the questions that my colleague and I asked at the very beginning of the article. (whoever is attentive and remembers - well done, that happiness of kindness and a hangover-free weekend:)

When creating the model, call center operators and subscribers, we ask ourselves such conditions
Given:
2 technical support operators serve users who call at regular intervals every two minutes, if one operator is busy picking up another. The working day is 480 minutes (8 hours without a lunch break, so to speak)
Define:
The load factor of support staff.

HELPDESK        STORAGE       2	        			 ;1   Number of operators helpdesk
**************************************************************************************************
	GENERATE        6,3					 ;2   The number of subscribers Ticket
	ADVANCE         (Exponential(1,0,2)),,			 ;3   during dialing
          ENTER            HELPDESK              			 ;4   incoming call
	TRANSFER         ALL,OPR1,OPR2,3       			 ;5   definition of operator availability
OPR1      SEIZE            OP1                               ;6   Verification of employment operator number 1
	ASSIGN          1,OP1                              ;7   If the operator is free in this case, accept a call
	TRANSFER        ,COME                              ;8   Jump to the process of service
OPR2      SEIZE            OP2                               ;9   Verification of employment operator number 1.
	ASSIGN          1,OP2                              ;10  If the operator is free in this case, accept a call
COME      LEAVE            HELPDESK                          ;11  Beginning the process of providing technical support
	ADVANCE         10,8              			 ;12  Service time
	RELEASE          P1                                ;13  The release of the operator
	TERMINATE       0                      			 ;14  Removes the Active Transaction from the simulation
	GENERATE        480                                ;15  Working day (minutes)
	TERMINATE       1                                  ;16  Minus one minute
	    START           1                                  	 ;17  Start from the first minute


As the last time I will describe line by line

Line 1 - HELPDESK STORAGE 2 - Create a drive Support service with a capacity of 2 employees
Line 2 - GENERATE 6.3; here we come to a different way of generating the block task, in this case the number 6 means that about 1 call rings every 6 times, the number 3 means that deviations from six minutes are ± 1.5 minutes. You could also set the GENERATE block like this
(Exponential (1,0,6)), in general, what is true for ADVANCE is also true for GENERATE in many ways.
Line 3 - ADVANCE (Exponential (1,0,2)) ,, - tells us how long it takes for the caller to remember the support telephone number and dial the number, and it takes us 2 minutes on an exponential distribution on average. digit 1 - selects a random number generator (from 1-7 I have not figured out how to work with them), digit 0 - determines the offset (for me it is also a mystery), digit 2 is actually minutes. I want to add that there are other distribution laws by which you can set the time period, but it is better to read about them in the textbook. Which I indicated at the beginning of the article.
Line 4 - ENTER HELPDESK - enter the drive (incoming call)
Line 5 - TRANSFER ALL, OPR1, OPR2,3 - tells us that this event is processed for all incoming calls (ALL), that the processing operators start with the label OPR1 and move in increments of 3 blocks until they reach the label OPR2
Line 6 - OPR1 SEIZE OP1 - this is our first label, on which the occupancy check of the first support service operator (OP1) is checked.
Line 7 - ASSIGN 1, OP1 - In case operator 1 is free. Then we pass the incoming call to him, if not then after three lines (from the 6th) we go to line 9
Line 8 - TRANSFER, COME - there is no need to find out about the busyness of the second operator, go to the label COME
Line 9 OPR2 SEIZE OP2 - if the first the operator was busy, we check the second
Line 10 - - ASSIGN 1, OP2 - and give the call to him.
Line 11 - COME LEAVE HELPDESK - the call leaves the drive for support services.
Line 12 - ADVANCE 10.8 - the time that the operator spends on giving the person advice on how to properly screw in the light bulb.
Line 13 - RELEASE P1; - the operator helped the man and freed himself. P1 in this case is a reference to a certain pointer (or parameter), I cannot explain this moment, but it works.
Line 14 - TERMINATE - (zero can not be written by default, and so zero), if you believe the help, in this case this block will tell the system that it is time to remove this iteration from the active loop and move on to the next. In any case, without it, the system will give us an error.
Lines 15-17 are similar to the lines of the first model.

As a result, we obtain the following data

results Model 2 - utilization rate of operators



The output structure is similar to the output structure of the first model, except that instead of the queue, the drive suggests you to deal with it yourself. By the way, the report generation parameters can be configured (I don’t have GPSS installed on this computer and I don’t want to install it, so take my word for now that the program settings have such an opportunity, well, if I don’t forget, I’ll add here on Monday how to do this)
So, we see that our operators are quite acceptable at about 75% and 87% respectively. We assume that two operators are quite enough to advise people how to properly screw in a light bulb. But you and I are a curious people, let's see what happens if you add another parasite with a phone to the guys.
To do this, consider a slightly modified model. I suggest you deal with it yourself.

HELPDESK        STORAGE       3	        			 ;1   Number of operators helpdesk
**************************************************************************************************
	GENERATE        6,3					 ;2   The number of subscribers Ticket
	ADVANCE         (Exponential(1,0,2)),,			 ;3   during dialing
          ENTER            HELPDESK              			 ;4   incoming call
	TRANSFER         ALL,OPR1,OPR3,3       			 ;5   definition of operator availability
OPR1      SEIZE            OP1                               ;6   Verification of employment operator number 1
	ASSIGN          1,OP1                              ;7   If the operator is free in this case, accept a call
	TRANSFER        ,COME                              ;8   Jump to the process of service
	SEIZE            OP2                               ;9   Verification of employment operator number 1.
	ASSIGN          1,OP2                              ;10   If the operator is free in this case, accept a call
	TRANSFER        ,COME                              ;11   Jump to the process of service
OPR3      SEIZE            OP3                               ;12   Verification of employment operator number 1.
	ASSIGN          1,OP3                              ;13  If the operator is free in this case, accept a call
COME      LEAVE            HELPDESK                          ;14  Beginning the process of providing technical support
	ADVANCE         10,8              			 ;15  Service time
	RELEASE          P1                                ;16  The release of the operator
	TERMINATE       0                      			 ;17  Removes the Active Transaction from the simulation
	GENERATE        480                                ;18  Working day (minutes)
	TERMINATE       1                                  ;19  Minus one minute
	START           1                                  ;20  Start from the first minute


Result under the spoiler

Results Model 2 - utilization rate of three operators



So, in the end, we see that we obviously do not need the third operator and we can safely go and remove the vacancy, and with it all the candidates.

Lastly, I want to tell you that GPSS-WORLD provides more extensive modeling capabilities than those that I told you about. Just because of the limitations of my knowledge, I can’t adequately demonstrate them to you. But, nevertheless, as a bonus, I will give an example of working with variables

	INITIAL X$APPLES,3		;1 Set Variable
	GENERATE	1		;2 set count of cicles
	SAVEVALUE APPLES-,1		;3 set APPLES=APPLES-1
	TERMINATE 1		;4 delete one iteration
	START	1		;5 1 Start from the first cicle


Let's line by line again

Line 1 - INITIAL X $ APPLES, 3; 1 set the value of the variable, X $ in this case somehow indicates the name of the variable, and the number three is the value that we will write to the APPLES variable (by the way, I'm not a fan of APPLE products it’s just that at that moment 3 apples were lying on the general table, and I took one for myself, just like in kindergarten problems in mathematics)
Line - 2 GENERATE 1 - create 1 iteration
Line 3 - SAVEVALUE APPLES-, 1; - save the variable apples its value minus one.
Lines 4-5 will help us finish the program.

Model 3 results - variables



To be honest, despite the fact that this example works and the unit is really subtracted from the variable, I don’t understand the full mechanism of working with variables, so I will leave it to the professionals.

Well, now what do you know about one of the tools with the help of which you can create a simulation model of the process, the tool is not the most convenient and it seems that it is not yet developed by the developers, but nevertheless, if you show imagination, you can conduct some research in one two days models and for example publish it in a scientific journal or at a conference (I already wrote about this before )
In any case, now you have 1 more tool to create, develop and make the world a better place. The right word is more interesting than popping a balloon on a smartphone while sitting in public transport.
Have a good weekend, good luck and good luck :)

Also popular now: