grocery store simulation
play

Grocery Store Simulation Project 1: Grocery Store Simulation - PDF document

Grocery Store Simulation Project 1: Grocery Store Simulation Project 1 Handouts / Description now on Web site Due Dates: The Grocery Store Simulation Minimum Effort Due: January 9, 2004 Full Project Due: January 17, 2004


  1. Grocery Store Simulation • Project 1: Grocery Store Simulation Project 1 – Handouts / Description now on Web site – Due Dates: The Grocery Store Simulation • Minimum Effort Due: January 9, 2004 • Full Project Due: January 17, 2004 Grocery Store Simulation Grocery Store Simulation • Goal for this project is to simulate the • CS2 Newsgroup register area of a large grocery store. – rit.cs.courses.4003.232 • Rules: – Store has a number of registers • Number of registers read in from standard in • Each register will have a queue (line) associated with it. • All lines are the same (no express, coupon only, no- candy lines) Grocery Store Simulation Grocery Store Simulation • Customer Entering a line • Simulation: – When a customer is ready to check out: – Input: • Will go to the register with the smallest line • A random number generator seed • Average rate of arrival of customers • Cashing out: • Average service time for cashiers – When a cashier is not busy, he/she will cash out • Number of registers the customer at the front of the queue • Amount of time to run the simulation – After checkout, the customer leaves the store and the cashier checks out the next customer. 1

  2. Grocery Store Simulation Grocery Store Simulation • Simulation: • Simulation: – Simulation loop (for passage of one unit of time) – Statistics collected: • Customer generator is asked for a list of new customers • Average customer service time • Each new customer places his/her self onto a register queue • Average customer waiting time • Each register checkout determines if current customer is done • Average cashier idle time – If yes, update statistics for the register and get next customer from the queue (if there is one) – No work actually done…this is a simulation • Update your clock – Questions so far? Grocery Store Simulation Grocery Store Simulation • Specification: • Specification: – To run: – Output: • java GroceryStore • Must print collected statistics after the simulation is – Input: complete. • From standard input (System.in) – Random Number seed (int) – Average customer arrival rate (double) • Since no “real” work is done, diagnostics will be – Average service time (double) printed to indicate what is going on with the – Number of cashiers (int) simulation. – Total time for simulation (int) • Must check data format..if incorrect print error and terminate. Grocery Store Simulation Grocery Store Simulation • Classes: • Classes: – GroceryStore – Register • Main program for running simulation • Models the cash registers. – Clock • Maintains a queue • Time keeper for the simulation • Service Customer ( checkIfCustomerDone()) – CustomerQueue • Must keep track of • Models the lines for each register – Total customers serviced • When a customer is added – message is printed – Total time servicing customers • When a customer is removed – message is printed. – Total time spent in queue – Customer – Total idle time • Models the customers in the system • Can determine shortest line and place themselves on the shortest line. 2

  3. Grocery Store Simulation Your Job… • Classes: • Write the classes: – CustomerGenerator – Javadocs included for all classes • Generates random set of customers for each time tick. • Clock – InvalidValueException • CustomerQueue • Thrown during invalid data entry • Customer – ExponentialRandom • Register • Determines time until next event – Please use RCS • Used by CustomerGenerator – java files supplied for GroceryStore & – PoissonRandom InvalidValueException (in RCS) • Determine number of events per unit of time – .class files suppied for all other classes. • Used by CustomerGenerator Circular Queue Important Algorithms/Data Structures • Queue • Data Structures – New items get placed at the end of the queue – Queue – Items get removed from the front of the queue • Algorithms • First in / First Out (FIFO) – Running the simulation – Finding the shortest line – Servicing a customer In here Out here Circular Queue Circular Queue • Queue methods • Implementation – add – Places a new object at the rear of the queue – Place data in an array – getFront – return object at front of queue without – Keep track of the front and rear of the queue removing it. – getSize – returns number of elements in the queue – Keep track of number of elements – isEmpty – returns a boolean indicating if the queue is empty – isFull – returns a boolean indicating if the queue is full – remove– Removes and returns element at the front of • Let’s see this in action. the queue 3

  4. Circular Queue Running the Simulation • For the CustomerQueue: – Must be dynamic – When full, and a new Customer is added, • Must make the queue larger. • Initial array size = 5 – isFull will always return false! Finding the Shortest Line Servicing a Customer 1. Check to see if we need to begin serving a new customer 2. Check to see if the current customer is finished Need new customer? Finished with current customer? • If we are finished with current customer: • If there is time left: – Check to see if there is anyone behind him or her in the 1. Decrement the time left on this customer. queue. 2. Is there still time left on this customer? • Yes, there are customers: • Time left: do nothing. 1. Remove the next customer from the queue and make him or her the current customer. • No time left: 2. Remember the time this customer will require to be serviced. 1. Record the data for the final statistics reporting. • No, there are no customers: 2. Set the current customer to null – Increment the idle time by 1 time unit. • If we are not finished with this customer, proceed • Otherwise, do nothing. to step 2. 4

  5. Testing your work Submissions • You can use try to test out your classes • 4 submissions – try cs2-grd project1-test infile – Minimum: Clock.java / CustomerQueue.java • Will run our solution on test data in file infile • due 1/9/04 • You can redirect the output into a file and then compare with • Need stubbed Customer class. our output – Submission 2: Customer.java / Register.java – try cs2-grd project1-test infile > correctSolution – java GroceryStore < infile > mySolution • due 1/17/04 – diff mySolution correctSolution • Can also submit your own java files to test • All submissions via try – try cs2-grd project1-test infile somefile.java – Sample input files include in /data directory of jar file. • NO LATE SUBMISSIONS! – Be sure that output matches exactly! Submissions Grading • 100 points for functionality • About the minimum submission – Up to 35 point deduction for bad implementation – Clock.java & CustomerQueue.java is the – Up to 30 point deduction for bad style minimum reasonable effort requirement for this • Including non-use of RCS project • Submission percentages • Due January 9, 2004 – Clock – 10 % – Must submit Clock.java & CustomerQueue.java – CustomerQueue – 20% successfully by Jan 9. – Customer – 30 % • Otherwise, you fail the course – Register – 30% – Advice: Submit Before Break!!! – All Together – 10 % Questions? • Tomorrow: – Java I/O 5

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend