コード例 #1
0
    model = Model(num_states, num_actions, batch_size)
    memory = Memory(memory_size)
    traffic_gen = TrafficGenerator(max_steps)
    sumoCmd = [
        sumoBinary, "-c", "intersection/tlcs_config_train.sumocfg",
        "--no-step-log", "true", "--waiting-time-memory",
        str(max_steps)
    ]
    saver = tf.train.Saver()

    with tf.Session() as sess:
        print("PATH:", path)
        print("----- Start time:", datetime.datetime.now())
        sess.run(model.var_init)
        sim_runner = SimRunner(sess, model, memory, traffic_gen,
                               total_episodes, gamma, max_steps,
                               green_duration, yellow_duration, sumoCmd)
        episode = 0

        while episode < total_episodes:
            print('----- Episode {} of {}'.format(episode + 1, total_episodes))
            start = timeit.default_timer()
            sim_runner.run(episode)  # run the simulation
            stop = timeit.default_timer()
            print('Time: ', round(stop - start, 1))
            episode += 1

        os.makedirs(os.path.dirname(path), exist_ok=True)
        saver.save(sess, path + "my_tlcs_model.ckpt")
        print("----- End time:", datetime.datetime.now())
        print("PATH:", path)
コード例 #2
0
    traffic_gen = TrafficGenerator(max_steps)
    sumoCmd = [
        sumoBinary, "-c", "intersection/tlcs_config_train.sumocfg",
        "--no-step-log", "true", "--waiting-time-memory",
        str(max_steps)
    ]
    saver = tf.train.Saver()

    with tf.Session() as sess:
        saver.restore(sess, path + "my_tlcs_model.ckpt")
        sim_runner = SimRunner(sess,
                               model,
                               memory,
                               traffic_gen,
                               1,
                               gamma,
                               max_steps,
                               green_duration,
                               yellow_duration,
                               sumoCmd,
                               demo=True)
        sim_runner.run(1)
        print("Wait time with model:", sim_runner.cumulative_wait_store[0])
        print("Avg queue length with model:",
              sim_runner.avg_intersection_queue_store[0])

    ##Primitive Traffic light, without model, round robin

    sim_runner = SimRunner(sess,
                           model,
                           memory,
コード例 #3
0
MIN_EPS = 0.001
DECAY = 0.0004
GAMMA = 0.8

NUM_EPISODE = 10000

model = Model(num_states, num_actions, BATCHSIZE)
mem = Memory(700000)
vis = VisuJSON(env._refZMP._X, env._refZMP._Y)

trajectory = {}

saver = tf.train.Saver()
with tf.Session() as sess:
    sess.run(model._var_init)
    sr = SimRunner(sess, model, env, mem, MAX_EPS, MIN_EPS, DECAY, GAMMA)
    cnt = 0
    while cnt < NUM_EPISODE + 1:
        start = time.time()

        # if cnt % 10 == 0:
        #     print('------------------------------------------------------------------------------')
        #     print('Episode {} of {}'.format(cnt+1, NUM_EPISODE))

        print(
            '------------------------------------------------------------------------------'
        )
        print('Episode {} of {}'.format(cnt + 1, NUM_EPISODE))

        env._refZMP._RealZmpX = []
        env._refZMP._RealZmpY = []
if __name__ == "__main__":

    # --- SUMO OPTIONS ---
    gui = False

    # attributes of the simulation
    max_steps = 5400
    green_duration = 10
    yellow_duration = 4
    path = "./results/"

    # setting the cmd mode or the visual mode
    if gui == False:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')

    # initializations
    traffic_gen = TrafficGenerator(max_steps)
    sumoCmd = [
        sumoBinary, "-c", "intersection/sim.sumocfg", "--no-step-log", "true",
        "--waiting-time-memory",
        str(max_steps)
    ]

    sim_runner = SimRunner(traffic_gen, max_steps, green_duration,
                           yellow_duration, sumoCmd)

    sim_runner.run()

    save_graphs(sim_runner, path)