Office of Operations
21st Century Operations Using 21st Century Technologies

Appendix D: Generation and Usage of Random Numbers in CORSIM

Introduction

CORSIM employs stochastic processes to simulate many aspects of real-world behavior, including driver behavior, vehicle operational characteristics, and decision-making processes.  To facilitate these stochastic models, CORSIM uses a pseudo-random number generation process.  Figure 69 shows the variation in average speed for a network run 10 times with different random number seeds.

This figure is a graph of the average system speed for ten separate runs of a network plus the mean of the ten runs.  The graph shows that the general trend of the speed is to start out at approximately 43 MPH and then decrease to about 30 MPH at 1,500 seconds into the simulation and then maintain that speed for the duration of the 3,600 second simulation.  The graph shows the even though the trend is similar, each run has much different values.   This shows the random variation in a stochastic model.

Figure 69 . Graph. Random variations in average speed among 10 runs.

The use of pseudo-random number generators is central to the modeling of stochastic processes in simulations.(22)  In their text on simulation, Law and Kelton provide a thorough discussion on the application and evaluation of random number generators.  Because the focus of this document is on CORSIM, the reader is referred to Law and Kelton for more information on the general application and properties of pseudo-random number generators.  In TSIS/CORSIM version 6.0, CORSIM uses a random number generator recommended by Law and Kelton that is portable, computationally efficient, and possesses good statistical performance characteristics.

Background

In TSIS/CORSIM versions 5.1 and earlier, CORSIM employed a pseudo-random number generator that exhibited poor statistical qualities, including:

  • The random number generator performed adequately for only a subset of its possible seed values, and the default seed values produced random number sequences that failed to pass several evaluation criteria.
  • The period of the random number sequence (when it began to repeat itself) depended on an arbitrarily selected multiplier, which could lead to short periods for the random number sequence.
  • Research indicated that even the use of valid values for the seed and for the multiplier could yield sequences that exhibit autocorrelation and fail to pass several of the performance tests identified by Law and Kelton.
  • The seed value was constrained to be an odd integer that could not end in 5.  That is, the seed value was constrained to end in 1, 3, 7, or 9.

Because of the poor statistical qualities of the pseudo-random number generator, it was replaced in TSIS/CORSIM version 6.0.  The CORSIM development team evaluated several generators, including the Marse-Roberts, Schrage, and FORTRAN intrinsic generators.  Law and Kelton described and recommended both the Marse-Roberts and Schrage generators.

Although the FORTRAN intrinsic generator has appealing qualities, not enough was known about it to recommend it over the other generators.  Furthermore, use of the FORTRAN intrinsic generator would require changes to the CORSIM code structure to support the generator’s need for multiple seeds; therefore, it was not selected.

The CORSIM development team conducted timing studies using the Marse-Roberts and Schrage generators.  In raw timing studies (generation of a large sequence of random numbers), the Schrage generator was found to be approximately twice as fast as the Marse-Roberts generator.  The team also conducted timing studies by using the generators in CORSIM on a variety of test cases.  The team determined that the Schrage generator had the least impact on the run-time performance of the simulation, providing approximately the same performance as the generator used in TSIS/CORSIM version 5.1 and earlier.  The Marse-Roberts generator had minimal impact on the run-time performance for smaller cases, but had a greater impact on larger, longer running cases.  That impact was amplified when conducting multiple runs of the simulation for statistical analysis.

Based on its analysis, the CORSIM development team chose the Schrage generator to replace the old CORSIM pseudo-random number generator.

Schrage Random Number Generator

The Schrage random number generator, recommended by Law and Kelton when computational speed is a concern, is a prime modulus multiplicative linear congruential generator (PMMLCG).  Although it is similar in nature to the previous CORSIM random number generator, its use of a prime modulus and large multiplier gives this generator much better statistical behavior than the one previously used by CORSIM.  Like the old CORSIM generator, this generator is also portable.  The Schrage generator employs the following recursive relation to compute the (n+1)st random number, Xn+1, from the nth random number, Xn:

This is the equation for the Schrage random number generator.  The random number upper case X subscript lower case n plus 1 equals lower case a times the nth random number, upper case X subscript lower case n, times mod lower case m, where lower case a equals 16,807 and lower case m equals 2 to the 31st power minus 1.

Figure 70. Equation. Schrage random number generator.

The choice of these numbers is based on the current word size (32-bit) used by most desktop computers.  The value of m is the largest prime number that fits in the 32-bit word size.

First, the sequence produced by this generator has a period of 231 - 2, regardless of the seed value used.  Second, it has been shown that this generator exhibits good statistical behavior. (22)  Finally, use of this generator does not place any restrictions on the seed values which can be any integer in the closed interval [1, 231-2].

Studies have indicated that the multiplier used in the Marse-Roberts generator yields better statistical performance than the multiplier used in the Schrage generator.(22)  On the other hand, the statistical performance of the Schrage generator is adequate and it is about twice as fast as the Marse-Roberts generator.

Usage of Random Numbers in CORSIM

As previously stated, CORSIM employs random numbers to implement the stochastic processes it uses to simulate aspects of real-world behavior, including driver behavior, vehicle operational characteristics, and decision-making processes.  CORSIM groups its stochastic processes into three categories, each category requiring a random number seed value.  The default values for the three seeds are contained in the “random.rns” file, which contains a list of 30 seed values for each of the three stochastic categories.  Thus, if 30 runs are completed for a given CORSIM file using the TSIS Output Processor, then each run will use different seed values from the “random.rns” file and thus result in different output results for each run due to the stochastic processes.

Instead of using the default seed values, an analyst can create their own random seed file to be used (e.g., robust lists of random seed values can be found in Law and Kelton(22)), keep the seed values constant between runs (thus resulting in identical results for multiple runs of the same CORSIM file), or have CORSIM generate the seed values randomly.  Refer to the CORSIM User’s Guide(1) for more information regarding random seed values in CORSIM. 

Traffic Stream Generation in NETSIM

NETSIM assigns a unique random number, based on a root seed, to each vehicle that is emitted into the network.  Each vehicle uses its seed to make random choices based on vehicle-driver characteristics and in determining the route it will take through the network.  The following NETISM processes are controlled by the vehicle-unique seed:

  • Bus Operations – decision by a bus to bypass a bus station.
  • Bus Operations – bus station dwell time.
  • Bus Operations – driver type assignment.
  • Driver familiarity in making lane change.
  • Driver type assignment for entry link vehicles.
  • Driver type assignment for source node vehicles.
  • Fleet type assignment.
  • Vehicle type assignment.
  • Interchange turn movement selection.
  • Upcoming turn movement selection.
  • HOV violator assignment for non-HOV vehicles.

When using a distribution for generating entry headways, changing the seed value used in obtaining headways can change the order in which vehicles are emitted into the network.  To obtain identical traffic streams between runs while allowing randomness in the entry headways, NETSIM assigns a seed to each combination of entry link and turn movement at the start of the simulation.  When a vehicle enters via an entry link, it is assigned the seed corresponding to its turn movement.  This isolates the assignment of vehicle seeds from the order in which vehicles are emitted into the network.

Specifically, the following process is used to generate vehicle seeds in NETSIM:

  • Using the user-specified seed, assign seeds to each entry link/ turn movement combination.
  • When a vehicle is to be emitted, assign its seed value according to the following formula:  vehicle seed = entry link by turn movement seed – 1.  The subtraction of 1 ensures scattering of seeds.
  • If the assigned vehicle seed is 0, reset it to the maximum seed value allowed by the generator.
  • Replace the “entry link by turn movement” seed with the next value in its random number sequence.

Response to Traffic Choices and Other Stochastic Processes

Time-dependent stochastic decision-making processes, other than vehicle headway generation and traffic stream generation, use a single user-specified seed.  This seed controls processes such as accepting available gaps for turns, determining the location and duration of lane blockages, and determining the inter-arrival times for pedestrians at an intersection.  At the beginning of the simulation, CORSIM makes a copy of this user-specified seed so that both the NETSIM and FRESIM logic have separate seeds, starting at the same value.  The following lists summarize how the random numbers in this generic category are used in NETSIM and FRESIM.

NETSIM:

  • Emergency Vehicles - driver awareness of and cooperation with emergency vehicle.
  • Lane Changing – discretionary lane change decision.
  • Lane Changing – driver familiarity in choosing goal lane.
  • Lane Changing – driver familiarity in making a lane change.
  • Left-turn jump determination.
  • Left-turn lagger gap acceptance.
  • Long-term event location.
  • Parking – event location.
  • Parking – inter-arrival time between parking events.
  • Parking – maneuver duration.
  • Pedestrian delay calculation.
  • Pedestrian inter-arrival time calculation.
  • Short-term event duration.
  • Short-term event location.
  • Spillback – determine if vehicle will discharge with spillback.
  • Spillback – determine if left-turner will discharge with spillback.
  • Upcoming movement choice for vehicle on FRESIM to NETSIM interface link.

FRESIM:

  • Determine lane in which to emit vehicle.
  • Driver type assignment.
  • Fleet type assignment.
  • Vehicle type assignment.
  • HOV – decision for HOV vehicle to enter an HOV lane.
  • HOV – determination if vehicle should reenter HOV lane after being forced out.
  • HOV – violator assignment for non-HOV vehicles.
  • Lane Changing – acceptable risk for lane changing based on cooperative driver.
  • Lane Changing – desire to make discretionary lane change.
  • Lane Changing – discretionary lane change advantage, left / right decision.
  • Lane Changing – lane change gap acceptance risk.
  • Lane Changing – mandatory lane change, left / right decision.
  • Lane Changing – random lane change decision.
  • Lane Changing – speed advantage for lane change.
  • Ramp meter cheater decision.
  • Random assignment for vehicle destination based on origin-destination probabilities.
  • Random perturbation of acceleration.

Vehicle Entry Headway Generation

When injecting vehicles into a network at an entry node, CORSIM can generate vehicle entry headways deterministically or stochastically, using one of several distribution types.  In the deterministic mode, vehicles are injected into the network at a constant headway.

In the stochastic mode, CORSIM uses a random sampling of a user-selected distribution to generate vehicle entry headways.  This process does not vary the number of vehicles emitted during each run; only the headways between the vehicles are varied.  CORSIM supports three types of distributions: normal (Gaussian), negative exponential, or Erlang.  Appendix E describes in more detail the different user-selected distributions possible for generating vehicle entry headways.

Office of Operations