A complete model

Updated: 2025-10-08

Now that you know the fundamentals of GPSS-Plus, let’s see how they all come together in a unified example.

We’re going to look at a piece of code that is quite a bit longer than what we’ve seen so far—almost 100 lines.

This model represents a system with different vehicle types that move through a work area for several cycles. Each one decides its route, performs tasks, and finishes after completing a number of cycles, entering the utility-vehicle or truck parking area as appropriate—occupying either a FACILITY or a STORAGE depending on the truck size.

This code introduces several new ideas.

The first thing we notice is a top-level structure with two GENERATE blocks and several PROCEDUREs.

The generates are visually separated so each one has its own activity, and they mark the entities born from them in a differentiated way.

GENERATE ... NAME:G_UTILITY_VEHICLES ; generates utility vehicles
   ....
   ASSIGN ...
   ....
   CALL PROC.MAIN
ENDGENERATE 1

And then we have the set of PROCEDUREs:

Process procedures:

PROC.MAIN              ; Main process
PROC.UTILITY_VEHICLES
PROC.TRUCKS

Decision procedures:

DECIDE.ROUTE
DECIDE.LOOP_OR_END

PROC.MAIN:

All the main logic is concentrated in the PROC.MAIN process, which is typically built around a WHILE loop that keeps entities inside until they meet the condition to finish all their tasks.

WHILE ("P$state"!="EXIT")
    ...
    ...
    ASSIGN state, ????
ENDWHILE

Inside it, the decision over the main routes each entity can take is typically a SWITCH with options or several nested IFs. It is a good practice to place these decisions into PROCEDUREs named DECIDE.*, so they are easy to recognize and you know in advance they usually return, directly, the name of the PROCEDURE to be invoked by the entity:

ENDPROCEDURE "P$VALUE" ; Will return 'PROC.UTILITY_VEHICLES' or 'PROC.TRUCKS'

That is: CALL DECIDE.AAA will return in P$AAA (the part before the dot is omitted) the value 'PROC.BBB', which can be used directly as CALL P$AAA.

CALL DECIDE.ROUTE           ; Executes decision logic
CALL "P$(ROUTE)"            ; Calls the procedure returned by the decision

Very similar to the decision to exit or continue looping through the cycle.

Other new elements are:

ADVANCE0 {TO:POS_ENTRY,flow:1,layout:H}

Here it is ADVANCE0 instead of ADVANCE because we only want a visual jump, without the entity consuming time by entering and leaving the event queue.

The last novelty is the use of another resource with grouping and statistics utility: QUEUER.

It has unlimited capacity and makes it easy to know how many—and which—entities are in a given zone.

QUEUE IN_PARKING  ; enter
...
...
DEPART IN_PARKING ; leave

In summary, the example shows:

  • How to use multiple GENERATE blocks with differentiated logic (trucks and utility vehicles).
  • How entities can dynamically decide routes (SWITCH, CALL, PROCEDURE).
  • How an internal per-entity loop (WHILE) is used to simulate iteration.
  • How to visualize flow using positions, subtitles, and styles.
  • How to combine different resources (FACILITY, STORAGE, QUEUE).
  • How to work with dynamic procedure names (P$(ROUTE)).

 

Example

QUEUER {NAME:IN_PARKING,X:413,Y:497}

FACILITY {NAME:UTILITY_VEHICLES, CAPACITY:4, X:413, Y:390}
STORAGE {NAME:TRUCKS, CAPACITY:5, X:412, Y:120}

POSITION {NAME:POS_ENTRY,X:240,Y:270}
POSITION {NAME:POS_EXIT,X:557,Y:316,TYPE:DECISION,TITLE:"END?"}
POSITION {NAME:POS_LOOP,X:225,Y:549}
POSITION {NAME:END,X:730,Y:324,TYPE:TERMINATE}

START 20

;************************************************************************
GENERATE 20,10,0,10 {NAME:G_UTILITY_VEHICLES,X:80,Y:363,ESUBTITLE:"P$cycles/3"}
ASSIGN VEHICLE_TYPE,1
MOD {RADIO:5,COLOR:#000066}
CALL PROC.MAIN
ENDGENERATE 1 ; ALIAS OF TERMINATE
;----------------------------
GENERATE 20,10,0,10 {NAME:G_TRUCKS,X:80,Y:199,ESUBTITLE:"P$cycles/3"}

ASSIGN VEHICLE_TYPE,FLOOR(RANDOM * 2 + 2)
MOD {RADIO:10,COLOR:#006600}
CALL PROC.MAIN
ENDGENERATE 1  ; ALIAS OF TERMINATE
;************************************************************************

PROCEDURE PROC.MAIN

ASSIGN cycles,1

ADVANCE0 {TO:POS_ENTRY,flow:1,layout:H}
ASSIGN state,"loop"

WHILE ("P$state"!="EXIT")

	QUEUE IN_PARKING

	CALL DECIDE.ROUTE ; return assign:ROUTE
    CALL "P$(ROUTE)"
    ADVANCE 20,18 {TO:POS_EXIT,flow:1,MERGE:"exit"}

	DEPART IN_PARKING
    
    CALL DECIDE.LOOP_OR_END
    ASSIGN state,"P$(LOOP_OR_END)"
ENDWHILE

ADVANCE 20,0 {TO:END,flow:1}

ENDPROCEDURE

;*****************************************************

PROCEDURE DECIDE.ROUTE
    ASSIGN VALUE,""
    SWITCH P$VEHICLE_TYPE
    CASE <=,1
	    ASSIGN VALUE,"PROC.UTILITY_VEHICLES"
    ENDCASE
    DEFAULT
    	ASSIGN VALUE,"PROC.TRUCKS"
    ENDCASE
    ENDSWITCH
	
ENDPROCEDURE "P$VALUE"
;---------------------------------------------
PROCEDURE DECIDE.LOOP_OR_END
    ASSIGN VALUE,"loop"
    ASSIGN cycles,P$cycles + 1
	IF (P$cycles > 3)
    	ASSIGN VALUE,"EXIT"
        MOD {SUBTITLE:"-EXIT-"}
    ELSE
        ADVANCE 30 {TO:POS_ENTRY,flow:1,VIA:POS_LOOP,layout:V}
	ENDIF
ENDPROCEDURE "P$VALUE"

;---------------------------------------------
PROCEDURE PROC.UTILITY_VEHICLES
    ADVANCE 20 {TO:UTILITY_VEHICLES,flow:1,DECISION:"resource"}
    SEIZE UTILITY_VEHICLES
    ADVANCE 55,40
    RELEASE UTILITY_VEHICLES
ENDPROCEDURE

PROCEDURE PROC.TRUCKS
    ADVANCE 20 {TO:TRUCKS,flow:1,DECISION:"resource"}
    ENTER TRUCKS, P$VEHICLE_TYPE
    ADVANCE 40,20
    LEAVE TRUCKS
ENDPROCEDURE
;----------------------------------