MulaiMulai sekarang secara gratis

Transportation model: defining process methods

Now that you have defined the model inputs, you are ready to create the model engine, which consists of the methods that will characterize your processes.

Two processes affect the time a given driver takes to travel a certain distance, which are: (1) actual driving time to travel the desired distance respecting the speed limit and the (2) waiting time at traffic lights.

Latihan ini adalah bagian dari kursus

Discrete Event Simulation in Python

Lihat Kursus

Petunjuk latihan

  • Use the Gaussian distribution to pseudo-randomly generate values for random_generated["Distance"].
  • Update distance_total by adding the new distance calculated.
  • Generate integer random values for random_generated["WaitTime"].

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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
Edit dan Jalankan Kode