Due Wednesday, February 26
This problem will involve the SimPy discrete-event simulation library, which relies heavily on the Python generator construct. Here are the details:
% python Elevator.py passenger_arrival_rate elevator_capacity mean_elevator_return_time max_simtime
Those command-line arguments are:
This is a difficult assignment. For that reason, I've made some changes from the original version:
Normally I frown on the practice by some instructors of providing students with code outlines in the problem specs. I make plenty of help available to those who need it, but only after they've spent a goodly amount of time trying to devise a code strategy.
In this case, though, due to the difficulty of the problem, I will give extensive hints here:
class G: # globals Rnd = Random(12345) elevProc = None # elevator process passProc = None # passenger process
class passClass(Process): def __init__(self): Process.__init__(self) self.passArrvRate = float(sys.argv[1]) # self.arrvs will be arrivals waiting for pickup self.arrvs = [0.0] self.nextArrv = None # for debugging/code verifying def Run(self): while True: # sim next arrival
self.arrvs = [0.0]
reactivate(G.elevProc)
yield passivate,self
When I was debugging my code for this problem, I used Python's built-in debugger, pdb. It's pretty primitive, but I configured it to give me important information at each pause. Specifically, I set these at the beginning of my debugging session:
b 43 b 55 b 59 b 74 b 76 alias c c;;now();;l;;G.elevProc;G.passProc
The last redefines the "continue" command to print out things at each pause of the debugger.
If you are willing to have a maximum grade of B+ on this assignment, you may do a scaled-down version:
Why is this considered "scaled-down"? First, of course, it's easier. But second, it is much less general. For example, it obviates our ability to model more sophisticated arrival schemes, such as balking, in which an arriving passenger sees a long line for the elevator and thus opts to take the stairs instead.