A Theme Park Simulation - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

A Theme Park Simulation

Description:

Use Java classes to deal with instances of rides, and perhaps with customers ... Like Merry-Go-Round or Bumper Cars. not like Ferris Wheel. If ride is empty ' ... – PowerPoint PPT presentation

Number of Views:138
Avg rating:3.0/5.0
Slides: 30
Provided by: anselmo9
Category:

less

Transcript and Presenter's Notes

Title: A Theme Park Simulation


1
A Theme Park Simulation
  • COMP 114
  • Tuesday April 16

2
Discrete Event Simulators
  • Grocery store example we did in class
  • Treat time as discrete
  • Move in small increments
  • Why? Much easier to program
  • Simulate whats happening over time

3
Roller Coaster Tycoon
  • Simulate events at an amusement park through the
    day.
  • Amusement park has rides with
  • Capacity (number of people that can go)
  • Time to run the ride
  • Lines have no size limit

4
Program 5 (last one!)
  • Build an Amusement Park simulation
  • Read park description from file
  • Simplified ride and customer behavior
  • No graphics!
  • Due Tues 4/30

5
Goals
  • Code linked list class
  • Code queue class
  • Use Java classes to deal with instances of rides,
    and perhaps with customers
  • Document properly
  • Use good Java style (naming, modularity,
    encapsulation)

6
Customers
  • Customers arrive at park each time step
  • with some probability
  • When customers leave ride, they may leave the
    park or go to another ride
  • Customers leave park
  • with some probability
  • If stay, go to another ride

7
Description File
  • Description of rides
  • Arrival probability
  • Departure probability
  • Simulation time

8
Comment Lines
  • Lines that begin with '' are comment
    lines      all other lines have data.

9
Description of Rides
  • ride      Rides begin with the word
    "ride", then a list of colon
    separated values        Name of ride       
    Time it takes to cycle the ride        Capacity
    - total number of people it holds.        Cost
    - pennies that it costs to run one cycle
    (not
    per-person)        Price - price (in pennies)
    per person to riderideFerris
    Wheel421225rideMerry-Go-Round610820

10
Ride Model
  • Simplified
  • Like Merry-Go-Round or Bumper Cars
  • not like Ferris Wheel
  • If ride is empty
  • capacity customers get on at once
  • Ride goes for cycle time
  • All customers get off ride

11
Other Data
  • arrival      Probability that a person
    will enter park at any given time step
    departure      Probability that a person will
    leave park when exiting ride
    closes      Time when park closes (0 is when
    park opens)arrival 0.7
  • departure 0.2
  • closes 100

12
Customer Movement
  • There is no travel delay between rides
  • When customer leaves ride, departure is
    probability he/she will leave park
  • If stay, customer has even probability of going
    to any ride
  • If there are four rides, chance of going to each
    is 25

13
When Park Closes
  • At closing time no more customers admitted to
    park.
  • After the park closes, you still need to empty
    it.
  • All customers in line are given rides
  • No more customers admitted to lines
  • They leave as soon as ride over

14
A Simulation Step
  • Empty any rides that are finished.
  • Send customers that just left rides either to the
    line at a ride, or to leave the park.
  • Check for a new arrival to the park.
  • Max one person per time step
  • If arrival, send to ride (doesnt leave)
  • Start any rides that are ready to go.
  • Was stopped and has customers

15
Random Numbers
  • Really pseudo-random numbers
  • Generated by a function
  • Distribution is pretty good (usually)

16
The Random Class
  • In java.util package
  • Make an instance of Random
  • Random rand new Random( 0 )
  • Argument is the seed, the number that the
    generating function uses to start
  • If you give no seed, one is chosen based on the
    current time of day

17
Getting a Random Number
  • Several methods to get random
  • integers, floats, doubles, bytes
  • Most useful is
  • double rand.nextDouble()
  • The number is between 0.0 and 1.0

18
Using
  • Roll dice (get random number)
  • If number is lower than arrival, customer enters
  • If number is lower than departure, customer
    leaves

19
Repeatable Sequences
  • For debugging youd like to have the same thing
    happen every time you try program.
  • Explicitly give a seed (like 0) to Random( ).

20
Park 1 Description
  • ride Ferris Wheel, 4, 2, 12, 25
  • ride Merry-Go-Round, 6, 10, 8, 20
  • arrival 0.7
  • closes 100
  • departure0.2

21
My Results
  • Time 0
  • rand 0.730967787376657
  • no arrival this time period
  • Time 1
  • rand 0.24053641567148587
  • 0 arrives at park
  • rand 0.6374174253501083
  • 0 on line for Merry-Go-Round
  • 0 riding Merry-Go-Round, out at 7
  • ...

22
Park Closes
  • PARK CLOSED AT 100
  • Time 103
  • 38 leaves park
  • 39 leaves park
  • 64 leaves park
  • 65 leaves park
  • 17 leaves park
  • 66 leaves park
  • 59 leaves park
  • 57 leaves park
  • 68 leaves park
  • 23 42 riding Ferris Wheel, out at 107
  • 33 riding Merry-Go-Round, out at 109

23
Park Empties
  • Time 167
  • 69 leaving Ferris Wheel
  • 69 leaves park
  • LAST CUSTOMER LEFT PARK AT 167
  • Ride Ferris Wheel cost 4.92 and made 19.50
  • Average wait was 31.3 and maximum was 65
  • Ride Merry-Go-Round cost 1.44 and made 15.60
  • Average wait was 1.4 and maximum was 5
  • Total profit 28.74

24
Product
  • Print
  • Time park can close,
  • average and max wait times for each of the rides,
  • cost to run each ride and
  • amount of money made for each ride.
  • Finally, print the profit for the day.
  • Look at class DecimalFormat for nice printout.
  • In package java.text

25
Debugging
  • I also printed the events as they occurred. This
    was very useful for debugging.
  • DONT HAND IN ON PAPER.

26
Hand In
  • Print the final results of running the test cases
    (Park1 and Park2) posted on the web site.
  • I have also posted the results of my
    implementation.
  • Let me know if you find bugs in mine!
  • I seeded the random number generator with a zero
    (IMPORTANT).
  • To get my results, must use same event order

27
Requirements
  • Use Classes and encapsulation
  • Implement a class Queue
  • Implement a SinglyLinkedList class
  • Implement the queues with a linked list
  • Add at tail, remove from head
  • Do not electronically copy Queue or Linked List
    code! I want you to understand code.
  • Make your Queues and List general
  • Should hold any Object
  • Not be tied to this problem!

28
Suggestions
  • Implement List class and test
  • Make a simple implementation
  • Just what you need for queue
  • Simpler than my example
  • Use a simple test program
  • Add, remove Strings
  • Implement Queue class and test
  • Then implement park

29
Event-Driven Simulation
  • Program 5 is simplistic
  • Customer arrival very basic
  • More accurate
  • subdivide time into micro-steps
  • Then impractical to visit each step
  • Instead, keep list of events go to next
  • Book Section 13.2
Write a Comment
User Comments (0)
About PowerShow.com