General Principles - Revived: Dr. Sanja Lazarova-Molnar
General Principles - Revived: Dr. Sanja Lazarova-Molnar
2
Outline
• Deals exclusively with dynamic, stochastic systems.
• Discrete-event models are appropriate for those systems for
which changes in system state occur only at discrete points in
time.
– Covers general principles and concepts:
• Event scheduling/time advance algorithm.
• The three prevalent world views.
– Introduces some of the notions of list processing.
3
Concepts in Discrete-Event Simulation
Activity vs. Delay
4
Concepts in Discrete-Event Simulation
Activity vs. Delay
5
Concepts in Discrete-Event Simulation
by Example
6
Concepts in Discrete-Event Simulation
• The definition of the model components provides a static
description of the model.
• A description of the dynamic relationships and interactions
between the components is also needed.
– e.g., how does each event affect system state? What events mark the
beginning or end of each activity? What is the system state at time 0?
• A discrete-event simulation is:
– The modeling over time of a system all of whose state changes occur at
discrete points in time.
– Proceeds by producing a sequence of system snapshots.
7
Event Scheduling/Time Advance Algorithm
• The mechanism for advancing simulation time and guaranteeing that
all events occur in correct chronological order.
• At any given time t, the future event list (FEL) contains all previously
scheduled future events and their associated event times (t1,t2, …)
– FEL is ordered by event time, and the event time satisfy:
t £ t1 £ t2 £ t3 £ … £ tn where t is the value of CLOCK
Repeat
8
Event Scheduling/Time Advance Algorithm
9
List Processing [Event Scheduling]
10
Future Events [Event Scheduling]
11
Future Events [Event Scheduling]
12
Manual Simulation Using Event Scheduling
• Grocery Store Example: Single-channel queue. Reconsider the single
checkout counter problem.
– The system consists of those customers waiting plus the one (if any) checking
out.
– For this example, a stopping time of 60 minutes is set.
– Model components:
• System state: LQ(t) – # of customers in line at time t, LS(t) - # being served at time t.
• Entities: the server and customers are not explicitly modeled, except in terms of the
state variables.
• Events: arrival (A), departure (D), stopping event (E).
• Event notices (event type, event time):
– (A, t), representing an arrival event to occur at future time t;
– (D, t), representing a customer departure at future time t;
– (E, 60), representing the simulation stop event at future time 60.
• Activities: interarrival time and service time.
• Delay: customer time spent in waiting line.
13
Grocery Store Example [Manual Simulation]
14
Grocery Store Example [Manual Simulation]
15
Grocery Store Example [Manual Simulation]
• Initial conditions are the 1st customer arrives at time 0 and begin service.
• Only two statistics: server utilization (B) & maximum queue lengths (MQ).
• Simulation table:
Arrival at time 8
Departure at time 4
Terminating event
at time 60
System State Cumulative Statistics
Clock LQ(t) LS(t) Future Event List Comment B MQ
First A occurs: (a* = 8),
0 0 1 (D, 4), (A, 8), (E, 60) schedule next A; (s*=4) 0 0
Schedule first D
4 0 0 (A, 8), (E, 60) First D occurs: (D, 4) 4 0
17
Grocery Store Example [Manual Simulation]
At time 16, when the departure event (D, 18, C3) is being executed, the response
time for customer C3 is computed by:
• Six dump trucks are used to haul coal from the entrance of a small
mine to the railroad.
– Each truck is loaded by one of two loaders.
– After loading, the truck immediately moves to the scale to be weighed.
– The loaders and the scale have a FCFS waiting line (or queue) for trucks.
– After being weighed, a truck begins a travel time (during which the truck
unloads) and returns to the loader queue.
20
Dump-Truck Example [Manual Simulation]
• The distributions of loading time, weighing time and travel time are:
Cumulative Random Digit
Loading Time Probability Probability Assignment
5 0.3 0.3 1-3
10 0.5 0.8 4-8
15 0.2 1 9-0
22
Dump-Truck Example [Manual Simulation]
23
Dump-Truck Example [Manual Simulation]
Truck 3 joins the weigh Truck 4 begins to load,
queue (because the scale is schedule an EL event for
• Simulation Table: occupied.) future time 10
25
Dump-Truck Example [Manual Simulation]
26
Dump-Truck Example [Manual Simulation]
27
Lists: Basic Properties and Operations
• Lists are a set of ordered or ranked records.
– In simulation, each record represents one entity or one event notice.
– They have top or head (1st item) and bottom or tail.
– Ways to traverse the list (to find the 2nd, 3rd, etc. items on the list) are
necessary.
• An entity identifier and its attributes are fields in the entity record.
• Each record on a list has a field that holds a “next pointer” that points
to the next record on the list.
28
Lists: Basic Properties and Operations
• The main operations on a list are:
– Removing a record from the top of the list
– Removing a record from any location on the list
– Adding an entity record to the top or bottom of the list
– Adding a record at an arbitrary position in the list, specified by the ranking rule.
• In the event-scheduling approach, when time is advanced and the
imminent event is due to be executed:
– First, the removal operation takes place.
– If an arbitrary event is being canceled, or an entity is removed from a list based
on some of its attributes to being an activity, then the second removal operation
is performed
– If a queue has the ranking rule earliest due date first, then, upon arrival at the
queue, an entity must be added to the list determined by the due-date ranking
rule.
29
Lists: Basic Properties and Operations
• For simulation on a computer:
– All records are stored in arrays: arrays hold successive records in contiguous
locations in computer memory, referenced by array index.
– All entities and event notices are represented by structure (as in C) or classes (as
in Java) allocated from RAM memory as needed, and tracked by pointers to a
record or structure.
30
Using Arrays [List Processing]
31
Using Arrays [List Processing]
32
Dump-Truck Example [List Processing]
• Recall the dump-truck problem: At clock time 10, there is waiting line of 3
dump trucks occurred at the weigh queue, specifically, DT3, DT2 and DT4 (in
this order.)
• Suppose the model is tracking one attribute of each dump truck: its arrival
time at the weigh queue, updated each time it arrives.
• Suppose that the entities are stored in records in an array dimensioned from
1 to 6, one record for each dump truck.
– Each entity is represented by a record with 3 fields:
• The first is an entity identifier,
• The second is the arrival time at the weigh queue,
• The last is pointer field to “point to” the next record.
[ DTi, arrival time at weigh queue, next index]
33
Dump-Truck Example [List Processing]
• At clock time 10, the list of entities in the weigh queue would be defined by:
headptr = 3
R(1) = [DT1, 0.0, 0], R(2) = [DT2, 10.0, 4], R(3) = [DT3, 5.0, 2]
R(4) = [DT4, 10.0, 0], R(5) = [DT5, 0.0, 0], R(6) = [DT6, 0.0, 0]
• To traverse the list, start with the head pointer, go to that record, retrieve that
record’s next point, and proceed. To create the list in its logical order, for example:
headptr = 3,
R(3) = [DT3, 5.0, 2], R(2) = [DT2, 10.0, 4], R(4) = [DT4, 10.0, 0]
– The zero entry for next point in R(4), as well as tailptr = 4, indicates that DT4 is at the end of
the list.
34
Dump-Truck Example [List Processing]
• At clock time 12, dump truck DT3 begins weighing and thus leaves the weigh
queue.
– To remove the DT3 entity record form the top of the list, update the head pointer
by setting it equal to the next pointer value of the record at the top of the list:
headptr = R(headptr, next)
– In this example, we get: headptr = R(3, next) = 2. Hence, dump truck DT2 in R(2)
is now at the top of the list.
35
Using Dynamic Allocation and Linked Lists [List
Processing]
36
Using Dynamic Allocation and
Linked Lists [List Processing]
• A record is referenced by a pointer instead of by an array index.
– A pointer to a record can be thought of as the physical or logical address
in computer memory of the record.
– If the 3rd item on the list is needed, we need to traverse the list, counting
items until we reach the record.
• Notation for records:
– Entities: [ID, attributes, next pointer]
– Event notices: [event type, event time, other data, next pointer]
• List types:
– Singly-linked lists: one-way linkage from the head of the list to its tail.
– Doubly-linked lists: records have two pointer fields, one for the next
record and one for the previous record.
37
Dump-Truck Example [List Processing]
• Event notices in the dump truck problem are expanded to include a pointer
to the next event notice on the future event list, and can be represented by:
[event type, event time, DTi, nextptr]
– Keep in mind that the records may be stored anywhere in computer memory.
38
Summary
• Introduced the major concepts and building blocks in simulation:
– Entities and attributes.
– Events and activities.
• Three major world views:
– Event-scheduling.
– Process interaction.
– Activity scanning.
• Basic notions of list processing are introduced to gain understanding
of this important underlying methodologies.
39