In this portion, each line of the program is explained.
This line names the program. This line is for documentation purposes only.
Begins the Variable declaration Section. Note that each type of declaration concludes with a semicolon.
Defines two file variables,
fin
andfout
that are used for I/O purposes.Defines an integer used to delay the reset event and a Boolean variable that is used as a condition to create a continuous loop in the Main Section.
Begins the Initialization Section which contains statements executed once - each time the Simulation Control Program is started.
Opens an input data file and attaches it to the variable name fin. This data file contains the test values for the east-west traffic flow.
Opens the file, trial.out, for output and attaches it to the variable fout. This file records all the malfunctions of the system.
Initializes the value of the data-item used to determine the duration of the green lights in both east-west and north-south directions. The Global Clock Unit is assumed to be seconds.
Initializes the gen_reset breakpoint so that it does not execute.
Beginning of the Breakpoint Definition Section. The defined breakpoint is simultaneously enabled. The name of this breakpoint is not defined. Unnamed breakpoints cannot be cancelled and reset in batch mode. They are continuously enabled during the execution of the Simulation Control Program.
Defines the breakpoint trigger as “being in the state of NORMAL_OP”. The breakpoint statements following the keyword do are executed when the trigger evaluates to true. That is, the statements are executed at each step while the system is operating normally.
Displays the current execution time in the Simulation Window after each
go
- in this case, after each step is concluded. The Simulation tool automatically updates the value of the predefined variable cur_clock at the end of eachgo
.Randomly selects an integer uniformly distributed between 1 and 100 and tests this value to see if it is equal to 1. This simulates situations that arise 1% of the time during normal operation.
When the test is true, the statements following the keyword
then
are executed.Generates the event
malfunction
. This simulates an electrical malfunction of the system. When the malfunction event occurs, the traffic lights flash.The time of the malfunction is recorded in the output file.
Ends the IF structured statement.
Ends the definition of the breakpoint.
Beginning of the Breakpoint Definition Section. The defined breakpoint is simultaneously enabled. The breakpoint is named gen_reset and runs every delay amount of time. The integer delay is set in the next breakpoint.
Generate the event reset. This resets the malfunction of the traffic lights.
Cancels any further execution of the gen_reset breakpoint until needed after the next malfunction.
Generates a new random value for the north-south traffic flow. It generates a value between 30 and 50 seconds.
Reads a new value from the data file for the east-west traffic flow.
Tests that the value from the data file does not exceed a maximum value.
The test is done in a
WHILE/LOOP
statement. This insures that the new input (from the user) cannot exceed the maximum value.When the input value fails the test, the user is prompted for a new value.
Ends the IF structured statement.
Ends this breakpoint definition.
Starts a new breakpoint executed when the flashing state is entered.
Sets the delay for the reset event to a number between 1 and 10.
Enables the execution of the gen_reset breakpoint.
- - Define Main Section to use required Go Type
Begins the Simulation Control Program Main Section whose statements are executed sequentially.
Sets the Boolean variable run to true.
Evaluates the trigger run and, if true, runs the WHILE/LOOP statements. Since this variable has just been set true, the loop runs continuously.
Note: Thego step
in the Synchronous Time Model advances the clock with each execution.
The Main Section is supplied here instead of using the default Main Section. The default main Section always advances the execution usinggo extended
.Ends the
WHILE
loop.