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 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 highway_exp_setup(sumo_params=None, vehicles=None, env_params=None, net_params=None, initial_config=None, traffic_lights=None): """ Creates an environment and scenario pair for highway test experiments. Parameters ---------- sumo_params: SumoParams type sumo-related configuration parameters, defaults to a time step of 0.1s and no sumo-imposed failsafe on human or rl vehicles vehicles: Vehicles type vehicles to be placed in the network, default is one vehicles with an IDM acceleration controller and ContinuousRouter routing controller. env_params: EnvParams type environment-specific parameters, defaults to a environment with no failsafes, where other parameters do not matter for non-rl runs net_params: NetParams type network-specific configuration parameters, defaults to a single lane highway of length 100 m initial_config: InitialConfig type specifies starting positions of vehicles, defaults to evenly distributed vehicles across the length of the network traffic_lights: TrafficLights type traffic light signals, defaults to no traffic lights in the network """ logging.basicConfig(level=logging.WARNING) if sumo_params is None: # set default sumo_params configuration sumo_params = SumoParams(sim_step=0.1, sumo_binary="sumo") if vehicles is None: # set default vehicles configuration vehicles = Vehicles() vehicles.add( veh_id="idm", acceleration_controller=(IDMController, {}), speed_mode="aggressive", routing_controller=(ContinuousRouter, {}), num_vehicles=1) if env_params is None: # set default env_params configuration additional_env_params = { "target_velocity": 8, "max_accel": 1, "max_decel": 1, "num_steps": 500 } env_params = EnvParams(additional_params=additional_env_params) if net_params is None: # set default net_params configuration additional_net_params = { "length": 100, "lanes": 1, "speed_limit": 30, "resolution": 40 } net_params = NetParams(additional_params=additional_net_params) if initial_config is None: # set default initial_config configuration initial_config = InitialConfig() if traffic_lights is None: # set default to no traffic lights traffic_lights = TrafficLights() # create the scenario scenario = HighwayScenario( name="RingRoadTest", generator_class=HighwayGenerator, vehicles=vehicles, net_params=net_params, initial_config=initial_config, traffic_lights=traffic_lights) # create the environment env = AccelEnv( env_params=env_params, sumo_params=sumo_params, scenario=scenario) return env, scenario