0% found this document useful (0 votes)
15 views

Simulation 2

This chapter discusses different types of simulation models. It describes static versus dynamic models, continuous-change versus discrete-change models for dynamic simulations, and deterministic versus stochastic models. It provides examples of static stochastic Monte Carlo simulations that can be done in spreadsheets, including simulating dice rolls and estimating areas under curves. It also gives an example of a single-period inventory simulation model to determine the optimal number of items to stock.

Uploaded by

hanakaleed1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Simulation 2

This chapter discusses different types of simulation models. It describes static versus dynamic models, continuous-change versus discrete-change models for dynamic simulations, and deterministic versus stochastic models. It provides examples of static stochastic Monte Carlo simulations that can be done in spreadsheets, including simulating dice rolls and estimating areas under curves. It also gives an example of a single-period inventory simulation model to determine the optimal number of items to stock.

Uploaded by

hanakaleed1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Industrial Systems Simulation (ID: 8054105-3)

Chapter 3 – Kinds of Simulation

The week of 01/10/2023


Dr. Hussain Abualkhair
College of Engineering – Industrial Engineering Program
Introduction
▪ Delineate in more detail (more than in Chapt. 1) the different kinds of simulation:
• Static vs. dynamic

• Continuous-change vs. discrete-change for dynamic models

• Deterministic vs. stochastic

▪ Logic for dynamic discrete-change simulations via manual simulation


• Spreadsheet-assisted for arithmetic, but NOT a general spreadsheet simulation model

▪ Spreadsheet simulation models


• Static – single-period inventory

• Dynamic – single-server waiting times in queue

▪ General-purpose programming languages for simulation


▪ Special-purpose simulation software

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 1
Kinds of Simulation
▪ “Simulation” is a very broad term – too broad, so need to qualify, and classify different kinds of
simulation
▪ Static vs. Dynamic
• Static: Passage of time plays no active or meaningful role in model execution; can often be done in spreadsheets
o Random numbers to simulate gambling games or lottery, or to estimate the value of an integral or inverse of a matrix
o Evaluate financial profit & loss statement subject to uncertainties in demand, interest rates, etc. … get distribution/histogram of
possible profits & losses to display risk, rather than just a single “projection”
• Dynamic: Passage of time is essential and explicit in model execution; can almost never be done in spreadsheets except
for very simple models
o Queueing systems, dynamic inventory systems, supply chains
o Key variable: simulation clock = current value of (simulated) time
• Should be real-valued, not integer-valued since simulated time is continuous
• Should jump between (exact) event times in continuous time, not be time-stepped or time-sliced … wasted computer effort, model distortion since
event times are rounded to nearest time-step boundary … see text for more

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 2
Kinds of Simulation (cont.)
▪ Continuous-change vs. discrete-change (for dynamic models)
▪ Dynamic models are described by state variables that describe the state as it changes over time (queue
length, inventory level)
• Continuous-change: State variables can change continuously over time, at any point in continuous time
o Fluid in a tank, pressure, strength level of a combat force
o Often described by differential equations, solved numerically
• Discrete-change: State variables can change only at instantaneous, separated, discrete points in time
o Most queueing models, many inventory models
o Simulation clock takes on only values corresponding to the time of occurrence of these discrete events, so jumps from the time of one
event to the time of the next event … nothing happens in between
o At time of each event, simulation logic alters state variables, other things (event calendar, statistical-tracking variables … coming soon)

Also: mixed
discrete-
continuous

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 3
Kinds of Simulation (cont.)
▪ Deterministic vs. stochastic
• Deterministic: All input values are fixed, non-random constants
o Manufacturing system with constant interarrival, service times
o Get same results from multiple runs, unless your change input(s)
• Stochastic: Some inputs are random draws (or samples or realizations) from probability distributions
o Manufacturing system with interarrival, service times that vary according to probability distributions … must specify
these input distributions from observed data (Chapt. 4)
o The random draws start with a random-number generator (also Chapt. 4), so running model once provides only a
sample (of size 1, not worth much) of what could happen
o So need to run it many times (or for a long time) to judge statistical behavior of output (precision of estimates,
spread/risk or results)
o Usually, subsequent executions of same model yield same results … instead, must replicate within same execution to
keep going in fixed “random”-number sequence … it’s actually good that it’s fixed (debugging, variance reduction)

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 4
Static Stochastic Monte Carlo
▪ Name comes from the Mediterranean gambling center.
▪ Simplest form of stochastic simulation.
▪ Sometimes used in spreadsheets and applications where the dynamic nature
of most systems is not an issue.
▪ Model 3-1: Throwing two dice
• Model_03_01.xls uses RAND and VLOOKUP functions to estimate the outcome of dice rolls
▪ Model 3-2: Monte Carlo integration
• Model_03_02.xls uses RAND and NORMDIST functions to estimate the area under a curve.

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 5
Model 3-3: Single-Period Inventory
▪ How many championship-logo team hats (h) to stock?
• Must decide on h now, can’t reduce/increase order, or re-order
• Over the next month is peak-period demand, assume D ~ DU[1000, 5000]
For i = 1000, 1001, …, 5000, P(D = i) = 1/(5000 + 1 – 1000)  0.000249938 Newsvendor problem (daily newspapers)
Much-studied, some analytical solutions
• Buy at w = $11.00; sell for r = $16.95 in peak period, c = $6.95 in “clearance” Applications – fresh food, blood banks
o Can eventually sell all in any post-peak “clearance” period at price c
• Number sold during peak period at r (profit r – w) is min(D, h)
• Number sold during clearance period at c (loss w – c) is max(h – D, 0)
• Total profit = Z(h) = r min(D, h) + c max(h – D, 0) – wh

Peak Clearance
revenue revenue

Total revenue Total cost


• Note that Z(h) is a random variable, since it depends on the r.v. D
o What h maximizes expected value of Z(h)? What about standard deviation (risk) of Z(h)? Shape of distribution of Z(h)?

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 6
Single-Period Inventory – Generating
Demands
▪ Must generate (draw) demands D from demand distribution
• Assume source of random numbers U: IID (Independent and Identically Distributed) draws from continuous U(0, 1)
o Chapt. 4 discusses random-number generators in general (tricky)
o Excel provides built-in function RAND() (no argument)
• Intuition:
o Want D ~ discrete uniform on a = 1000, 1001, …, 5000 = b
o “Stretch” U: (b + 1 – a)U will be continuously uniformly distributed between 0 and b + 1 – a
o “Shift” this up by a: a + (b + 1 – a)U will be continuously uniformly distributed between a and b + 1
o Truncate down to next-lower integer: D = a + (b + 1 – a)U will be discretely uniformly distributed on a, a + 1, …, b
• Get b + 1 only if U = 1, probability-zero event (since U is continuous), so ignore
o Confirm: for i = a, a + 1, …, b,
P(D = i) = P(i ≤ (b + 1 – a)U < i + 1) = 1/(b + 1 – a) = 1/(5000 + 1 – 1000)  0.000249938, as desired! (more details on the algebra in book)

Truncation function in Excel: INT(.)

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 7
Single-Period Inventory – Strategy
▪ Static simulation model
• Replicate many times (50, chosen somewhat arbitrarily), not just one run, observe many (50) IID values of Z(h) by
observing just as many values on D, and using the profit formula
• Each replication will be a row in the spreadsheet
• Try multiple values of h, subject each to the same realized demands D
o Could use independent demands D across different values of h, but using the same D’s is better since differences across h will be more
likely due to h, and not just getting different D’s (since you’re not)

• For each h, get statistics on the 50 observed (simulated) Z(h)’s – average, standard deviation, 95% confidence interval on
E(Z(h)), min, max, and proportion < 0 (estimates probability of losing money)
• Also make histogram of the 50 IID values of the Z(h)’s for each h, I-beam confidence-interval plot vs. h to estimate
expected-profit-maximizing h
o Will not get into the Excel graphics details for these graphs … see file

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 8
Single-Period Inventory – Excel File
▪ Model_03_03.xls , two sheets (tabs at bottom)
• First uses only built-in Excel tools, second uses @RISK add-in (which you must have and already loaded to view this sheet
properly)
▪ First (Excel-only) sheet:
• Input parameters in “true blue” area A4..B9
o Important “spreadsheet-engineering” point – rest of sheet uses these values, which are not “hard-wired” in the rest of the sheet, so if
you change any of these the whole sheet updates itself – a spreadsheet model, not just a spreadsheet … what if cost, prices changed?
• Demands D in Col. F, worst/best possible at top (1000 and 5000)
• Five trial values of h (Row 3), for each three columns with peak-period units sold, clearance units sold, profit
• Summary statistics in rows 57-64 (see formulas in these cells)
• Histograms in Rows 66-77
• I-beam confidence-interval plots in Cols. A-B
• Tap F9 key to recalculate whole sheet with “fresh” random numbers

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 9
Single-Period Inventory – Observations
▪ Choosing h = 1000 is riskless
• You know that peak-period demand will be at least 1000
• So you know you sell out every time, get profit $5950 every time, no variation, no risk (downside or upside)
▪ At the other extreme, choosing h = 5000 is very risky
• Will always be stuck with inventory to dump at clearance (downside)
• But will never lose any peak-period sales (upside)
▪ Rows 5-6 show best possible, worst possible profit for each h
▪ Intermediate values of h appear better than either extreme
• Higher h implies higher risk (histogram spreads, probability of loss, width of confidence interval on expected profit), both
downside and upside
• Choosing h around 3000 or 4000 appears to maximize expected profit … tap F9 and watch I-beam plot on the left as a
function of h

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 10
Single-Period Inventory – With @RISK
▪ Second sheet (tab at bottom) in Model_03_03.xls uses @RISK spreadsheet-simulation add-in
• You must have @RISK, and you must have it loaded, for this sheet to display properly

▪ Greatly facilitates spreadsheet simulation:


• You still have to create the basic model, with profit formulas, different values of h, etc. – but only one replication (row) of it
(Row 7)
• Demand cell (F7) is replaced by an @RISK probability distribution, RiskIntUniform(1000,5000) for discrete uniform on this
range
o @RISK supplies many different probability distributions, and a good random-number generator (does not use Excel’s RAND())

• Identify “response” cells or interest, in this case the profit cells for each value of h
• Specify number of replications (hundreds, thousands no problem)
• @RISK automatically compiles many statistics on the identified response cells (mean, standard deviation, extremes,
quantiles, histograms, …)

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 11
Dynamic Simulation

▪ Passage of time is essential and explicit in model execution; can


almost never be done in spreadsheets except for very simple models
• Queueing systems, dynamic inventory systems, supply chains
• Key variable: simulation clock = current value of (simulated) time
o Should be real-valued, not integer-valued since simulated time is continuous
o Should jump between (exact) event times in continuous time, not be time-stepped or
time-sliced … wasted computer effort, model distortion since event times are rounded
to nearest time-step boundary … see text for more

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 12
Model 3-4: Manual Simulation – Setup
▪ All dynamic simulations operate via the same logic underneath, though high-level simulation software spares you from this
• But it’s important to see how it works, e.g. for debugging

• Also, it’s the logic used if coding a dynamic simulation in C++, Java, etc. Given Arrival, Service Times (Minutes)
Entity (patient) Arrival Interarrival Service
▪ Example: single-server queue, same as registration desk in urgent-care clinic in Chapt. 2 Number Time Time Time
1 0.000000 0.486165
Registration 2 1.965834 1.965834 0.665121
3 2.275418 0.309584 0.354917
Arriving Reg. Desk Departing 4 2.909957 0.634539 0.563653
5 4.033363 1.123406 0.051575
patients patients 6 5.136229 1.102866 2.652734
7 6.539427 1.403198 0.379540
8 6.744513 0.205086 0.330272
The last three service times
Patient being 9 7.845616 1.101103 2.985174
are not used.
registered 10 8.330407 0.484791 0.290218
Queue
• First arrival at time 0, arrival times “given” (actually, see Sec. 5.2.1) … inter-arrival times computed from them, more useful
File: Model_03_01.xls
• Service times “given” (Sec. 5.2.1, again) from book’s website

• End simulation (abruptly) at time 8 minutes, even if patients present

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 13
Manual Simulation – Metrics
▪ Utilization of server (proportion or percent of time busy)
▪ Average, minimum, maximum of:
Discrete-time processes
• Number of entities in system (WIP) a.k.a. observational, tally
• Number of entities in queue (queue length)

• Total entity (patient) time in system (entry-exit)


Continuous-time processes
• Entity time in queue a.k.a. time-persistent,
discrete-change
▪ Averages of discrete-time processes are just simple averages
▪ (Continuous) time averages:
Let: L(t) = number in system (WIP) at time t Also have “count”-type
Lq(t) = number in queue at time t statistics – how many patients
B(t) = 1 if server is at time t, 0 if idle at time t didn’t wait in queue, etc.
Time-averages (T = simulation run length = 8 minutes):

Time-average number in system (WIP) = 0TL(t)dt/T

Time-average number in queue = T0 Lq(t) dt/T

Server utilization (proportion) = T0 B(t) dt/T

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 14
Manual Simulation – Events
▪ Identify events that occur at instants of simulated time, may change the system state variables
• Arrival of a patient entity Why no separate event for
starting registration service?
• Departure of a patient entity, after completing registration service
• End of the simulation, at time 8 minutes (artificial event, to stop run)
▪ Event calendar (list): data structure with future-events info
• When in the simulated future an event will occur
• Type of event
• Entity involved (if applicable)
▪ Simulation proceeds by identifying the next (soonest) event in the event calendar
• Execute that event’s logic to update state variables, statistical-tracking variables, event calendar itself (may depend on state
of system)
• No (simulation) time passes during an event – simulated time stands still
▪ Initialize clock, state variables, statistical-tracking variables, event calendar – line 19 in Model_03_01.xls

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 15
Manual Simulation – Arrival-Event Logic
In Model_03_04.xls, each row 19-35 is an event, just after it’s happened

▪ Schedule the next arrival (Col. J) for now (clock in Col. A), plus next interarrival time (Col. C, rows 6-14)
▪ Compute rectangle areas under B(t), L(t), Lq(t) between time of last event and now; record into Cols. O-Q
(will be added up at end of simulation for total areas)
▪ If server is now idle
• Arriving (lucky) entity goes right into service, no wait in queue
• Note time of arrival (now, Col. A) in Col. G for later computation of time in system
• Schedule entity’s departure for now (Col. A) plus next service time (Col. D, rows 5-10), put into Col. K
• Record 0 queue time (Col. N)
▪ Else (server is already busy)
• Entity queues up; put arrival time at end of queue list (Cols. H-I)

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 16
Manual Simulation – Departure-Event
Logic
▪ Compute rectangle areas under B(t), L(t), Lq(t) between time of last event and now;
record into Cols. O-Q (will be added up at end for total areas)
▪ Compute departing entity’s time in system (Col. A – Col. G), put into Col. M
▪ If queue is not empty
• Remove 1st entity from queue, start service: Copy arrival time in H in row above into G in
this row
• Schedule this entity’s departure as now (Col. A) plus the next service time, put into Col. K
• Compute time in queue for this entity, (Col. A – Col. G), put into Col. N
▪ Else (queue is empty)
• Make server status (Col. D) in this row 0
What about scheduling the time of the next arrival?

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 17
Manual Simulation – End-Simulation-
Event Logic
▪ Compute final rectangle areas under B(t), L(t), Lq(t) between time of last event and now (end of simulation, to
bring them up to the end of the simulation); record into Cols. O-Q (will be added up at end for total areas)
▪ Compute output performance measures in Rows 36-38
• Minimum, maximum computations are straightforward (rows 37-38)
• Averages of discrete-time (observational, tally) output process are also straightforward (M36, N36)
o Why no standard-deviation computations? The numbers are there …
• Continuous-time averages, though, need to add up rectangle areas (SUM functions in O36 – Q36), then divide by final simulation
clock value (A35)
▪ During event processing, computer time is needed, but no simulation time passes (simulation clock stands still)
▪ In spreadsheet we saved individual output values (M-Q) and summarized at end, but better to update
accumulators
▪ Spreadsheet is not a general “model” … logic depends on input

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 18
Manual Simulation – Continuous-Time
Outputs

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 19
Spreadsheet Simulation Models
▪ Not just use a spreadsheet to help with arithmetic, as in Model 3-1 manual simulation, but build general
spreadsheet model that’s robust, can take different inputs and still execute properly
• Model_03_04.xls did not have such generality or robustness … the structure and choice of the formulas in the body depended on the
particular input arrival and service times at the top … if those times were changed, the spreadsheet would in general no longer be valid
▪ Static simulations can often be done effectively in spreadsheets
• With, without special simulation add-ins (@RISK, Crystal Ball, Risk Solver)
• Make many replications of a given spreadsheet’s logic, record results as histograms, summary measures … much better than just
“running” the spreadsheet once to get a single-number “projection”
o Can measure risk, often very important, missed in “projections”

▪ Dynamic simulations are nearly impossible to do in spreadsheets


• Except for the most extremely simple (trivial?) cases, due to complex logic that doesn’t fit well in two-dimensional thinking/modeling

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 20
General-Purpose Programming Languages
▪ Could code up logic in manual simulation in C++, Java, Matlab, …
• In fact, even the formatting of the slides for arrival-event logic, departure-event logic, resembles procedural code structure
▪ Historically has been done a lot, sometimes still is
• Execution speed
• Complete flexibility to model even quirky behavior
• Painstaking to write, (analyst-)time-consuming, error-prone
▪ Still need to identify events, define their logic, lots more work:
• Also data structures for state variables, statistical-tracking variables, clock, event calendar
• Tie event programs together with logic to execute the next event
• Program ending conditions, summarization of results
• Random-number generator, generating random “variates” from desired input distributions (Chapt. 4)
▪ Can sometimes link such code as modules to larger model

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 21
Special-Purpose Simulation Software
▪ Saw several approaches to doing simulations in this chapter:
• Manual – OK for learning principles, obviously completely impractical for any real applications
• General-purpose programming languages –complete flexibility and speed, but too time-consuming, error-prone for models of
complex systems
• Spreadsheets – work well for static “risk” simulations (especially with an appropriate add-in), but just can’t handle the logic and
data-structure complexity of general dynamic simulations
o Dynamic simulation of waiting times in queue in a spreadsheet was possible only via Lindley’s recurrence, which was only for that output

▪ Specialized dynamic simulation software has actually been around since the 1960s (see text for a very brief
history)
• Simio is a relatively new entry, but developed by the same people who earlier developed several other packages, so lots of
experience behind it
• Simio uses an object-oriented graphical approach to simplify modeling

COLLEGE OF ENGINEERING – INDUSTRIAL ENGINEERING PROGRAM TU.EDU.SA


Chapter 3 Approaches to Simulation 22

You might also like