Example #1
0
def case2():

    # CASE 2 - crash elevator.
    elevators_num = 2
    floors_num = 40

    c = Controller(elevators_num, floors_num)
    c.start()

    # create some random floors to use for testing
    random_floors = []
    for i in range(10):
        floor = random.randrange(1,floors_num-1)
        random_floors.append(floor)

    called_floors = []

    floor = random_floors.pop()
    print floor
    called_floors.append(floor)
    c.request_up(floor)

    time.sleep(5)

    for e in c.elevators:
        if c.elevators[e].status != Elevator.WAITING:
            c.crash(e)

    time.sleep(10)

    running1 = True
    running2 = True
    while running1 or running2:
        if c.elevators[0].status == Elevator.WAITING or c.elevators[0].status == Elevator.OFFLINE:
            running1 = False
        if c.elevators[1].status == Elevator.WAITING or c.elevators[0].status == Elevator.OFFLINE:
            running2 = False

    for e in c.elevators:
        c.elevators[e].running = False
Example #2
0
def main(argv=None):
    floors = 0
    elevators = 0

    if argv is None:
        argv = sys.argv
    try:
        try:
            opts, args = getopt.getopt(argv[1:], "f:e:h", ["floors=", "elevators=", "help"])
        except getopt.error, msg:
             raise Usage(msg)

        for opt, arg in opts:
            if opt in ('-e', '--elevators'):
                elevators = arg
            if opt in ('-f', '--floors'):
                floors = arg

        if elevators > 0 and floors > 0:
            c = Controller(int(elevators), int(floors))
            c.start()
            process = True

            while process:
                var = raw_input("Enter command: ")
                var =  var.split(' ')
                command = var[0]
                if command == 'quit':
                    process = False
                else:

                    if command == 'up':
                        # command expected in the form of 'up floor_num'
                        floor = var[1]
                        c.request_up(int(floor))
                    elif command == 'down':
                        # command expected in the form of 'down floor_num'
                        floor = var[1]
                        c.request_down(int(floor))
                    elif command == 'elevator':
                        # command expected in the form of 'elevator elevator_num floor_num'
                        elevator_num = var[1]
                        floor = var[2]
                        c.request_floor(int(elevator_num), int(floor))
                    elif command == 'crash':
                        # command expected in the form of 'crash elevator_num'
                        elevator_num = var[1]
                        c.crash(int(elevator_num))


        else:
            print 'Elevator Bank Program'
            print 'usage: python elevator_bank.py -f num_floors -e num_elevators\n'
            print 'f num_floors    : enter the number of floors as a positive integer.  The first floor is 0.'
            print 'e num_elevators : enter the number of elevators as a positive integer.  The first elevator is 0.'
            print '-----------'
            print 'COMMANDS'
            print 'up floor_num - request up from a floor'
            print 'down floor_num - request down from a floor'
            print 'elevator elevator_num floor_num - Once inside of an elevator request a floor'
            print 'crash elevator_num - Crash an elevator'