Implementation - Department of Computer Science

advertisement
Simulation
Implementation
Using high-level languages
1
Implementation of a SingleServer Queuing System
Two Main Entities
SERVER: Busy= 0/1
QUEUE: Qsize= #
Two Critical Events – for customers
Arrival
Complete Service (Depart)
How do these entities interact?
Initialization?
How are each of the variables affected?
How should simulation terminate?
2
Snapshot or System Image
State of the system at a
given time
State variables
Queue
Future Events List (FEL)
3
Generating Future Events
Bootstrapping: a method for
generating an arrival stream on an
“as you go” basis
As opposed to generating all
events at once
a.k.a. on-the-fly
4
Generating Future Events
Process
1. Generate initial arrival; when it is
removed from FEL generate new
interarrival time - add to clock for
arrival time- place next arrival on
FEL
2. When item is placed in service,
generate service time - add to clock
– place completion event on FEL
5
DATA Structures
Future Events List (FEL)
Queue (1 or more)
What information is required for each
one?
What information is not required but
might be convenient?
When and how are insertions & deletions
made?
When are various units of information
generated (calculated)?
6
Queue
Standard FIFO
Customer identification
Time entered queue
Arrival time
Type of service being
requested (if more than one)
7
Future Events List
Array implementation
Each row represents a specific
event
Customer ID (identification number)
Time of occurrence
Search for smallest time to get the
“next event”
8
Future Events List
Linked List
ordered by time of
occurrence
Event Type
Time of Occurrence
Identification of customer
9
Generating Arrivals
Initialize at a fixed time or time zero
One for each type of arrival
Subsequent arrivals are generated as
arrival is removed
Remove arrival- generate IAT- add to
current time (clock) - put on FEL
At any time, there should only be one
arrival of any given type
10
Generating Departures
Complete Service
Generated when customer enters the
service that will cause the departure
Not necessarily upon arrival, not if
enter queue, only when enter service
Enter service (from queue or from
arrival) - generate service time - add
to current time (clock) - put on FEL
11
Generating Events
Terminate Event
Only one: placed on FEL at
initialization
Snapshot Event (Status Report)
Initialize 1st one
Remove from FEL- add time
unit - return to FEL
12
What? Me Simulate?
Paper by Dr. Halverson
13
Generation of Events
Initialization of FEL
One arrival (of each type)
Snapshot
Stop event
Generation of Arrival
When removed from FEL,
generate next arrival
14
MAIN
Initialize FEL, statistical variables, clock
Remove next-event from FEL
While not stop-event
Clock = next-event.time
Case next-event of
Arrival: produce next arrival
call ARRIVE
Departure: call DEPART
Snapshop: call SNAPSHOT
Remove next-event from FEL
Stop-simulation: call STATS; call OUTPUT
15
ARRIVE
If server_status = busy
Then call ENTER-QUEUE
Else call ENTER-SERVICE
16
DEPART
If queue = empty
Then server_status= free
Else call
REMOVE-FROM-QUEUE
17
ENTER-SERVICE
server_status = busy
Generate departure event
Update service stats
18
ENTER-QUEUE
Add customer to queue
Update queue statistics
19
REMOVE-FROM-QUEUE
Update queue and statistics
Call ENTER-SERVICE
20
STATS
Compute final averages,
totals, etc.
IAT, Service time, Utilization
Queue length, max, min, average
Number arrivals, departures
Wait time, Time in system
21
SNAPSHOT
Generate next Snapshot event,
place in FEL
Print State variables
Print Queue
Print FEL
22
OUTPUT
Print results
23
PROJECT #1
Must follow the guidelines
presented in class for the form of
your program.
Must use object oriented
approach
Print out of Code due in 1 week
24
Download