Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Modeling Complex Systems (cont’d.)

Similar presentations


Presentation on theme: "Chapter 2 Modeling Complex Systems (cont’d.)"— Presentation transcript:

1 Chapter 2 Modeling Complex Systems (cont’d.)
11/26/2018 Chapter 2 Modeling Complex Systems (cont’d.) Last time, simlib was introduced for modeling the complex system. Simlib provides list processing, random number generation, and statistics collecting functions such as sampst for discrete time data, timest for continuous-time data, and filest for records in a list. We also use Simlib to simulate M/M/1 queueing system.

2 Use Simlib Determine events, event graph, flow charts,
11/26/2018 Determine events, event graph, flow charts, Determine what lists are needed, what their attributes are Determine sampst, timest variables Determine and assign usage of random-number streams Declare some global or local variables write main function and event functions (and maybe other functions), Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

3 2.5 TIME-SHARED COMPUTER MODEL; 2.5.1 Problem Statement
11/26/2018 Think times of jobs at terminals: Expon (mean = 25 sec.) Processing times of jobs at CPU: Expon (mean = 0.8 sec.) Fixed number of terminals (and jobs), n Processing rule: round-robin Each visit to CPU is  q = 0.1 sec. (a quantum) If job still needs > q sec., it gets q sec, then kicked out If job still needs  q sec., it gets what it needs, returns to its terminal Compromise between extremes of FIFO (q = ) and SJF (q = 0) Swap time:  = 0.15 sec. Elapse whenever a job enters CPU before processing starts Response time of ith job Ri = (time ith job returns to terminal) – (time ith job left its terminal) Each operator at each terminal thinks for an amount of time that is an exponential random variable with mean 25 seconds, and then sends to the CPU a job having service time distributed exponentially with mean 0.8 second. Arriving jobs join a single queue for the CPU but are served in a round-robin manner. The CPU allocates to each job a maximum service quantum of length q = 0.1 second. If a job requires more than q seconds, the CPU will spends q +  seconds on the job, which rejoins at the end of queue with its remaining service time reduced by q seconds. If the (remaining) service time of a job, s seconds, I no more than q, the CPU spends s seconds, plus a fixed swap time of  processing the job, the job returns to its terminal. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

4 2.5.1 Problem Statement (cont’d.)
11/26/2018 Initially, computer empty and idle, all n jobs in the think state at their terminals For n = 10, 20, …, 80 Stopping rule: 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 sec.? Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

5 Event Graph . . . 1 2 n Enter Service End Simulation End CPU run
11/26/2018 1 Enter Service End Simulation 2 . End CPU run . . n Event graph, computer model If an event node has incoming arcs that are all thin and smooth, this event can be eliminated from the model. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

6 2.5.2 simlib Program Events simlib lists, attributes:
11/26/2018 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, for now) (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] Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

7 2.5.2 simlib Program (cont’d.); 2.5.3 Simulation Output and Discussion
11/26/2018 sampst variable: 1 = response times timest variables: none (use filest or out_filest) Random-number streams: 1 = think times, 2 = service times Program files and Simulation out put Input file tscomp.in min_terms max terms incr_terms num_responses_ required mean_think mean_service quantum swap Figure 2.15 – external definitions (at top of file) Figure 2.16 – function main Figure 2.18 – function arrive (flowchart: Figure 2.17) Figure 2.20 – function start_cpu_run (flowchart: Figure 2.19) Figure 2.22 – function end_cpu_run (flowchart: Figure 2.21) Figure 2.23 – function report Figure 2.24 – output report tscomp.out Looks like max n is a little under 60 – sure? Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

8 10 1.324 0.156 0.358 Time-shared computer model
11/26/2018 Time-shared computer model Number of terminals to 80 by 10 Mean think time seconds Mean service time seconds Quantum seconds Swap time seconds Number of jobs processed Number of Average Average Utilization terminals response time number in queue of CPU Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

9 2.6 MULTITELLER BANK W/ JOCKEYING; 2.6.1 Problem Statement
11/26/2018 Service times: Expon (mean = 4.5 min.) Interarrival times: Expon (mean = 1 min.) 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 (9 am to 5 pm). If all tellers are idle at that time, stop immediately If any tellers are busy, operate until all customers leave service Customers in the bank before 5 pm will be served. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

10 2.6.1 Problem Statement (cont’d.)
11/26/2018 Jockeying (line-hopping) 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 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 Estimate Time-average total number of customers in (all) queues Average, max delay of customers in queue(s) Question: What’s the effect of the number of tellers (4-7)? Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

11 simlib Program 11/26/2018 Events 1 = Arrival of a customer to the bank 2 = Departure of a customer from a teller (need to know which 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] sampst variable: 1 = delay of customers in queue(s) Now event has one more attribute teller number for event of type 2 so we can manage the queues and jockeying rule correctly. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

12 Event Graph initiate Arrival Departure Close doors
11/26/2018 Arrival Departure initiate Close doors Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

13 2.6.2 simlib Program ; 2.6.3 Simulation Output and Discussion
11/26/2018 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 Refer to pp in the book (Figures ) and the file mtbank.c Input file mtbank.in parameters: min_tellers max_tellers mean_interarrival mean_service length_doors_open Figure 2.27 – external definitions (at top of file) Figure 2.28 – function main Figure 2.30 – function arrive (flowchart: Figure 2.29) Figure 2.32 – function depart (flowchart: Figure 2.31) Figure 2.34 – function jockey (flowchart: Figure 2.33) Figure 2.35 – function report Figure 2.36 – output report mtbank.out Looks like 4 tellers would be a disaster, 6 might be worth it, 7 not (sure?) Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

14 Discussions In arrive () /* Schedule a service completion. */
11/26/2018 In arrive () /* Schedule a service completion. */ transfer[3] = teller; /* Define third attribute of type-two event-list record before event_schedule. */ event_schedule( sim_time + expon(mean_service, STREAM_SERVICE), EVENT_DEPARTURE); Event: EVENT_CLOSE_DOORS Scheduled in the beginning to happen after 8 hours (at 5 pm) When it occurs, remove the next-arrival event, thus cut off the arrival stream A simulation ends when the event list is empty. In arrive () function, when a service completion is schedule, transfer[3] must be define since event_schedule only fills in the first two fields of transfer array. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

15 Discussions 11/26/2018 The avg. of sum of the individual queue lengths = the sum of their avg queue lengths Is this also true for maximum? i.e. the maximum total # of customers in the queues = the total of the maximum # of customers in each queue? In arrive () function, when a service completion is schedule, transfer[3] must be define since event_schedule only fills in the first two fields of transfer array. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

16 Discussions 11/26/2018 From mtbank.out, with four tellers, both the avg number of customers in the queues and the delay in queue are large. Is this also true for maximum? i.e. the maximum total # of customers in the queues = the total of the maximum # of customers in each queue? In arrive () function, when a service completion is schedule, transfer[3] must be define since event_schedule only fills in the first two fields of transfer array. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

17 2.7 JOB-SHOP MODEL; 2.7.1 Problem Statement
Five workstations Number of identical machines at each workstation as shown Network of multiserver queues Three types of jobs Interarrival times (all job types combined) expon (mean = 0.25 hour) Job type determined just after arrival Type 1, 2, 3 w.p. 0.3, 0.5, 0.2 Workstation routes for job types: Type 1: 3  1  2  5 (shown at left) Type 2: 4  1  3 Type 3: 2  5  1  4  3 Mean service times (2-Erlang distrib.): Type 1:  0.60  0.85  0.50 Type 2:  0.80  0.75 Type 3:  0.25  0.70  0.90  1.0 Initially empty and idle Stop at time 365  8 hours Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

18 2.7.1 Problem Statement (cont’d.)
Estimate Average total delay in queues for each job type separately Overall average total delay in queues over all job types, weighted by their (known) probabilities of occurrence Why not just average the total delay in queues over all the jobs that show up and get through? For each machine group separately: Average delay in queue there (all job types lumped together) Time-average number of jobs in queue (all job types together) Group utilization = Number of machines in the group Question: If you could add one machine to the shop, to which group should it go? Time-average number of machines that are busy Number of machines in the group Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

19 2.7.2 simlib Program Events simlib lists, attributes:
1 = Arrival of a job to the system 2 = Departure of a job from a particular station 3 = End of the simulation simlib lists, attributes: 1, …, 5 = queues, attributes = [time of arrival to station, job type, task number] 25 = event list, attributes = [event time, event type, job type (if event type = 2), task number (if event type = 2)] (Task number of a job is how far along it is on its route, measured in stations, so starts at 1, then is incremented by 1 for each station) Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

20 2.7.2 simlib Program (cont’d.)
sampst variables: 1, …, 5, = delay in queue at machine group 1, …, 5 6, 7, 8 = total delay in queues for job type 1, 2, 3 timest variables: 1, …, 5 = number of machines busy at machine group 1, …, 5 (We’ll keep our own, non-simlib variable num_machines_busy[j] to track the number of machines busy in group j) Random-number streams: 1 = interarrival times, 2 = job-type coin flip, 3 = service times Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

21 2.7.2 simlib Program (cont’d.); 2.7.3 Simulation Output and Discussion
Refer to pp in the book (Figures ) and the file jobshop.c Figure 2.39 – external definitions (at top of file) Figure 2.40 – function main Figure 2.42 – function arrive (flowchart: Figure 2.41) Note that arrive serves two purposes – new arrival event, “arrival” of an “old” job to its next machine group Figure 2.44 – function depart (flowchart: Figure 2.43) Note that depart (and this function) is the event of leaving a particular machine group, which may or may not be the end of the road for a job Figure 2.45 – function report Figure 2.46 – output report mtbank.out Looks like congested machine groups are 1, 2, and 4 (sure?) Reruns with extra machine at each of these in turn – add machine to 4 (?) Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

22 2.8 EFFICIENT EVENT-LIST MANIPULATION
Have seen two different ways to store, handle the event list Sequential by event type – search for smallest entry for next event Must always look at the whole event list Ranked in increasing order by event time – insert correctly, take next event from top Event insertion might not require looking at the whole list In large simulations with many events, event-list processing can consume much of the total computing time (e.g., 40%) Generally worth it to try hard to manage the event list efficiently Better methods – binary search, storing event list as a tree or heap Exploit special structure of model to speed up event-list processing e.g., if time a record stays on event list is approximately the same for all events, insert a new event via a bottom-to-top search Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

23 Example of Process-Oriented Simulation
Approaches to modeling and simulation (Chapter 1) Event-scheduling – as described above, coded in general-purpose language Process – focuses on entities and their “experience,” usually requires special-purpose simulation software, also called process-oriented Process-oriented simulation of MM1 mm1posim.c using CSIM library from Mesquite Software Inc. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

24 Simlin function list_file
In list_file(int option, int list) , “Cut” versus “Copy” transfer array Cut – transfer is allocated new memory (*row).value = transfer; /* Make room for new transfer. */ transfer = (float *) calloc(maxatr + 1, sizeof(float)); Copy – transfer is unchanged, values is copied to the list. (*row).value = (float *) calloc(maxatr + 1, sizeof(float)); for (item = 0; item <= maxatr; ++item) (*row).value[item] = transfer[item]; Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

25 Stopping Rule M/M/1: # of customers left the waiting queue (Ch 1 & 2)
M/M/1: simulation time (Ch 1) Time Shared Computer Model: # of jobs completed (Ch 2) Multiteller Bank Model: closing time, allowing existing customers to finish (Ch 2) Job Shop Model: simulation time (Ch 2) Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

26 Stats Collection Average, maximum, minimum delay in queue(s)
Length of queue, total length of queues Server or servers utilization Average, maximum, minimum response time Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

27 Chapter 3 Simulation Software

28 CONTENTS 3.1 Introduction
3.2 Comparison of Simulation Packages with Programming Languages 3.3 Classification of Simulation Software 3.4 Desirable Software Features 3.5 General-Purpose Simulation Packages 3.6 Object-Oriented Simulation 3.7 Examples of Application-Oriented Simulation Packages Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

29 3.1 INTRODUCTION Activities common to most simulations:
Random-number generation … draws from U(0, 1) distribution Random-variate generation … draws from probability distributions specified as part of the inputs to the model Advancing simulated time Determining the next event from the event list, and passing control to the appropriate event logic Adding records to lists, deleting records from lists Collecting output statistics and reporting results Detecting error conditions Simulation software packages are designed to do these things (and more) for you Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

30 3.2 COMPARISON OF SIMULATION PACKAGES WITH PROGRAMMING LANGUAGES
Advantages of simulation packages Provide most modeling features, so “programming” effort, cost is reduced, often significantly Natural framework for simulation modeling Usually make it easier to modify models Better error detection for simulation-specific errors Advantages of general-purpose programming languages More widely known, available Usually executes faster … if well written May allow more modeling flexibility Software cost is usually lower Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

31 3.3 CLASSIFICATION OF SIMULATION SOFTWARE
General-purpose vs. application-oriented packages Traditionally: simulation languages and simulators Languages were flexible but required programming, simulators were easy to use but not very flexible Now, almost all simulation software uses graphical interface so is relatively easy to use, learn Distinction now is between general-purpose simulation software and applications-oriented package Specific applications include manufacturing, call centers, telecommunications, etc. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

32 3.3 Classification of Simulation Software (cont’d.)
Modeling approaches Event-scheduling approach – as in Chaps. 1 and 2 Can uses general programming languages, or some simulation languages During processing of an event, no simulated time passes Process-interaction approach Now used by most simulation software Instead of identifying events, identify entities (a.k.a. processes) that are created, flow around or through the system, maybe leave May have multiple realizations of an entity/process May have different kinds of entities/processes “Program” consists of a description of what happens to the different kinds of processes (including their entry and exit) Usually expressed graphically, like a flowchart During processing of an entity/process, simulated time usually passes Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

33 3.3 Classification of Simulation Software (cont’d.)
Common modeling elements Entities – represent customers, parts, messages, paperwork, airplane, etc. Attributes – Information stored with each entity Usually, every individual entity has the same set of attributes, but the values differ to distinguish the entities Some attributes are automatic, others are user-defined and user-maintained Resources – servers, machines, workers, nodes, links, runways, gates, agents, clerks, etc. Queues – where entities wait if resources are not available Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

34 3.4 DESIRABLE SOFTWARE FEATURES
General capabilities Modeling flexibility – ability to drill down to lower levels of programming, create custom modeling constructs Ease of use Hierarchical modeling – submodels containing submodels, etc. Fast execution speed Ability to create user-friendly front/back ends for template creation Run-time version for wide distribution of model Import/export data from/to other applications Automatic execution of models for different input-parameter combinations Combined discrete/continuous modeling Ability to initialize in other than empty & idle state Save state at end to re-start later Affordable Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

35 3.4 Desirable Software Features (cont’d.)
Hardware and software requirements Matches platform/OS – Windows, UNIX, MacOS Animation and dynamic graphics Concurrent vs. postprocessing 2D vs. 3D Import CAD drawings Display statistics, graphs dynamically during execution Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

36 3.4 Desirable Software Features (cont’d.)
Statistical capabilities Adequate random-number generator for basic U(0, 1) variates Statistical properties, cycle length, adequate streams and substreams RNG seeds should have good defaults, be fixed – not dependent on clock Comprehensive list of input probability distributions Continuous, discrete, empirical Ability to make independent replications Confidence-interval formation for output performance measures Warmup Experimental design Optimum-seeking Customer support and documentation Output reports and graphics Standard defaults, customizable – stored in database for postprocessing Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

37 3.5 GENERAL-PURPOSE SIMULATION PACKAGES
Two popular general-purpose simulation packages Arena and Extend Both GUI, drag/drop/connect/detail the modules (blocks) Some additional general-purpose simulation packages AweSim, Micro Saint, GPSS/SLX, SIMPLE++, SIMUL8, Taylor Enterprise Dynamics Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

38 3.6 OBJECT-ORIENTED SIMULATION
OO programming and OO simulation originated in the same product – SIMULA, from the 1960s OO simulation has objects that interact as simulation progresses through simulated time Objects contain data, methods Also have encapsulation, inheritance, etc. Recent software product for OO simulation – MODSIM III Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

39 3.7 EXAMPLES OF APPLICATION-ORIENTED SIMULATION PACKAGES
Oriented toward specific classes of applications Manufacturing Communications Process reengineering and service systems Health care Call centers Standalone animation – links to multiple simulation-modeling packages Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems

40 Homework 2 11/26/2018 Download simlib from and use new  simlib.c, which  copies the attributes of the record and leaves them intact in the transfer array for subsequent use when a record is placed into a list Solve the problem 2.4 (d) in the textbook with additional output measurements such as the maximum number of customers waiting in the queues and the utilization defined in 2.4 (c) Submit a write up for the problem with the explanation of the code you add and modify, the C code, the output file. Due February 2 in class. Simulation Modeling and Analysis – Chapter 2 – Modeling Complex Systems


Download ppt "Chapter 2 Modeling Complex Systems (cont’d.)"

Similar presentations


Ads by Google