CPSC 531: Simulation Examples 1 CPSC 531: Some more examples – Time-shared computer and multi-teller bank Instructor: Anirban Mahanti Office: ICT 745 Email: [email protected]Class Location: TRB 101 Lectures: TR 15:30 – 16:45 hours Class web page: http://pages.cpsc.ucalgary.ca/~mahanti/teaching/F05/CPSC53 1/ Notes derived from “Simulation Modeling and Analysis” by A. Law and W. Kelton, Third edition, McGraw Hill, 2000.
30
Embed
CPSC 531: Simulation Examples1 CPSC 531: Some more examples – Time-shared computer and multi-teller bank Instructor: Anirban Mahanti Office: ICT 745 Email:
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
CPSC 531: Simulation Examples 1
CPSC 531: Some more examples –Time-shared computer and multi-teller bank
Notes derived from “Simulation Modeling and Analysis” by A. Law and W. Kelton, Third edition, McGraw Hill, 2000.
CPSC 531: Simulation Examples 2
Objective Under simulation fundamentals via
examples Time-shared computer model Multi-teller bank with jockeying Job shop model
Get a grip of “simlib”
CPSC 531: Simulation Examples 3
Time-Shared Computer Model
CPSC 531: Simulation Examples 4
Problem Specification Terminals “think” and then issue jobs Think times exponentially distributed - 25 s Job service times also exponentially distributed -
0.8 s Job processing rule: round-robin
Each visit to CPU is q = 0.1 sec. (a quantum)• If remaining processing requirement > q sec., it gets q sec,
then kicked out• If remaining processing requirement q sec., it gets what it
needs, returns to its terminal Other job processing possibilities: FIFO, SJF, LIFO etc.
Swap time: = 0.15 sec. Elapse whenever a job enters CPU before processing starts
CPSC 531: Simulation Examples 5
Problem Specification Response time of a job = (time job returns to
terminal) – (time it left its terminal) Initially, computer empty and idle, all n jobs
in the think state at their terminals Stopping rule: 1000 response times collected Output:
Average of the response times Time-average number of jobs in queue for the CPU CPU utilization
Question: how many terminals (n) can be loaded on and hold average response time to under 30 s?
CPSC 531: Simulation Examples 6
Turning the specifications to a prog.
Job ArrivalCPU
ProcessingEnd
Simulation
Terminals
CPSC 531: Simulation Examples 7
Simlib program: events, lists, etc Events
1 = Arrival of a job to the computer (at end of a think time)2 = A job leaves the CPU (done or kicked out)3 = End simulation (scheduled at time 1000th job gets done)(Also, have “utility” non-event function start_CPU_run to
remove first job from queue, put it into the CPU)
simlib lists, attributes:1 = queue, attributes = [time of arrival of job to computer,
remaining service time]2 = CPU, attributes = [time of arrival of job to computer,
remaining service time]• In CPU, if remaining service time > 0 then job has this much
CPU time needed after current CPU pass; if remaining service time 0, job will be done after this pass
25 = event list, attributes = [event time, event type]
CPSC 531: Simulation Examples 8
Simlib program: variables, random streams
sampst variable: 1 = response times
timest variables: none (use filest on the lists)
Random-number streams: 1 = think times, 2 = service times
CPSC 531: Simulation Examples 9
Overview of function main()/* ……… code fragment from main() ……….. */for (num_terms = min_terms; num_terms <= max_terms; num_terms += incr_terms) { init_simlib(); /* Initialize simlib */
maxatr = 4; /* NEVER SET maxatr TO BE SMALLER THAN 4. */num_responses = 0; /* Initialize the non-simlib statistical counter. */
for (term = 1; term <= num_terms; ++term) /* Schedule the first arrival to the CPU from each terminal. */
/* Invoke the appropriate event function. */ switch (next_event_type) {
case EVENT_ARRIVAL: arrive(); break;
case EVENT_END_CPU_RUN: end_CPU_run(); break;
case EVENT_END_SIMULATION: report(); break; } } while (next_event_type != EVENT_END_SIMULATION); }
CPSC 531: Simulation Examples 10
The arrive() functionFunction arrive()
Place job in queue
CPU idle?Yes
No
Return
Start CPU run
CPSC 531: Simulation Examples 11
The arrive() functionvoid arrive(void) /* Event function for arrival of job at CPU after think time. */{
/* Place the arriving job at the end of the CPU queue. Note that the following attributes are stored for each job record: 1. Time of arrival to the computer. 2. The (remaining) CPU service time required (here equal to the total service time since the job is just arriving). */
Things to do Look at the simlib code for the time shared
computer model Try problem 2.3 from the LK00 text book
Our next stop will be Multi-teller Bank with Jockeying
CPSC 531: Simulation Examples 15
Multi-teller Bank
New arrivals: If there’s an idle teller, choose leftmost (idle) teller If all tellers are busy, choose shortest queue (ties –
leftmost)
Initially empty and idle Termination: close doors at time 480 min.
If all tellers are idle at that time, stop immediately If any tellers are busy, operate until all customers leave
service
Interarrival times:Expon (mean = 1 min.) Service times:
Expon (mean = 4.5 min.)
CPSC 531: Simulation Examples 16
Jockeying Rules Suppose teller i (i fixed) finishes service — e.g., i =
3 above Then either teller i becomes idle, or queue i
becomes one shorter Maybe a customer at the end of some other queue
j ( i) moves to teller i (if now idle) or the end of the now-shorter queue i
For each teller/queue k, let nk = number of customers facing (in queue + in service) teller k just after teller i finishes service
Procedure: If nj > ni + 1 for some j i, then a jockey will occur If nj > ni + 1 for several values of j i, pick the closest j
(min |j – i|) If nj > ni + 1 for two equally closest (left and right) values
of j i, pick the left (smaller) value of j
CPSC 531: Simulation Examples 17
Performance Metrics
Estimate Time-average total number of customers in (all)
queues Average, max delay of customers in queue(s)
What’s the effect of the number of tellers?
CPSC 531: Simulation Examples 18
Simlib program: events, lists, etc Events
1 = Arrival of a customer to the bank2 = Departure of a customer from a teller (need to know
teller #)3 = Close doors at time 480 min. (may or may not be The
End)(Also, have “utility” non-event function jockey to see if
anyone wants to jockey, and, if so, carry it out)
simlib lists, attributes (n = number of tellers):1, …, n = queues, attributes = [time of arrival to queue]n + 1, …, 2n = tellers, no attributes = (dummy lists for
utilizations)25 = event list, attributes = [event time, event type,
teller number if event type = 2]
CPSC 531: Simulation Examples 19
Simlib program: variables, streams sampst variable: 1 = delay of customers in
queue(s) timest variables: none … use filest for
time-average number in queues since time-average of total = total of time averages (details in book)
Random-number streams:1 = interarrival times, 2 = service times
CPSC 531: Simulation Examples 20
The main() function// code fragment// … see text for the restevent_schedule(expon(mean_interarrival, STREAM_INTERARRIVAL), EVENT_ARRIVAL); /* Schedule the first
arrival. */
/* Schedule the bank closing. (Note need for consistency of units.) */ event_schedule(60 * length_doors_open, EVENT_CLOSE_DOORS);
/* Run the simulation while the event list is not empty. */ while (list_size[LIST_EVENT] != 0) { /* Determine the next event. */ timing(); /* Invoke the appropriate event function. */ switch (next_event_type) { case EVENT_ARRIVAL: arrive(); break; case EVENT_DEPARTURE: depart((int) transfer[3]); /* transfer[3] is teller number */
break; case EVENT_CLOSE_DOORS: event_cancel(EVENT_ARRIVAL); break; } }
CPSC 531: Simulation Examples 21
The arrive() function
CPSC 531: Simulation Examples 22
The depart() function
CPSC 531: Simulation Examples 23
The depart() function …void depart(int teller) /* Departure event function. */{ /* Check to see whether the queue for teller "teller" is empty. */ if (list_size[teller] == 0)
/* The queue is empty, so make the teller idle. */ list_remove(FIRST, num_tellers + teller);
else { /* The queue is not empty, so start service on a customer. */ list_remove(FIRST, teller); sampst(sim_time - transfer[1], SAMPST_DELAYS); transfer[3] = teller; /* Define before event_schedule. */ event_schedule(sim_time + expon(mean_service, STREAM_SERVICE), EVENT_DEPARTURE); } /* Let a customer from the end of another queue jockey to the end of this queue, if possible. */ jockey(teller);}
CPSC 531: Simulation Examples 24
The jockey() function
CPSC 531: Simulation Examples 25
Things to do Look at the simlib code for the multi-teller
bank model Try problem 2.4 from the LK00 text book
Some food for thought How about replacing this multiple-teller
multiple-queue model with a single-queue multiple-teller model?
CPSC 531: Simulation Examples 26
Job Shop Model Five workstations
Number of identical machines at each workstation as shown