Transportation model: defining the generator
Well done; you have defined your model inputs and outputs and the model processes you characterized using Python methods. Now, it's time to put a generator together that will sequence all your model processes.
Este ejercicio forma parte del curso
Discrete Event Simulation in Python
Instrucciones del ejercicio
- Call the function
road_travel()
created before, which calculates the road travel time, and clock in the time it takes to complete it. - Call the function
wait_traffic_light()
created before, which calculates the waiting time at traffic lights, and clock in the time it takes to complete it.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
def all_processes(env, inputs):
road_stretch, distance_total, traffic_light = 0, 0, 0
while True:
road_stretch += 1
# Call function calculates road travel time
distance, distance_total = ____(inputs, distance_total)
yield env.____(distance/inputs['Speed_limit_ms'])
print(f"> Road Stretch #{road_stretch} \nLength = {distance} m , Cumulative distance travelled = {distance_total} m , Total time elapsed = {env.now} sec")
traffic_light += 1
# Call function that calculates waiting time at a traffic light
waitTime_traffic_light_sec = ____(inputs, distance_total)
yield env.____(waitTime_traffic_light_sec)
print(f"> Traffic Light #{traffic_light} \nWait time = {waitTime_traffic_light_sec} sec, Time lapsed = {env.now} sec")