Esempio n. 1
0
def main():
    traci.start(sumoCmd)

    simulation_step = 0   
    atom_time = 30
    yell_time = 3
    traffic_data = []
    controlTLIds = "0"
    phaseDefs = ['GrrrGrrr', 'rGrrrGrr', 'rrGrrrGr', 'rrrGrrrG']
    yelloPhases = ['yrrryrrr', 'ryrrryrr', 'rryrrryr', 'rrryrrry']
    index = 0
    while simulation_step < 864000:

        ryg = yelloPhases[index % 4]
        traci.trafficlight.setRedYellowGreenState(controlTLIds, ryg)
        for j in range(yell_time):
            traci.simulationStep()

        ryg = phaseDefs[index % 4]
        traci.trafficlight.setRedYellowGreenState(controlTLIds, ryg)
        for j in range(atom_time-yell_time):
            traci.simulationStep()
        # for _ in range(ato_time):
        #     traci.simulationStep()
        simulation_step = simulation_step + atom_time
        index += 1

        traffic_data.append(measure_traffic_step(controlTLIds,simulation_step))

    traffic_data = pd.DataFrame(traffic_data)
    traffic_data.to_csv("/home/hjj/exp_test_v2/Test/TestData/real/static_real.csv")
    traci.close()
    collect_tripinfo(trip_file,'/home/hjj/exp_test_v2/Test/TestData/real/static_real')
Esempio n. 2
0
def main():
    traci.start(sumoCmd)

    agent = Agent(traci, True)
    traci.close()
    # start simulation
    traci.start(sumoCmd)
    agent.reset()
    simulation_steps = 0
    traffic_data = []
    yell_time = 3
    atom_time = 30
    controlTLIds = "0"

    while simulation_steps < 60000:

        traffic_data.append(
            measure_traffic_step(controlTLIds, simulation_steps))
        agent.state = agent._getState()
        action, current_phase = agent.agentAct()

        if action == current_phase:
            agent.setRYG(action, False)
            for j in range(atom_time):
                traci.simulationStep()
        else:
            agent.setRYG(current_phase, True)
            for j in range(yell_time):
                traci.simulationStep()
            agent.setRYG(action, False)
            for j in range(atom_time - yell_time):
                traci.simulationStep()

        agent._getReward()  # stop training
        simulation_steps += atom_time
        # The END of simulationSteps loop

    traci.close()

    traffic_data = pd.DataFrame(traffic_data)
    traffic_data.to_csv(
        "/home/hjj/exp_test/Test/TestData/near_unba/a2c/interval30/a2c_near_unba_30_new.csv"
    )
    collect_tripinfo(
        trip_file,
        '/home/hjj/exp_test/Test/TestData/near_unba/a2c/interval30/a2c_near_unba_30_new'
    )
Esempio n. 3
0
def main():
    traci.start(sumoCmd)

    simulation_step = 0
    ato_time = 30
    traffic_data = []
    controlTLIds = "0"
    while simulation_step < 6000:
        for _ in range(ato_time):
            traci.simulationStep()
        simulation_step = simulation_step + ato_time
        traffic_data.append(measure_traffic_step(controlTLIds,
                                                 simulation_step))
    traffic_data = pd.DataFrame(traffic_data)
    traffic_data.to_csv("run_data/static_over.csv")
    traci.close()
    collect_tripinfo(trip_file, 'run_data/static_over')
Esempio n. 4
0
def main():
    traci.start(sumoCmd)

    agent = Agent(traci, True)
    traci.close()
    # start simulation
    traci.start(sumoCmd)
    agent.reset()
    simulation_steps = 0
    traffic_data = []
    yell_time = 3
    atom_time = 30
    controlTLIds = "0"

    while simulation_steps < 864000:

        traffic_data.append(
            measure_traffic_step(controlTLIds, simulation_steps))
        action, current_phase = agent.agentAct()

        if action == current_phase:
            agent.setRYG(action, False)
            for j in range(atom_time):
                traci.simulationStep()
        else:
            agent.setRYG(current_phase, True)
            for j in range(yell_time):
                traci.simulationStep()
            agent.setRYG(action, False)
            for j in range(atom_time - yell_time):
                traci.simulationStep()

        agent.agentCulReward(is_sim=True)  # stop training
        simulation_steps += atom_time
        # The END of simulationSteps loop

    traci.close()

    traffic_data = pd.DataFrame(traffic_data)
    traffic_data.to_csv(
        "/home/hjj/exp_test_v2/Test/TestData/real/dqn_real.csv")
    collect_tripinfo(trip_file,
                     '/home/hjj/exp_test_v2/Test/TestData/real/dqn_real')