Event-drive SimulationCS-2303, C-Term 20101 Project #3 – Event-driven Simulation CS-2303 System Programming Concepts (Slides include materials from The.

Slides:



Advertisements
Similar presentations
Hash Tables and Constant Access Time CS-2303, C-Term Hash Tables and Constant Access Time CS-2303 System Programming Concepts (Slides include materials.
Advertisements

Generating Random Numbers
Modeling & Simulation. System Models and Simulation Framework for Modeling and Simulation The framework defines the entities and their Relationships that.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 19 Scheduling IV.
Binary TreesCS-2303, C-Term Binary Trees (and Big “O” notation) CS-2303 System Programming Concepts (Slides include materials from The C Programming.
Linked Lists in C and C++ CS-2303, C-Term Linked Lists in C and C++ CS-2303 System Programming Concepts (Slides include materials from The C Programming.
More on Dynamic Memory Allocation Seokhee Jeon Department of Computer Engineering Kyung Hee University 1 Illustrations, examples, and text in the lecture.
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.
CS Data Structures I Chapter 7 Queues II. 2 Topics Queue Application Simulation Comparison of List, Stack and Queue.
COSC2006 Chapter 8 Queues III
Simulation of multiple server queuing systems
FIN 685: Risk Management Topic 5: Simulation Larry Schrenk, Instructor.
An Introduction to Programming with C++ Fifth Edition
Chapter 22 Simulation with Process Model to accompany Operations Research: Applications and Algorithms 4th edition by Wayne L. Winston Copyright (c) 2004.
Programming Assignment #3 CS-2301, B-Term Programming Assignment #3 User-defined Functions Due, November 18, 11:59 PM (Assignment adapted from C:
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Loose endsCS-2301, B-Term “Loose Ends” CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.
Hash TablesCS-2301, B-Term Hash Tables and Constant Access Time CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming.
Simulation.
"Loose ends"CS-2301 D-term “Loose Ends” CS-2301 System Programming C-term 2009 (Slides include materials from The C Programming Language, 2 nd edition,
More on Operator Overloading CS-2303, C-Term More on Operator Overloading CS-2303 System Programming Concepts (Slides include materials from The.
Simulating Single server queuing models. Consider the following sequence of activities that each customer undergoes: 1.Customer arrives 2.Customer waits.
1 Random numbers Random  completely unpredictable. No way to determine in advance what value will be chosen from a set of equally probable elements. Impossible.
Symbolic Constants in CCS-2303, C-Term Digression – Symbolic Constants in C CS-2303, System Programming Concepts (Slides include materials from The.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
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.
Monté Carlo Simulation MGS 3100 – Chapter 9. Simulation Defined A computer-based model used to run experiments on a real system.  Typically done on a.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Simulation Examples ~ By Hand ~ Using Excel
1 Performance Evaluation of Computer Networks: Part II Objectives r Simulation Modeling r Classification of Simulation Modeling r Discrete-Event Simulation.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
TK1924 Program Design & Problem Solving Session 2011/2012 L6: Queues.
 1  Outline  stages and topics in simulation  generation of random variates.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
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.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 18: Stacks and Queues (part 3)
Data Structures Using Java1 Chapter 7 Queues. Data Structures Using Java2 Chapter Objectives Learn about queues Examine various queue operations Learn.
Can’t provide fast insertion/removal and fast lookup at the same time Vectors, Linked Lists, Stack, Queues, Deques 4 Data Structures - CSCI 102 Copyright.
CPSC 441 Tutorial TA: Fang Wang. Simulation Methodology Plan: Introduce basics of simulation modeling Define terminology and methods used Introduce simulation.
Reid & Sanders, Operations Management © Wiley 2002 Simulation Analysis D SUPPLEMENT.
1 CMPSCI 187 Computer Science 187 Introduction to Introduction to Programming with Data Structures Lecture 13: Queues Announcements.
Network Protocol Simulation: A look at Discrete Event Simulation Grant D. Lanterman 5/21/2004.
Chapter 7 Queues Introduction Queue applications Implementations.
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.
+ Arrays & Random number generator. + Introduction In addition to arrays and structures, C supports creation and manipulation of the following data structures:
1D Arrays and Random Numbers Artem A. Lenskiy, PhD May 26, 2014.
ONE DIMENSIONAL ARRAYS AND RANDOM NUMBERS. Introduction In addition to arrays and structures, C supports creation and manipulation of the following data.
 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,
MODELING AND SIMULATION CS 313 Simulation Examples 1.
Simulation Examples And General Principles Part 2
Simulation modelling real processes to make predictions.
Modeling and Simulation
Chapter 1 What is Simulation?. Fall 2001 IMSE643 Industrial Simulation What’s Simulation? Simulation – A broad collection of methods and applications.
Review Array Array Elements Accessing array elements
ADVANTAGES OF SIMULATION
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Modeling and Simulation CS 313
COMPUTER 2430 Object Oriented Programming and Data Structures I
Demo on Queuing Concepts
Linked Lists in C and C++
Programming Assignment #5
Homework #5 — Monte Carlo Simulation
More elements of Python programs
Applications of Stacks and Queues
CSCS-200 Data Structure and Algorithms
While Loops in Python.
Presentation transcript:

Event-drive SimulationCS-2303, C-Term Project #3 – Event-driven Simulation CS-2303 System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie and from C: How to Program, 5 th and 6 th editions, by Deitel and Deitel)

Event-drive SimulationCS-2303, C-Term Definitions Simulation:– A computer program that mimics the behavior of people and objects in a system Event-Driven Simulation:– A simulation that is organized around the timing of events representing significant points in the actions of the people or objects

Event-drive SimulationCS-2303, C-Term Simulations Widely used in computing and technology for helping to understand the behavior of systems that are too hard to model in other forms –Processor scheduling –Traffic and highway analysis –Rivers and streams and flooding –Robot movement and control –Network congestion –Satellites and space craft –…

Event-drive SimulationCS-2303, C-Term Programming Assignment #3 Model the behavior of customers queuing in a bank –Specifically, the effects of one queue for all tellers versus separate queues for each teller –Specifically, the effect of providing just enough tellers versus providing extra tellers Figures of merit –Customer waiting time – i.e., how long before being served –Bank staffing – i.e., how many tellers needed to support a particular level of customer traffic

Event-drive SimulationCS-2303, C-Term Key Events for this Simulation Customer arrivals I.e., customers walk into bank and get in line Uniform distribution throughout a period of time Start of teller service I.e., teller starts serving person at front of line End of teller service I.e., teller finishes serving a customer, looks for next one Teller goes idle I.e., no customers in line, teller does something else for a short period of time.

Event-drive SimulationCS-2303, C-Term Event Queue Linked list, ordered by event time Earliest event time is at front to list, latest at end New events are added in time order List elements – struct containing Time of event Kind of event Link to next event Simulated clock – a numerical value containing the time of the most recent event from event queue Suggest float to represent time

Event-drive SimulationCS-2303, C-Term Other Queues Teller queue Linked list representing customers lining up in front of a teller (or group of tellers) New arrivals added to end (i.e., tail) of list Waiting customers served from beginning (i.e., head) of list Definition:– Queue A linked list in which items are added to the tail and from which items are removed from the head Strictly speaking, the Event Queue is not a true queue — items are added in time order, not at tail.

Event-drive SimulationCS-2303, C-Term Your Program Initialize:– Get parameters of simulation from command line Generate customer arrivals, insert into event queue Generate idle tellers, insert into event queue Do the simulation Get first item from event queue Update simulated clock to time of event Perform action of the event Gather statistics about the event or action Repeat until no more events Print out statistics

Event-drive SimulationCS-2303, C-Term Actions of the Simulation Customer arrival:– Place customer at end of shortest teller queue Idle teller:– Gather idle statistics Check if customer is waiting in teller queue If yes, generate service event, insert into event queue If not, generate new idle event in event queue Service complete:– Gather customer service statistics Check if new customer is waiting in teller queue Insert service event or idle event in event queue as above If multiple shortest queues select one at random

Event-drive SimulationCS-2303, C-Term Statistics to Gather How many minutes, on average, does a customer wait to get service? How many minutes, on average, does a customer spend in the bank? How many minutes total do tellers spend in idle state? How many minutes total do tellers spend serving customers?

Event-drive SimulationCS-2303, C-Term Notes Service events may occur after last arrival E.g., after simulating one hour of arrivals, there may still be customers in the bank at the end of that hour, waiting for service Simulation stops if there are no more customers waiting in any queue

Event-drive SimulationCS-2303, C-Term Random Number Generators Random numbers are needed frequently in engineering & scientific computations Simulations, arrival times, etc. Exercising other code Analyzing system performance Definition: Random Number Generator A function that returns a seemingly random number each time it is called (Usually) within a specified range Repeated calls yield a sequence of numbers that appear random!

Event-drive SimulationCS-2303, C-Term Random Number Generators (continued) Algorithmic –Retain information in static variables –Scramble numbers to get something that “looks” random on each call Entire mathematical theory about them –Evaluating the quality of the randomness See §5.10 of D&D or pp. 46, 252 of K&R

Event-drive SimulationCS-2303, C-Term Problem with Random Number Generators Don’t give the same answer each time! Difficult to get reproducible behavior when debugging! Solution:– the seed A numeric value for initializing the internal state So that the generator produces the same sequence each time

Event-drive SimulationCS-2303, C-Term Linux Random Number Generators There are many! Suggested int rand(void) Returns values in range 0.. RAND_MAX rand() % r returns values in range 0.. (r-1) for integer r Seeding:– srand(unsigned int seed) –Get value of seed from (optional) command line argument srand(time(NULL)) –Seeds to current time (measured in seconds since the beginning)

Event-drive SimulationCS-2303, C-Term Questions on Programming Assignment? Next Topic – Linked Lists