Ejemplo n.º 1
0
def case3():
    ## this case tests the optimizing function.
    ## elevator 0 will reach it's destination after elevator 2 starts to attempt to service the request.
    ## since elevator 0's status changes to WAITING and it is closer to floor 12
    ## elevator 2 is cancelled and elevator 0 will overtake the request.

    elevators_num = 3
    floors_num = 40

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

    c.request_up(10)
    time.sleep(25)
    c.request_down(8)
    time.sleep(5)
    c.request_up(12)
    time.sleep(5)

    running1 = True
    running2 = True
    running3 = True

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

    for e in c.elevators:
        c.elevators[e].running = False
Ejemplo n.º 2
0
def case4():
    ## test the ability for an elevator to switch it final request and store the previous request into a pending request array
    ## initially elevator 2 will be heading for floor 12
    ## but we recieve a 5th request before any other elevators can service this request.
    ## since elevator 2 is going to floor 12.  It switches to floor 14 and then comes back down to floor 12

    elevators_num = 4
    floors_num = 40

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

    c.request_up(10)
    time.sleep(1)
    c.request_down(8)
    time.sleep(1)
    c.request_down(12)
    time.sleep(1)
    c.request_up(15)
    time.sleep(1)
    c.request_down(14)
    time.sleep(1)

    running1 = True
    running2 = True
    running3 = True
    running4 = True

    while running1 or running2 or running3 or running4:
        if c.elevators[0].status == Elevator.WAITING:
            running1 = False
        if c.elevators[1].status == Elevator.WAITING:
            running2 = False
        if c.elevators[2].status == Elevator.WAITING:
            running3 = False
        if c.elevators[3].status == Elevator.WAITING:
            running3 = False

    for e in c.elevators:
        c.elevators[e].running = False
Ejemplo n.º 3
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'