Chap 3
Chap 3
VR
Time Time
Time Time
Customer n+1
进程:由若干个有序事件及有序活动组成,描述了他所包括的事
件和活动间的相互逻辑关系及时序 关系
例如:顾客到达系统、排队、接受服务、服务完毕离开 --- 一个进
程
进程
排队活动 服务活动
Delay
Acustomer’s wait in queue until
Able or Baker becomes free
Questions
How does each event affect system
state,entity attributes, and set
contents?
How are activities defined?
Which events trigger the beginning
(and end) of each type of delay?
What’s system state at time 0?
How to get the simulation started?
Prototype system snapshot
Overview
Concepts in Discrete-Event
Simulation
The Event-Scheduling algorithm
Examples
List processing
Other Algorithm
Summary
Customer n
Time Time
Time Time
Customer n+1
The event-scheduling
algorithm
Simulation clock
Simulated time
FEL
(event type, occur at time)
t < t1 < t2 < t3 <…< tn
Algorithm
1. Remove the event notice for
the imminent event from FEL
2. Advance CLOCK to imminent
event time
3. Execute imminent event:
update system state, change
entity attributes, and set
membership as needed
Algorithm(cont’d)
4. Generate future events(if
necessary) and place their
event notice on FEL ranked by
event time
5. Update cumulative statistics
and counters
Algorithm(cont’d)
Simulation start
Set CLOCK to 0
Initialize all system state variables
and others for data collection
Initialize FEL
Simulation end
Set simulation end event
Set simulation CLOCK for end
Overview
Concepts in Discrete-Event
Simulation
The Event-Scheduling algorithm
Examples
List processing
Other Algorithm
Summary
Manual simulation using
event scheduling
Example 1
Reconsiderthe grocery store
with one checkout counter.
Example 1 (cont’d)
Model
System state
LQ(t): the number of customers
served(0 or 1) at time t
Example 1 (cont’d)
Entities
Arrival:A
Departure: D
to occur at time 60
Why service begin not as a
event
Conditional event: the first at
queue + server is idle
Not a primary event
Only primary event at FEL
Example 1 (cont’d)
Event notices
(A,t): an arrival event to occur
at future time t
(D,t): a customer departure at
future time t
(E,60): the simulation
Example 1 (cont’d)
Activities
Interarrivaltime
Service time
Delay
line
Example 1 (cont’d)
Cumulativestatistics
B: server busy time
MQ: Maximum queue length
How to generate a new event
The first arrival event come , a
second arrival event is generated.
1. an interarrival time is generated ----
a*
2. Current time----t , the resulting
(future) event time----t*=t+a*
3. t* is used to position the new arrival
event
a service-completion event
When one customer completes service, at
current time CLOCK t , if the next
customer is present, then a new service
time, s*, will be generated for the next
customer.
The next service-completion event will be
scheduled to occur at future time t*=t+s*
placing onto the FEL a new event notice of
type service completion with event time t*
System state Cumulative
statistics
Clock FEL B MQ
LQ(t) LS(t)
0 0 1 (D,4)(A,8) 0 0
(E,60)
4 0 0 (A,8)(E,60) 4 0
8 0 1 (D,9)(A,14) 4 0
(E,60)
9 0 0 (A,14)(E,60) 5 0
14 0 1 (A,15)(D,18) 5 0
(E,60)
15 1 1 (D,18)(A,23) 6 1
Metrics
Server utilitilization
= busy time/total simulated time
Maximum queue length
Example 2
The checkout-counter
simulation, continued
To estimate mean response
time and mean proportion of
customers who spends 4 or
more minutes in the system
Example 2 (cont’d)
Entities
(Ci,t):
representing customer Ci
who arrived at time t.
Example 2 (cont’d)
Event notices
(A,t, Ci), the arrival of customer
Ci at future time t.
(D,
t, Cj), the depature of
customer Cj at future time t.
Example 2 (cont’d)
New cumulative statistics
S: the sum of customer response
times for all customers who have
departed by the current time
F: the total number of customers
who spend 4 or more minutes at
checkout counter.
Example 2 (cont’d)
ND: the total number of
departures up to the current
simulation time
Cl System Cumulative
oc state statistics
FEL S ND F
k LQ(t LS(t
) )
0 0 1 (C1,0) (D,4,C1)(A,8,C2) 0 0 0
(E,60)
4 0 0 (A,8,C2)(E,60) 4 1 1
8 0 1 (C2,8) (D,9,C2) 4 1 1
(A,14,C3)(E,60)
9 0 0 (A,14,C3)(E,60) 5 2 1
14 0 1 (C3,14 (A,15,C4) 5 2 1
) (D,18,C3)(E,60)
15 1 1 (C3,14 (D,18,C3) 5 2 1
Example 2 (cont’d)
Metrics
The average response time =
S/ND
Theproportion of customers who
spend 4 or more minutes in the
system = F/ND
Overview
Concepts in Discrete-Event
Simulation
The Event-Scheduling algorithm
Examples
Other Algorithm
List processing
Summary
Process-interaction approach
Concentrate on processes
The life cycle of one entity
a process is a time-sequenced list of
events, activities, and delays,
including demands for resources,
Resources’ capacites are limited
waiting process interact
Why popular
intuitive appeal
allow an analyst to describe the
process in terms of high-level
block or network constructs ,while
interaction among processes is
handled automatically.
Process-interaction approach
Arrival Begin End
event service service
Delay Activity
Time Time
Customer n+1
Customer n
Time Time
Process-interaction approach
events are being scheduled on a future
event list
entities are being placed onto lists
whenever they face delays
causing one process to temporarily
suspend its execution while other
processes proceed.
hidden from a modeler's view
Need to have a basic understanding
The activity-scanning approach
the event-scheduling and the
process-interaction approaches use a
variable time advance
The activity-scanning approach uses
a fixed time increment
a rule-based approach to decide
whether any activities can begin at
each point in simulated time
The activity-scanning approach
modeler concentrates on the
activities of a model and those
conditions that allow an activity to
begin.
At each clock advance, the
conditions for each activity are
checked and, if the conditions are
true, then the corresponding
activity begins.
The activity-scanning approach
simple in concept and leads to
modular models
the repeated scanning result in
slow runtime on computers
the three-phase approach
Here ---- the three-phase approach
pure activity-scanning+ some
features of event scheduling
avoidance of unnecessary
scanning
keeping the main advantages of
the activity-scanning approach
the three-phase approach
two kinds of activities : B and C.
1. B: activities bound to occur;
Eg: primary events units(activities of
duration-zero time ),
unconditional activities.
2. C : activities that are conditional
upon certain conditions being true.
the three-phase approach
FEL
B can be scheduled ahead of time
(event-scheduling approach).
allows variable time advance.
The FEL contains only B-type
events.
the three-phase approach
Scanning
Scanning to check if any C-type
activities can begin or C-type
events occur happens only at the
end of each time advance,
after all B events have completed.
the three-phase approach
Phase A Remove all the imminent events
from the FEL and advance the clock to its
event time.
Phase B Execute all B-type events that
were removed from the FEL. free
resources, change system state
Phase C Scan the conditions that trigger
each C-type activity and activate any
whose conditions are met
Example
Six dump trucks: Each truck is loaded
by one of two loaders.
Loading-- scale--travel.
Both the loaders and the scale have a
first-come first-served waiting line (or
queue) for trucks.
The purpose : estimate the loader
and scale utilizations
two cumulative statistics
Activity time
the utilizations
Use activity scanning
Process interaction
Overview
Concepts in Discrete-Event
Simulation
The Event-Scheduling algorithm
Examples
Other Algorithm
List processing
Summary
List processing
Implementation methods
Static
List -> array
Dynamic List -> pointer
Here, dynamic
For details, refer to books such
as “Data Structure”
List processing(cont’d)
Operations
Inserta record to the list
Where? The top, end or
middle?
Remove a record from the list
middle?
List processing(cont’d)
Records
Event notices
Ranking rules
By time ( the latest, the first )
By priority
List header
List processing(cont’d)
Insert operation ( by time )
Find the appropriate place
Insert
Top
Middle
end
Header
5 8
q Insert to
3 the top
Header
3 5 8
Header
3 8
q
Insert to
5 the middle
Header
3 5 8
Header
3 5
q Insert to
8 the tail
Header
3 5 8
List processing(cont’d)
Remove operation ( by time )
Find the appropriate place
Remove
Top
Middle
end
Header
3 5 8
q Remove
3 from the top
Header
5 8
Overview
Concepts in Discrete-Event
Simulation
The Event-Scheduling algorithm
Examples
List processing
Other Algorithm
Summary
Summary
Major concepts and building
blocks in simulation
Entities
Attributes
Events
Activities
Summary(cont’d)
Event-scheduling/time-advance
algorithm
List processing
homework
Bank’s book
Excise 7
Two weeks