So far we have seen how GPSS-Plus is, in its essence, a discrete event simulation engine. However, it is also capable of simulating continuous systems—those in which changes occur gradually over time.
What is a continuous system?
A continuous system is one where values change without interruptions. For example:
- The level of a tank being filled.
- The temperature of a furnace being heated.
- The velocity of a car accelerating smoothly.
In these cases, there are no discrete "jumps" like those in a queue or a customer entering or leaving. The change happens progressively.
How to simulate that in a discrete environment?
The answer is: cheating, but intelligently. Instead of simulating a constant and fluid change, we divide it into small time steps, fast enough so that it looks continuous.
It is like cinema: each frame is a static image, but when played at 24 frames per second, we perceive motion.
How is this done in GPSS-Plus?
With key adjustments:
SYSTEM {type:OPTIONS, TIME_DECIMALS:1, SPEED:5}
TIME_DECIMALS:1indicates that time is measured with one decimal place (0.1).SPEED:5sets the system update to a medium speed. From 0 (pause) to 10 (maximum speed). A medium speed (5) means that 10 AC1 instants take approximately 1 second. WithSPEED:2, 1 second is roughly equivalent to 1 AC1.
The engine remains discrete. Time does not advance on its own; it advances when an entity is serviced or an event is triggered. What we do is generate many small events in rapid succession.
Example: Filling a tank
We are going to fill a tank with a variable flow rate (for example, following a sine function to make it more dynamic).
To do this, we use a timer, which launches a block of code every 0.1 units of time. It does not generate transactions or statistics: it just executes.
SYSTEM {TYPE:ON_TIMER, TRIGGER:filling, INTERVAL: 0.1}
Each time the PROCEDURE is triggered, we will:
- Calculate a flow rate based on an oscillating function, previously defined with
FUNCTION TYPE:MATH. - Add that flow to the current tank level.
- Visually update the level.
- Display the value on the screen.
- Stop the simulation if the tank becomes full.
In this case, each cycle calculated the flow rate and added it to the level using a simple formula:
SAVEVALUE level, X$level + X$flow * 0.1
This method is called the Euler method, and it is the simplest form of numerical integration.
It estimates that during the time interval between AC1$ and AC1$ + 0.1, the tank will fill by an amount equal to the flow rate at instant AC1$ multiplied by the 0.1 interval.
In the next step, it will perform the same calculation again using the new flow rate value at that instant. And so on, adding small amounts as if it were a sum of rectangles: that is, in essence, an integral.
Example
/*
Continuous system within the discrete
*/
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
SYSTEM {type:OPTIONS, TIME_DECIMALS:1, SPEED:5}
SYSTEM {TYPE:ON_TIMER, TRIGGER:filling, INTERVAL: 0.1}
Graphic {NAME:alert,Type:TEXT,X:291,Y:342,Text:"alert"}
Function {Name:fcFlow, Type:Math, Expression:"0.6 + SIN(A) * 4"}
INITIAL level, 0
INITIAL flow, 1.2
INITIAL phase, 0
INITIAL constant, 0.6
include ./library_graphics/speedometer.lib
START 100
PROCEDURE PRE_RUN
assign config,{title:"Tank"
,x:100,y:60
,width:100 ,height:180
,min_value: 0
,max_value: 100
,"color":"#ff0000"}
call tank.speedometer.init,V$config
assign config,{title:"Flow Rate"
,x:300,y:60
,width:100 ,height:180
,min_value: -10
,max_value: 10
,"color":"orange"}
call flow.speedometer.init,V$config
TERMINATE_VE
ENDPROCEDURE
PROCEDURE filling
; Oscillate flow rate as a function of simulated time
SAVEVALUE flow, FN$(fcFlow,X$fase)
; Increment the phase smoothly
SAVEVALUE phase, X$fase + 0.1
; Add flow to the level, according to the time interval
SAVEVALUE level, X$level + X$flow * 0.1
; Rounded values for display
ASSIGN tFlow, round(X$flow, 2)
ASSIGN tLevel, round(X$level, 2)
CALL tank.speedometer.set, P$tLevel
CALL flow.speedometer.set, P$tFlow
; Status visualization
IF (X$level>=100)
MOVE {name:alert, text:"TANK FULL!"}
STOP
ELSE
MOVE {name:alert, text:"Level: P$tLevel - Flow: P$tFlow"}
ENDIF
TERMINATE
ENDPROCEDURE 1