运输模型:定义过程方法
既然您已经定义了模型输入,接下来就可以创建模型引擎了,其中包含用于表征各个过程的方法。
有两个过程会影响司机在特定距离上的行程时间:(1) 在遵守限速的前提下实际驾驶该距离所需的时间,(2) 在交通信号灯前等待的时间。
本练习是课程的一部分
Python 中的离散事件模拟
练习说明
- 使用高斯分布伪随机生成
random_generated["Distance"]的取值。 - 通过加上新计算的距离来更新
distance_total。 - 为
random_generated["WaitTime"]生成随机整数取值。
交互式实操练习
通过完成这段示例代码来试试这个练习。
def road_travel(inputs, distance_total):
# Use the Gaussian method to generate distance values
distance = ____.____(inputs['Dist_between_intersections_m'][0], inputs['Dist_between_intersections_m'][1])
# Update the total distance
distance_total += ____
return distance, distance_total
def wait_traffic_light(inputs, distance_total):
# Generate random (integer) waiting times
waitTime_traffic_light_sec = ____.____(0, inputs['Max_waitTime_traffic_lights_sec'])
return waitTime_traffic_light_sec