Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ORIGINAL CODE: # In this simulation the library numpy is used and it is named it np import numpy as np # The
ORIGINAL CODE:
# In this simulation the library numpy is used and it is named it np
import numpy as np
# The seed below initializes the random generator to always obtain the same result.
# DO NOT CHANGE THIS VALUE AND RERUN THIS CELL EVERYTIME YOU RUN THE PROGRAM.
nprandom.seed
# Variables are defined in this cell
v # Rate of vehicles per second
queueMoveTime # Time it takes a vehicle to clear the intersection
redTime # Red light time in seconds
greenTime # Green light time in seconds
nVehi # Number of vehicles arriving at the intersection
nRep # Counter for number of repetitions
nQueue # Counter for number of times vehicles queue
isRed True # Initialize the light as red
isGreen False
# Monte Carlo simulation
nsim # Number of simulation
while nRep nsim:
# Red light cycle
if isRed:
nRep nRep # Count replicates
nVehi nVehi nprandom.poissonv redTime
isRed False
isGreen True
# Green light cycle
else:
time queueMoveTime
while isGreen:
if nVehi :
nVehi nVehi
nVehi nVehi nprandom.poissonv queueMoveTime
else:
break
time time queueMoveTime
if time greenTime:
break
if nVehi :
nQueue nQueue
# Reset light to Red
isRed True
isGreen False
# Calculate the probability of queuing
pQueue nQueue nsim
printThe probability of queuing at the intersection is pQueue Answer question in image using this info.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started