MR. KAY'S WILD RIDE
PROBLEM DESCRIPTION

[This document provides an overview of the simulation. It discusses some details of behavior and implementation, but it is not a complete, formal specification document.]

1. Introduction

At amusement parks like Disneyland, there are many attractions (usually rides, but also stores and restaurants). In successful amusement parks (also called theme parks), there are also many customers. Customers visit one attraction after another; usually more customers want to visit an attraction than the attraction can hold at one time, so often customers spend time waiting in line.

Amusement park operators pay a lot of attention to the way customers flow through the park. They want all the attractions to be operating at full capacity, and they want people to spend as little time as possible in line so they will have a good time and come back again.

Since hundreds of millions of dollars go into the design of a new amusement park, it pays to plan ahead, and to predict as accurately as possible how people will behave when the park is open. One good tool for this is computer simulation.

2. Simulation

Simulation is different from reality. If we want to know how well a newly-designed helicopter or racing schooner will perform, we might build a prototype and try it out. If we want to know how many incoming freshmen will graduate in four years or less, we might simply admit those students and keep track of them over their college careers. If we want to know which arrangement of rides works best, we could build them and see what happens. But those approaches cost a lot and take too long.

We can call the helicopter, the schooner, the students, or the amusement park a system (which means no more than "a group of things forming a unified whole"). We can design models of these systems and how they behave, simplified descriptions that leave out unnecessary detail (like the color of the sail or the freshman's height or the shape of the cars in "Mr. Toad's Wild Ride"). [Of course, the major pitfall in designing these models is omitting a detail that is not unnecessary; perhaps a freshman's height does affect his or her success in school.] And we can code these models as computer programs, running them over and over, easily changing various values, to help predict the systems' performance without all the bothersome cost, time, and detail of the real thing. That's simulation.

One type of simulation involves the behavior of a population (such as the students above, but not the schooner or helicopter). One approach to population simulation involved statistical changes to the population as a whole (e.g., "If there's a black plague epidemic, the population decreases by 25%"). Another approach is to represent each individual in the population separately, by an object in a program; object-oriented programming is a natural way to implement simulations like this. The simulator, then, gives each object a turn, during which the object can change its status and possibly affect its environment. We can call it one "round" of the simulation when each individual object has had one turn. The simulation will typically continue for a specified number of rounds, or until some condition occurs (such as all the objects finishing their work).

3. This Problem

Since Orange County is a center of theme parks, you decide to offer a simulation service for theme park designers. Your first step is to design and implement the software that you will use.

Your program will simulate two different classes of objects: attractions and customers.

As described below, each attraction will have certain information, such as its location in the park, the number of customers it can handle at once, the amount of time customers have spent waiting in line before actually starting the ride, and the amount of time it takes a customer to complete the ride once he or she starts it. Each attraction will also perform operations such as taking the next customers in line, releasing customers after their turn is over, informing customers how long the wait will be, and so on.

Each customer will start with a "wishlist"—the list of attractions he or she wants to visit during the day, each with a priority that indicates how important the attraction is to that customer. Each customer will also have some way of deciding, at any moment, which attraction to visit next. The customer might use a simple-minded decision algorithm, such as "Always go to the ride with the next highest priority." But some customers might be more clever; they might decide to start with the rides that are furthest from the entrance, because the crowds will be smaller, or they might decide to postpone some rides if the wait in line looks too long, or they might choose a lower-priority ride if it happens to be nearby.

When you specify each customer to the system, you will be able to choose from a few different decision strategies; others could be implemented. [In fact, prospective customers who want to get the most out of their trip will also be able to use your service (providing you an additional stream of income); they will be able to try out different decision strategies and see which one works best. In fact, we think we've seen a web site that provides just such a planning service.] More information about customers appears below.

Your program, then, will be a simulation system that manages the two kinds of objects. After setting things up initially—the attractions, the customers, the opening and closing times of the park—it will cycle through the minutes of the day. At each minute, it will give a turn to each customer entering the park and each customer just leaving a ride, so they can apply their decision strategies, coming up with the ride to visit next. Also, every ride will get a turn to take in some customers and release some customers, depending on the size of its line and the amount of time it takes to go through the attraction. Finally, each customer who is "in transit" from one place to the next will move closer to his or her goal. So at the end of each cycle, some customers will be in line for rides, some will actually be on the rides, and some will be walking from one ride to another.

Then, at the next minute, the whole cycle repeats again. The simulator stops shortly after it reaches the park's closing time. (Since customers might actually be on a ride at the exact time the park closes, you have to allow time for them to finish and leave the park). At the end of the day, the simulator prints some statistics about each customer's visit.

A realistic simulation might operate second-by-second instead of a minute at a time; however, that would take 60 times the computing power so to keep things simple, especially if we have a lot of customers, we'll leave things on a minute-by-minute basis for now.

4. Attractions

Each ride will store this information:

Different rides load and discharge their passengers differently; this affects the length of time it takes to complete the ride and the number of passengers the ride can handle.

4.1. Ride Loading Characteristics

Each ride maintains a queue of customers waiting to ride it. At each minute, the ride may take some people from this queue and put them on the ride, and it will take any people who have completed the ride and send them back out into the park to decide which ride to visit next. This continues until closing time, after which nobody else can get in line and the ride empties out its queue.

At each minute, the ride has to figure out if any cars are loaded and ready to be dispatched on the ride, if any cars are empty and ready to load, and if any cars have completed the ride and are ready to unload. Different rides differ in the precise details of how they handle their passengers; we can categorize rides as cycle rides, continuous rides, or interval rides.

4.1.1. Cycle Rides

You could also call cycle rides "stop-and-go" rides. Everyone gets on the ride at once, the ride does what it does, and then everyone gets off. Nobody is riding while people are unloading and the new people are loading. A show in a theater is a cycle ride; so are carousels and the "Dumbo" ride at Disneyland. To describe a cycle ride, you need to specify the amount of time the ride is in motion and the amount of time it takes to unload and load the ride. Finally, a cycle ride will start as scheduled if some of its cars are empty, but it will not start if it has no passengers at all.

At the beginning of each cycle, the ride will decide whether to add one more car to the ride, remove one car, or make no change. If the number of people waiting in line is greater than the current capacity of the ride, and if fewer than the maximum number of cars are in use, it will add one car. It will remove one car from the ride if two or more cars were empty during each of the last three cycles.

4.1.2. Continuous Rides

Continuous rides never stop; they are like a circular conveyer belt that goes around and around. Escalators and ski lifts are continuous rides; so was the "Sky Ride" aerial tram at Disneyland. There is no separate loading time for a continuous ride; it loads one car per minute and you need only the length of the ride to describe it. On a continuous ride, if an empty car is ready to leave, it can leave even if nobody's in it. However, no more than one car may leave in a single minute.

At any minute, if more than five carloads of people are waiting in line, the ride will add one car (up to the maximum). If there has been a sequence of empty cars launched that's longer than one-third of the number of cars on the ride, then the ride will remove one car.

4.1.3. Interval Rides

On an interval ride, cars are loaded, unloaded, and dispatched at certain set intervals. As a car pulls up to the load point, riders who have just completed the ride exit to their left. Then the people who are waiting to ride enter the car from the right. The loaded car is released to the dispatch point a few yards down the line, where it is launched. If nobody is waiting for the ride, cars remain waiting to be loaded; on interval rides, no empty cars are launched. On the other hand, no more than one car may be launched per minute. To describe an interval ride, you need the length of the ride and the length of time it takes to unload and reload a car. Subways are interval rides (except that subways have multiple loading points and not everybody in a car gets on and off at the same place); so are roller coasters, including Disneyland's "Matterhorn" and "Space Mountain".

At any minute, the ride will add one car to be loaded if the number of people waiting is more than the current number of cars could accommodate in one full circuit of the ride. (Thus, if there are currently 10 cars on the ride, each holding 6 people, you'll add one car if there are more than 60 people in line.) It will remove one car if more than one empty car has been waiting to load for over 10 minutes.

4.2. Other Kinds of Rides

You can imagine still other kinds of rides. For example, some attractions allow the customer to spend as much time as he or she wants: stores and museums are like this, and so is "Tom Sawyer's Island" at Disneyland. But for now, the simulator will not model rides like these.

5. Customers

  Each customer who enters the park has these characteristics:

5.1. The Customer Wishlist

Each customer comes to the park with a prioritized wishlist, listing the names of the rides the customer wants to ride with a priority for each ride. Some customers may just visit each ride in priority order and then leave the park, but customers may also have more sophisticated ways of choosing their rides.

Starting from the original wishlist, the customer creates and maintains a working agenda, another prioritized list of rides that can change from time to time. Every time the customer finishes a ride, for example, the customer removes the ride just finished from the agenda. We discuss below what happens when the agenda is empty or the park's closing time arrives. The customer will also keep track of which rides he or she has visited, which may be used in deciding which ride to visit next.

The priorities are represented by integers, with lower values indicating higher priorities (so a customer's number-one priority comes before the number-two priority, for example).

5.2. Decision Strategies

The simulator allows customers to specify one of three strategies for choosing a next ride (i.e., reprioritizing the agenda so that the next ride is at the front):

(In our park, the waiting time for any ride is available to the customer from any location; there are courtesy phones and large message boards that keep the customers up to date, so they don't have to walk over to a ride to see how long the wait is.)

Other strategies could be imagined and implemented.

Each customer can also specify an exit strategy that determines when the customer will leave the park:

When the working agenda is empty, if the customer is not yet ready to leave, the customer will refill the working agenda as follows: Add all the rides in the park that the customer hasn't visited yet, and if the agenda runs out again, add the closest 15 rides to the customer's current location.

6. Distance

Distances in the park are measured in "distance units"; one unit is the distance someone can walk in one minute, which makes calculation easy. Locations are given in an x-y (Cartesian) coordinate system, in which the park's entrance/exit is (0,0). The simulator calculates distances between rides by the straight-line Euclidean distance; it does not take obstacles into account. When you calculate walking times based on distances, you should convert any non-integer distances to the next highest integer, since the simulator keeps track of everything in whole minutes.

7. Operation of the Simulator

Broadly speaking, your simulator will let the user run one or more simulations, each of which will behave as follows:

8. Input

The simulator will read plain text input files, one describing the rides and one describing the customers. In both files, lines with an asterisk in the first column are ignored (and thus can serve as comments in the input) and empty lines are also ignored.

8.1. Input of Rides

The basic input format for rides is as follows:
    Ride_Name
    entrance_X  entrance_Y
    exit_X  exit_Y
    initial_num_of_cars  max_num_of_cars  capacity_per_car
    Ride_Type
    ride_time  loading_time

The ride type must be one of the following: Continuous, Cycle, or Interval. For continuous rides, no loading time is specified.

Here is an example:
* Sample ride file
Polymorphic Paddleboats
4 1
4 1
1 2 1
Cycle
3 3
Inheritance Insanity
2 2
4 6
1 3 1
Continuous
5

8.2. Input of Customers

The basic input format for customers is as follows:
    Customer_name
    time_entered_hour  time_entered_minutes
    Customer_type
    Exit_strategy
    exit_time_hour  exit_time_minuts
    wish_list_priority1  wish_list_ride1
    wish_list_priority2  wish_list_ride2
    wish_list_priority3  wish_list_ride3
    ...
    wish_list_priorityN  wish_list_rideN
    ----

The customer type must be one of the following: Closest Ride First, Highest Priority First, or Shortest Time First. The exit strategy must be one of the following: Empty Wish List, Park Closing Time, or Set Time. If the exit strategy is Set Time, the following line must specify an exit time (both hours and minutes); for the other exit strategies no exit time line will appear.

All the hour fields are based on a 24-hour clock.

The delimiter "----", starting in the first column, signals the end of a customer's wishlist.

Here is an example:

* Sample customer file:
John McCarthy
9 15
Closest Ride First
Empty Wish List
3 Polymorphic Paddleboats
2 Inheritance Insanity
----
Donald E. Knuth
9 25
Highest Priority First
Set Time
10 00
2 Inheritance Insanity
8 Casting Coaster
----
9. Output

The simulator gathers a variety of statistics on the rides and the customers.

For each customer, it keeps track of the name of each attraction visited, and for each, the times when the customer got in line, got onto the ride, and completed the ride. It can also compute the total time spent in the park, the total time spent in line, the total time spent riding rides, and the percentage of rides on the original wishlist that the customer visited. The user can also view the customer with the most or least time in the park or in line.

For each ride, it keeps track of the total number of riders, the average number per minute, the minimum, maximum, and average number of cars, and the minimum, maximum, and average line length and waiting time. The user can also view the attraction with the most or fewest visitors or the longest or shortest average waiting time.

The user can also view the statistics for a specific customer or attraction by name or write all the statistics to a file for later review.