Permalink
Browse files

IT'S ALIVE

  • Loading branch information...
1 parent 1e9ff0b commit 752ac4873f5999b4ca18d97c797afaa7966a89a0 @spooty89 spooty89 committed Dec 16, 2011
Showing with 27 additions and 27 deletions.
  1. +8 −6 elevator.py
  2. +7 −6 elevator_group.py
  3. +8 −15 elevator_sim.py
  4. +4 −0 rand.py
View
@@ -1,3 +1,5 @@
+from rand import generator
+from period import is_morning, is_afternoon, is_evening
# We use a probability of 0.01 in place of floors that did not have any
# passengers get off on
@@ -140,13 +142,13 @@ class Elevator(object):
def __init__(self, type_):
self.type = type_
self.num_passengers = 0
- if self.type = TYPE_F:
+ if self.type == TYPE_F:
self.capacity = 11
- elif self.type = TYPE_L:
+ elif self.type == TYPE_L:
self.capacity = 10
- elif self.type = TYPE_I:
+ elif self.type == TYPE_I:
self.capacity = 10
- elif self.type = TYPE_E:
+ elif self.type == TYPE_E:
self.capacity = 11
def pick_floor(self, time):
@@ -163,7 +165,7 @@ def pick_floor(self, time):
# TODO
def service_time(self, time):
- return self.idle_time(time) + self.busy_time(time) + ...
+ return self.idle_time(time) + self.busy_time(time)
def idle_time(self, time):
if self.type == TYPE_F:
@@ -188,7 +190,7 @@ def idle_time(self, time):
elif is_evening(time):
return 219
elif self.type == TYPE_E:
- if is_morning(time):: #11am
+ if is_morning(time): #11am
return 51
elif is_afternoon(time):
return 1
View
@@ -1,10 +1,11 @@
import rand
from elevator import Elevator
+from period import is_morning, is_afternoon, is_evening
TYPE_F_ARRIVAL_DISTRS = {
'morning': [3, 5, 1, 2, 2, 1, 3, 3, 8, 1, 8, 3],
'afternoon': [1, 0, 1, 0, 1, 1, 2, 2, 1, 1, 0, 2, 3],
- 'evening': [2, 0, 0, 0, 0, 0, 3, 1, 1, 0, 0]
+ 'evening': [0, 0, 0, 0, 0, 0, 3, 1, 1, 0, 0, 2]
}
TYPE_L_ARRIVAL_DISTRS = {
@@ -41,18 +42,18 @@ def __init__(self, type_, count):
self.next_gen = 0
def create_passengers(self, time):
- minute_period = time / 60 % 60
+ minute_period = (time / 60) % 60
minute_period -= minute_period % 5
index = minute_period / 5
arrivals = 0
- if is_morning(time)
- arrivals = rand.poisson(arrival_distrs[self.type]['morning'][index])
+ if is_morning(time):
+ arrivals = rand.poisson(5, arrival_distrs[self.type]['morning'][index])
elif is_afternoon(time):
- arrivals = rand.poisson(arrival_distrs[self.type]['afternoon'][index])
+ arrivals = rand.poisson(5, arrival_distrs[self.type]['afternoon'][index])
elif is_evening(time):
- arrivals = rand.poisson(arrival_distrs[self.type]['evening'][index])
+ arrivals = rand.poisson(5, arrival_distrs[self.type]['evening'][index])
self.pool = arrivals
View
@@ -1,23 +1,11 @@
from system import System
from event import Event
from elevator import Elevator
+from elevator_group import ElevatorGroup
import rand
import elevator
ONE_DAY = 24*60*60 # in seconds
-
-MORNING_END = 6*60*60 # 11am
-AFTERNOON_END = MORNING_END + 6*60*60
-EVENING_END = AFTERNOON_END + 6*60*60
-
-def is_morning(time):
- return 0 <= time <= MORNING_END
-
-def is_afternoon(time):
- return MORNING_END < time <= AFTERNOON_END
-
-def is_evening(time):
- return AFTERNOON_END < time <= EVENING_END
class ElevatorArriveEvent(Event):
def __init__(self, time, group, index):
@@ -38,12 +26,15 @@ def initialize(self):
self.schedule_event(ElevatorArriveEvent(time, elevator_group, i))
def update(self):
- temp = self.clock.time() / 300
+ temp = self.clock.time() / 60
+ #print temp
for elevator_group in self.elevator_groups:
if elevator_group.next_gen <= temp:
while elevator_group.next_gen <= temp:
elevator_group.next_gen += 5
+ print self.clock.time()
elevator_group.create_passengers(self.clock.time())
+ print "generated passengers\n"
def handle(self, event):
if isinstance(event, ElevatorArriveEvent):
@@ -58,13 +49,15 @@ def handle(self, event):
else:
elevator.num_passengers = group.pool
group.pool = 0
+ #print elevator.num_passengers
# schedule next arrival
cur_time = self.clock.time()
service_time = elevator.service_time(cur_time)
time = cur_time + service_time
self.schedule_event(ElevatorArriveEvent(time, group, index))
else:
- temp = group.next_gen
+ #print self.clock.time()
+ temp = group.next_gen*60
self.schedule_event(ElevatorArriveEvent(temp, group, index))
View
@@ -50,12 +50,16 @@ def bernoulli(p):
def exponential(lambda_):
""" Returns duration of time between events given rate of arrival lambda_
"""
+ if lambda_ == 0:
+ return 0
rand = random.random()
return -1 / lambda_ * math.log(1-rand)
def poisson(t, lambda_):
""" Returns number of events in time t given rate lambda_
"""
+ if lambda_ == 0:
+ return 0
time = 0
num_events = 0
while time < t:

0 comments on commit 752ac48

Please sign in to comment.