—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-1 Day 3 Section 5 - Event Approach to Simulation –Events.

Slides:



Advertisements
Similar presentations
C Structures What is a structure? A structure is a collection of related variables. It may contain variables of many different data types---in contrast.
Advertisements

Chapter 3 Process Description and Control
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Module R2 CS450. Next Week R1 is due next Friday ▫Bring manuals in a binder - make sure to have a cover page with group number, module, and date. You.
Parallel and Distributed Simulation
Intro to Arena A Third Simulation. Model 3 We add more features to Model 2, also from Ch. 5 of Simulation with Arena. The justification for adding features.
—————————— CACI Products Company ————————————————————————————— SimScript II.5 —————————————— 3-1 Day 2 Section 3 - Introduction to Process Simulation –Modeling.
—————————— CACI Products Company —————————————————————————————— SimScript II.5 —————————————— 9-1 Day 5 Section 9 - Continuous Simulation –Exercise 9 Section.
F Day 3 Section 5 - Event Approach to Simulation Events
Simulation. Example: A Bank Simulator We are given: –The number of tellers –The arrival time of each customer –The amount of time each customer requires.
—————————— CACI Products Company ———————————————————————————— SimScript II.5 —————————————— Day 1, Section 2 Problem Solution C:\Program Files\Simscript3\models\Heath2.
Process Description and Control Module 1.0. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor.
—————————— CACI Products Company —————————————————————————————— SimScript II.5 —————————————— 10-1 Day 5 Section 9 - Contiuous Simulation –Exercise 9 Section.
—————————— CACI Products Company ———————————————————————————— SimScript II.5 —————————————— 8-1 Day 4 Section 7 - Simulation Control –User Interface Forms.
—————————— CACI Products Company ———————————————————————————— SimScript II.5 —————————————— Day 1, Section 1 Problem Solution C:\Program Files\Simscript3\models\READFILE2.
Components and Organization of Discrete-event Simulation Model
—————————— CACI Products Company —————————————————————————————— SimScript II.5 —————————————— 2-1 Day 1 Section 1 - The General Purpose Language –Overview.
Simscript II.5 Building simulation model with SIMSCRIPT II.5.
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
Discrete Event Simulation Event-Oriented Simulations By Syed S. Rizvi.
Simulating Single server queuing models. Consider the following sequence of activities that each customer undergoes: 1.Customer arrives 2.Customer waits.
—————————— CACI Products Company ————————————————————————————— SimScript II.5 —————————————— 4-1 Day 2 Section 3 - Introduction to Process Simulation –Modeling.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
CPSC 531: DES Overview1 CPSC 531:Discrete-Event Simulation Instructor: Anirban Mahanti Office: ICT Class Location:
Chapter 12 Pointers and linked structures. 2 Introduction  The data structures that expand or contract as required during the program execution is called.
Lab 01 Fundamentals SE 405 Discrete Event Simulation
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
Verification & Validation
Object Oriented Analysis & Design SDL Threads. Contents 2  Processes  Thread Concepts  Creating threads  Critical sections  Synchronizing threads.
ETM 607 – Discrete Event Simulation Fundamentals Define Discrete Event Simulation. Define concepts (entities, attributes, event list, etc…) Define “world-view”,
Lists. Container Classes Many applications in Computer Science require the storage of information for collections of entities e.g. a student registration.
6 Memory Management and Processor Management Management of Resources Measure of Effectiveness – On most modern computers, the operating system serves.
Entities and Objects The major components in a model are entities, entity types are implemented as Java classes The active entities have a life of their.
1 QUEUES. 2 Definition A queue is a linear list in which data can only be inserted at one end, called the rear, and deleted from the other end, called.
+ Simulation Design. + Types event-advance and unit-time advance. Both these designs are event-based but utilize different ways of advancing the time.
Chapter 2 – Fundamental Simulation ConceptsSlide 1 of 46 Chapter 2 Fundamental Simulation Concepts.
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Simulation Using computers to simulate real- world observations.
NETW 707 Modeling and Simulation Amr El Mougy Maggie Mashaly.
1 Simulation Implementation Using high-level languages.
Reid & Sanders, Operations Management © Wiley 2002 Simulation Analysis D SUPPLEMENT.
MODELING EXAMPLES Types of model Conceptual Containing components that have not been clearly Identified in terms of theoretic categories such as state,
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Object Oriented Simulation with OOSimL Conditional Waiting.
OPERATING SYSTEMS CS 3530 Summer 2014 Systems and Models Chapter 03.
Dr. Anis Koubâa CS433 Modeling and Simulation
(C) J. M. Garrido1 Objects in a Simulation Model There are several objects in a simulation model The activate objects are instances of the classes that.
COMP155 Computer Simulation September 10, Discrete Event Simulation  discrete event simulation: state variable change only at a discrete set of.
4330/6310 FIRST ASSIGNMENT Spring 2015 Jehan-François Pâris
CS433 Modeling and Simulation Lecture 09 – Part 02 Discrete Events Simulation Dr. Anis Koubâa 27 Dec 2008 Al-Imam.
 Simulation enables the study of complex system.  Simulation is a good approach when analytic study of a system is not possible or very complex.  Informational,
Simulation Examples And General Principles Part 2
CDA6530: Performance Models of Computers and Networks Chapter 8: Statistical Simulation ---- Discrete Event Simulation (DES) TexPoint fonts used in EMF.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Chapter 1 What is Simulation?. Fall 2001 IMSE643 Industrial Simulation What’s Simulation? Simulation – A broad collection of methods and applications.
OPERATING SYSTEMS CS 3502 Fall 2017
Operating Systems (CS 340 D)
Modeling and Simulation (An Introduction)
ADVANTAGES OF SIMULATION
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Operating Systems (CS 340 D)
Topics Introduction to File Input and Output
Process Description and Control
Discrete Event “Hand” Simulation of a GI/GI/1 Queue
MECH 3550 : Simulation & Visualization
Chapter 4: Simulation Designs
Topics Introduction to File Input and Output
SIMSCRIPT SIMSCRIPT is a general-purpose simulation language
Presentation transcript:

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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 

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-2 Section 5 - The Event Approach to Simulation Part 1 - Events

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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.

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-4 Scheduling Events Schedule an END.TAKEOFF in 2 minutes (event) Activate a DEPARTURE now (process) Activate, reactivate, schedule and reschedule are synonyms

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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.

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-8 Passing Arguments to Events (continued) –New routine Event END.TAKEOFF Given.AC ''Pointer to an airplane … … End ‘’END.TAKEOFF

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-9 Passing Arguments to Events (continued) System Attributes ET.AIRCRAFT.POINTER.AIRPLANE.AC

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-10 Section 5 - The Event Approach to Simulation Part 2 - Implementation of the Event Approach

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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.

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 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 Every END.TAKEOFF has 15 an ET.AIRCRAFT.POINTER Define ET.AIRCRAFT.POINTER as a pointer variable Temporary entities Every AIRPLANE has 22 an AP.BEGIN.WAIT.TIME and 23 belongs to the QUE.RUNWAY and 24 the EXE.RUNWAY Define AP.BEGIN.WAIT.TIME as a real variable The system owns 29 the QUE.RUNWAY and 30 the EXE.RUNWAY 31

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— '' Global variables 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 Define NO.OF.RUNWAYS and 42 MAX.NO.OF.WAITING.AIRPLANES 43 as integer variables 44 Define MAX.WAITING.TIME as a real variable 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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 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 Print 2 lines thus Enter the minimum and maximum takeoff times (in minutes) Minimum time: 16 Read MINIMUM.TAKE.OFF.TIME Print 1 line thus Maximum time: 20 Read MAXIMUM.TAKE.OFF.TIME Print 1 line thus Enter the number of runways 24 Read NO.OF.RUNWAYS Print 1 line thus Enter the run length (in hours) 28 Read RUN.LENGTH End ''READ.DATA

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 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 <=.TIME.TO.QUIT 9 10 Schedule a NEW.AIRPLANE now 11 Reschedule this AIRPLANE.GENERATOR 12 in uniform.f(MINIMUM.INTER.DEPARTURE.TIME, 13 MAXIMUM.INTER.DEPARTURE.TIME, 14 1) minutes 15 Endif ''time.v <=.TIME.TO.QUIT 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 ** Read as / using unit Stop End ''FINAL.REPORT

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— Event NEW.AIRPLANE 2 3 Define.AP as an integer variable 4 5 Create an AIRPLANE called.AP 6 7 If N.EXE.RUNWAY < 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 Else File.AP in the QUE.RUNWAY 20 Let AP.BEGIN.WAIT.TIME(.AP) = time.v 21 Let MAX.NO.OF.WAITING.AIRPLANES 22 = max.f(N.QUE.RUNWAY, MAX.NO.OF.WAITING.AIRPLANES) Endif ''N.EXE.RUNWAY < NO.OF.RUNWAYS End ''NEW.AIRPLANE

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 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 Remove.AC from the EXE.RUNWAY 12 Destroy the AIRPLANE called.AC 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 20 in uniform.f(MINIMUM.TAKE.OFF.TIME, 21 MAXIMUM.TAKE.OFF.TIME, 22 2) minutes 23 Let.WAITING.TIME = time.v - AP.BEGIN.WAIT.TIME(.AIRPLANE) 24 Let MAX.WAITING.TIME = max.f(.WAITING.TIME, MAX.WAITING.TIME) 25 Endif ''the QUE.RUNWAY is not empty End ''END.TAKEOFF

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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.

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-19 This page is intentionally blank

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-20 Section 5 - The Event Approach to Simulation Part 3 - Canceling Events

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-21 More on The Event Set I.AIRPLANE GENERATOR I.NEW. AIRPLANE I.END. TAKEOFF I.FINAL. REPORT F.EV.S L.EV.S Ev.s consists of multiple sets - one for each process and event defined in the preamble. This cuts search time.

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-24 Exercise 5 The Port Problem Using Events C:\Program Files\Simscript3\models\EventPort

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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 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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-26 Preamble 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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-27 Preamble (continued) ''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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-28 Main Routine & Initialization 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 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

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-29 Generate Ships Event SHIP.GENERATOR saving the event notice If time.v <= RUN.LENGTH Schedule a REQUEST.DOCK now Reschedule this SHIP.GENERATOR in uniform.f(4.0, 18.0, 1) hours Endif ''time.v <= RUN.LENGTH End ''SHIP.GENERATOR

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-30 Request the Dock 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) < 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) < NUMBER.OF.DOCKS(1) End ''REQUEST.DOCK

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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) < NUMBER.OF.TUGS(1) 8 9 File.RQT.SHIP.PTR in the EXE.TUG(1) ''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 ''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 Else ''tug is unavailable so wait in the tug's queue File.RQT.SHIP.PTR in the QUE.TUG(1) Endif ''N.EXE.TUG(1) < NUMBER.OF.TUGS(1) End ''REQUEST.TUG

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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 Remove the first.QUEUED.SHIP.PTR from the QUE.TUG(1) 12 File.QUEUED.SHIP.PTR in the EXE.TUG(1) 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) ''Send the queued ship on its way 27 Schedule a RELEASE.TUG giving.QUEUED.SHIP.PTR in 1 hour Endif ''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(!)

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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) End ''RELEASE.TUG

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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.SHIP.PTR) 12 Add.WAITING.TIME to TOTAL.WAITING.TIME 13 Let MAX.WAITING.TIME = max.f(MAX.WAITING.TIME,.WAITING.TIME) ''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 ''Check the dock queue for ships 20 If the QUE.DOCK(1) is not empty 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 Endif End ''RELEASE.DOCK

—————————— CACI Products Company ——————————————————————————————— SimScript II.5 —————————————— 5-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 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 Skip 2 lines Read as / using unit Stop End ''FINAL.REPORT