next up previous
Next: About this document

CS341, Spring 1996
LISP Assignment #2
Assigned 4/16, due 4/26.

This assignment will involve modifying the elevator simulation code, which is located in the directory ~c341/code/psl2. You might start by looking at the file loader.lisp, which contains a list of what's in the other files. You can load that file, execute the function (load-simulator) then the function (simulate) to watch it run. You can pass an optional argument to simulate saying how many iterations you want it to run. The default is 100.

  1. Simulations are generally built and run to gather statistics about the environment. In this case we might be interested in how long an average passenger had to wait before getting on an elevator, and also for each floor how long passengers had to wait. The simulation currently doesn't keep track of that information, but you're going to change that. The easiest way to keep track is probably to do the following.

    To keep track of the total waiting time per floor:

    1. Add a new slot to each floor structure keeping track of the total number of passenger minutes waited. (I'm using ``minute'' as shorthand for ``simulator time units.'') Make sure these are initialized to zeros.
    2. Every iteration through the simulation, increment this value for each floor with the number of passengers at that floor.
    3. Modify summarize-simulation to report the total waiting time for each floor. It probably makes sense to divide this number by the number of minutes in the simulation, otherwise longer simulations will look worse.

    To compute the average waiting time per passenger, you can add two numbers to the sim data structure: the total number of minutes waited, and the total number of passengers in the simulation. Every iteration through the simulation, you can increment total minutes waited by the number of passengers currently waiting at floors. Every time a passenger is added to the simulation, you can increment the total number of passengers. Then modify summarize-simulation to report on the average waiting time per passenger.

  2. Running the simulator with this new information may reveal bottlenecks at some floors. One solution might be to define ``express'' elevators. An express elevator is one that serves just two floors, floor 0 and another designated floor. (The designated floor can be different for different elevators.) Express elevators can go twice as fast as other elevators. changes:
    1. Add a slot to the elevator structure that stores the floor (other than 0) it can stop at. You should put this information in a parameter like the elevator capacities are done. See parameters.lisp.
    2. Also change the speed parameter of these express elevators to be twice as fast as the others.
    3. You will have to change the code in iterate.lisp to assure (1) that an elevator never stops at a floor it is not allowed to stop at, and (2) that an elevator never takes on a passenger whose destination is a floor that it cannot stop at.

  3. Does the express elevator idea help? That is, can you convert some or all of the elevators to express elevators (without adding any new ones) and improve the bottlenecks?

  4. Extra credit: if you watch the simulation carefully, you will notice some very strange things about how the elevators move. First of all, if a passenger arrives at an upper floor, all the elevators will move for that floor at once. Second, suppose there is a single passenger at floor 5 who wants to go down. The will go up to get the passenger, but then they will pass it by, go all the way up to the top, turn around, then come back down. On the way back down they will stop and pick up the passengers(s).

    Fix both these oddities. One idea for doing so is implementing some sort of ``call button'' idea. When a passenger arrives at a floor, a particular elevator gets ``called'' to service that floor. An elevator at floor 1 servicing a call on floor 9 could also answer a call on floor 5 on its way, but it would never reverse its direction to answer the call.

    You don't have to stick to this scheme: just try to figure out a ``smarter'' way of sending elevators to floors, and implement it.





next up previous
Next: About this document



Dave Grove
Wed Apr 17 08:59:56 PDT 1996