Day 3 - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Day 3

Description:

16 File .AIRPLANE in the EXE.RUNWAY. 17 Schedule an END.TAKEOFF ... 25 Endif ''the QUE.RUNWAY is not empty. 26. 27 End ''END.TAKEOFF ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 36
Provided by: jeffryge
Category:
Tags: day | runway

less

Transcript and Presenter's Notes

Title: Day 3


1
Day 3
  • Section 5 - Event Approach to Simulation
  • Events
  • Implementation of the Event Approach
  • Canceling Events
  • Exercise 5
  • Section 6 - Simulation Output Analysis
  • Random Numbers and Statistics
  • Modernizing a Bank - with replications
  • Presentation Graphics
  • Exercise 6

F
2
Section 5 - The Event Approach to Simulation
  • Part 1 - Events

3
Modeling with Events instead of Processes
  • Instead of putting a sequence of events in a
    single process, we may model them separately.
  • Mechanism is the same
  • Event notice
  • Event routine
  • Rather than 1 process with 2 events there will be
    2 separate event types and routines.
  • Cannot use resources, so we'll write our own code
    to mimic them.

4
Scheduling Events
  • Schedule an END.TAKEOFF in 2 minutes (event)
  • Activate a DEPARTURE now (process)
  • Activate, reactivate, schedule and reschedule are
    synonyms

5
Memory for Events
  • Same as processes
  • Event notice for each instance
  • Local memory for each instance
  • Event notice destroyed on entry, not return
  • Local memory released when the event routine
    completes execution

6
Passing Arguments to Events
  • Events are routines. They can receive but not
    yield arguments.
  • Arguments are passed to routines immediately
    because control is passed immediately.
  • Events do not get control immediately, so we need
    a temporary storage for the values.

7
Passing Arguments to Events (continued)
  • Use attributes of event notices
  • In Preamble
  • Every END.TAKEOFF has an ET.AIRCRAFT.POINTER
  • In another routine
  • Schedule an END.TAKEOFF called .ET in 4 minutes
  • Let ET.AIRCRAFT.POINTER(.ET) .AIRPLANE

8
Passing Arguments to Events (continued)
  • New routine
  • Event END.TAKEOFF
  • Given
  • .AC ''Pointer to an airplane
  • ltStatementsgt
  • End END.TAKEOFF

9
Passing Arguments to Events (continued)
10
Section 5 - The Event Approach to Simulation
  • Part 2 - Implementation of the Event Approach

11
The Airport Model (revisited)
  • As an example of discrete event simulation, let's
    rewrite the process version of the airport as a
    sequence of events.
  • We'll break the process DEPARTURE into two
    events, use sets to simulate the resource,
    RUNWAY, and put the waiting time data in a
    temporary entity.

12
  • 1 Preamble
  • 2
  • 3 '' The Airport Model using events - CACI
    Products Company
  • 4 '' files AIRPORT1.SRC
  • 5
  • 6 Normally mode is undefined
  • 7
  • 8 Event notices include
  • 9 AIRPLANE.GENERATOR,
  • 10 NEW.AIRPLANE,
  • 11 END.TAKEOFF and
  • 12 FINAL.REPORT
  • 13
  • 14 Every END.TAKEOFF has
  • 15 an ET.AIRCRAFT.POINTER
  • 16
  • 17 Define ET.AIRCRAFT.POINTER as a
    pointer variable
  • 18
  • 19 Temporary entities

13
  • 32 '' Global variables
  • 33
  • 34 Define MINIMUM.INTER.DEPARTURE.TIME,
  • 35 MAXIMUM.INTER.DEPARTURE.TIME,
  • 36 MINIMUM.TAKE.OFF.TIME,
  • 37 MAXIMUM.TAKE.OFF.TIME and
  • 38 RUN.LENGTH
  • 39 as real variables
  • 40
  • 41 Define NO.OF.RUNWAYS and
  • 42 MAX.NO.OF.WAITING.AIRPLANES
  • 43 as integer variables
  • 44 Define MAX.WAITING.TIME as a real
    variable
  • 45
  • 46 End ''Preamble

1 Main 2 3 Call READ.DATA
4 5 Schedule a FINAL.REPORT in
RUN.LENGTH hours 6 Schedule an
AIRPLANE.GENERATOR now 7 8 Start
simulation 9 10 End ''Main
14
  • 1 Routine READ.DATA
  • 2
  • 3 Print 3 lines thus
  • Enter the minimum and maximum times between
    airplane departures
  • (in minutes)
  • Minimum time
  • 7 Read MINIMUM.INTER.DEPARTURE.TIME
  • 8
  • 9 Print 1 line thus
  • Maximum time
  • 11 Read MAXIMUM.INTER.DEPARTURE.TIME
  • 12
  • 13 Print 2 lines thus
  • Enter the minimum and maximum takeoff times
    (in minutes)
  • Minimum time
  • 16 Read MINIMUM.TAKE.OFF.TIME
  • 17
  • 18 Print 1 line thus
  • Maximum time

15
  • 1 Event AIRPLANE.GENERATOR
  • 2 saving the event notice
  • 3
  • 4 Define .TIME.TO.QUIT as a real variable
  • 5
  • 6 Let .TIME.TO.QUIT RUN.LENGTH /
    hours.v
  • 7
  • 8 If time.v lt .TIME.TO.QUIT
  • 9
  • 10 Schedule a NEW.AIRPLANE now
  • 11 Reschedule this AIRPLANE.GENERATOR
  • 12 in uniform.f(MINIMUM.INTER.DEPARTU
    RE.TIME,
  • 13 MAXIMUM.INTER.DEPARTU
    RE.TIME,
  • 14 1) minutes
  • 15 Endif ''time.v lt .TIME.TO.QUIT
  • 16
  • 17 End ''AIRPLANE.GENERATOR

1 Event FINAL.REPORT 2 3 Print
4 lines with time.v hours.v, 4
MAX.WAITING.TIME hours.v
minutes.v, 5
MAX.NO.OF.WAITING.AIRPLANES thus The
simulation ended at . hours The
maximum waiting time was . minutes
The maximum number of aircraft waiting at any
one time was . 10 11
Read as / using unit 5 12 13 Stop
14 15 End ''FINAL.REPORT
16
  • 1 Event NEW.AIRPLANE
  • 2
  • 3 Define .AP as an integer variable
  • 4
  • 5 Create an AIRPLANE called .AP
  • 6
  • 7 If N.EXE.RUNWAY lt NO.OF.RUNWAYS
  • 8
  • 9 File .AP in the EXE.RUNWAY
  • 10 Schedule an END.TAKEOFF
  • 11 Given
  • 12 .AP
  • 13 in uniform.f(MINIMUM.TAKE.OFF.TIME
    ,
  • 14 MAXIMUM.TAKE.OFF.TIME
    ,
  • 15 2) minutes
  • 16
  • 17 Else
  • 18
  • 19 File .AP in the QUE.RUNWAY

17
  • 1 Event END.TAKEOFF
  • 2 Given
  • 3 .AC
  • 4
  • 5 Define .AC and
  • 6 .AIRPLANE
  • 7 as pointer variables
  • 8
  • 9 Define .WAITING.TIME as a real variable
  • 10
  • 11 Remove .AC from the EXE.RUNWAY
  • 12 Destroy the AIRPLANE called .AC
  • 13
  • 14 If the QUE.RUNWAY is not empty
  • 15 Remove the first .AIRPLANE from the
    QUE.RUNWAY
  • 16 File .AIRPLANE in the EXE.RUNWAY
  • 17 Schedule an END.TAKEOFF
  • 18 Given
  • 19 .AIRPLANE

18
  • Enter the minimum and maximum times
    between airplane departures
  • (in minutes)
  • Minimum time 1
  • Maximum time 3
  • Enter the minimum and maximum takeoff
    times (in minutes)
  • Maximum time 3
  • Minimum time 5
  • Enter the number of runways 2
  • Enter the run length (in hours) 10
  • The simulation ended at 10.0 hours
  • The maximum waiting time was 8.03
    minutes
  • The maximum number of aircraft
    waiting at any one
  • time was 5.

19
This page is intentionally blank
20
Section 5 - The Event Approach to Simulation
  • Part 3 - Canceling Events

21
More on The Event Set
22
Example of Cancellation
  • Let .AC F.EXE.RUNWAY
  • For each .ET in ev.s (I.END.TAKEOFF)
  • with ET.AIRCRAFT.POINTER (.ET) .AC
  • Find the first case
  • If found
  • Cancel the END.TAKEOFF called .ET
  • Destroy the END.TAKEOFF called .ET
  • Remove .AC from EXE.RUNWAY
  • File .AC in MAINTENANCE.FACILITY
  • Endif ''found

23
Pros and Cons of Events and Processes
  • Pros for Events
  • Less memory
  • Event notices have 5 attributes instead of 9
  • Local memory not saved
  • Event notice not saved
  • Cons for Events
  • Need alternative to resources
  • Why are events used?
  • Habit
  • Event modeling is older than process modeling
  • Easier for new simulation programmer to grasp

24
Exercise 5
  • The Port Problem Using Events
  • C\Program Files\Simscript3\models\EventPort

25
Pacific Port Problem using Events
  • See "EventPort" Directory for Model
  • With 1 tug and 3 docks, a 365-day simulation
    results in
  • 792 ships being unloaded
  • Average waiting time is 4.01 hours
  • Maximum waiting time of 34.00 hours
  • How do these results compare with your process
    version of the Pacific Port Problem?
  • Consider changes to model
  • Dock is held longer than need be - especially if
    more tugs are used.
  • Tug moves instantly to appropriate location (dock
    vs. harbor entrance). Assume travel time without
    a ship is 15 minutes

26
Preamble
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3
4 35 36 37 38 39
Preamble '' CACI Products Company '' '' The Port
model using events - Day 1 Solution '' Source
Code EventPort.SRC Normally mode is
undefined ''Major events are requesting
releasing the dock and the tugs. Event notices
include SHIP.GENERATOR,
REQUEST.DOCK, REQUEST.TUG,
RELEASE.TUG, RELEASE.DOCK and
FINAL.REPORT Every REQUEST.TUG has an
RQT.SHIP.PTR Define RQT.SHIP.PTR as a
pointer variable Every RELEASE.TUG has an
RLT.SHIP.PTR Define RLT.SHIP.PTR as a
pointer variable Every RELEASE.DOCK has an
RD.SHIP.PTR Define RD.SHIP.PTR as a
pointer variable ''SHIPS are the entities
that travel through the system Temporary
entities Every SHIP has a
SHIP.ARRIVAL.TIME, a SHIP.STATUS and
a SHIP.UNLOAD.TIME and belongs to
the QUE.DOCK, the EXE.DOCK,
the QUE.TUG and the EXE.TUG Define
SHIP.ARRIVAL.TIME and SHIP.UNLOAD.TIME
as real variables Define
SHIP.STATUS as an integer variable
27
Preamble (continued)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
57 58 59 60 61 62 63 64 65 66
''Service is provided by a HARBOR that
contains docks and tugs Permanent entities
Every HARBOR has a
NUMBER.OF.DOCKS and a
NUMBER.OF.TUGS and owns a
QUE.DOCK, an EXE.DOCK, a
QUE.TUG and an EXE.TUG Define
NUMBER.OF.DOCKS and NUMBER.OF.TUGS as integer
variables '' Input Global variables
Define RUN.LENGTH as a real variable ''
Output Global Variables provide statistics
collection Define TOTAL.WAITING.TIME and
MAX.WAITING.TIME as real variables Define
NO.OF.SHIPS.SERVED as an integer variable ''
Synonyms provide clarity to the model Define
..AT.HARBOR to mean 1 Define ..TO.DOCK to mean
2 Define ..AT.DOCK to mean 3 Define
..TO.SEA to mean 4 Define ..AT.SEA to mean
5 End ''Preamble
28
Main Routine Initialization
1 2 3 4 5 6 7 8 9 10
Main Call READ.DATA ''to set up simulation
Schedule a FINAL.REPORT in RUN.LENGTH days
Schedule a SHIP.GENERATOR now ''to create new
ships Start simulation End ''Main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25
Routine READ.DATA Define .NBR.TUGS and
.NBR.DOCKS as integer variables Open
unit 10 for input, name "PORT.DAT" Use
unit 10 for input Skip 3 fields
Read .NBR.TUGS Skip 3 fields
Read .NBR.DOCKS Skip 3 fields
Read RUN.LENGTH Close unit 10
''Create 1 harbor that contains .NBR.DOCKS
.NBR.TUGS Let N.HARBOR 1 Create
each HARBOR Let NUMBER.OF.TUGS(1)
.NBR.TUGS Let NUMBER.OF.DOCKS(1)
.NBR.DOCKS End ''READ.DATA
29
Generate Ships
Event SHIP.GENERATOR saving the event notice
If time.v lt RUN.LENGTH Schedule a
REQUEST.DOCK now Reschedule this
SHIP.GENERATOR in uniform.f(4.0, 18.0, 1) hours
Endif ''time.v lt RUN.LENGTH End
''SHIP.GENERATOR
1 2 3 4 5 6 7 8 9 10 11
30
Request the Dock
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 3
4 35 36 37 38 39 40 41
Event REQUEST.DOCK Define .PROBABILITY as a
real variable Define .SHIP as a pointer
variable ''Create a new ship and set up
attributes for unloading time, ''arrival time
and status. Arrival time is used to calculate
''the total time in system when the ship leaves
the harbor. Create a SHIP called .SHIP
''Unloading time differs for each type of ship
Let .PROBABILITY random.f(2) Select case
.PROBABILITY Case 0.0 to 0.25
Let SHIP.UNLOAD.TIME(.SHIP)
uniform.f(16.0,20.0,3) Case 0.25 to 0.80
Let SHIP.UNLOAD.TIME(.SHIP)
uniform.f(21.0, 27.0, 3) Default
Let SHIP.UNLOAD.TIME(.SHIP)
uniform.f(32.0, 40.0, 3) Endselect
''.PROBABILITY ''Store time ship enters
system Let SHIP.ARRIVAL.TIME(.SHIP) time.v
''Set status Let SHIP.STATUS(.SHIP)
..AT.HARBOR ''Grab dock if available. Then
schedule a request for a Tug ''to take SHIP
to the dock If N.EXE.DOCK(1) lt
NUMBER.OF.DOCKS(1) File .SHIP in the
EXE.DOCK(1) Schedule a REQUEST.TUG giving
.SHIP now Else File .SHIP in the
QUE.DOCK(1) Endif ''N.EXE.DOCK(1) lt
NUMBER.OF.DOCKS(1) End ''REQUEST.DOCK
31
Request the Tug
1 Event REQUEST.TUG 2 given
.RQT.SHIP.PTR 3 4 Define
.RQT.SHIP.PTR as a pointer variable 5 6
''Tug is available 7 If
N.EXE.TUG(1) lt NUMBER.OF.TUGS(1) 8 9
File .RQT.SHIP.PTR in the EXE.TUG(1) 10
11 ''Change the ship status. If ship
has just been created, 12 ''indicate
that it will be taken to the dock by the tug.
13 ''If the ship was already at the dock,
then it has unloaded 14 ''its cargo and
is ready to depart to sea 15 Select
case SHIP.STATUS(.RQT.SHIP.PTR) 16
Case ..AT.HARBOR 17 Let
SHIP.STATUS(.RQT.SHIP.PTR) ..TO.DOCK 18
Case ..AT.DOCK 19 Let
SHIP.STATUS(.RQT.SHIP.PTR) ..TO.SEA 20
Default 21 Print 1 line with
time.v and SHIP.STATUS(.RQT.SHIP.PTR) thus
. ERROR in REQUEST.TUG Invalid
ship status 23 Stop 24
Endselect 25 26 ''1 hour is
needed to move the ship to or from the dock 27
Schedule a RELEASE.TUG giving
.RQT.SHIP.PTR in 1 hour 28 29 Else
''tug is unavailable so wait in the tug's queue
30 31 File .RQT.SHIP.PTR in the
QUE.TUG(1) 32 33 Endif
''N.EXE.TUG(1) lt NUMBER.OF.TUGS(1) 34 35
End ''REQUEST.TUG
32
Release the Tug
1 Event RELEASE.TUG 2 given
.RLT.SHIP.PTR 3 4 Define
.RLT.SHIP.PTR and .QUEUED.SHIP.PTR as pointer
variables 5 6 ''Release the tug
and let tug take the first queued 7
''ship to its destination. Note that tug
position ignored(!) 8 Remove
.RLT.SHIP.PTR from the EXE.TUG(1) 9 If
the QUE.TUG(1) is not empty 10 11
Remove the first .QUEUED.SHIP.PTR from the
QUE.TUG(1) 12 File .QUEUED.SHIP.PTR in
the EXE.TUG(1) 13 14 Select
case SHIP.STATUS(.QUEUED.SHIP.PTR) 15
Case ..AT.HARBOR 16 Let
SHIP.STATUS(.QUEUED.SHIP.PTR) ..TO.DOCK 17
Case ..AT.DOCK 18 Let
SHIP.STATUS(.QUEUED.SHIP.PTR) ..TO.SEA 19
Default 20 Print 1 line
with time.v and 21
SHIP.STATUS(.QUEUED.SHIP.PTR) thus
. ERROR in RELEASE.TUG Invalid next
ship status 23 Stop 24
Endselect ''SHIP.STATUS(.QUEUED.SHIP.PTR)
25 26 ''Send the queued ship on its
way 27 Schedule a RELEASE.TUG giving
.QUEUED.SHIP.PTR in 1 hour 28 29
Endif 30 31 ''If the ship has just
arrived at the dock, start unloading. 32
''Schedule the end of the unloading activity -
when tug needed again. 33 ''If ship
heading out from dock, schedule an immediate
release of 34 ''the dock. Note that dock
could be release earlier(!)
33
Release the Tug (continued)
35 Select case SHIP.STATUS(.RLT.SHIP.PTR)
36 Case ..TO.DOCK 37
Let SHIP.STATUS(.RLT.SHIP.PTR) ..AT.DOCK 38
Schedule a REQUEST.TUG giving
.RLT.SHIP.PTR 39 in
SHIP.UNLOAD.TIME(.RLT.SHIP.PTR) hours 40
Case ..TO.SEA 41 Let
SHIP.STATUS(.RLT.SHIP.PTR) ..AT.SEA 42
Schedule a RELEASE.DOCK giving
.RLT.SHIP.PTR now 43 Default 44
Print 1 line with time.v and
SHIP.STATUS(.RLT.SHIP.PTR) thus
. ERROR in RELEASE.TUG Invalid current
ship status 46 Stop 47
Endselect ''SHIP.STATUS(.RLT.SHIP.PTR) 48
49 End ''RELEASE.TUG
34
Release the Dock
1 Event RELEASE.DOCK 2 Given
.RD.SHIP.PTR 3 4 Define
.RD.SHIP.PTR and .QUEUED.SHIP.PTR as pointer
variable 5 Define .WAITING.TIME as a
real variable 6 7 ''Collect
waiting time statistics and count number of ships
served 8 Add 1 to NO.OF.SHIPS.SERVED
9 Let .WAITING.TIME 10
(time.v - SHIP.ARRIVAL.TIME(.RD.SHIP.PTR))
hours.v - 11 SHIP.UNLOAD.TIME(.RD.S
HIP.PTR) 12 Add .WAITING.TIME to
TOTAL.WAITING.TIME 13 Let
MAX.WAITING.TIME max.f(MAX.WAITING.TIME,.WAITING
.TIME) 14 15 ''Release the dock
and free up computer memory 16 Remove
.RD.SHIP.PTR from the EXE.DOCK(1) 17
Destroy the SHIP called .RD.SHIP.PTR 18
19 ''Check the dock queue for ships 20
If the QUE.DOCK(1) is not empty 21
22 Remove the first .QUEUED.SHIP.PTR
from the QUE.DOCK(1) 23 File
.QUEUED.SHIP.PTR in the EXE.DOCK(1) 24
Let SHIP.STATUS(.QUEUED.SHIP.PTR)
..AT.HARBOR 25 Schedule a
REQUEST.TUG giving .QUEUED.SHIP.PTR now 26
27 Endif 28 29 End ''RELEASE.DOCK
35
Final Report
1 Event FINAL.REPORT 2 3 Skip
2 output lines 4 5 Print 4 lines
with RUN.LENGTH thus Pacific Port Problem
(Answer to Student Problem 1) Run length
is days. 10 Skip 2 output lines
11 12 Print 4 lines with time.v, 13
NO.OF.SHIPS.SERVED, 14
TOTAL.WAITING.TIME/NO.OF.SHIPS
.SERVED and 15
MAX.WAITING.TIME thus After . days,
ships have been unloaded. The
average waiting time was . hours. The
maximum waiting time was . hours. 20
21 Skip 2 lines 22 23 Read as /
using unit 5 24 25 Stop 26 27
End ''FINAL.REPORT
Write a Comment
User Comments (0)
About PowerShow.com