def bay_bridge_example(render=None, use_inflows=False, use_traffic_lights=False): """ Perform a simulation of vehicles on the Oakland-San Francisco Bay Bridge. Parameters ---------- render: bool, optional specifies whether to use the 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 network Returns ------- exp: flow.core.experiment.Experiment A non-rl experiment demonstrating the performance of human-driven vehicles simulated by sumo on the Bay Bridge. """ sim_params = SumoParams(sim_step=0.6, overtake_right=True) if render is not None: sim_params.render = render car_following_params = SumoCarFollowingParams( speedDev=0.2, speed_mode="all_checks", ) lane_change_params = SumoLaneChangeParams( lc_assertive=20, lc_pushy=0.8, lc_speed_gain=4.0, model="LC2013", lane_change_mode="no_lat_collide", # lcKeepRight=0.8 ) vehicles = VehicleParams() vehicles.add( veh_id="human", acceleration_controller=(SimCarFollowingController, {}), routing_controller=(BayBridgeRouter, {}), car_following_params=car_following_params, lane_change_params=lane_change_params, num_vehicles=1400) additional_env_params = {} env_params = EnvParams(additional_params=additional_env_params) traffic_lights = TrafficLightParams() 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(inflows=inflow) net_params.template = TEMPLATE # download the template 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__)), TEMPLATE), "wb+") as f: f.write(data_to_write) initial_config = InitialConfig( spacing="uniform", min_gap=15, edges_distribution=EDGES_DISTRIBUTION.copy()) network = BayBridgeNetwork( name="bay_bridge", vehicles=vehicles, traffic_lights=traffic_lights, net_params=net_params, initial_config=initial_config) env = BayBridgeEnv(env_params, sim_params, network) return Experiment(env)
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 bay_bridge_toll_example(render=None, use_traffic_lights=False): """Perform a simulation of the toll portion of the Bay Bridge. This consists of the toll booth and sections of the road leading up to it. Parameters ---------- render : bool, optional specifies whether to use the gui during execution use_traffic_lights: bool, optional whether to activate the traffic lights in the network Note ---- Unlike the bay_bridge_example, inflows are always activated here. """ sim_params = SumoParams(sim_step=0.4, overtake_right=True) if render is not None: sim_params.render = render car_following_params = SumoCarFollowingParams( speedDev=0.2, speed_mode="all_checks", ) lane_change_params = SumoLaneChangeParams( model="LC2013", lcCooperative=0.2, lcSpeedGain=15, lane_change_mode="no_lat_collide", ) vehicles = VehicleParams() vehicles.add(veh_id="human", acceleration_controller=(SimCarFollowingController, {}), routing_controller=(BayBridgeRouter, {}), car_following_params=car_following_params, lane_change_params=lane_change_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(inflows=inflow, template=TEMPLATE) # download the template 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__)), TEMPLATE), "wb+") as f: f.write(data_to_write) initial_config = InitialConfig( spacing="uniform", # "random", min_gap=15, edges_distribution=EDGES_DISTRIBUTION.copy()) network = BayBridgeTollNetwork(name="bay_bridge_toll", vehicles=vehicles, net_params=net_params, initial_config=initial_config) env = BayBridgeEnv(env_params, sim_params, network) return Experiment(env)
def bay_bridge_example(sumo_binary=None, use_inflows=False, use_traffic_lights=False): """ Performs a simulation of human-driven vehicle 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)