def figure_eight_example(render=None): """Perform a simulation of vehicles on a figure eight. Parameters ---------- render: bool, optional specifies whether to use the gui during execution Returns ------- exp: flow.core.experiment.Experiment A non-rl experiment demonstrating the performance of human-driven vehicles on a figure eight. """ sim_params = AimsunParams(sim_step=0.5, render=False, emission_path='data') if render is not None: sim_params.render = render vehicles = VehicleParams() vehicles.add( veh_id="human", acceleration_controller=(IDMController, {}), num_vehicles=14) env_params = EnvParams() net_params = NetParams( additional_params=ADDITIONAL_NET_PARAMS.copy()) network = FigureEightNetwork( name="figure8", vehicles=vehicles, net_params=net_params) env = TestEnv(env_params, sim_params, network, simulator='aimsun') return Experiment(env)
flow_params = dict( # name of the experiment exp_tag='figure8', # name of the flow environment the experiment is running on env_name=AccelEnv, # name of the network class the experiment is running on network=FigureEightNetwork, # simulator that is used by the experiment simulator='traci', # sumo-related parameters (see flow.core.params.SumoParams) sim=SumoParams(render=True, ), # environment related parameters (see flow.core.params.EnvParams) env=EnvParams( horizon=1500, additional_params=ADDITIONAL_ENV_PARAMS.copy(), ), # network-related parameters (see flow.core.params.NetParams and the # network's documentation or ADDITIONAL_NET_PARAMS component) net=NetParams(additional_params=ADDITIONAL_NET_PARAMS.copy(), ), # vehicles to be placed in the network at the start of a rollout (see # flow.core.params.VehicleParams) veh=vehicles, )
def get_flow_params(num_automated=1, horizon=1500, simulator="traci", multiagent=False): """Return the flow-specific parameters of the figure eight network. This network consists of two rings, placed at opposite ends of the network, and connected by an intersection with road segments of length equal to the diameter of the rings. If two vehicles attempt to cross the intersection from opposing directions, the dynamics of these vehicles are constrained by right-of-way rules provided by the simulator. We consider a figure eight with a ring radius of 30 m and total length of 402m. The network contains a total of 14 vehicles. We study various levels of mixed-autonomy. This benchmark is adapted from the following article: Vinitsky, Eugene, et al. "Benchmarks for reinforcement learning in mixed-autonomy traffic." Conference on Robot Learning. 2018. Parameters ---------- num_automated : int number of automated (RL) vehicles horizon : int time horizon of a single rollout simulator : str the simulator used, one of {'traci', 'aimsun'} multiagent : bool whether the automated vehicles are via a single-agent policy or a shared multi-agent policy with the actions of individual vehicles assigned by a separate policy call Returns ------- dict flow-related parameters, consisting of the following keys: * exp_tag: name of the experiment * env_name: environment class of the flow environment the experiment is running on. (note: must be in an importable module.) * network: network class the experiment uses. * simulator: simulator that is used by the experiment (e.g. aimsun) * sim: simulation-related parameters (see flow.core.params.SimParams) * env: environment related parameters (see flow.core.params.EnvParams) * net: network-related parameters (see flow.core.params.NetParams and the network's documentation or ADDITIONAL_NET_PARAMS component) * veh: vehicles to be placed in the network at the start of a rollout (see flow.core.params.VehicleParams) * initial (optional): parameters affecting the positioning of vehicles upon initialization/reset (see flow.core.params.InitialConfig) * tls (optional): traffic lights to be introduced to specific nodes (see flow.core.params.TrafficLightParams) Raises ------ AssertionError if the `num_automated` parameter is a value other than 1, 2, 7, or 14 """ assert num_automated in [1, 2, 7, 14], \ "num_automated must be one of [1, 2, 7 14]" # We evenly distribute the autonomous vehicles in between the human-driven # vehicles in the network. num_human = 14 - num_automated human_per_automated = int(num_human / num_automated) vehicles = VehicleParams() for i in range(num_automated): vehicles.add(veh_id='human_{}'.format(i), acceleration_controller=(IDMController, { 'noise': 0.2 }), routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", decel=1.5, ), num_vehicles=human_per_automated) vehicles.add(veh_id='rl_{}'.format(i), acceleration_controller=(RLController, {}), routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", accel=MAX_ACCEL, decel=MAX_DECEL, ), num_vehicles=1) return dict( # name of the experiment exp_tag='figure_eight', # name of the flow environment the experiment is running on env_name=MultiAgentAccelPOEnv if multiagent else AccelEnv, # name of the network class the experiment is running on network=FigureEightNetwork, # simulator that is used by the experiment simulator=simulator, # sumo-related parameters (see flow.core.params.SumoParams) sim=SumoParams( sim_step=0.1, render=False, ), # environment related parameters (see flow.core.params.EnvParams) env=EnvParams( horizon=horizon, additional_params={ 'target_velocity': TARGET_VELOCITY, 'max_accel': MAX_ACCEL, 'max_decel': MAX_DECEL, 'sort_vehicles': False, "full_observation_fn": full_observation_fn }, ), # network-related parameters (see flow.core.params.NetParams and the # network's documentation or ADDITIONAL_NET_PARAMS component) net=NetParams(additional_params=ADDITIONAL_NET_PARAMS.copy(), ), # vehicles to be placed in the network at the start of a rollout (see # flow.core.params.VehicleParams) veh=vehicles, # parameters specifying the positioning of vehicles upon init/reset # (see flow.core.params.InitialConfig) initial=InitialConfig(), )
def para_produce_rl(HORIZON=3000, NUM_AUTOMATED=7): # time horizon of a single rollout HORIZON = 1500 # number of rollouts per training iteration N_ROLLOUTS = 20 # number of parallel workers N_CPUS = 2 # number of automated vehicles. Must be less than or equal to 22. NUM_AUTOMATED = NUM_AUTOMATED assert NUM_AUTOMATED in [1, 2, 7, 14], \ "num_automated must be one of [1, 2, 7 14]" # desired velocity for all vehicles in the network, in m/s TARGET_VELOCITY = 20 # maximum acceleration for autonomous vehicles, in m/s^2 MAX_ACCEL = 3 # maximum deceleration for autonomous vehicles, in m/s^2 MAX_DECEL = 3 # We evenly distribute the automated vehicles in the network. num_human = 14 - NUM_AUTOMATED human_per_automated = int(num_human / NUM_AUTOMATED) vehicles = VehicleParams() for i in range(NUM_AUTOMATED): # Add one automated vehicle. vehicles.add(veh_id="rl_{}".format(i), acceleration_controller=(RLController, {}), routing_controller=(ContinuousRouter, {}), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", accel=MAX_ACCEL, decel=MAX_DECEL, ), num_vehicles=1) # Add a fraction of the human driven vehicles. vehicles.add(veh_id="human_{}".format(i), acceleration_controller=(IDMController, { "noise": 0.2 }), car_following_params=SumoCarFollowingParams( speed_mode="obey_safe_speed", decel=1.5), routing_controller=(ContinuousRouter, {}), num_vehicles=human_per_automated) flow_params = dict( # name of the experiment exp_tag="multiagent_figure_eight", # name of the flow environment the experiment is running on env_name=MultiAgentAccelPOEnv, # name of the network class the experiment is running on network=FigureEightNetwork, # simulator that is used by the experiment simulator='traci', # sumo-related parameters (see flow.core.params.SumoParams) sim=SumoParams(sim_step=0.1, render=False, restart_instance=False), # environment related parameters (see flow.core.params.EnvParams) env=EnvParams( horizon=HORIZON, additional_params={ 'target_velocity': TARGET_VELOCITY, 'max_accel': MAX_ACCEL, 'max_decel': MAX_DECEL, 'sort_vehicles': False }, ), # network-related parameters (see flow.core.params.NetParams and the # network's documentation or ADDITIONAL_NET_PARAMS component) net=NetParams(additional_params=ADDITIONAL_NET_PARAMS.copy(), ), # vehicles to be placed in the network at the start of a rollout (see # flow.core.params.VehicleParams) veh=vehicles, # parameters specifying the positioning of vehicles upon initialization/ # reset (see flow.core.params.InitialConfig) initial=InitialConfig()) flow_params['env'].horizon = HORIZON return flow_params
# environment related parameters (see flow.core.params.EnvParams) env=EnvParams( horizon=HORIZON, additional_params={ 'target_velocity': 20, 'max_accel': 3, 'max_decel': 3, 'sort_vehicles': False }, ), # network-related parameters (see flow.core.params.NetParams and the # network's documentation or ADDITIONAL_NET_PARAMS component) net=NetParams( additional_params=ADDITIONAL_NET_PARAMS.copy(), ), # vehicles to be placed in the network at the start of a rollout (see # flow.core.params.VehicleParams) veh=vehicles, # parameters specifying the positioning of vehicles upon initialization/ # reset (see flow.core.params.InitialConfig) initial=InitialConfig(), ) def setup_exps(): """Return the relevant components of an RLlib experiment.
from flow.networks.figure_eight import ADDITIONAL_NET_PARAMS # ENV1_NET PARAMS ADDITIONAL_NET_PARAMS_ENV1 = ADDITIONAL_NET_PARAMS.copy() ADDITIONAL_NET_PARAMS_ENV1["lanes"] = 2 ADDITIONAL_NET_PARAMS_ENV1["resolution"] = 40 ADDITIONAL_NET_PARAMS_ENV1["radius_ring"] = 60