ComeçarComece de graça

Transportation model: defining model inputs

Let's put it together and build all the model components.

You have been asked to optimize the traffic lights of the city of Chicago to improve traffic flow. A discrete-event model is beneficial in these situations.

The first step is to measure the average length of roads between intersections, which you concluded to be 100 meters on average with a standard deviation of about 20 meters, which means that a driver is expected to encounter a traffic light every 80-120 meters.

The speed limit in Chicago is 30 mph (approximately 50 km/h). The city officials informed you that, on average, the light remains red for up to 90 seconds. Start by defining the inputs and outputs of your model.

Este exercício faz parte do curso

Discrete Event Simulation in Python

Ver curso

Instruções do exercício

  • Set the mean and standard deviation of the inputs["Dist_between_intersections_m"] array.
  • Apply the Gaussian distribution to generate RandomGener["Distance"] values.
  • Apply a random method to generate integers for RandomGener["WaitTime"].

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Define the model inputs
inputs = {"Dist_between_intersections_m": [____, ____],
    	  "Speed_limit_ms": 50 * 1000 / (60 * 60),
          "Max_waitTime_traffic_lights_sec": 90}
random_generated = {"Distance": [], "WaitTime": []}

for i in range(5000):
	# Use the random package to generate pseudo-random values
    random_generated["Distance"].append(random.____(inputs['Dist_between_intersections_m'][0],inputs['Dist_between_intersections_m'][1]))
    random_generated["WaitTime"].append(random.____(0, inputs['Max_waitTime_traffic_lights_sec']))

# Plot the randomly generated distance "events"
plt.hist(random_generated["Distance"], bins=100)
plt.xlabel('# Events')
plt.ylabel('# Distance travelled (m)')
plt.show()
Editar e executar o código