CSC 205 Programming II Lecture 22 Carwash Simulation.

Slides:



Advertisements
Similar presentations
Ceng-112 Data Structures I Chapter 5 Queues.
Advertisements

Data Structures Lecture 13: QUEUES Azhar Maqsood NUST Institute of Information Technology (NIIT)
CS 206 Introduction to Computer Science II 03 / 04 / 2009 Instructor: Michael Eckmann.
CHAPTER 7 Queues.
Fundamentals of Python: From First Programs Through Data Structures
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.”
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Today’s Agenda  Stacks  Queues  Priority Queues CS2336: Computer Science II.
Comp 245 Data Structures Queues. Introduction to the Queue ADT It is a FIFO (first-in, first-out) structure Access to the Queue can take place at two.
Queues and Priority Queues
Data and information These are philosophical categories These are philosophical categories We are not able to give exact definition We are not able to.
COSC2006 Chapter 8 Queues III
Chapter 13 Queues and Priority Queues CS Data Structures Mehmet H Gunes Modified from authors’ slides.
Queues21 Queues II: Applications. queues22 Palindrome recognition Palindrome: collection of characters that reads the same backwards and forwards Examples:
© 2006 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 Queues CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck Spring 2008.
1 Queues Queue Concept Queue Design Considerations Queues in Java Collections APIs Queue Applications Reading L&C , 9.3.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
Simulation with ArenaChapter 2 – Fundamental Simulation Concepts Discrete Event “Hand” Simulation of a GI/GI/1 Queue.
Cmpt-225 Queues. A queue is a data structure that only allows items to be inserted at the end and removed from the front Queues are FIFO (First In First.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
1 Data Structures  We can now explore some advanced techniques for organizing and managing information  Chapter 12 of the book focuses on: dynamic structures.
Chapter 7 Queues. © 2005 Pearson Addison-Wesley. All rights reserved7-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
Queues Chapter 8 Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved
Queues, Deques, and Priority Queues Chapter Chapter Contents Specifications for the ADT Queue Using a Queue to Simulate a Waiting Line The Classes.
© 2004 Pearson Addison-Wesley. All rights reserved12-1 Chapter 12 : Collections Intermediate Java Programming Summer 2007.
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.”
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Data Structures - Queues
Queues and Priority Queues
Queues CSI 1101 N. El Kadri. 2 Definitions A queue is a linear abstract data type such that insertions are made at one end, called the rear, and removals.
CHAPTER 05 Compiled by: Dr. Mohammad Omar Alhawarat Stacks & Queues.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues (slightly modified by Dan Fleck)
1 CS 132 Spring 2008 Chapter 8 Queues. 2 Queue A data structure in which the elements are added at one end, called the rear, and deleted from the other.
Data Structures Using C++ 2E Chapter 8 Queues. Data Structures Using C++ 2E2 Objectives Learn about queues Examine various queue operations Learn how.
© 2006 Pearson Addison-Wesley. All rights reserved8 A-1 Chapter 8 Queues.
Computer Science 112 Fundamentals of Programming II Modeling and Simulation.
Data Structures (part 2). Stacks An Everyday Example Your boss keeps bringing you important items to deal with and keeps saying: “Put that last ‘rush’
Chapter 12: Collections by Lewis and Loftus (Updated by Dan Fleck) Coming up: Collections.
Queue What is a queue?. Queues A queue is similar to waiting in line for a service, e.g., at the bank, at the bathroom –The first item put on the queue.
ICOM 4035 – Data Structures Lecture 10 – Queue ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel.
The Abstract Data Type Queue A queue New items enter at the back, or rear, of the queue Items leave from the front of the queue First-in, first-out (FIFO)
Question of the Day  Three people check into a hotel for which they pay the manager $30. The manager finds out the rate is $25 and gives $5 to the bellboy.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
UNIT II Queue. Syllabus Contents Concept of queue as ADT Implementation using linked and sequential organization. – linear – circular queue Concept –
Chapter 8 Queues. © 2004 Pearson Addison-Wesley. All rights reserved 8-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear, of.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
© 2011 Pearson Addison-Wesley. All rights reserved 8 B-1 Chapter 8 (continued) Queues.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
Discrete Event Simulation
Chapter 7 Queues Introduction Queue applications Implementations.
(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.
Give Eg:? Queues. Introduction DEFINITION: A Queue is an ordered collection of element in which insertions are made at one end and deletions are made.
Queues 1. Queue  a queue represents a sequence of elements where elements can be added at the back of the sequence and removed from the front of the.
Lecture 10 b Stacks b Queues. 2 Stacks b A stack ADT is linear b Items are added and removed from only one end of a stack b It is therefore LIFO: Last-In,
Chapter 7 A Queues. © 2004 Pearson Addison-Wesley. All rights reserved7 A-2 The Abstract Data Type Queue A queue –New items enter at the back, or rear,
1 Data Structures CSCI 132, Spring 2014 Lecture 7 Queues.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 7: Queues Data Abstraction & Problem Solving with C++
Queues Chapter 8 (continued)
Queues Chapter 4.
Stacks and Queues.
Queues Chapter 4.
Chapter 13 Queues and Priority Queues
Queues.
Stack A data structure in which elements are inserted and removed only at one end (called the top). Enforces Last-In-First-Out (LIFO) Uses of Stacks Evaluating.
Discrete Event “Hand” Simulation of a GI/GI/1 Queue
Chapter 8 Queues © 2006 Pearson Addison-Wesley. All rights reserved.
Visit for more Learning Resources
CSCS-200 Data Structure and Algorithms
Queues.
Presentation transcript:

CSC 205 Programming II Lecture 22 Carwash Simulation

Recap: Queue A queue is an ordered, linear data structure New items are added at the rear end Items are removed from the front end It’s a “first-in, first-out” (FIFO) structure Queue operations Enqueue – add an item to the rear end Dequeue – remove the front item Peek – get the content of the top item

Carwash Simulation

The Problem A carwash station can wash one car at a time Time needed to wash a car is measured in seconds Cars may arrive at any given second A probability can be assumed Cars arrived when the washer is busy have to wait in line First-come, first-served The goal: find out the average waiting time for a given period of time (in seconds)

Program Specification Input Time needed to wash one car The probability that a new customer arrives at any given second The total length of time to be simulated Output Car arrival and leaving history Number of customers serviced Average time that a customer spent in line during the simulation

Design Objects relevant to the carwash problem A collection of cars: CarQueue Car Washer Other objects used in the simulation Random arrival time generator: BooleanSource Average time calculator: Averager The application driver class: CarWashApp

Detailed Design Key design concept Determine which properties of a real-world object are relevant to the problem at hand Car Arrival timestamp Sequence number CarQueue A linked list object is used as a queue Three operations enqueue, dequeue, isEmpty

Detailed Design – continued Washer Variables Time (in seconds) needed to wash a car Time left to finish washing the current car Operations Start washing set washTimeLeft to secondsForWash Reduce remaining time Decrement washTimeLeft if it is not zero Test if the washer is busy It’s busy if washTimeLeft is greater than zero

Detailed Design – continued BooleanSource Variable: probability Operation: query returns true only if Math.random() < probability Averager Variables A count and a sum Operations addNumber: update both count and sum howManyNumbers: return count average: return sum/count

Car Wash Application carWashSimulate Three parameters Time needed to wash a car Probability Total time Echo input parameters Validate parameters Processing car washing with a loop Output results

Car Wash Application Within the loop Check if a new car arrives Check whether we can start washing another car That is if washer is not busy, and The queue is not empty Reduce the remaining time during washing a car

Sample Simulation C:\courses\CSC205\labs\carwash>java CarWashApp2 Seconds to wash one car: 1000 Probability of customer arrival during a second: Total simulation seconds: 5000 Car Arrived Left Waited Customers served: 5 Average wait: sec