This example shows a simple case of integration between the model and an external JavaScript class in the context of discrete-event simulation.
The model defines a network of interconnected cities. Based on these connections, it builds a weighted graph and represents it visually. The external PathSolver class does not build the system or control its execution: it only solves route queries on that graph.
The model is responsible for:
- defining cities and connections
- calculating weights between nodes
- building the graph
- calling the solver with a query
- visually traversing the returned route
In this way, the algorithmic part is encapsulated in the class, while GPSS-Plus continues to control the system's flow, time, and representation.
The external class is limited to answering questions such as:
get_path: find a route between two nodesget_tour: find an optimized route with multiple stops
Example
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
GRAPHIC {NAME:Text1,TYPE:TEXT,X:641,Y:30,TEXT:"Hello"}
LOAD_CLASS https://gpss-plus.com/imports_js/PathSolver.js
INSTANCE_CLASS {NAME: brain, CLASS: PathSolver}
INCLUDE /manual_es/Season_13_logica_externa/bbdd.mod
START 1
GENERATE 0,0,0,1 {visible:0}
; 1. Query contract
ASSIGN query, { op: "get_path", from: "Salamanca", to: "A_Coruna" }
; 2. Solver call
EXEC_CLASS { name: brain, in: V$query, assign: result }
; 3. Show result
MOVE {
NAME: Text1,
TEXT: "Route: X$(result.path.LENGTH) steps. Dist: X$(result.total_dist)",
color:red
}
; 4. Step-by-step movement
FOREACH point, IN, V$(result.path)
ADVANCE 10 { TO: "position_P$point" }
ENDFOREACH
MOD {color:red}
; Unordered stops
ASSIGN stops, ["Malaga", "Valencia"]
; Optimized tour
ASSIGN q, {
op: "get_tour",
start_node: "Madrid",
end_node: "Barcelona",
stops: V$stops
}
EXEC_CLASS { name: brain, in: V$q, assign: routePlan }
FOREACH stop, IN, V$(routePlan.optimized_path)
MOD {subtitle:"P$stop"}
ADVANCE 10 { TO: "position_P$stop" }
ENDFOREACH
ENDGENERATE 1
;----------------------------------------------------------------------
PROCEDURE PRE_RUN
CALL build_city_map
CALL build_weighted_graph
ASSIGN pack, { op: "init_graph", data: V$(weighted_graph) }
EXEC_CLASS { name: brain, in: V$pack }
TERMINATE_VE
ENDPROCEDURE