Batch Mode Simulation : A Sample Simulation Control Program : Explaining the Program

Explaining the Program

In this portion, each line of the program is explained.

Program tlight

This line names the program. This line is for documentation purposes only.

variable

Begins the Variable declaration Section. Note that each type of declaration concludes with a semicolon.

file fin, fout ;

Defines two file variables, fin and fout that are used for I/O purposes.

integer delay;
Boolean run ;

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.

init

Begins the Initialization Section which contains statements executed once - each time the Simulation Control Program is started.

open (fin, ‘trial.dat’, input) ;

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.

open (fout, ‘trial.out’, output) ;

Opens the file, trial.out, for output and attaches it to the variable fout. This file records all the malfunctions of the system.

ns_green_time := 15 ;
ew_green_time := 20 ;

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.

cancel breakpoint gen_reset ;

Initializes the gen_reset breakpoint so that it does not execute.

end init

End of Initialization Section

- - breakpoint Section
set breakpoint

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.

[in(normal_op)] do

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.

write(‘current time = ‘, cur_clock, ‘\n’) ;

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 each go.

if rand_iuniform(1,100) = 1

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.

then

When the test is true, the statements following the keyword then are executed.

malfunction ;

Generates the event malfunction. This simulates an electrical malfunction of the system. When the malfunction event occurs, the traffic lights flash.

write(fout,‘malfunction occurred at ‘, cur_clock, ‘\n’)

The time of the malfunction is recorded in the output file.

end if

Ends the IF structured statement.

end breakpoint

Ends the definition of the breakpoint.

set breakpoint gen_reset => every delay do

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.

reset ;

Generate the event reset. This resets the malfunction of the traffic lights.

cancel breakpoint gen_reset ;

Cancels any further execution of the gen_reset breakpoint until needed after the next malfunction.

ns_green_time := rand_iuniform(30,50) ;

Generates a new random value for the north-south traffic flow. It generates a value between 30 and 50 seconds.

read(fin, ew_green_time) ;

Reads a new value from the data file for the east-west traffic flow.

while ew_green_time > 20

Tests that the value from the data file does not exceed a maximum value.

loop

The test is done in a WHILE/LOOP statement. This insures that the new input (from the user) cannot exceed the maximum value.

write(‘Data for ew_green_time exceeds limit. \n’) ;
write(‘Enter a value for ew_green_time less than 20: \n’) ;
 

When the input value fails the test, the user is prompted for a new value.

read(ew_green_time)
 
Note: A new value for the east-west traffic flow is read from the keyboard.

end loop

Note: Ends the WHILE/LOOP statement.

end if

Ends the IF structured statement.

end breakpoint

Ends this breakpoint definition.

set breakpoint
en(flashing) do
 

Starts a new breakpoint executed when the flashing state is entered.

delay:=rand_iuniform(1,10)

Sets the delay for the reset event to a number between 1 and 10.

set breakpoint gen_reset;

Enables the execution of the gen_reset breakpoint.

end breakpoint;
Note: Ends this breakpoint definition.

- - Define Main Section to use required Go Type

begin

Begins the Simulation Control Program Main Section whose statements are executed sequentially.

tr!(run) ;

Sets the Boolean variable run to true.

while run

Evaluates the trigger run and, if true, runs the WHILE/LOOP statements. Since this variable has just been set true, the loop runs continuously.

loop

Begins the WHILE loop.

go step

Note: The go 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 using go extended.

end loop

 

Ends the WHILE loop.

end

Ends the Main Section.

end.

Ends the Simulation Control Program.