CSCI 1300, Section 100
Hints on Assignment 6


1. Click here to download an executable that shows you the way your program should work.   Remember t hat you must also download probabilities.dat to run the code.  Also, run the program from a DOS window, and run it using
elevate | more
the "| more" will cause the program to print out one screen at a time.  Alternatively, you can run
elevate > outfile.dat
and the output will be dumped into the file outfile.dat.  Then you can edit "outfile.dat" with emacs to go through the output time step by time step.

2. Before you begin this assignment, reread the program design advice we have prepared for you.

3. To generate random numbers, use the rand() function which produces a number in the interval 0 - 32767 (this is the nonnegative range of a signed 16-bit  or short integer).  To seed the random number generator, use srand(seed). This function should be called one time at the start of your program.  The prototypes for the rand() and srand(seed) functions can be obtained by including stdlib.h.  An example of random number generation is in the class examples called random.cxx.  The last loop in this program should give you a clue about how to select a destination floor when a passenger enters the elevator.

4. A reminder that you can use inline conditionals to make your code more compact.  For example, suppose you want to print "passenger" or "passengers" depending on whether one individual or more than one individual boards the elevator.   If n is the number of passengers who board, you can use:
cout << n << " passenger" << (n > 1 ? "s" : "") << " board." << endl;
The code in the parentheses tests to see if n is greater than 1; if so, the code evaluates to the string "s", and if not, the code evaluates to the null string.

5. You are on the wrong track if you are trying to keep track of information on individual passengers.  The only information you need to represent about passengers is: (a) the number of passengers waiting on each floor who want to go in a given direction, and (b) the number of passengers currently on the elevator who have requested a given destination floor.  Once a passenger reaches their destination, you don't need to keep track of the passenger further.

Your program should not have an upper limit on the number of passengers in the simulation.  If you find that you need to specify this upper limit, then you are probably on the wrong track.  See Prof. Mozer or a TA.

6. Here is the pseudocode Professor Mozer discussed in lecture to generate floor calls:
loop for each floor F
   loop for each direction D
      generate random number r between 0 and 1
      if r is between 0 and p_call(F,D) then
 create a new passenger waiting for elevator on floor F in dir D
 total_call_time += current_time;
total_number_calls ++;
repeat
repeat
mean_call_time = total_call_time / total_number_calls
Note that a random number is generated for each floor in each direction.  This is because each button press is an independent random event.  Likewise, when you generate a destination floor for each passenger entering the elevator, the random number generator should be called once for each passenger, and then a floor should be selected based on that random number.

7. Here are the huge hints Professor Mozer gave on data structures in class on Dec 4.  Note that you need to figure out how to deal with the fact that there are 3 elevators.
Elevator data
-------------
1. elevator floor
   int floor;

2. elevator direction
   int direction; // 0 for down, 1 for up

3. elevator door status (open, closed)
   int status; // 0 for closed, 1 for open
4. number of passengers in elevator to go to floors 0-8
   int n_pass[9];
Passenger floor data
--------------------

1. number of passengers on floor F waiting to go in direction D
   int n_pass_wait[9][2];
Probabilities
-------------

1. probability of a floor call on floor F in direction D
   p_call[F][D]

2. probability of choosing destination floor G given that passenger
   boarded elevator on floor F in direction D
   p_destination[F][D][G]
mean_call_time = total_call_time / total_number_calls

8. To get a ballpark idea of whether your program is working right, Professor Mozer ran his elevator program for 10000 time steps and obtained the following statistics:

mean time between call and boarding:  12.0712 time steps
mean time between boarding and arrival:  8.70838 time steps

You may not get exactly the same numbers, but if you run your simulation, the numbers you get should be close (say, +/- .2).