Skip to content

Commit d4ba3fe

Browse files
committed
minor edits to taxi_sim.py
1 parent 7d7a716 commit d4ba3fe

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

control/simulation/taxi_sim.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111

1212
def compute_delay(interval):
13+
"""Compute action delay using exponential distribution"""
1314
return int(random.expovariate(1/interval)) + 1
1415

1516

1617
def taxi_process(ident, trips):
18+
"""Yield to simulator issuing event at each state change"""
1719
trip_ends = 0
1820
for i in range(trips):
1921
prowling_ends = trip_ends + compute_delay(FIND_PASSENGER_INTERVAL)
@@ -33,6 +35,7 @@ def __init__(self, actors):
3335
self.time = 0
3436

3537
def schedule_events(self):
38+
"""Advance each actor to next state, scheduling events"""
3639
for actor in list(self.actors):
3740
try:
3841
future_event = next(actor)
@@ -42,6 +45,7 @@ def schedule_events(self):
4245
self.events.put(future_event)
4346

4447
def run(self, end_time):
48+
"""Schedule and execute events until time is up"""
4549
while self.time < end_time:
4650
self.schedule_events()
4751
if self.events.empty():
@@ -66,6 +70,7 @@ def extract_seed(args):
6670

6771

6872
def main(args):
73+
"""Parse command line, build actors and run simulation"""
6974
extract_seed(args)
7075
if args:
7176
end_time = int(args[0])

0 commit comments

Comments
 (0)