開始使用免費開始

運輸模型:定義程序方法

現在你已經定義好模型輸入,接下來要建立模型引擎,也就是用來描述各個程序的方法。

有兩個程序會影響駕駛在特定距離上的行駛時間:(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
編輯並執行程式碼