Download - Stochastic Simulation

Transcript

Wu

Stochastic Simulation

Cathy Wu

1.041/1.200/11.544 Transportation: Foundations and Methods

2021-10-13

Wu

Outline1. Urban traffic simulation2. Simulation pro's and con's3. Simulation of an š‘€/š‘€/1 queueing system4. Random number generation5. Replications6. Simulation for traffic modeling

Sources & further readingā€¢ Lecture slides from Prof. Carolina Osorio (MIT 1.041)

Wu

Traffic simulation

Ā§ Source: "Scale and Complexity Tradeoffs In Surface Transportation Modeling", Karl E.Wunderlich.

Ā§ Simulation video

Metro Reglon

UrbanCorridor

Freeway Segment

SingleInterchange

LiquidFlow

Particle

Flow

CarFollowlng

Intra-vehicleDynamics

Macro

Meso

Micro

Nano

Wu

Stochastic simulation modelsĀ§ Def. Simulation: Modeling approach, the aim of which is to

approximate (i.e. simulate) the systems' behaviour with the help of models that:ā€¢ are computer-based models that try to imitate the behavior of a physical

systemā€¢ account for uncertainty: need to mimic randomness in a computer, i.e.

simulate random events

Wu

Simulation pro's and conā€™sĀ§ Advantages

ā€¢ May be suitable for problems that are not analytically tractableā€¢ Greater level of modeling detail (does not necessarily mean increased realism)ā€¢ Allows for simulated experiments of otherwise costly (e.g. high risk) or infeasible

field experimentsā€¢ What-if analysis: trial and error procedureā€¢ Useful to test the validity of mathematical assumptions (e.g. to validate analytical

models)Ā§ Disadvantages

ā€¢ What-if analysis: difficult to develop causal relationshipsā€¢ Computationally expensive mathematical tool (need for many replications)ā€¢ Proper statistical analysis of the outputs is complexā€¢ Detailed model requires very detailed data to be formulated and calibratedā€¢ Data quality, "garbage-in, garbage-out"ā€¢ Difficult to use to perform optimization (simulation-based optimization)

Ā§ Just as analytical models, simulation models are based on numerous assumptions and approximations, use it with caution and keep in mind that it's a simplification of reality, i.e. a MODEL!

Wu

Stochastic simulation modelsĀ§ Running simple simulations enables to:

further understand the concepts of random variables, their distributions and realizations

Ā§ Understanding the main underlying concepts of a simulation model enables to: understand the complexity and need for a rigorous validation of simulation models and statistical analysis of outputs

Wu

Queueing modelsĀ§ Exact

ā€¢ Analytical: closed-form expressionsā€¢ Numerical methods (e.g. global balance equations)

Ā§ Approximateā€¢ Analytical: use of bounds or decomposition methodsā€¢ Simulation

Wu

Stochastic simulation modelsĀ§ How to simulate a simple queue?Ā§ How to advance time?Ā§ Need to mimic randomness in a computer, i.e. simulate random

eventsā€¢ How to generate random numbers?ā€¢ How to generate random observations from a probability distribution?

Wu

Simulation models for queuing systemsĀ§ Discrete-event simulation (DES)Ā§ Continuous-time: event driven simulationĀ§ The system is modeled by a set of discrete statesĀ§ The system can change states when an event occursĀ§ Between events the system does not change statesĀ§ Identify the events that lead to state changesĀ§ For each event, describe:

ā€¢ the new stateā€¢ changes in the system attributesā€¢ triggered events

Ā§ The simulator keeps an event list of the events that are scheduled to happen with their scheduled timeThe events are ordered chronologically

Ā§ Once an event is carried out, the simulation dock is advanced to the time the next event is scheduled to start

Wu

Discrete event simulation model: M/M/1Ā§ State of the system: š‘ š‘” = number of customers in the queueing system at

time š‘”Ā§ Events:

ā€¢ arrival of a new customerā€¢ service completion for the customer currently in service

Ā§ Update system state and record information at time of each eventĀ§ State transition mechanism for event-driven simulation:

š‘ š‘” = 'š‘ preceding event + 1, if an arrival occurs at time š‘”š‘ preceding event āˆ’ 1, if a service completion occurs at time š‘”

Ā§ Simulation end: if the simulation clock exceeds a pre-specified (simulation) time or number of customers observed reaches a specified limit

Ā§ How to obtain the time and type of next event?

Wu

Discrete Event Simulation Model: M/M/1Ā§ š“=: arrival time of customer š‘›Ā§ š·=: departure time (service completion time) of customer š‘›Ā§ š»=: inter-arrival (arrival headway) time of customer š‘›Ā§ š‘†=: service time of customer š‘›

Wu

Random number generationĀ§ Approach

1. Generate "independent" draws from a uniform distribution,2. Then generate draws from an arbitrary distribution

Wu

Uniform random numbersĀ§ A ā€œrandom numberā€ for computer simulation purposes is a random

observation from the uniform distribution on the interval [0, 1], i.e., sampled from š‘ˆ 0,1

Ā§ Most software have functions that allow easy generation of random numbers.ā€¢ Successive random numbers generated by random.random() can be

considered mutually independent samples from š‘ˆ 0,1Ā§ In Python: import random; random.random()Ā§ In Excel: RAND()

ā€¢ To return a matrix (n-by-m) of observations that can also be considered mutually independent samples from š‘ˆ 0,1Ā§ In Python: import numpy as np; np.random.rand(n, m)Ā§ In Matlab: rand(n,m)

Wu

Uniform random numbersĀ§ Pseudorandom number generator:

ā€¢ A deterministic algorithm for generating a sequence of numbers that approximates the properties of random numbers

Ā§ Most software use linear-congruential methods which involve modulo arithmetic Recursive algorithm:

š‘Ÿ=GH = š‘˜š‘Ÿ= + š‘Ž mod š‘šwhere š‘˜, š‘Ž, and š‘š are positive integers (š‘˜ < š‘š, š‘Ž < š‘š).Choose š‘ŸO, the seed

Ā§ What is a good random number generator?1. a long (maximum) period between repeat cycles2. covers unit interval uniformly3. same for higher dimensional unit-cubes4. does not show obvious patterns5. fools statistical tests when used in simulations6. efficiency of the algorithm

Wu

Ā§ Based on š‘ˆ 0, 1 variables, generate variables from an arbitrary discrete dbn

Ā§ Discrete r.v. š‘‹ has pmf:š‘ƒ š‘‹ = š‘„S = š‘šS, š‘˜ = 1,ā€¦ , š¾

Ā§ Split the unit interval into š¾ subintervals of length š‘šH,š‘šV,ā€¦ ,š‘šWĀ§ Draw a uniform random number š‘Ÿ in [0, 1]Ā§ If š‘Ÿ falls into the subinterval belonging to š‘šS then the r.v. realization

is š‘‹ = š‘„SĀ§ Implementation:

1. Let š‘Ÿ be a draw from š‘ˆ 0, 12. Initialize š‘˜ = 0, š‘ = 03. š‘ = š‘ +š‘šS4. If š‘Ÿ < š‘, set š‘‹ = š‘„S and stop.5. Otherwise, set š‘˜ = š‘˜ + 1 and go to step 3.

Discrete random number generation

Wu

Ā§ Most popular methodĀ§ Inverse transform method (a.k.a. inverse

function method)Ā§ Based on the following property:

ā€¢ š‘‹ continuous r.v. with cdf FX(x),ā€¢ Then the new r.v. š‘Œ = š¹[ š‘„ is uniformly

distributed over 0,1ā€¢ š‘ƒ š¹[\H š‘ˆ ā‰¤ š‘Ÿ = š¹[(š‘Ÿ)

Ā§ Draw a uniform number š‘Ÿ in 0,1Ā§ Set š‘„ = š¹\H(š‘Ÿ)Ā§ Note: the cdf is not always available in

closed-form: e.g. normal dbn

Continuous random number generation

Wu

Example: exponential r.v.

sampleSize = 1000;lambda= 0.5;

r = rand(sampleSize,l);x = -log(r)/lambda;

r x

histogram(x)

0 01000 1000

Wu

Discrete Event Simulation Model: M/M/1Ā§ š“!: arrival time of customer š‘›Ā§ š·!: departure time (service completion time) of customer š‘›Ā§ š»!: inter-arrival (arrival headway) time of customer š‘›Ā§ š‘†!: service time of customer š‘›

Ā§ 'š“" = 0š“! = š“!#" + š»!, š‘› = 2, 3, ā€¦

Ā§ 'š·" = š‘†"š·! = š‘†! +max š“!, š·!#" , š‘› = 2, 3, ā€¦

where max š“!, š·!#" represents the time that service starts for customer š‘›Ā§ š»! and š‘†! are generated from two exponential random variables. How can we generate these?

bš»! = āˆ’ $% &'

( = āˆ’ $% &)!*()(

š‘†! = āˆ’ $% &-. = āˆ’ $% &)!*()

.

Wu

Replications

Wu

ReplicationsĀ§ The outputs from a simulation model are random variablesĀ§ Running the simulator provides realizations of these r.v.Ā§ Replications allow us to:

ā€¢ Obtain independent observations.This allows us to apply classical statistical methods to analyze the outputs:e.g. central limit theorem, confidence intervals

ā€¢ Estimate system performance measures (e.g. empirical cdf) that enable us to understand the "typical" behavior of the system

ā€¢ Have an idea of the underlying (unknown and often) complex distribution of the output variable

Ā§ How to obtain different replications with a simulation software?ā€¢ For a given replication the sequence of random numbers are generated starting

with an initial number, called the seedā€¢ Each time you launch the simulation with the same seed, you obtain identical

resultsā€¢ Saving/knowing the seed, allows you to reproduce your resultsā€¢ Launching the simulation with different seeds, yields different realizations

Wu

Reminder: Central Limit TheoremLet š‘‹H, š‘‹V, ā€¦ , š‘‹= be a set of š‘› independent and identically distributed random variables with mean šœ‡ and a finite variance šœŽV. Let the sample average be defined as

š‘†= ā‰”š‘‹H +ā‹Æ+ š‘‹=

š‘›

As š‘› ā†’ āˆžš‘†= ā†’ š’© šœ‡, ĻƒV/n

Regardless of distribution of š‘‹k!

Wu

Statistical issuesĀ§ The statistical analysis of the results of a simulation can be difficultĀ§ Impact of initial conditions (warm-up period)Ā§ Selection of starting conditionsĀ§ Correlation between successive observations/samples (e.g., waiting

times of passengers in a system)Ā§ Number and length of required replications:

ā€¢ Many replications vs. single long replication (which is then partitioned)Ā§ Confidence intervalsĀ§ Statistical tests

Wu

Simulation projectĀ§ Problem definitionĀ§ Model formulationĀ§ Data collectionĀ§ Model developmentĀ§ VerificationĀ§ ValidationĀ§ Experiments (e.g. what-if analysis)Ā§ Results: analysis and presentationĀ§ Implementation

Wu

Recall: (Simple) multi-lane modeling

Stochastic single-lane model

Pdisappear high

Pappear high

Pappear low

Pdisappear low

hi(k)

xi-1(k), vi-1(k)

xi(k), vi (k)

Wu, Cathy, Eugene Vinitsky, Aboudy Kreidieh, and Alexandre Bayen. "Multi-lane reduction: A stochastic single-lane model for lane changing." IEEE ITSC, 2017.

Wu

Model Calibration - ProbabilitiesExtractheadwayswhenlanechangesoccurFittolog-normaldistribution

Fitoflog-normaldistributionforthetotaldistributionofheadwaysandtheconditionaldistributionofheadwayswhenavehiclelanechangesintoalane,respectively,computedfor7:50amontheUS101.

Slide credit: Eugene VinitskyWu, Cathy, Eugene Vinitsky, Aboudy Kreidieh, and Alexandre Bayen. "Multi-lane reduction: A stochastic single-lane model for lane changing." IEEE ITSC, 2017.

Wu

Lane change outClosing the gap

Lane change inGap opening

slope = velocity

Wu, Cathy, Eugene Vinitsky, Aboudy Kreidieh, and Alexandre Bayen. "Multi-lane reduction: A stochastic single-lane model for lane changing." IEEE ITSC, 2017.

Time-space diagram

Wu

Opportunities of simulation for transportationĀ§ Environmentally-friend traffic management or network designĀ§ Improve the reliability and robustness of transportation networksĀ§ Design of integrated transportation systemsĀ§ Inform vehicle design