args = prs.parse_args() experiment_time = str(datetime.now()).split('.')[0] out_csv = 'outputs/2way-single-intersection/sarsa_lambda{}'.format(args.lamb) write_route_file('nets/2way-single-intersection/single-intersection-gen.rou.xml', 400000, 100000) env = SumoEnvironment(net_file='nets/2way-single-intersection/single-intersection.net.xml', single_agent=True, route_file=args.route, out_csv_name=out_csv, use_gui=args.gui, num_seconds=args.seconds, min_green=args.min_green, max_green=args.max_green, max_depart_delay=0, time_to_load_vehicles=120, phases=[ traci.trafficlight.Phase(32, "GGrrrrGGrrrr"), traci.trafficlight.Phase(2, "yyrrrryyrrrr"), traci.trafficlight.Phase(32, "rrGrrrrrGrrr"), traci.trafficlight.Phase(2, "rryrrrrryrrr"), traci.trafficlight.Phase(32, "rrrGGrrrrGGr"), traci.trafficlight.Phase(2, "rrryyrrrryyr"), traci.trafficlight.Phase(32, "rrrrrGrrrrrG"), traci.trafficlight.Phase(2, "rrrrryrrrrry") ]) for run in range(1, args.runs+1): obs = env.reset() agent = TrueOnlineSarsaLambda(env.observation_space, env.action_space, alpha=args.alpha, gamma=args.gamma, epsilon=args.epsilon, fourier_order=21) done = False
import numpy as np from sumo_rl.environment.env import SumoEnvironment import traci if __name__ == '__main__': ray.init() register_env( "4x4grid", lambda _: SumoEnvironment( net_file='nets/4x4-Lucas/4x4.net.xml', route_file='nets/4x4-Lucas/4x4c1c2c1c2.rou.xml', out_csv_name='outputs/4x4grid/a3c-4x4grid', use_gui=False, num_seconds=80000, time_to_load_vehicles=120, max_depart_delay=0, phases=[ traci.trafficlight.Phase(35, "GGGrrr"), # north-south traci.trafficlight.Phase(2, "yyyrrr"), traci.trafficlight.Phase(35, "rrrGGG"), # west-east traci.trafficlight.Phase(2, "rrryyy") ])) trainer = A3CTrainer( env="4x4grid", config={ "multiagent": { "policy_graphs": { '0': (A3CTFPolicy, spaces.Box(low=np.zeros(10), high=np.ones(10)),
args = prs.parse_args() experiment_time = str(datetime.now()).split('.')[0] out_csv = 'outputs/2way-single-intersection/{}_alpha{}_gamma{}_eps{}_decay{}_reward{}'.format( experiment_time, args.alpha, args.gamma, args.epsilon, args.decay, args.reward) env = SumoEnvironment( net_file='nets/2way-single-intersection/single-intersection.net.xml', route_file=args.route, out_csv_name=out_csv, use_gui=args.gui, num_seconds=args.seconds, min_green=args.min_green, max_green=args.max_green, max_depart_delay=0, time_to_load_vehicles=120, phases=[ traci.trafficlight.Phase(32, "GGrrrrGGrrrr"), traci.trafficlight.Phase(2, "yyrrrryyrrrr"), traci.trafficlight.Phase(32, "rrGrrrrrGrrr"), traci.trafficlight.Phase(2, "rryrrrrryrrr"), traci.trafficlight.Phase(32, "rrrGGrrrrGGr"), traci.trafficlight.Phase(2, "rrryyrrrryyr"), traci.trafficlight.Phase(32, "rrrrrGrrrrrG"), traci.trafficlight.Phase(2, "rrrrryrrrrry") ]) if args.reward == 'queue': env._compute_rewards = env._queue_average_reward else: env._compute_rewards = env._waiting_time_reward for run in range(1, args.runs + 1):
if __name__ == '__main__': experiment_time = str(datetime.now()).split('.')[0] out_csv = 'outputs/big-intersection/sarsa-f7' #+ experiment_time env = SumoEnvironment( net_file='nets/big-intersection/big-intersection.net.xml', single_agent=True, route_file='nets/big-intersection/routes.rou.xml', out_csv_name=out_csv, use_gui=False, num_seconds=5400, yellow_time=4, min_green=5, max_green=60, max_depart_delay=300, time_to_load_vehicles=0, phases=[ traci.trafficlight.Phase(30, "GGGGrrrrrrGGGGrrrrrr"), traci.trafficlight.Phase(4, "yyyyrrrrrryyyyrrrrrr"), traci.trafficlight.Phase(15, "rrrrGrrrrrrrrrGrrrrr"), traci.trafficlight.Phase(4, "rrrryrrrrrrrrryrrrrr"), traci.trafficlight.Phase(30, "rrrrrGGGGrrrrrrGGGGr"), traci.trafficlight.Phase(4, "rrrrryyyyrrrrrryyyyr"), traci.trafficlight.Phase(15, "rrrrrrrrrGrrrrrrrrrG"), traci.trafficlight.Phase(4, "rrrrrrrrryrrrrrrrrry") ]) fixed_tl = False agent = TrueOnlineSarsaLambda(env.observation_space, env.action_space, alpha=0.000000001,
# if id == 'gneJ00': # return 'gneJ00' # else: return 'offset_agent' if __name__ == '__main__': ray.init() register_env( "2TLS", lambda _: SumoEnvironment( net_file= '/home/sonic/Desktop/sumo-rl-research-offset/sumo-rl-research/experiments/nets/Research/case04/intersection.net.xml', route_file= '/home/sonic/Desktop/sumo-rl-research-offset/sumo-rl-research/experiments/nets/Research/case04/intersection.rou.xml', out_csv_path='outputs/case04/', out_csv_name='DDPG', use_gui=False, num_seconds=12240612, time_to_load_vehicles=612, max_depart_delay=0)) trainer = DDPGTrainer( env="2TLS", config={ "multiagent": { "policy_graphs": { 'offset_agent': (DDPGTFPolicy, spaces.Box(low=np.zeros(2), high=np.array(['inf'] * 2)), spaces.Box(low=np.array([0, 0]),
import numpy as np from sumo_rl.environment.env import SumoEnvironment import traci if __name__ == '__main__': env = SumoEnvironment(net_file='nets/2way-single-intersection/single-intersection.net.xml', route_file='nets/2way-single-intersection/single-intersection-vhvh.rou.xml', out_csv_name='outputs/2way-single-intersection/dqn-vhvh2-stable-mlp-bs', single_agent=True, use_gui=True, num_seconds=100000, time_to_load_vehicles=120, max_depart_delay=0, phases=[ traci.trafficlight.Phase(32000, 32000, 32000, "GGrrrrGGrrrr"), traci.trafficlight.Phase(2000, 2000, 2000, "yyrrrryyrrrr"), traci.trafficlight.Phase(32000, 32000, 32000, "rrGrrrrrGrrr"), traci.trafficlight.Phase(2000, 2000, 2000, "rryrrrrryrrr"), traci.trafficlight.Phase(32000, 32000, 32000, "rrrGGrrrrGGr"), traci.trafficlight.Phase(2000, 2000, 2000, "rrryyrrrryyr"), traci.trafficlight.Phase(32000, 32000, 32000, "rrrrrGrrrrrG"), traci.trafficlight.Phase(2000, 2000, 2000, "rrrrryrrrrry") ]) model = DQN( env=env, policy=MlpPolicy, learning_rate=1e-3, buffer_size=50000, exploration_fraction=0.1,
if __name__ == '__main__': ray.init() register_env( "2way-single-intersection", lambda _: SumoEnvironment( net_file= 'nets/2way-single-intersection/single-intersection.net.xml', route_file= 'nets/2way-single-intersection/single-intersection-gen.rou.xml', out_csv_name='outputs/2way-single-intersection/a3c-contexts', use_gui=False, num_seconds=100000, time_to_load_vehicles=120, max_depart_delay=0, phases=[ traci.trafficlight.Phase(32000, "GGrrrrGGrrrr"), traci.trafficlight.Phase(2000, "yyrrrryyrrrr"), traci.trafficlight.Phase(32000, "rrGrrrrrGrrr"), traci.trafficlight.Phase(2000, "rryrrrrryrrr"), traci.trafficlight.Phase(32000, "rrrGGrrrrGGr"), traci.trafficlight.Phase(2000, "rrryyrrrryyr"), traci.trafficlight.Phase(32000, "rrrrrGrrrrrG"), traci.trafficlight.Phase(2000, "rrrrryrrrrry") ])) trainer = A3CAgent( env="2way-single-intersection", config={ "multiagent": { "policy_graphs": {
return '0' if __name__ == '__main__': ray.init() register_env( "2x2grid", lambda _: SumoEnvironment( net_file='nets/2x2grid/2x2.net.xml', route_file='nets/2x2grid/2x2.rou.xml', out_csv_name='outputs/2x2grid/a3c-contexts', use_gui=False, num_seconds=100000, time_to_load_vehicles=120, max_depart_delay=0, phases=[ traci.trafficlight.Phase(32, "GGrrrrGGrrrr"), traci.trafficlight.Phase(2, "yyrrrryyrrrr"), traci.trafficlight.Phase(32, "rrGrrrrrGrrr"), traci.trafficlight.Phase(2, "rryrrrrryrrr"), traci.trafficlight.Phase(32, "rrrGGrrrrGGr"), traci.trafficlight.Phase(2, "rrryyrrrryyr"), traci.trafficlight.Phase(32, "rrrrrGrrrrrG"), traci.trafficlight.Phase(2, "rrrrryrrrrry") ])) trainer = A3CTrainer( env="2x2grid", config={ "multiagent": { "policy_graphs": { '0':
if __name__ == '__main__': alpha = 0.1 gamma = 0.99 decay = 1 runs = 1 env = SumoEnvironment( net_file='nets/4x4-Lucas/4x4.net.xml', route_file='nets/4x4-Lucas/4x4c2.rou.xml', use_gui=True, num_seconds=40000, time_to_load_vehicles=300, max_depart_delay=0, phases=[ traci.trafficlight.Phase(35000, 35000, 35000, "GGGrrr"), # north-south traci.trafficlight.Phase(2000, 2000, 2000, "yyyrrr"), traci.trafficlight.Phase(35000, 35000, 35000, "rrrGGG"), # west-east traci.trafficlight.Phase(2000, 2000, 2000, "rrryyy") ]) for run in range(1, runs + 1): initial_states = env.reset() ql_agents = { ts: QLAgent(starting_state=env.encode(initial_states[ts]), state_space=env.observation_space, action_space=env.action_space,
100000) # multiprocess environment n_cpu = 2 env = SubprocVecEnv([ lambda: SumoEnvironment( net_file='nets/2way-single-intersection/single-intersection.net.xml', route_file= 'nets/2way-single-intersection/single-intersection-gen.rou.xml', out_csv_name= 'outputs/2way-single-intersection/a2c-contexts-5s-vmvm-400k', single_agent=True, use_gui=False, num_seconds=400000, min_green=5, time_to_load_vehicles=120, max_depart_delay=0, phases=[ traci.trafficlight.Phase(32000, "GGrrrrGGrrrr"), traci.trafficlight.Phase(2000, "yyrrrryyrrrr"), traci.trafficlight.Phase(32000, "rrGrrrrrGrrr"), traci.trafficlight.Phase(2000, "rryrrrrryrrr"), traci.trafficlight.Phase(32000, "rrrGGrrrrGGr"), traci.trafficlight.Phase(2000, "rrryyrrrryyr"), traci.trafficlight.Phase(32000, "rrrrrGrrrrrG"), traci.trafficlight.Phase(2000, "rrrrryrrrrry") ]) for i in range(n_cpu) ]) model = A2C(MlpPolicy, env, verbose=1,
return "4708662059" else: return "5870232715" if __name__ == '__main__': ray.init() register_env( "2TLS", lambda _: SumoEnvironment( net_file= '/home/sonic/Desktop/sumo-rl-suwon/sumo-rl-suwon/experiments/nets/suwon/osm_rl.net.xml', route_file= '/home/sonic/Desktop/sumo-rl-suwon/sumo-rl-suwon/experiments/nets/suwon/osm.rou.xml', out_csv_path='outputs/Test4/', out_csv_name='DQN', use_gui=True, num_seconds=44000, time_to_load_vehicles=300, max_depart_delay=0)) trainer = DQNTrainer( env="2TLS", config={ "multiagent": { "policy_graphs": { '3210041371': (DQNTFPolicy, spaces.Box(low=np.zeros(16), high=np.array(['inf'] * 16)), spaces.Discrete(2), {}),
args = prs.parse_args() ns = args.ns * 1000 we = args.we * 1000 experiment_time = str(datetime.now()).split('.')[0] out_csv = 'outputs/single-intersection/{}_alpha{}_gamma{}_eps{}_decay{}_reward{}'.format( experiment_time, args.alpha, args.gamma, args.epsilon, args.decay, args.reward) env = SumoEnvironment( net_file='nets/single-intersection/single-intersection.net.xml', route_file=args.route, out_csv_name=out_csv, use_gui=args.gui, num_seconds=args.seconds, min_green=args.min_green, max_green=args.max_green, max_depart_delay=0, phases=[ traci.trafficlight.Phase(ns, ns, ns, "GGrr"), # north-south traci.trafficlight.Phase(2000, 2000, 2000, "yyrr"), traci.trafficlight.Phase(we, we, we, "rrGG"), # west-east traci.trafficlight.Phase(2000, 2000, 2000, "rryy") ]) if args.reward == 'queue': env._compute_rewards = env._queue_average_reward else: env._compute_rewards = env._waiting_time_reward for run in range(1, args.runs + 1): initial_states = env.reset() ql_agents = {
prs.add_argument("-s", dest="seconds", type=int, default=100000, required=False, help="Number of simulation seconds.\n") prs.add_argument("-r", dest="reward", type=str, default='wait', required=False, help="Reward function: [-r queue] for average queue reward or [-r wait] for waiting time reward.\n") prs.add_argument("-v", action="store_true", default=False, help="Print experience tuple.\n") prs.add_argument("-runs", dest="runs", type=int, default=1, help="Number of runs.\n") args = prs.parse_args() experiment_time = str(datetime.now()).split('.')[0] out_csv = '{}_alpha{}_gamma{}_eps{}_decay{}_reward{}'.format(experiment_time, args.alpha, args.gamma, args.epsilon, args.decay, args.reward) env = SumoEnvironment(net_file='nets/single-intersection/single-intersection.net.xml', single_agent=True, route_file=args.route, out_csv_name=out_csv, use_gui=args.gui, num_seconds=args.seconds, min_green=args.min_green, max_green=args.max_green, max_depart_delay=0, phases=[ traci.trafficlight.Phase(args.ns, "GGrr"), # north-south traci.trafficlight.Phase(2, "yyrr"), traci.trafficlight.Phase(args.we, "rrGG"), # west-east traci.trafficlight.Phase(2, "rryy") ]) env = VisualizationEnv( env=env, episodic=False, features_names=['Phase 0', 'Phase 1', 'Elapsed time'] + ['Density lane ' + str(i) for i in range(4)] + ['Queue lane ' + str(i) for i in range(4)], actions_names=['Phase 0', 'Phase 1'] )