I suggest that you write some time unit conversion methods and call them regularly, so you don't end up worrying about when to divide by 1000 and when to multiply by 1000 and when to round off and how.
In real life a passenger comes to the elevator at (say) floor F planning to go to floor G. If there are N floors, that means there are N*(N-1) kinds of trips. We'd need to specify the arrival rate in passengers/second for each kind.
Our first simplification is to assume that all passengers boarding the elevator anywhere other than the main floor will go to the main floor rather than to any intermediate floor. That means we have only 2(N-1) kinds of trips, those going to main from somewhere and those going somewhere from main.
Our second simplification is to assume that each passenger boarding at the main floor to go up makes a random decision at each floor about whether or not to get off at that floor. Real passengers don't behave that way, but the simulator doesn't care whether we specify the trips to a particular exit floor in terms of passenger arrivals at main or as a decision made at random at each floor.
Finally, we assume passengers are conserved. That is, we assume that in the long run the rate at which passengers leave the elevator at any floor other than main is the same as the rate at which they arrive at the elevator to go back to main.
With these assumptions we need only this input data about trips:
With this we can actually compute the rate at which passengers arrive at the floors other than main. In fact I've done that for you in the static method compute in class $CS310/elevators/ArrivalRates.java
It follows from this discussion that some of what's in the .els file is irrelevant is irrelevant.
This line matters:
# probability that a passenger on board leaves at floor f 1.0 0.7 0.9 0.5 0.3 0.2 0.5 0.3 0.5 0.1 0.1 1.0but it should be recommented:
# probability that a passenger on board travelling away from # main leaves at a particular floor. Must begin and end with 1.0. # The value for main itself is never used. 1.0 0.7 0.9 0.5 0.3 0.2 0.5 0.3 0.5 0.1 0.1 1.0
The only entries on these two lines that we need now are the ones for main - the other arrival rates will be computed and the other probabilities are always 1.0 and 0.0 as shown. But to keep the parsing unchanged we will not change the input format.
# passengers/second arriving at a floor 0.0067 0.04 0.06 0.03 0.013 0.0167 0.057 0.01 0.05 0.0067 0.043 0.0167 # probability that a person arriving at a floor wants to go up # (these values assume all trips are to or from main, which is 2) 1.0 1.0 0.8 0 0 0 0 0 0 0 0 0
But it's a mistake to pay too much attention to performance early in the design process, since attempts to speed things up will distract you from making good design decisions. Here's how to address the question. (Details to follow.)
I have added error handling to the simulator package that prevents you from changing the actionTime of an Event that is already on the event queue!
If there are people on board when the elevator stops and the departure probability is 0.3 then loop on the list of people on board choose a random number between 0.0 and 1.0 if the number < 0.3 that person leaves the elevator
public boolean debug = false;
public static void out(String s)
{
if (debug) {
System.out.println(s);
}
}
Then in your code you always write
Debug.out("some message");
and when you want debugging just say someplace
Debug.debug = true;