From b2c5e579501b6dd30b6928b7733a35fc600ad66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cari=C3=B1o=20Baz=C3=A1n?= Date: Tue, 24 Nov 2015 14:40:45 -0500 Subject: [PATCH 1/5] Update Simulation.py --- Simulation.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Simulation.py b/Simulation.py index e9d3f95..9e3c6b8 100644 --- a/Simulation.py +++ b/Simulation.py @@ -4,16 +4,6 @@ class Simulation: - #elevators = [] - #elevators.append( Retail_Elevator ) - #elevators.append( Residential_Elevator_Lower ) - #elevators.append( Residential_Elevator_Luxury ) - #elevators.append( Office_Elevator_Lower ) - #elevators.append( Office_Elevator_Luxury ) - #elevators.append( Mechanical_Elevator ) - #elevators.append( Observatory_Elevator ) - #elevators.append( Key_Card_Elevator ) - AllWaitingList = [ [], [], [], [], [], [], [], [] ] AllWaitingPickUp = [ [], [], [], [], [], [], [], [] ] AllElevators = [ [], [], [], [], [], [], [], [] ] @@ -22,7 +12,7 @@ class Simulation: cntTrips = [ 0, 0, 0, 0, 0, 0, 0, 0] maxTime = [ 0, 0, 0, 0, 0, 0, 0, 0] - print Key_Card_Elevator.currentFloor + print "Simulation begins here" for it in range( 0, 11 ): AllElevators[ 0 ].append( Key_Card_Elevator ) @@ -49,13 +39,15 @@ class Simulation: AllWaitingPickUp[ 5 ].append( [] ) for it in range( 0, 2 ): - AllElevators[ 5 ].append( Observatory_Elevator ) + AllElevators[ 6 ].append( Observatory_Elevator ) AllWaitingPickUp[ 6 ].append( [] ) for it in range( 0, 4 ): AllElevators[ 7 ].append( Mechanical_Elevator ) AllWaitingPickUp[ 7 ].append( [] ) + print len( AllWaitingPickUp[ 7 ] ) + flag = False # Check from 7:00 to 10:00 for moment in range( 0, 1080 ): @@ -89,8 +81,9 @@ class Simulation: #WaitingList.append( waitingGroup ) # Check all of the elevators - for typeElevator in range( 0, 7 ): + for typeElevator in range( 0, 8 ): + print "Checking Elevator " + `typeElevator` WaitingList = AllWaitingList[ typeElevator ] WaitingPickup = AllWaitingPickUp[ typeElevator ] Elevators = AllElevators[ typeElevator ] @@ -234,7 +227,9 @@ class Simulation: doorsOpen = False - + print cntTime + print cntTrips + print maxTime From 4b3c7f50d7ac77f5fc3ad6e23b99fccb78cc07d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cari=C3=B1o=20Baz=C3=A1n?= Date: Tue, 24 Nov 2015 14:41:17 -0500 Subject: [PATCH 2/5] Update elevator.py --- elevator.py | 80 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 27 deletions(-) diff --git a/elevator.py b/elevator.py index 74ef5c6..0648f1b 100644 --- a/elevator.py +++ b/elevator.py @@ -1,14 +1,15 @@ import random -import simulation class Elevator: - id - status = { "ready":True, "traveling":False} + #id + status = {"ready":True, "traveling":False} currentFloor = 1 destinations = [] - - #floorAccess + destinations.extend(range(1, 82)) + floorAccess = 0 + holding = 0 + doorsOpen = False def __init__(self): self.id = None @@ -18,65 +19,93 @@ def getFloor(self): return self.currentFloor def setFloor(self, floor): - self.currentFloor = floor + self.currentFloor = 1 + holding = 0 + doorsOpen = True class Retail_Elevator(Elevator): status = "ready" - #floorAccess + floorAccess = range(1, 6) currentFloor = 1 - destinationFloor = 1 + def __init__(self): self.status = "ready" self.currentFloor = 1 - self.destinationFloor = 1 -class Residential_Elevator(Elevator): +class Residential_Elevator_Lower(Elevator): + + status = "ready" + currentFloor = 1 + floorAccess = range(23, 40) + + def __init__(self): + self.status = "ready" + self.currentFloor = 1 + + +class Residential_Elevator_Luxury(Elevator): - id status = "ready" currentFloor = 1 - destinationFloor = 1 - #floorAccess + floorAccess = range(63, 80) def __init__(self): - self.id self.status = "ready" self.currentFloor = 1 - self.destinationFloor = 1 -class Office_Elevator(Elevator): +class Office_Elevator_Lower(Elevator): - id status ="ready" currentFloor = 1 - destinationFloor = 1 - #floorAccess + floorAccess = range(7, 20) + +class Office_Elevator_Luxury(Elevator): + + status ="ready" + currentFloor = 1 + floorAccess = range(43, 60) class Mechanical_Elevator(Elevator): - id status="ready" currentFloor = 1 - destinationFloor = 1 - #floorAccess + floorAccess = range(1, 81) def __init__(self): - self.id self.status = "ready" self.currentFloor = 1 - self.destinationFloor = 1 +class Observatory_Elevator(Elevator): + + status="ready" + currentFloor = 1 + floorAccess = range(1, 81) + + def __init__(self): + self.status = "ready" + self.currentFloor = 1 + + +class Key_Card_Elevator(Elevator): + + status="ready" + currentFloor = 1 + floorAccess = range(1, 81) + + def __init__(self): + self.status = "ready" + self.currentFloor = 1 @@ -87,6 +116,3 @@ def __init__(self): e1.setFloor(2) print e1.getFloor() - - - From d104fc9bf99c19986506f214d314d8c59770c0a3 Mon Sep 17 00:00:00 2001 From: Tomas Carino Bazan Date: Tue, 1 Dec 2015 01:19:25 -0500 Subject: [PATCH 3/5] Delete Simulation.py --- Simulation.py | 240 -------------------------------------------------- 1 file changed, 240 deletions(-) delete mode 100644 Simulation.py diff --git a/Simulation.py b/Simulation.py deleted file mode 100644 index 9e3c6b8..0000000 --- a/Simulation.py +++ /dev/null @@ -1,240 +0,0 @@ -from Elevator import Elevator, Retail_Elevator, Residential_Elevator_Lower, Residential_Elevator_Luxury, Office_Elevator_Lower, Office_Elevator_Luxury, Mechanical_Elevator, Observatory_Elevator, Key_Card_Elevator -#from people import People, Group -#import queue - -class Simulation: - - AllWaitingList = [ [], [], [], [], [], [], [], [] ] - AllWaitingPickUp = [ [], [], [], [], [], [], [], [] ] - AllElevators = [ [], [], [], [], [], [], [], [] ] - - cntTime = [ 0, 0, 0, 0, 0, 0, 0, 0] - cntTrips = [ 0, 0, 0, 0, 0, 0, 0, 0] - maxTime = [ 0, 0, 0, 0, 0, 0, 0, 0] - - print "Simulation begins here" - - for it in range( 0, 11 ): - AllElevators[ 0 ].append( Key_Card_Elevator ) - AllWaitingPickUp[ 0 ].append( [] ) - - for it in range( 0, 4 ): - AllElevators[ 1 ].append( Retail_Elevator ) - AllWaitingPickUp[ 1 ].append( [] ) - - for it in range( 0, 7 ): - AllElevators[ 2 ].append( Office_Elevator_Lower ) - AllWaitingPickUp[ 2 ].append( [] ) - - for it in range( 0, 3 ): - AllElevators[ 3 ].append( Residential_Elevator_Lower ) - AllWaitingPickUp[ 3 ].append( [] ) - - for it in range( 0, 7 ): - AllElevators[ 4 ].append( Office_Elevator_Luxury ) - AllWaitingPickUp[ 4 ].append( [] ) - - for it in range( 0, 2 ): - AllElevators[ 5 ].append( Residential_Elevator_Luxury ) - AllWaitingPickUp[ 5 ].append( [] ) - - for it in range( 0, 2 ): - AllElevators[ 6 ].append( Observatory_Elevator ) - AllWaitingPickUp[ 6 ].append( [] ) - - for it in range( 0, 4 ): - AllElevators[ 7 ].append( Mechanical_Elevator ) - AllWaitingPickUp[ 7 ].append( [] ) - - print len( AllWaitingPickUp[ 7 ] ) - - flag = False - # Check from 7:00 to 10:00 - for moment in range( 0, 1080 ): - - if flag == False: - - print "banter" - #str_test = raw_input() - - #tim, current, destination, people, request = str_test.split() - - else: - - flag = False - - #if tim != moment: - - #flag = True - #continue - - request = 5 - - - - WaitingList = AllWaitingList[ request ] - WaitingPickup = AllWaitingPickUp[ request ] # curent, destination, people - Elevators = AllElevators[ request ] - - # DONT FORGET TO ADD IN - #waitingGroup = ( tim, current, destination, people ) - #WaitingList.append( waitingGroup ) - - # Check all of the elevators - for typeElevator in range( 0, 8 ): - - print "Checking Elevator " + `typeElevator` - WaitingList = AllWaitingList[ typeElevator ] - WaitingPickup = AllWaitingPickUp[ typeElevator ] - Elevators = AllElevators[ typeElevator ] - - elevatorsLen = len( Elevators ) - - # Have people get off at this floor - for idx in range( 0, elevatorsLen ): - - particularElevator = Elevators[ idx ] - particularWaitingPickup = WaitingPickup[ idx ] - - # Avoid checking elevators that are empty - if particularElevator.holding == 0: - - # Update elevators that are empty, but have already been assigned somebody to pick up - if len( WaitingPickup[ idx ] ) > 0: - - increment = particularWaitingPickup[ 0 ] - particularWaitingPickup[ 1 ] - particularElevator.currentFloor -= abs( increment ) / increment - - continue - - # Update current floor - if particularElevator.currentFloor < particularElevator.destinations[ 0 ][ 0 ]: - - particularElevator.currentFloor = particularElevator.currentFloor - 1 - else: - - particularElevator.currentFloor = particularElevator.currentFloor + 1 - - # Simulate people getting off at this floor - for group in range( len( particularElevator.destinations ) ): - - if particularElevator.destinations[ group ][ 0 ] == particularElevator.currentFloor: - particularElevator.holding = particularElevator.holding - particularElevator.destinations[ group ][ 1 ] - - particularElevator.remove( ( particularElevator.destinations[ group ] ) ) - - particularElevator.doorsOpen = True - - # Have people get on at this floor - for idx in range( 0, elevatorsLen ): - - particularElevator = Elevators[ idx ] - particularWaitingPickup = WaitingPickup[ idx ] - - # Check if the elevator can still carry more people, and if the elevator open - if particularElevator.holding == 12 or particularElevator.doorsOpen == False: - - continue - - # Check if the open elevator will pickup anybody on this floor - for group in range( 0, len( WaitingList ) ): - - particularGroup = WaitingList[ group ] - - # Check if elevator is currently on a floor with people waiting to be picked up - if particularElevator.currentFloor != particularGroup[ 0 ]: - - continue - - if len( particularElevator.destinations ) != 0: - - dir1 = particularElevator.currentFloor - particularElevator.destinations[ 0 ][ 0 ] - dir2 = particularGroup[ 0 ] - particularGroup[ 1 ] - - if dir1 != dir2: - - continue - - willGetOn = min( particularGroup[ 2 ], 12 - particularElevator.holding ) - stillWaiting = particularGroup[ 2 ] - willGetOn - - particularElevator.holding += willGetOn - particularElevator.destinations.append( ( particularGroup[ 1 ], willGetOn ) ) - - addTime = 10 * ( moment - particularGroup[ 0 ] + abs( particularGroup[ 1 ] - particularGroup[ 2 ] ) ) - - cntTime[ idx ] += addTime - cntTrips[ idx ] += 1 - maxTime[ idx ] = max( maxTime[ idx ], addTime ) - - if stillWaiting == 0: - - WaitingList[ idx ].remove( particularGroup ) - - else: - - particularGroup[ 2 ] = stillWaiting - - if particularElevator.holding == 12: - - break - - # Check if there are currently people waiting to be picked up that have not yet been assigned an elevator - # This also takes care of empty elevators - if len( WaitingList ) != 0: - - # Make empty elevators head move towards people that have been waiting the longest (i.e. first element of WaitingList) - for idx in range( 0, elevatorsLen ): - - particularElevator = Elevators[ idx ] - particularWaitingPickup = WaitingPickup[ idx ] - - # Avoid considering elevators that are already occupied, or headed towards somebody - if len( particularElevator.destinations ) != 0 or len( particularWaitingPickup ) != 0: - - continue - - nextPickUp = -1 - - # Check to see if there are people waiting to be picked up, that have not yet been assigned an elevator - for PickUpIdx in range( 0, WaitingList ): - - takenCareOf = False - - for takenCareOfIdx in range( 0, len( Elevators ) ): - - if WaitingPickup[ takenCareOfIdx ][ 0 ] == WaitingList[ PickUpIdx ]: - - takenCareOf = True - break - - if takenCareOf == True: - - continue - - nextPickUp = PickUpIdx - break - - # If there are no people waiting to be picked up, or all of them have already been assigned an elevator - if nextPickUp == -1: - - break - - particularWaitingPickup.append( WaitingList[ nextPickUp ] ) - - increment = WaitingPickup[ 0 ][ 0 ] - WaitingPickup[ 0 ][ 1 ] - particularElevator.currentFloor -= abs( increment ) / increment - - doorsOpen = False - - print cntTime - print cntTrips - print maxTime - - - - - - print "PROJECT COMPILED!" - - From ab535d734dc4f8a0c520e4861e9e52876f0f98e0 Mon Sep 17 00:00:00 2001 From: Tomas Carino Bazan Date: Tue, 1 Dec 2015 01:19:34 -0500 Subject: [PATCH 4/5] Delete elevator.py --- elevator.py | 118 ---------------------------------------------------- 1 file changed, 118 deletions(-) delete mode 100644 elevator.py diff --git a/elevator.py b/elevator.py deleted file mode 100644 index 0648f1b..0000000 --- a/elevator.py +++ /dev/null @@ -1,118 +0,0 @@ -import random - -class Elevator: - - #id - status = {"ready":True, "traveling":False} - currentFloor = 1 - destinations = [] - destinations.extend(range(1, 82)) - floorAccess = 0 - holding = 0 - doorsOpen = False - - def __init__(self): - self.id = None - - - def getFloor(self): - return self.currentFloor - - def setFloor(self, floor): - self.currentFloor = 1 - holding = 0 - doorsOpen = True - - - - -class Retail_Elevator(Elevator): - status = "ready" - floorAccess = range(1, 6) - currentFloor = 1 - - - def __init__(self): - self.status = "ready" - self.currentFloor = 1 - - - - -class Residential_Elevator_Lower(Elevator): - - status = "ready" - currentFloor = 1 - floorAccess = range(23, 40) - - def __init__(self): - self.status = "ready" - self.currentFloor = 1 - - -class Residential_Elevator_Luxury(Elevator): - - status = "ready" - currentFloor = 1 - floorAccess = range(63, 80) - - def __init__(self): - self.status = "ready" - self.currentFloor = 1 - - - -class Office_Elevator_Lower(Elevator): - - status ="ready" - currentFloor = 1 - floorAccess = range(7, 20) - -class Office_Elevator_Luxury(Elevator): - - status ="ready" - currentFloor = 1 - floorAccess = range(43, 60) - - -class Mechanical_Elevator(Elevator): - - status="ready" - currentFloor = 1 - floorAccess = range(1, 81) - - def __init__(self): - self.status = "ready" - self.currentFloor = 1 - - -class Observatory_Elevator(Elevator): - - status="ready" - currentFloor = 1 - floorAccess = range(1, 81) - - def __init__(self): - self.status = "ready" - self.currentFloor = 1 - - -class Key_Card_Elevator(Elevator): - - status="ready" - currentFloor = 1 - floorAccess = range(1, 81) - - def __init__(self): - self.status = "ready" - self.currentFloor = 1 - - - -e1 = Retail_Elevator() - -print "Status of retail elevator is", e1.status - -e1.setFloor(2) - -print e1.getFloor() From 59f1b01e75bbe054ba0823016845d97514b1dd4c Mon Sep 17 00:00:00 2001 From: Tomas Carino Bazan Date: Tue, 1 Dec 2015 01:19:40 -0500 Subject: [PATCH 5/5] Delete people.py --- people.py | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 people.py diff --git a/people.py b/people.py deleted file mode 100644 index 92d6d1a..0000000 --- a/people.py +++ /dev/null @@ -1,9 +0,0 @@ -import elavator -import random - -class People: - destinationFloor = random.randint(0,100) - -class Group(People): - currentFloor = random.randint(0,100) - numPeople = random.randint(1,12)