Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def makeMove(action, transition_time):
if action == 1:
traci.trafficlight.setPhase("0", (int(traci.trafficlight.getPhase("0")) + 1) % 4)
# traci.simulationStep()
# traci.simulationStep()
# traci.simulationStep()
# traci.simulationStep()
return getState(transition_time)
Average_Q_lengths = []
sum_q_lens = 0
AVG_Q_len_perepisode = []
num_history = 20
batch_history = 20
transition_time = 50
model = build_model(batch_history)
print(model.summary())
generate_routefile()
traci.start([sumoBinary, "-c", "data/cross.sumocfg",
"--tripinfo-output", "tripinfo.xml"])
traci.trafficlight.setPhase("0", 0)
nA = 4###
state = getState()
experience = []
for i in range(num_history):
experience.append(state)
for episode in range(num_episode):
traci.trafficlight.setPhase("0", 0)
print("INITIAL EXPERIENCE : ")
print(experience)
counter = 0
stride = 0
while traci.simulation.getMinExpectedNumber() > 0:
print("Episode # ", episode)
def makeMove(action, transition_time, experience):
if action == 1:
traci.trafficlight.setPhase("0", (int(traci.trafficlight.getPhase("0")) + 1) % 4)
for _ in range(transition_time):
experience.pop(0)
traci.simulationStep()
experience.append(getState())
# traci.simulationStep()
# traci.simulationStep()
# traci.simulationStep()
# traci.simulationStep()
newState = getState()
return newState, experience
def makeMove(leftAction, rightAction, transition_time):
if leftAction == 1:
traci.trafficlight.setPhase("0", (int(traci.trafficlight.getPhase("0")) + 1) % 4)
if rightAction == 1:
traci.trafficlight.setPhase("10", (int(traci.trafficlight.getPhase("10")) + 1) % 4)
return getState(transition_time)
'2si') + traci.edge.getLastStepHaltingNumber('1si')
for i in range(10):
stepz += 1
reward1 += traci.edge.getLastStepVehicleNumber(
'4si') + traci.edge.getLastStepVehicleNumber('3si')
reward2 += traci.edge.getLastStepHaltingNumber(
'2si') + traci.edge.getLastStepHaltingNumber('1si')
traci.trafficlight.setPhase('0', 0)
waiting_time += (traci.edge.getLastStepHaltingNumber('1si') + traci.edge.getLastStepHaltingNumber(
'2si') + traci.edge.getLastStepHaltingNumber('3si') + traci.edge.getLastStepHaltingNumber('4si'))
traci.simulationStep()
if(action == 1 and light[0][0][0] == 1):
for i in range(6):
stepz += 1
traci.trafficlight.setPhase('0', 5)
waiting_time += (traci.edge.getLastStepHaltingNumber('1si') + traci.edge.getLastStepHaltingNumber(
'2si') + traci.edge.getLastStepHaltingNumber('3si') + traci.edge.getLastStepHaltingNumber('4si'))
traci.simulationStep()
for i in range(10):
stepz += 1
traci.trafficlight.setPhase('0', 6)
waiting_time += (traci.edge.getLastStepHaltingNumber('1si') + traci.edge.getLastStepHaltingNumber(
'2si') + traci.edge.getLastStepHaltingNumber('3si') + traci.edge.getLastStepHaltingNumber('4si'))
traci.simulationStep()
for i in range(6):
stepz += 1
traci.trafficlight.setPhase('0', 7)
waiting_time += (traci.edge.getLastStepHaltingNumber('1si') + traci.edge.getLastStepHaltingNumber(
'2si') + traci.edge.getLastStepHaltingNumber('3si') + traci.edge.getLastStepHaltingNumber('4si'))
traci.simulationStep()
def _set_green_phase(self, action_number):
if action_number == 0:
traci.trafficlight.setPhase("TL", PHASE_NS_GREEN)
elif action_number == 1:
traci.trafficlight.setPhase("TL", PHASE_NSL_GREEN)
elif action_number == 2:
traci.trafficlight.setPhase("TL", PHASE_EW_GREEN)
elif action_number == 3:
traci.trafficlight.setPhase("TL", PHASE_EWL_GREEN)
def makeMove(action, transition_time):
if action == 1:
traci.trafficlight.setPhase("0", (int(traci.trafficlight.getPhase("0")) + 1) % 4)
# traci.simulationStep()
# traci.simulationStep()
# traci.simulationStep()
# traci.simulationStep()
return getState(transition_time)
def makeMoves(leftAction, rightAction, transition_time):
if leftAction == 1:
traci.trafficlight.setPhase("0", (int(traci.trafficlight.getPhase("0")) + 1) % 4)
if rightAction == 1:
traci.trafficlight.setPhase("10", (int(traci.trafficlight.getPhase("10")) + 1) % 4)
return getStates(transition_time)
def _set_green_phase(self, action_number):
if action_number == 0:
traci.trafficlight.setPhase("TL", PHASE_NS_GREEN)
elif action_number == 1:
traci.trafficlight.setPhase("TL", PHASE_NSL_GREEN)
elif action_number == 2:
traci.trafficlight.setPhase("TL", PHASE_EW_GREEN)
elif action_number == 3:
traci.trafficlight.setPhase("TL", PHASE_EWL_GREEN)