- •Table of Contents
- •Chapter 1. Using GPSS World
- •Lesson 1 - The GPSS World Program
- •Lesson 2 - Running a Simulation
- •Lesson 3 - Problems
- •Lesson 4 - The Text Editor
- •Lesson 6 - The ADVANCE Block
- •Lesson 9 - GPSS World Commands
- •Lesson 10 - Manual Simulation
- •Lesson 11 - The Graphics Windows
- •Lesson 12 - Reading from and Writing to External Files
- •Lesson 14 - Reports
- •Lesson 15 - Session Journaling
- •Lesson 16 - Continuous Modeling
- •Lesson 17 - PLUS
- •Lesson 19 - Experiments
- •Chapter 2. Applications
- •1. TURNSTIL.GPS
- •2. TELEPHON.GPS
- •3. PERIODIC.GPS
- •4. TVREPAIR.GPS
- •5. QCONTROL.GPS
- •6. ORDERPNT.GPS
- •7. MANUFACT.GPS
- •8. TEXTILE.GPS
- •9. OILDEPOT.GPS
- •10. ASSEMBLY.GPS
- •11. ROBOTFMS.GPS
- •12. BICYCLE.GPS
- •13. STOCKCTL.GPS
- •14. LOCKSIMN.GPS
- •15. FOUNDRY.GPS
- •16. TAPEPREP.GPS
- •17. TRAFFIC.GPS
- •18. POWDER.GPS
- •19. QTHEORY.GPS
- •20. SUPERMRK.GPS
- •21. SHIPPORT.GPS
- •22. EXCHANGE.GPS
- •23. FMSMODEL.GPS
- •24. ETHERNET.GPS
- •25. PREDATOR.GPS
18.000 - 19.000 16 74.73
19.000 - _ 465 100.00 SAVEVALUE RETRY VALUE XMIT_NODE 0 178.000 XMIT_BEGIN 0 998.881
FEC XN PRI BDT ASSEM CURRENT NEXT PARAMETER VALUE 1882 0 1000.095 1882 26 27
MESSAGE_TIME 1.214 NODE_ID 178.000 RETRIES 0.000
1944 0 1000.448 1944 0 1
1945 0 2000.000 1945 0 34
Let’s look at statistics in the new Standard Report. To shorten the listing, we only used statistics from the first 10 workstations. The other 190 are similar. We see that the Ethernet utilization has grown to 97.7%, and that there were 214 collisions in the simulated time. Many of the transactions experienced multiple collisions.
Clearly, the time spent backing off from collisions was a large component of the additional message delay times.
All this information is available in the online Facilities and Blocks Windows. You should open these windows to be sure you can find the information. Look at both Detailed View and Non-Detailed View in these windows.
If you wish to go on to the next lesson, close all windows related to this model.
CLICK ON The X-Upper Right of Each Window
Otherwise, to end the session
CLICK ON The X-Upper Right of Main Window.
25. PREDATOR.GPS
Predator-Prey Model
A population of rabbits has grown uncontrollably on a small island. The problem is so severe that local farmers expend considerable effort just to break even financially. They want to introduce a population of foxes to bring the situation under control.
The problem is to use the Lotka-Volterra predator prey model in PREDATOR.GPS to simulate the phenomenon. What will happen if a population of 80 foxes is released? How many foxes must be released to eradicate the rabbits?
; GPSS World Sample File - PREDATOR.GPS
******************************************************************
**
*Lotka-Volterra Predator-Prey Model *
**
*Operation: *
*Plot Foxes and Rabbits: X 12000; Y 0-3000 *
*START 1 *
******************************************************************
******************************************************************
*
* Don’t forget to parenthesize the ODEs.
*
******************************************************************
Foxes INTEGRATE (FoxRate()) Rabbits INTEGRATE (RabbitRate())
******************************************************************
*
*The Initial Values
******************************************************************
Foxes EQU 80 Rabbits EQU 1000
******************************************************************
*The Model Parameters
*
******************************************************************
K_ EQU 0.2000 ;Predator Efficiency
A_ EQU 0.0080 ;Predator Death Rate B_ EQU 0.0002 ;Foray (Grazing) Factor C_ EQU 0.0400 ;Prey Birth Rate
******************************************************************
**
*Discrete Simulation Control Segment *
**
******************************************************************
GENERATE 10000 TERMINATE 1
PROCEDURE FoxRate() BEGIN /***************************************************************** Growth Rate for the Fox Population
*****************************************************************/
TEMPORARY BirthRate, DeathRate, TotRate;
/* Limit the Variable, so we can experiment safely. */ IF (Foxes < 0) THEN Foxes = 0;
IF (Foxes > 10e50) THEN Foxes = 10e50 ;
BirthRate = K_ # B_ # Foxes # Rabbits; DeathRate = A_ # Foxes;
TotRate = BirthRate - DeathRate;
RETURN TotRate;
END;
PROCEDURE RabbitRate() BEGIN /***************************************************************** Growth Rate for the Rabbit Population
*****************************************************************/
TEMPORARY BirthRate, DeathRate, TotRate;
/* Limit the Variable, so we can experiment safely. */ IF (Rabbits < 0) THEN Rabbits = 0;
IF (Rabbits > 10e50) THEN Rabbits = 10e50 ; BirthRate = C_ # Rabbits;
DeathRate = B_ # Foxes # Rabbits ; TotRate = BirthRate - DeathRate; RETURN TotRate;
END;
In this model, we use single letters followed by underscores to name constants. This ensures that there will be no clashes with PLUS or GPSS keywords. Since PLUS Expressions used outside PLUS Procedures should be parenthesized, the invocations in Operand A of the INTEGRATE Commands are enclosed in outer parentheses.
To run the simulation and create a Plot, in the Model Window
CHOOSE File / Open
and in the dialog box
SELECT PREDATOR
and then
SELECT OK
Next, create the simulation
CHOOSE Command / Create Simulation
Now, we set up a Plot of the fox and rabbit populations, to observe the dynamics.
CHOOSE Window / Simulation Window / Plot Window
Then in the Edit Plot Window enter the information as shown below. You should be looking at a similar dialog box on your screen to the one shown below. We’ll plot the Fox population and Rabbit population on the same plot. Remember to position the mouse pointer at the beginning of each box and click once before you begin to type. Do not press the
e since that is used when all information has been typed in the box.
Figure 25—1. The Fox and Rabbit Population Edit Plot Window.
CLICK ON Plot
CLICK ON Memorize
Then enter the Rabbits
Next to Label, replace the current value
TYPE Rabbits
and for the Expression, replace the current value
TYPE Rabbits
and
CLICK ON Plot
CLICK ON Memorize
SELECT OK
Adjust the Plot Window to a comfortable viewing size. Now, let’s get the simulation started.
CHOOSE Command / START
and
SELECT OK
The simulation will end when 10000 time units have passed.
Your Plot Window should look like this:
Figure 25—2. Fox and Rabbit Population Dynamics.
As you can see, the introduction of foxes causes the rabbit population to decline. Eventually the fox population can no longer be supported, and it too decreases. Eventually there are no longer enough foxes to hold the rabbits in check, and population explosion occurs. With abundant prey, the fox population eventually grows to the point where the rabbits are again under control.
Let’s now determine how many foxes, to the nearest thousand, must be introduced to eliminate the rabbits. Although we could do everything interactively, it’s easy to simply change the starting Fox population and retranslate the model.
In the Model Window change the Foxes initial value from 80 to 2000.
CHOOSE Command / Retranslate
CHOOSE Command / START
and
SELECT OK
As we can see, during the simulation the populations oscillated even with such a large number of foxes. Let’s try 3000. In the Model Window change the Foxes initial value from 2000 to 3000.
CHOOSE Command / Retranslate
CHOOSE Command / START
and
SELECT OK
After 3 oscillations, the rabbit population died out. With all the prey gone, the fox population also collapsed. Take a look at the values of the Foxes and Rabbits User Variables in the Standard Report. They are both 0.
According to this model, 3000 foxes must be introduced to completely eradicate the rabbits. What happens when 4000 foxes are introduced? Does the system still oscillate?
The integration of ordinary differential equations is sensitive to the conditions you set up. You can expect to be surprised with floating point overflows and the exceeding of error tolerance during the continuous phase, if you haven’t set the derivatives up correctly. In some cases, if you are willing to accept a little less accuracy, you can increase the Integration Tolerance in the Simulation Page of the Model Settings Notebook. Often, you will need to control the variables explicitly. Notice in the predator prey model how the populations are explicitly kept nonnegative in the PLUS Procedures used to evaluate the derivatives.
In practice, differential equations that cause floating point exceptions are often not realistic. Those that are, can usually be replaced by better behaving equivalents that still are able to model the real system.
If you have moved your Plot Window around during this lesson, and discovered that not all the points were redrawn, you can increase the size of the saved point list. To do so, open the Reports Page of the Model Settings Notebook,
and type in the new value in the Saved Plot Points entry field.
Now, if you wish to experiment with other models in this tutorial close all windows related to this model.
CLICK ON The X-Upper Right of Each Window
Otherwise, to end the session
CLICK ON The X-Upper Right of Main Window.
We’ve finished with our tutorial lessons. You may find in the future that many of them will serve as good templates for your own models. If you have questions, please don’t hesitate to contact us through our web site.