def sugiyama_example(sumo_binary=None): sumo_params = SumoParams(sim_step=0.1, sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add( veh_id="idm", acceleration_controller=(IDMController, {}), routing_controller=(ContinuousRouter, {}), num_vehicles=22) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) additional_net_params = ADDITIONAL_NET_PARAMS.copy() net_params = NetParams(additional_params=additional_net_params) initial_config = InitialConfig(bunching=20) scenario = LoopScenario( name="sugiyama", generator_class=CircleGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def start(): sumo_params = SumoParams(sim_step=0.1, sumo_binary="sumo") sumo_params.sumo_binary = 'sumo' vehicles = Vehicles() vehicles.add(veh_id="idm", acceleration_controller=(IDMController, {}), routing_controller=(ContinuousRouter, {}), num_vehicles=22) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) additional_net_params = ADDITIONAL_NET_PARAMS.copy() net_params = NetParams(additional_params=additional_net_params) initial_config = InitialConfig(bunching=20) scenario = LoopScenario(name="sugiyama", generator_class=CircleGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = AccelEnv(env_params, sumo_params, scenario) env._close()
def figure_eight_example(sumo_binary=None): sumo_params = SumoParams(sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add(veh_id="idm", acceleration_controller=(IDMController, {}), lane_change_controller=(StaticLaneChanger, {}), routing_controller=(ContinuousRouter, {}), initial_speed=0, num_vehicles=14) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) additional_net_params = ADDITIONAL_NET_PARAMS.copy() net_params = NetParams(no_internal_links=False, additional_params=additional_net_params) scenario = Figure8Scenario(name="figure8", generator_class=Figure8Generator, vehicles=vehicles, net_params=net_params) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def grid_example(sumo_binary=None): inner_length = 300 long_length = 500 short_length = 300 n = 2 m = 3 num_cars_left = 20 num_cars_right = 20 num_cars_top = 20 num_cars_bot = 20 tot_cars = (num_cars_left + num_cars_right) * m \ + (num_cars_top + num_cars_bot) * n grid_array = { "short_length": short_length, "inner_length": inner_length, "long_length": long_length, "row_num": n, "col_num": m, "cars_left": num_cars_left, "cars_right": num_cars_right, "cars_top": num_cars_top, "cars_bot": num_cars_bot } sumo_params = SumoParams(sim_step=0.1, sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add(veh_id="human", routing_controller=(GridRouter, {}), num_vehicles=tot_cars) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) additional_net_params = { "grid_array": grid_array, "speed_limit": 35, "horizontal_lanes": 1, "vertical_lanes": 1, "traffic_lights": True } net_params = NetParams(no_internal_links=False, additional_params=additional_net_params) initial_config = InitialConfig() scenario = SimpleGridScenario(name="grid-intersection", generator_class=SimpleGridGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def highway_example(sumo_binary=None): """ Perform a simulation of vehicles on a highway. Parameters ---------- sumo_binary: bool, optional specifies whether to use sumo's gui during execution Returns ------- exp: flow.core.SumoExperiment type A non-rl experiment demonstrating the performance of human-driven vehicles on a figure eight. """ sumo_params = SumoParams(sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add(veh_id="human", acceleration_controller=(IDMController, {}), num_vehicles=20) vehicles.add(veh_id="human2", acceleration_controller=(IDMController, {}), num_vehicles=20) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) inflow = InFlows() inflow.add(veh_type="human", edge="highway", probability=0.25, departLane="free", departSpeed=20) inflow.add(veh_type="human2", edge="highway", probability=0.25, departLane="free", departSpeed=20) additional_net_params = ADDITIONAL_NET_PARAMS.copy() net_params = NetParams(in_flows=inflow, additional_params=additional_net_params) initial_config = InitialConfig(spacing="uniform", shuffle=True) scenario = HighwayScenario(name="highway", generator_class=HighwayGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def two_loops_merge_straight_example(sumo_binary=None): sumo_params = SumoParams(sim_step=0.1, emission_path="./data/", sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary # note that the vehicles are added sequentially by the generator, # so place the merging vehicles after the vehicles in the ring vehicles = Vehicles() vehicles.add(veh_id="idm", acceleration_controller=(IDMController, {}), lane_change_controller=(SumoLaneChangeController, {}), routing_controller=(ContinuousRouter, {}), num_vehicles=7, sumo_car_following_params=SumoCarFollowingParams( minGap=0.0, tau=0.5), sumo_lc_params=SumoLaneChangeParams()) vehicles.add(veh_id="merge-idm", acceleration_controller=(IDMController, {}), lane_change_controller=(SumoLaneChangeController, {}), routing_controller=(ContinuousRouter, {}), num_vehicles=10, sumo_car_following_params=SumoCarFollowingParams( minGap=0.01, tau=0.5), sumo_lc_params=SumoLaneChangeParams()) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) additional_net_params = ADDITIONAL_NET_PARAMS.copy() additional_net_params["ring_radius"] = 50 additional_net_params["inner_lanes"] = 1 additional_net_params["outer_lanes"] = 1 additional_net_params["lane_length"] = 75 net_params = NetParams( no_internal_links=False, additional_params=additional_net_params ) initial_config = InitialConfig( x0=50, spacing="uniform", additional_params={"merge_bunching": 0} ) scenario = TwoLoopsOneMergingScenario( name="two-loop-one-merging", generator_class=TwoLoopOneMergingGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config ) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def merge_example(sumo_binary=None): sumo_params = SumoParams(sumo_binary="sumo-gui", emission_path="./data/", sim_step=0.2, restart_instance=True) if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add(veh_id="human", acceleration_controller=(IDMController, { "noise": 0.2 }), num_vehicles=5) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS, sims_per_step=5, warmup_steps=0) inflow = InFlows() inflow.add(veh_type="human", edge="inflow_highway", vehs_per_hour=(1 - RL_PENETRATION) * FLOW_RATE, departLane="free", departSpeed=10) inflow.add(veh_type="human", edge="inflow_merge", vehs_per_hour=100, departLane="free", departSpeed=7.5) additional_net_params = ADDITIONAL_NET_PARAMS.copy() additional_net_params["merge_lanes"] = 1 additional_net_params["highway_lanes"] = 1 additional_net_params["pre_merge_length"] = 500 net_params = NetParams(in_flows=inflow, no_internal_links=False, additional_params=additional_net_params) initial_config = InitialConfig(spacing="uniform", perturbation=5.0, lanes_distribution=float("inf")) scenario = MergeScenario(name="merge-baseline", generator_class=MergeGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = WaveAttenuationMergePOEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def highway_example(sumo_binary=None): sumo_params = SumoParams(sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add(veh_id="human", acceleration_controller=(IDMController, {}), num_vehicles=20) vehicles.add(veh_id="human2", acceleration_controller=(IDMController, {}), num_vehicles=20) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) inflow = InFlows() inflow.add(veh_type="human", edge="highway", probability=0.25, departLane="free", departSpeed=20) inflow.add(veh_type="human2", edge="highway", probability=0.25, departLane="free", departSpeed=20) additional_net_params = ADDITIONAL_NET_PARAMS.copy() net_params = NetParams(in_flows=inflow, additional_params=additional_net_params) initial_config = InitialConfig(spacing="uniform", shuffle=True) scenario = HighwayScenario(name="highway", generator_class=HighwayGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def figure_eight_example(sumo_binary=None): """ Perform a simulation of vehicles on a figure eight. Parameters ---------- sumo_binary: bool, optional specifies whether to use sumo's gui during execution Returns ------- exp: flow.core.SumoExperiment type A non-rl experiment demonstrating the performance of human-driven vehicles on a figure eight. """ sumo_params = SumoParams(sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add(veh_id="idm", acceleration_controller=(IDMController, {}), lane_change_controller=(StaticLaneChanger, {}), routing_controller=(ContinuousRouter, {}), speed_mode="no_collide", initial_speed=0, num_vehicles=14) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) additional_net_params = ADDITIONAL_NET_PARAMS.copy() net_params = NetParams(no_internal_links=False, additional_params=additional_net_params) scenario = Figure8Scenario(name="figure8", generator_class=Figure8Generator, vehicles=vehicles, net_params=net_params) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def bay_bridge_example(sumo_binary=None, use_inflows=False, use_traffic_lights=False): """ Perform a simulation of vehicles on the Oakland-San Francisco Bay Bridge. Parameters ---------- sumo_binary: bool, optional specifies whether to use sumo's gui during execution use_inflows: bool, optional whether to activate inflows from the peripheries of the network use_traffic_lights: bool, optional whether to activate the traffic lights in the scenario Returns ------- exp: flow.core.SumoExperiment type A non-rl experiment demonstrating the performance of human-driven vehicles simulated by sumo on the Bay Bridge. """ sumo_params = SumoParams(sim_step=0.6, overtake_right=True) if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary sumo_car_following_params = SumoCarFollowingParams(speedDev=0.2) sumo_lc_params = SumoLaneChangeParams( lcAssertive=20, lcPushy=0.8, lcSpeedGain=4.0, model="LC2013", # lcKeepRight=0.8 ) vehicles = Vehicles() vehicles.add(veh_id="human", acceleration_controller=(SumoCarFollowingController, {}), routing_controller=(BayBridgeRouter, {}), speed_mode="all_checks", lane_change_mode="no_lat_collide", sumo_car_following_params=sumo_car_following_params, sumo_lc_params=sumo_lc_params, num_vehicles=1400) additional_env_params = {} env_params = EnvParams(additional_params=additional_env_params) traffic_lights = TrafficLights() inflow = InFlows() if use_inflows: # south inflow.add(veh_type="human", edge="183343422", vehsPerHour=528, departLane="0", departSpeed=20) inflow.add(veh_type="human", edge="183343422", vehsPerHour=864, departLane="1", departSpeed=20) inflow.add(veh_type="human", edge="183343422", vehsPerHour=600, departLane="2", departSpeed=20) inflow.add(veh_type="human", edge="393649534", probability=0.1, departLane="0", departSpeed=20) # no data for this # west inflow.add(veh_type="human", edge="11189946", vehsPerHour=1752, departLane="0", departSpeed=20) inflow.add(veh_type="human", edge="11189946", vehsPerHour=2136, departLane="1", departSpeed=20) inflow.add(veh_type="human", edge="11189946", vehsPerHour=576, departLane="2", departSpeed=20) # north inflow.add(veh_type="human", edge="28413687#0", vehsPerHour=2880, departLane="0", departSpeed=20) inflow.add(veh_type="human", edge="28413687#0", vehsPerHour=2328, departLane="1", departSpeed=20) inflow.add(veh_type="human", edge="28413687#0", vehsPerHour=3060, departLane="2", departSpeed=20) inflow.add(veh_type="human", edge="11198593", probability=0.1, departLane="0", departSpeed=20) # no data for this inflow.add(veh_type="human", edge="11197889", probability=0.1, departLane="0", departSpeed=20) # no data for this # midway through bridge inflow.add(veh_type="human", edge="35536683", probability=0.1, departLane="0", departSpeed=20) # no data for this net_params = NetParams(in_flows=inflow, no_internal_links=False) net_params.netfile = NETFILE # download the netfile from AWS if use_traffic_lights: my_url = "https://s3-us-west-1.amazonaws.com/flow.netfiles/" \ "bay_bridge_TL_all_green.net.xml" else: my_url = "https://s3-us-west-1.amazonaws.com/flow.netfiles/" \ "bay_bridge_junction_fix.net.xml" my_file = urllib.request.urlopen(my_url) data_to_write = my_file.read() with open( os.path.join(os.path.dirname(os.path.abspath(__file__)), NETFILE), "wb+") as f: f.write(data_to_write) initial_config = InitialConfig(spacing="uniform", min_gap=15) scenario = BayBridgeScenario(name="bay_bridge", generator_class=BayBridgeGenerator, vehicles=vehicles, traffic_lights=traffic_lights, net_params=net_params, initial_config=initial_config) env = BayBridgeEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def grid_example(sumo_binary=None): inner_length = 300 long_length = 500 short_length = 300 n = 2 m = 3 num_cars_left = 20 num_cars_right = 20 num_cars_top = 20 num_cars_bot = 20 tot_cars = (num_cars_left + num_cars_right) * m \ + (num_cars_top + num_cars_bot) * n grid_array = { "short_length": short_length, "inner_length": inner_length, "long_length": long_length, "row_num": n, "col_num": m, "cars_left": num_cars_left, "cars_right": num_cars_right, "cars_top": num_cars_top, "cars_bot": num_cars_bot } sumo_params = SumoParams(sim_step=0.1, sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary vehicles = Vehicles() vehicles.add(veh_id="human", routing_controller=(GridRouter, {}), num_vehicles=tot_cars) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) tl_logic = TrafficLights(baseline=False) phases = [{ "duration": "31", "minDur": "8", "maxDur": "45", "state": "GGGrrrGGGrrr" }, { "duration": "6", "minDur": "3", "maxDur": "6", "state": "yyyrrryyyrrr" }, { "duration": "31", "minDur": "8", "maxDur": "45", "state": "rrrGGGrrrGGG" }, { "duration": "6", "minDur": "3", "maxDur": "6", "state": "rrryyyrrryyy" }] tl_logic.add("center0", phases=phases, programID=1) tl_logic.add("center1", phases=phases, programID=1) tl_logic.add("center2", tls_type="actuated", phases=phases, programID=1) additional_net_params = { "grid_array": grid_array, "speed_limit": 35, "horizontal_lanes": 1, "vertical_lanes": 1 } net_params = NetParams(no_internal_links=False, additional_params=additional_net_params) initial_config = InitialConfig() scenario = SimpleGridScenario(name="grid-intersection", generator_class=SimpleGridGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config, traffic_lights=tl_logic) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def bay_bridge_bottleneck_example(sumo_binary=None, use_traffic_lights=False): """ Performs a non-RL simulation of the bottleneck portion of the Oakland-San Francisco Bay Bridge. This consists of the toll booth and sections of the road leading up to it. Parameters ---------- sumo_binary: bool, optional specifies whether to use sumo's gui during execution use_traffic_lights: bool, optional whether to activate the traffic lights in the scenario Note ---- Unlike the bay_bridge_example, inflows are always activated here. """ sumo_params = SumoParams(sim_step=0.4, overtake_right=True) if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary sumo_car_following_params = SumoCarFollowingParams(speedDev=0.2) sumo_lc_params = SumoLaneChangeParams(model="LC2013", lcCooperative=0.2, lcSpeedGain=15) vehicles = Vehicles() vehicles.add(veh_id="human", acceleration_controller=(SumoCarFollowingController, {}), routing_controller=(BayBridgeRouter, {}), speed_mode="all_checks", lane_change_mode="no_lat_collide", sumo_car_following_params=sumo_car_following_params, sumo_lc_params=sumo_lc_params, num_vehicles=50) additional_env_params = {} env_params = EnvParams(additional_params=additional_env_params) inflow = InFlows() inflow.add(veh_type="human", edge="393649534", probability=0.2, departLane="random", departSpeed=10) inflow.add(veh_type="human", edge="4757680", probability=0.2, departLane="random", departSpeed=10) inflow.add(veh_type="human", edge="32661316", probability=0.2, departLane="random", departSpeed=10) inflow.add(veh_type="human", edge="90077193#0", vehs_per_hour=2000, departLane="random", departSpeed=10) net_params = NetParams(in_flows=inflow, no_internal_links=False, netfile=NETFILE) # download the netfile from AWS if use_traffic_lights: my_url = "https://s3-us-west-1.amazonaws.com/flow.netfiles/" \ "bay_bridge_TL_all_green.net.xml" else: my_url = "https://s3-us-west-1.amazonaws.com/flow.netfiles/" \ "bay_bridge_junction_fix.net.xml" my_file = urllib.request.urlopen(my_url) data_to_write = my_file.read() with open( os.path.join(os.path.dirname(os.path.abspath(__file__)), NETFILE), "wb+") as f: f.write(data_to_write) initial_config = InitialConfig( spacing="uniform", # "random", min_gap=15) scenario = BayBridgeTollScenario(name="bay_bridge_toll", generator_class=BayBridgeTollGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = BayBridgeEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)
def loop_merge_example(sumo_binary=None): """ Perform a simulation of vehicles on a loop merge. Parameters ---------- sumo_binary: bool, optional specifies whether to use sumo's gui during execution Returns ------- exp: flow.core.SumoExperiment type A non-rl experiment demonstrating the performance of human-driven vehicles on a loop merge. """ sumo_params = SumoParams(sim_step=0.1, emission_path="./data/", sumo_binary="sumo-gui") if sumo_binary is not None: sumo_params.sumo_binary = sumo_binary # note that the vehicles are added sequentially by the generator, # so place the merging vehicles after the vehicles in the ring vehicles = Vehicles() vehicles.add(veh_id="idm", acceleration_controller=(IDMController, {}), lane_change_controller=(SumoLaneChangeController, {}), routing_controller=(ContinuousRouter, {}), num_vehicles=7, speed_mode="no_collide", sumo_car_following_params=SumoCarFollowingParams(minGap=0.0, tau=0.5), sumo_lc_params=SumoLaneChangeParams()) vehicles.add(veh_id="merge-idm", acceleration_controller=(IDMController, {}), lane_change_controller=(SumoLaneChangeController, {}), routing_controller=(ContinuousRouter, {}), num_vehicles=10, speed_mode="no_collide", sumo_car_following_params=SumoCarFollowingParams(minGap=0.01, tau=0.5), sumo_lc_params=SumoLaneChangeParams()) env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) additional_net_params = ADDITIONAL_NET_PARAMS.copy() additional_net_params["ring_radius"] = 50 additional_net_params["inner_lanes"] = 1 additional_net_params["outer_lanes"] = 1 additional_net_params["lane_length"] = 75 net_params = NetParams(no_internal_links=False, additional_params=additional_net_params) initial_config = InitialConfig(x0=50, spacing="uniform", additional_params={"merge_bunching": 0}) scenario = TwoLoopsOneMergingScenario( name="two-loop-one-merging", generator_class=TwoLoopOneMergingGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = AccelEnv(env_params, sumo_params, scenario) return SumoExperiment(env, scenario)