Exemple #1
0
    # name of the flow environment the experiment is running on
    env_name='PO_TrafficLightGridEnv',

    # name of the scenario class the experiment is running on
    scenario='SimpleGridScenario',

    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        sim_step=1,
        render=False,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        additional_params=additional_env_params,
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # scenario's documentation or ADDITIONAL_NET_PARAMS component)
    net=net_params,

    # vehicles to be placed in the network at the start of a rollout (see
    # flow.core.vehicles.Vehicles)
    veh=vehicles,

    # parameters specifying the positioning of vehicles upon initialization/
    # reset (see flow.core.params.InitialConfig)
    initial=initial_config,
)
Exemple #2
0
    # simulator that is used by the experiment
    simulator='traci',

    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        sim_step=0.5,
        render=False,
        print_warnings=False,
        restart_instance=True,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        warmup_steps=40,
        sims_per_step=1,
        horizon=HORIZON,
        additional_params=additional_env_params,
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # network's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        inflows=inflow,
        additional_params=additional_net_params,
    ),

    # 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/
Exemple #3
0
    # 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=True,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        warmup_steps=750,
        clip_actions=False,
        additional_params={
            "sort_vehicles": False,
            "max_accel": 1,
            "max_decel": 1,
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # network's documentation or ADDITIONAL_NET_PARAMS component)
    net=net_params,

    # 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)
Exemple #4
0
def run_task(*_):
    """Implement the run_task method needed to run experiments with rllab."""
    sim_params = AimsunParams(sim_step=0.5, render=False, seed=0)

    vehicles = VehicleParams()
    vehicles.add(veh_id="rl",
                 acceleration_controller=(RLController, {}),
                 routing_controller=(ContinuousRouter, {}),
                 num_vehicles=1)
    vehicles.add(veh_id="idm",
                 acceleration_controller=(IDMController, {}),
                 routing_controller=(ContinuousRouter, {}),
                 num_vehicles=21)

    additional_env_params = {
        "target_velocity": 8,
        "ring_length": None,
        "max_accel": 1,
        "max_decel": 1
    }
    env_params = EnvParams(horizon=HORIZON,
                           additional_params=additional_env_params,
                           warmup_steps=1500)

    additional_net_params = {
        "length": 230,
        "lanes": 1,
        "speed_limit": 30,
        "resolution": 40
    }
    net_params = NetParams(additional_params=additional_net_params)

    initial_config = InitialConfig(spacing="uniform", bunching=50)

    print("XXX name", exp_tag)
    scenario = LoopScenario(exp_tag,
                            vehicles,
                            net_params,
                            initial_config=initial_config)

    env_name = "WaveAttenuationPOEnv"
    simulator = 'aimsun'
    pass_params = (env_name, sim_params, vehicles, env_params, net_params,
                   initial_config, scenario, simulator)

    env = GymEnv(env_name, record_video=False, register_params=pass_params)
    horizon = env.horizon
    env = normalize(env)

    policy = GaussianMLPPolicy(
        env_spec=env.spec,
        hidden_sizes=(3, 3),
    )

    baseline = LinearFeatureBaseline(env_spec=env.spec)

    algo = TRPO(
        env=env,
        policy=policy,
        baseline=baseline,
        batch_size=15000,
        max_path_length=horizon,
        n_itr=500,
        # whole_paths=True,
        discount=0.999,
        # step_size=v["step_size"],
    )
    algo.train(),
Exemple #5
0
def variable_lanes_exp_setup(sim_params=None,
                             vehicles=None,
                             env_params=None,
                             net_params=None,
                             initial_config=None,
                             traffic_lights=None):
    """
    Create an environment and network variable-lane ring road.

    Each edge in this network can have a different number of lanes. Used for
    test purposes.

    Parameters
    ----------
    sim_params : flow.core.params.SumoParams
        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 : flow.core.params.EnvParams
        environment-specific parameters, defaults to a environment with no
        failsafes, where other parameters do not matter for non-rl runs
    net_params : flow.core.params.NetParams
        network-specific configuration parameters, defaults to a figure eight
        with a 30 m radius
    initial_config : flow.core.params.InitialConfig
        specifies starting positions of vehicles, defaults to evenly
        distributed vehicles across the length of the network
    traffic_lights: flow.core.params.TrafficLightParams
        traffic light signals, defaults to no traffic lights in the network
    """
    logging.basicConfig(level=logging.WARNING)

    if sim_params is None:
        # set default sim_params configuration
        sim_params = SumoParams(sim_step=0.1, render=False)

    if vehicles is None:
        # set default vehicles configuration
        vehicles = VehicleParams()
        vehicles.add(veh_id="idm",
                     acceleration_controller=(IDMController, {}),
                     car_following_params=SumoCarFollowingParams(
                         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,
            "sort_vehicles": False
        }
        env_params = EnvParams(additional_params=additional_env_params)

    if net_params is None:
        # set default net_params configuration
        additional_net_params = {
            "length": 230,
            "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 = TrafficLightParams()

    flow_params = dict(
        # name of the experiment
        exp_tag="VariableLaneRingRoadTest",

        # name of the flow environment the experiment is running on
        env_name=AccelEnv,

        # name of the network class the experiment is running on
        network=VariableLanesNetwork,

        # simulator that is used by the experiment
        simulator='traci',

        # sumo-related parameters (see flow.core.params.SumoParams)
        sim=sim_params,

        # environment related parameters (see flow.core.params.EnvParams)
        env=env_params,
        # network-related parameters (see flow.core.params.NetParams and the
        # network's documentation or ADDITIONAL_NET_PARAMS component)
        net=net_params,

        # 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=initial_config,

        # traffic lights to be introduced to specific nodes (see
        # flow.core.params.TrafficLightParams)
        tls=traffic_lights,
    )

    # create the network
    network = VariableLanesNetwork(name="VariableLaneRingRoadTest",
                                   vehicles=vehicles,
                                   net_params=net_params,
                                   initial_config=initial_config,
                                   traffic_lights=traffic_lights)

    # create the environment
    env = AccelEnv(env_params=env_params,
                   sim_params=sim_params,
                   network=network)

    # reset the environment
    env.reset()

    return env, network, flow_params
def para_produce_rl(HORIZON=3000):
    # Create default environment parameters
    env_params = EnvParams()

    # Vehicle definition
    vehicles = VehicleParams()
    num_vehicles = 1
    vehicles.add(
        veh_id="human",
        routing_controller=(GridRouter, {}),
        lane_change_controller=(SimLaneChangeController, {}),
        car_following_params=SumoCarFollowingParams(
            min_gap=2.5,
            decel=7.5,  # avoid collisions at emergency stops
        ),
        lane_change_params=SumoLaneChangeParams(
                lane_change_mode=1621,
            ),
        num_vehicles=num_vehicles)

    # whether to allow turns at intersections
    ALLOW_TURNS = False
    
    # initialize traffic lights, used when you want define your own traffic lights
    tl_logic = TrafficLightParams(baseline=False) # To see static traffic lights in action, the `TrafficLightParams` object should be instantiated with `baseline=False`

    # when use off_ramp_grid.net.xml file, you should use a phase state example as "GGGgrrrrGGGgrrrr"
    # when use off_ramp_grid_turn.net.xml file, you should use a phase state example as "GGGggrrrrrGGGggrrrrr"
    if ALLOW_TURNS:
        phases = [{
            "duration": "31",
            "minDur": "8",
            "maxDur": "45",
            # for actuated traffic lights, you can add these optional values below
            # "maxGap": int, describes the maximum time gap between successive vehicle sthat will cause the current phase to be prolonged
            # "detectorGap": int, determines the time distance between the (automatically generated) detector and the stop line in seconds
            # "showDetectors": bool, toggles whether or not detectors are shown in sumo-gui
            "state": "GGGggrrrrrGGGggrrrrr"
        }, {
            "duration": "6",
            "minDur": "3",
            "maxDur": "6",
            "state": "yyyyyrrrrryyyyyrrrrr"
        }, {
            "duration": "31",
            "minDur": "8",
            "maxDur": "45",
            "state": "rrrrrGGGggrrrrrGGGgg"
        }, {
            "duration": "6",
            "minDur": "3",
            "maxDur": "6",
            "state": "rrrrryyyyyrrrrryyyyy"
        }]
        tl_logic.add("center0", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
        tl_logic.add("center1", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
        tl_logic.add("center2", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
        tl_logic.add("center3", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
    else:
        phases = [{
            "duration": "31",
            "minDur": "8",
            "maxDur": "45",
            # for actuated traffic lights, you can add these optional values below
            # "maxGap": int, describes the maximum time gap between successive vehicle sthat will cause the current phase to be prolonged
            # "detectorGap": int, determines the time distance between the (automatically generated) detector and the stop line in seconds
            # "showDetectors": bool, toggles whether or not detectors are shown in sumo-gui
            "state": "GGGgrrrrGGGgrrrr"
        }, {
            "duration": "6",
            "minDur": "3",
            "maxDur": "6",
            "state": "yyyyrrrryyyyrrrr"
        }, {
            "duration": "31",
            "minDur": "8",
            "maxDur": "45",
            "state": "rrrrGGGgrrrrGGGg"
        }, {
            "duration": "6",
            "minDur": "3",
            "maxDur": "6",
            "state": "rrrryyyyrrrryyyy"
        }]

        # THIS IS A BUG THAT I DON'T KNOW WHY IT HAPPENS!!!!!!
        phase0 = [{
            "duration": "31",
            "minDur": "8",
            "maxDur": "45",
            "state": "GGrrGGrrGGrrGGrr"
        }, {
            "duration": "6",
            "minDur": "3",
            "maxDur": "6",
            "state": "yyrryyrryyrryyrr"
        }, {
            "duration": "31",
            "minDur": "8",
            "maxDur": "45",
            "state": "rrGGrrGGrrGGrrGG"
        }, {
            "duration": "6",
            "minDur": "3",
            "maxDur": "6",
            "state": "rryyrryyrryyrryy"
        }]

        tl_logic.add("center0", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
        tl_logic.add("center1", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
        tl_logic.add("center2", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
        tl_logic.add("center3", phases=phases, programID=1, detectorGap=1,tls_type="actuated")
    
    flow_params = dict(
    exp_tag='offramp_multiagent_inflow_1.0_speed_20',
    env_name=MultiTrafficLightGridPOEnv,
    network=offRampGrid,
    simulator='traci',
    sim=SumoParams(
        sim_step=0.1,
        render=False,
        #emission_path='./data',
        restart_instance=True,
    ),
    env=EnvParams(
        horizon=3000, additional_params=ADDITIONAL_ENV_PARAMS.copy(),
    ),
    net=net_params,
    veh=vehicles,
    initial=initial_config,
    # used when you define your own traffic lights
    #tls=tl_logic,
    )
    #flow_params['env'].horizon = HORIZON
    return flow_params
import numpy as np
import collections

# create some default parameters parameters
HORIZON = 3000
# HORIZON = 1000
# number of rollouts per training iteration
N_ROLLOUTS = 12
# number of parallel workers
N_CPUS = 2

env_params = EnvParams(horizon=HORIZON,
                       sims_per_step=1,
                       warmup_steps=0,
                       additional_params={
                           "max_accel": 3,
                           "max_decel": -2,
                           "target_velocity": 7,
                           "lane_change_duration": 4,
                           "num_rl": 1,
                       })
initial_config = InitialConfig(edges_distribution=['highway_0'])

vehicles = VehicleParams()
vehicles.add(
    veh_id="human",
    acceleration_controller=(IDMController, {
        "noise": 0.2
    }),
    # lane_change_controller=(StaticLaneChanger, {}),
    car_following_params=SumoCarFollowingParams(
        max_speed=10,
Exemple #8
0
    simulator='traci',

    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        restart_instance=True,
        sim_step=SIM_STEP,
        render=False,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        additional_params={
            "target_velocity": V_TARGET,
            "switch_time": SWITCH_TIME,
            "num_observed": CARS_OBSERVED,
            "discrete": DISCRETE,
            "tl_type": "actuated",
            "num_local_edges": LOCAL_EDGES,
            "num_local_lights": LOCAL_LIGHTS,
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # network's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        inflows=inflow,
        additional_params={
            "speed_limit": V_TARGET,  # inherited from grid0 benchmark
            "grid_array": {
                "short_length": SHORT_LENGTH,
                "inner_length": INNER_LENGTH,
Exemple #9
0
def run_task(_):
    """Implement the run_task method needed to run experiments with rllab."""
    sumo_params = SumoParams(sumo_binary="sumo-gui",
                             sim_step=0.2,
                             restart_instance=True)

    # RL vehicles constitute 5% of the total number of vehicles
    vehicles = Vehicles()
    vehicles.add(veh_id="human",
                 acceleration_controller=(IDMController, {
                     "noise": 0.2
                 }),
                 speed_mode="no_collide",
                 num_vehicles=5)
    vehicles.add(veh_id="rl",
                 acceleration_controller=(RLController, {}),
                 speed_mode="no_collide",
                 num_vehicles=0)

    # Vehicles are introduced from both sides of merge, with RL vehicles
    # entering from the highway portion as well
    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="rl",
               edge="inflow_highway",
               vehs_per_hour=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_env_params = {
        "target_velocity": 25,
        "num_rl": NUM_RL,
        "max_accel": 1.5,
        "max_decel": 1.5
    }
    env_params = EnvParams(horizon=HORIZON,
                           sims_per_step=5,
                           warmup_steps=0,
                           additional_params=additional_env_params)

    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",
                                   lanes_distribution=float("inf"))

    scenario = MergeScenario(name="merge-rl",
                             generator_class=MergeGenerator,
                             vehicles=vehicles,
                             net_params=net_params,
                             initial_config=initial_config)

    env_name = "WaveAttenuationMergePOEnv"
    pass_params = (env_name, sumo_params, vehicles, env_params, net_params,
                   initial_config, scenario)

    env = GymEnv(env_name, record_video=False, register_params=pass_params)
    env = normalize(env)

    policy = GaussianMLPPolicy(
        env_spec=env.spec,
        hidden_sizes=(32, 32, 32),
    )

    baseline = LinearFeatureBaseline(env_spec=env.spec)

    algo = TRPO(
        env=env,
        policy=policy,
        baseline=baseline,
        batch_size=HORIZON * N_ROLLOUTS,
        max_path_length=HORIZON,
        n_itr=1000,
        # whole_paths=True,
        discount=0.999,
    )
    algo.train(),
Exemple #10
0
additional_env_params = {
    "target_velocity": 40,
    "disable_tb": True,
    "disable_ramp_metering": True,
    "controlled_segments": controlled_segments,
    "symmetric": False,
    "observed_segments": num_observed_segments,
    "reset_inflow": False,
    "lane_change_duration": 5,
    "max_accel": 3,
    "max_decel": 3,
    "inflow_range": [1000, 2000]
}
env_params = EnvParams(
    additional_params=additional_env_params,
    warmup_steps=40,
    sims_per_step=2,
    horizon=horizon)

flow_rate = 1500 * SCALING
print('flow rate is ', flow_rate)
env_name = "DesiredVelocityEnv"

inflow = InFlows()
inflow.add(
    veh_type="human",
    edge="1",
    vehs_per_hour=flow_rate * (1 - AV_FRAC),
    departLane="random",
    departSpeed=10)
inflow.add(
    sim=SumoParams(
        restart_instance=True,
        sim_step=1,
        render=False,
        emission_path='~/flow/data',
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=200,
        additional_params={
            "target_velocity": 11,
            "switch_time": 4,
            "yellow_phase_duration": 4,
            "num_observed": 2,
            "discrete": False,
            "tl_type": "actuated",
            "num_local_edges": 4,
            "num_local_lights": 4,
            "benchmark":
            "PressureLightGridEnv",  # This should be the string name of the benchmark class
            "benchmark_params": "BenchmarkParams"
        }),

    # network-related parameters (see flow.core.params.NetParams and the
    # network's documentation or ADDITIONAL_NET_PARAMS component)
    net=net_params,

    # vehicles to be placed in the network at the start of a rollout (see
    # flow.core.params.VehicleParams)
    veh=vehicles,
Exemple #12
0
    env_name="AccelEnv",

    # name of the scenario class the experiment is running on
    scenario="Figure8Scenario",

    # sumo-related parameters (see flow.core.params.SumoParams)
    sumo=SumoParams(
        sim_step=0.1,
        render=False,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        additional_params={
            "target_velocity": 20,
            "max_accel": 3,
            "max_decel": 3,
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # scenario's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        no_internal_links=False,
        additional_params=deepcopy(ADDITIONAL_NET_PARAMS),
    ),

    # vehicles to be placed in the network at the start of a rollout (see
    # flow.core.vehicles.Vehicles)
    veh=vehicles,
def make_flow_params(n_rows, n_columns, edge_inflow):
    """
    Generate the flow params for the experiment.

    :param n_rows:
    :param n_columns:
    :param edge_inflow:
    :return:
    """
    # we place a sufficient number of vehicles to ensure they confirm with the
    # total number specified above. We also use a "right_of_way" speed mode to
    # support traffic light compliance
    vehicles = VehicleParams()
    num_vehicles = (N_LEFT + N_RIGHT) * n_columns + (N_BOTTOM + N_TOP) * n_rows
    vehicles.add(
        veh_id="human",
        acceleration_controller=(SimCarFollowingController, {}),
        car_following_params=SumoCarFollowingParams(
            min_gap=2.5,
            max_speed=V_ENTER,
            decel=7.5,  # avoid collisions at emergency stops
            speed_mode="right_of_way",
        ),
        routing_controller=(GridRouter, {}),
        num_vehicles=num_vehicles)

    # inflows of vehicles are place on all outer edges (listed here)
    outer_edges = []
    outer_edges += ["left{}_{}".format(n_rows, i) for i in range(n_columns)]
    outer_edges += ["right0_{}".format(i) for i in range(n_rows)]
    outer_edges += ["bot{}_0".format(i) for i in range(n_rows)]
    outer_edges += ["top{}_{}".format(i, n_columns) for i in range(n_rows)]

    # equal inflows for each edge (as dictate by the EDGE_INFLOW constant)
    inflow = InFlows()
    for edge in outer_edges:
        inflow.add(veh_type="human",
                   edge=edge,
                   vehs_per_hour=edge_inflow,
                   departLane="free",
                   departSpeed=V_ENTER)

    flow_params = dict(
        # name of the experiment
        exp_tag="grid_0_{}x{}_i{}_multiagent".format(n_rows, n_columns,
                                                     edge_inflow),

        # name of the flow environment the experiment is running on
        env_name='MultiTrafficLightGridPOEnv',

        # name of the scenario class the experiment is running on
        scenario="SimpleGridScenario",

        # simulator that is used by the experiment
        simulator='traci',

        # sumo-related parameters (see flow.core.params.SumoParams)
        sim=SumoParams(
            restart_instance=True,
            sim_step=1,
            render=False,
        ),

        # environment related parameters (see flow.core.params.EnvParams)
        env=EnvParams(
            horizon=HORIZON,
            additional_params={
                "target_velocity": 50,
                "switch_time": 3,
                "num_observed": 2,
                "discrete": False,
                "tl_type": "actuated",
                "num_local_edges": 4,
                "num_local_lights": 4,
            },
        ),

        # network-related parameters (see flow.core.params.NetParams and the
        # scenario's documentation or ADDITIONAL_NET_PARAMS component)
        net=NetParams(
            inflows=inflow,
            no_internal_links=False,
            additional_params={
                "speed_limit": V_ENTER + 5,  # inherited from grid0 benchmark
                "grid_array": {
                    "short_length": SHORT_LENGTH,
                    "inner_length": INNER_LENGTH,
                    "long_length": LONG_LENGTH,
                    "row_num": n_rows,
                    "col_num": n_columns,
                    "cars_left": N_LEFT,
                    "cars_right": N_RIGHT,
                    "cars_top": N_TOP,
                    "cars_bot": N_BOTTOM,
                },
                "horizontal_lanes": 1,
                "vertical_lanes": 1,
            },
        ),

        # 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
        # or reset (see flow.core.params.InitialConfig)
        initial=InitialConfig(
            spacing='custom',
            shuffle=True,
        ),
    )
    return flow_params
    # 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,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        warmup_steps=750,
        additional_params={
            'max_accel': 1,
            'max_decel': 1,
            'ring_length': [230, 230],
            'target_velocity': 4
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # scenario's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(additional_params={
        'length': 230,
        'lanes': 1,
        'speed_limit': 30,
        'resolution': 40,
        'num_rings': NUM_RINGS
    }, ),
Exemple #15
0
    # simulator that is used by the experiment
    simulator='traci',

    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        sim_step=0.1,
        render=True,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        warmup_steps=750,
        clip_actions=False,
        additional_params={
            "max_accel": 1,
            "max_decel": 1,
            "ring_length": [220, 270],
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # network's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(additional_params={
        "length": 260,
        "lanes": 1,
        "speed_limit": 30,
        "resolution": 40,
    }, ),

    # vehicles to be placed in the network at the start of a rollout (see
    #    additional_params=additional_env_params,
    #),
    sim=SumoParams(
        restart_instance=True,
        sim_step=0.5,
        render=False,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        sims_per_step=1,
        warmup_steps=0,
        additional_params={
            "max_accel": 2.6,
            "max_decel": 4.5,
            "target_velocity": 30,
            "num_rl": NUM_RL,
            "eta1": ETA_1,
            "eta2": ETA_2,
        },
    ),
    net=NetParams(
        inflows=inflow,
        additional_params=additional_net_params,
    ),
    veh=vehicles,
    initial=InitialConfig(),
)

# SET UP EXPERIMENT
        no_step_log=False,  # this disables log writing?
        sim_step=0.5,  # Daniel updated from osm.sumocfg
        lateral_resolution=0.25,  # determines lateral discretization of lanes
        render=
        False,  #True,             # False for training, True for debugging
        restart_instance=True,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        sims_per_step=2,  #5,
        warmup_steps=0,
        additional_params={
            "max_accel": 1.5,
            "max_decel": 1.5,
            "target_velocity": 30,
            "num_rl":
            NUM_RL,  # used by WaveAttenuationMergePOEnv e.g. to fix action dimension
            "ignore_edges": ["59440544#0"],
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # scenario's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        inflows=inflow,
        #no_internal_links=False,
        additional_params=additional_net_params,
        template={
            "net": scenario_road_data["net"],  # see above
Exemple #18
0
def get_flow_params(fixed_boundary,
                    stopping_penalty,
                    acceleration_penalty,
                    evaluate=False,
                    multiagent=False,
                    imitation=False):
    """Return the flow-specific parameters of the single lane highway network.

    Parameters
    ----------
    fixed_boundary : bool
        specifies whether the boundary conditions update in between resets
    stopping_penalty : bool
        whether to include a stopping penalty
    acceleration_penalty : bool
        whether to include a regularizing penalty for accelerations by the AVs
    evaluate : bool
        whether to compute the evaluation reward
    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
    imitation : bool
        whether to use the imitation environment

    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)
    """
    # steps to run before the agent is allowed to take control (set to lower
    # value during testing)
    warmup_steps = 50 if os.environ.get("TEST_FLAG") else 500

    additional_net_params = ADDITIONAL_NET_PARAMS.copy()
    additional_net_params.update({
        # length of the highway
        "length": 2500,
        # number of lanes
        "lanes": 1,
        # speed limit for all edges
        "speed_limit": 30,
        # number of edges to divide the highway into
        "num_edges": 2,
        # whether to include a ghost edge of length 500m. This edge is provided
        # a different speed limit.
        "use_ghost_edge": True,
        # speed limit for the ghost edge
        "ghost_speed_limit": END_SPEED,
        # length of the cell imposing a boundary
        "boundary_cell_length": 300,
    })

    vehicles = VehicleParams()
    inflows = InFlows()

    # human vehicles
    vehicles.add(
        "human",
        num_vehicles=0,
        acceleration_controller=(IDMController, {
            "a": 1.3,
            "b": 2.0,
            "noise": 0.3 if INCLUDE_NOISE else 0.0
        }),
        car_following_params=SumoCarFollowingParams(min_gap=0.5),
        lane_change_params=SumoLaneChangeParams(
            model="SL2015",
            lc_sublane=2.0,
        ),
    )

    inflows.add(veh_type="human",
                edge="highway_0",
                vehs_per_hour=int(TRAFFIC_FLOW * (1 - PENETRATION_RATE)),
                depart_lane="free",
                depart_speed=TRAFFIC_SPEED,
                name="idm_highway_inflow")

    # automated vehicles
    vehicles.add(
        "rl",
        num_vehicles=0,
        acceleration_controller=(RLController, {}),
    )

    inflows.add(veh_type="rl",
                edge="highway_0",
                vehs_per_hour=int(TRAFFIC_FLOW * PENETRATION_RATE),
                depart_lane="free",
                depart_speed=TRAFFIC_SPEED,
                name="rl_highway_inflow")

    # SET UP THE FLOW PARAMETERS

    if multiagent:
        if imitation:
            env_name = None  # to be added later
        else:
            env_name = AVOpenMultiAgentEnv
    else:
        if imitation:
            env_name = AVOpenImitationEnv
        else:
            env_name = AVOpenEnv

    return dict(
        # name of the experiment
        exp_tag="highway",

        # name of the flow environment the experiment is running on
        env_name=env_name,

        # name of the network class the experiment is running on
        network=HighwayNetwork,

        # simulator that is used by the experiment
        simulator="traci",

        # environment related parameters (see flow.core.params.EnvParams)
        env=EnvParams(evaluate=evaluate,
                      horizon=HORIZON,
                      warmup_steps=warmup_steps,
                      sims_per_step=3,
                      additional_params={
                          "max_accel": 0.5,
                          "max_decel": 0.5,
                          "target_velocity": 10,
                          "stopping_penalty": stopping_penalty,
                          "acceleration_penalty": acceleration_penalty,
                          "inflows": None if fixed_boundary else INFLOWS,
                          "rl_penetration": PENETRATION_RATE,
                          "num_rl": 10,
                          "control_range": [500, 2300],
                          "expert_model": (IDMController, {
                              "a": 1.3,
                              "b": 2.0,
                          }),
                      }),

        # sumo-related parameters (see flow.core.params.SumoParams)
        sim=SumoParams(
            sim_step=0.4,
            render=False,
            restart_instance=True,
            use_ballistic=True,
        ),

        # network-related parameters (see flow.core.params.NetParams and the
        # network's documentation or ADDITIONAL_NET_PARAMS component)
        net=NetParams(inflows=inflows,
                      additional_params=additional_net_params),

        # 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(),
    )
Exemple #19
0
def para_produce_rl(HORIZON=3000, NUM_AUTOMATED=4):

    # time horizon of a single rollout
    HORIZON = 3000
    # 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

    # We evenly distribute the automated vehicles in the network.
    num_human = 22 - NUM_AUTOMATED
    humans_remaining = num_human

    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, {}),
                     num_vehicles=1)

        # Add a fraction of the remaining human vehicles.
        vehicles_to_add = round(humans_remaining / (NUM_AUTOMATED - i))
        humans_remaining -= vehicles_to_add
        vehicles.add(veh_id="human_{}".format(i),
                     acceleration_controller=(IDMController, {
                         "noise": 0.2
                     }),
                     car_following_params=SumoCarFollowingParams(min_gap=0),
                     routing_controller=(ContinuousRouter, {}),
                     num_vehicles=vehicles_to_add)

        flow_params = dict(
            # name of the experiment
            exp_tag="multiagent_ring",

            # name of the flow environment the experiment is running on
            env_name=MultiAgentWaveAttenuationPOEnv,

            # name of the network class the experiment is running on
            network=RingNetwork,

            # 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,
                warmup_steps=750,
                clip_actions=False,
                additional_params={
                    "max_accel": 1,
                    "max_decel": 1,
                    "ring_length": [220, 270],
                },
            ),

            # network-related parameters (see flow.core.params.NetParams and the
            # network's documentation or ADDITIONAL_NET_PARAMS component)
            net=NetParams(additional_params={
                "length": 260,
                "lanes": 1,
                "speed_limit": 30,
                "resolution": 40,
            }, ),

            # 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
Exemple #20
0
sim_params = SumoParams(sim_step=0.1, render=False)

# EnvParams specifies environment and experiment-specific parameters that either affect the training process or the dynamics of various components within the network. For the environment WaveAttenuationPOEnv, these parameters are used to dictate bounds on the accelerations of the autonomous vehicles, as well as the range of ring lengths (and accordingly network densities) the agent is trained on.

#Finally, it is important to specify here the horizon of the experiment, which is the duration of one episode (during which the RL-agent acquire data).

from flow.core.params import EnvParams

env_params = EnvParams(
    # length of one rollout
    horizon=HORIZON,
    warmup_steps=750,
    clip_actions=False,
    additional_params={
        # maximum acceleration of autonomous vehicles
        "max_accel": 1,
        # maximum deceleration of autonomous vehicles
        "max_decel": 1,
        # bounds on the ranges of ring road lengths the autonomous vehicle
        # is trained on
        "ring_length": [490, 520],
    },
)

#Now, we have to specify our Gym Environment and the algorithm that our RL agents will use. Similar to the network, we choose to use on of Flow's builtin environments, a list of which is provided by the script below.

import flow.envs as flowenvs

print(flowenvs.__all__)

#We will use the environment "WaveAttenuationPOEnv", which is used to train autonomous vehicles to attenuate the formation and propagation of waves in a partially observable variable density ring road. To create the Gym Environment, the only necessary parameters are the environment name plus the previously defined variables. These are defined as follows:
def bottleneck_example(flow_rate, horizon, restart_instance=False,
                       render=None):
    """
    Perform a simulation of vehicles on a bottleneck.

    Parameters
    ----------
    flow_rate : float
        total inflow rate of vehicles into the bottleneck
    horizon : int
        time horizon
    restart_instance: bool, optional
        whether to restart the instance upon reset
    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 bottleneck.
    """
    if render is None:
        render = False

    sim_params = AimsunParams(
        sim_step=0.5,
        render=render,
        restart_instance=restart_instance)

    vehicles = VehicleParams()

    vehicles.add(
        veh_id="human",
        num_vehicles=1)

    additional_env_params = {
        "target_velocity": 40,
        "max_accel": 1,
        "max_decel": 1,
        "lane_change_duration": 5,
        "add_rl_if_exit": False,
        "disable_tb": DISABLE_TB,
        "disable_ramp_metering": DISABLE_RAMP_METER
    }
    env_params = EnvParams(
        horizon=horizon, additional_params=additional_env_params)

    inflow = InFlows()
    inflow.add(
        veh_type="human",
        edge="1",
        vehsPerHour=flow_rate,
        departLane="random",
        departSpeed=10)

    traffic_lights = TrafficLightParams()
    if not DISABLE_TB:
        traffic_lights.add(node_id="2")
    if not DISABLE_RAMP_METER:
        traffic_lights.add(node_id="3")

    additional_net_params = {"scaling": SCALING, "speed_limit": 30/3.6}
    net_params = NetParams(
        inflows=inflow,
        no_internal_links=False,
        additional_params=additional_net_params)

    initial_config = InitialConfig(
        spacing="random",
        min_gap=5,
        lanes_distribution=float("inf"),
        edges_distribution=["2", "3", "4", "5"])

    scenario = BottleneckScenario(
        name="bay_bridge_toll",
        vehicles=vehicles,
        net_params=net_params,
        initial_config=initial_config,
        traffic_lights=traffic_lights)

    env = BottleneckEnv(env_params, sim_params, scenario, simulator='aimsun')

    return Experiment(env)
    env_name='AccelEnv',

    # name of the scenario class the experiment is running on
    scenario='Figure8Scenario',

    # sumo-related parameters (see flow.core.params.SumoParams)
    sumo=SumoParams(
        sim_step=0.1,
        render=False,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        additional_params={
            'target_velocity': 20,
            'max_accel': 3,
            'max_decel': 3,
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # scenario's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        no_internal_links=False,
        additional_params=ADDITIONAL_NET_PARAMS,
    ),

    # vehicles to be placed in the network at the start of a rollout (see
    # flow.core.vehicles.Vehicles)
    veh=vehicles,
Exemple #23
0
def traffic_light_grid_mxn_exp_setup(row_num=1,
                                     col_num=1,
                                     sim_params=None,
                                     vehicles=None,
                                     env_params=None,
                                     net_params=None,
                                     initial_config=None,
                                     tl_logic=None):
    """
    Create an environment and network pair for traffic light grid 1x1 test experiments.

    Parameters
    ----------
    row_num: int, optional
        number of horizontal rows of edges in the traffic light grid network
    col_num: int, optional
        number of vertical columns of edges in the traffic light grid network
    sim_params : flow.core.params.SumoParams
        sumo-related configuration parameters, defaults to a time step of 1s
        and no sumo-imposed failsafe on human or rl vehicles
    vehicles : Vehicles type
        vehicles to be placed in the network, default is 5 vehicles per edge
        for a total of 20 vehicles with an IDM acceleration controller and
        GridRouter routing controller.
    env_params : flow.core.params.EnvParams
        environment-specific parameters, defaults to a environment with
        failsafes, where other parameters do not matter for non-rl runs
    net_params : flow.core.params.NetParams
        network-specific configuration parameters, defaults to a 1x1 traffic
        light grid with traffic lights on
    initial_config : flow.core.params.InitialConfig
        specifies starting positions of vehicles, defaults to evenly
        distributed vehicles across the length of the network
    tl_logic: flow.core.params.TrafficLightParams
        specifies logic of any traffic lights added to the system
    """
    logging.basicConfig(level=logging.WARNING)

    if tl_logic is None:
        tl_logic = TrafficLightParams(baseline=False)

    if sim_params is None:
        # set default sim_params configuration
        sim_params = SumoParams(sim_step=1, render=False)

    if vehicles is None:
        vehicles_per_edge = 5
        num_edges = 2 * (row_num + col_num)
        total_vehicles = num_edges * vehicles_per_edge
        vehicles = VehicleParams()
        vehicles.add(veh_id="idm",
                     acceleration_controller=(IDMController, {}),
                     car_following_params=SumoCarFollowingParams(min_gap=2.5,
                                                                 tau=1.1,
                                                                 max_speed=30),
                     routing_controller=(GridRouter, {}),
                     num_vehicles=total_vehicles)

    if env_params is None:
        # set default env_params configuration
        additional_env_params = {
            "target_velocity": 50,
            "switch_time": 3.0,
            "tl_type": "controlled",
            "discrete": False
        }

        env_params = EnvParams(additional_params=additional_env_params,
                               horizon=100)

    if net_params is None:
        # set default net_params configuration
        total_vehicles = vehicles.num_vehicles
        num_entries = 2 * row_num + 2 * col_num
        assert total_vehicles % num_entries == 0, "{} total vehicles should " \
                                                  "be divisible by {" \
                                                  "}".format(total_vehicles,
                                                             num_entries)
        grid_array = {
            "short_length": 100,
            "inner_length": 300,
            "long_length": 3000,
            "row_num": row_num,
            "col_num": col_num,
            "cars_left": int(total_vehicles / num_entries),
            "cars_right": int(total_vehicles / num_entries),
            "cars_top": int(total_vehicles / num_entries),
            "cars_bot": int(total_vehicles / num_entries)
        }

        additional_net_params = {
            "length": 200,
            "lanes": 2,
            "speed_limit": 35,
            "resolution": 40,
            "grid_array": grid_array,
            "horizontal_lanes": 1,
            "vertical_lanes": 1
        }

        net_params = NetParams(additional_params=additional_net_params)

    if initial_config is None:
        # set default initial_config configuration
        initial_config = InitialConfig(spacing="custom",
                                       additional_params={"enter_speed": 30})

    flow_params = dict(
        # name of the experiment
        exp_tag="Grid1x1Test",

        # name of the flow environment the experiment is running on
        env_name=TrafficLightGridTestEnv,

        # name of the network class the experiment is running on
        network=TrafficLightGridNetwork,

        # simulator that is used by the experiment
        simulator='traci',

        # sumo-related parameters (see flow.core.params.SumoParams)
        sim=sim_params,

        # environment related parameters (see flow.core.params.EnvParams)
        env=env_params,
        # network-related parameters (see flow.core.params.NetParams and the
        # network's documentation or ADDITIONAL_NET_PARAMS component)
        net=net_params,

        # 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=initial_config,

        # traffic lights to be introduced to specific nodes (see
        # flow.core.params.TrafficLightParams)
        tls=tl_logic)

    # create the network
    network = TrafficLightGridNetwork(name="Grid1x1Test",
                                      vehicles=vehicles,
                                      net_params=net_params,
                                      initial_config=initial_config,
                                      traffic_lights=tl_logic)

    # create the environment
    env = TrafficLightGridTestEnv(env_params=env_params,
                                  sim_params=sim_params,
                                  network=network)

    # reset the environment
    env.reset()

    return env, network, flow_params
Exemple #24
0
    def test_reset_inflows(self):
        """Tests that the inflow  change within the expected range when calling
        reset."""
        # set a random seed for inflows to be the same every time
        np.random.seed(seed=123)

        sim_params = SumoParams(sim_step=0.5, restart_instance=True)

        vehicles = VehicleParams()
        vehicles.add(veh_id="human")
        vehicles.add(veh_id="followerstopper")

        # edge name, how many segments to observe/control, whether the segment
        # is controlled
        controlled_segments = [("1", 1, False), ("2", 2, True), ("3", 2, True),
                               ("4", 2, True), ("5", 1, False)]
        num_observed_segments = [("1", 1), ("2", 3), ("3", 3), ("4", 3),
                                 ("5", 1)]
        env_params = EnvParams(
            additional_params={
                "target_velocity": 40,
                "disable_tb": True,
                "disable_ramp_metering": True,
                "controlled_segments": controlled_segments,
                "symmetric": False,
                "observed_segments": num_observed_segments,
                "reset_inflow": True,  # this must be set to True for the test
                "lane_change_duration": 5,
                "max_accel": 3,
                "max_decel": 3,
                "inflow_range": [1000, 2000]  # this is what we're testing
            }
        )

        inflow = InFlows()
        inflow.add(veh_type="human",
                   edge="1",
                   vehs_per_hour=1500,  # the initial inflow we're checking for
                   departLane="random",
                   departSpeed=10)

        net_params = NetParams(
            inflows=inflow,
            additional_params={"scaling": 1, "speed_limit": 23})

        scenario = BottleneckScenario(
            name="bay_bridge_toll",
            vehicles=vehicles,
            net_params=net_params)

        env = DesiredVelocityEnv(env_params, sim_params, scenario)

        # reset the environment and get a new inflow rate
        env.reset()
        expected_inflow = 1353.6  # just from checking the new inflow

        # check that the first inflow rate is approximately what the seeded
        # value expects it to be
        for _ in range(500):
            env.step(rl_actions=None)
        self.assertAlmostEqual(
            env.k.vehicle.get_inflow_rate(250)/expected_inflow, 1, 1)
Exemple #25
0
    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        restart_instance=True,
        sim_step=0.5,
        render=False,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        sims_per_step=2,
        warmup_steps=0,
        additional_params={
            "max_accel": 9,
            "max_decel": 9,
            "target_velocity": 30,
            "num_rl": NUM_RL,
            "max_num_vehicles": VEHICLE_NUMBER,
            "main_rl": MAIN_RL,
            "main_human": MAIN_HUMAN,
            "merge_human": MERGE_HUMAN,
            #"use_seeds":"/home/flow/flow_2020_07_14_19_32_55.589614/seeds.pkl",
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # network's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        inflows=inflow,
        additional_params=additional_net_params,
    ),
Exemple #26
0
def merge_example(render=None):
    """
    Perform a simulation of vehicles on a merge.

    Parameters
    ----------
    render: 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 merge.
    """
    sumo_params = SumoParams(render=True,
                             emission_path="./data/",
                             sim_step=0.2,
                             restart_instance=False)

    if render is not None:
        sumo_params.render = render

    vehicles = Vehicles()
    vehicles.add(veh_id="human",
                 acceleration_controller=(IDMController, {
                     "noise": 0.2
                 }),
                 speed_mode="no_collide",
                 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=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(inflows=inflow,
                           no_internal_links=False,
                           additional_params=additional_net_params)

    initial_config = InitialConfig(spacing="uniform", perturbation=5.0)

    scenario = MergeScenario(name="merge-baseline",
                             vehicles=vehicles,
                             net_params=net_params,
                             initial_config=initial_config)

    env = WaveAttenuationMergePOEnv(env_params, sumo_params, scenario)

    return SumoExperiment(env, scenario)
vehicles = VehicleParams()
vehicles.add(
    veh_id="human",
    lane_change_controller=(StaticLaneChanger,{}),
    acceleration_controller=(OV_FTL, {'alpha':.5,'beta':20.0,'s0':12.0,'s_star':2.0,'vM':30.0,'nosie':.5}),
    )

# vehicles.add(
#     veh_id="downstream_boundary",
#     acceleration_controller=(LinearOVM,{'v_max':traffic_speed}),
#     initial_speed=traffic_speed,
#     num_vehicles=1
#     )


env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS)

inflow = InFlows()
inflow.add(
    veh_type="human",
    edge="highway_0",
    vehs_per_hour=traffic_flow,
    departSpeed=traffic_speed,
    departLane="free")


additional_net_params = ADDITIONAL_NET_PARAMS.copy()
additional_net_params['lanes'] = 1
additional_net_params['length'] = 10000

Exemple #28
0
    simulator='traci',

    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        sim_step=0.2,
        render=False,
        restart_instance=True,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        sims_per_step=5,
        warmup_steps=0,
        additional_params={
            "max_accel": 1.5,
            "max_decel": 1.5,
            "target_velocity": 20,
            "num_rl": NUM_RL,
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # scenario's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        inflows=inflow,
        additional_params=additional_net_params,
    ),

    # vehicles to be placed in the network at the start of a rollout (see
    # flow.core.params.VehicleParams)
Exemple #29
0
    simulator='traci',

    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        restart_instance=True,
        sim_step=0.5,
        render=False,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=HORIZON,
        sims_per_step=2,
        warmup_steps=0,
        additional_params={
            "max_accel": 1.5,
            "max_decel": 1.5,
            "target_velocity": 20,
            "num_rl": NUM_RL,
            "ignore_edges": ["inflow_highway"],
        },
    ),

    # network-related parameters (see flow.core.params.NetParams and the
    # network's documentation or ADDITIONAL_NET_PARAMS component)
    net=NetParams(
        inflows=inflow,
        additional_params=additional_net_params,
    ),

    # vehicles to be placed in the network at the start of a rollout (see
    # flow.core.params.VehicleParams)
Exemple #30
0
def grid_example(render=None):
    """
    Perform a simulation of vehicles on a grid.

    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 and balanced traffic lights on a grid.
    """
    v_enter = 10
    inner_length = 300
    long_length = 500
    short_length = 300
    n_rows = 2
    n_columns = 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) * n_columns \
        + (num_cars_top + num_cars_bot) * n_rows

    grid_array = {
        "short_length": short_length,
        "inner_length": inner_length,
        "long_length": long_length,
        "row_num": n_rows,
        "col_num": n_columns,
        "cars_left": num_cars_left,
        "cars_right": num_cars_right,
        "cars_top": num_cars_top,
        "cars_bot": num_cars_bot
    }

    sim_params = SumoParams(sim_step=0.1, render=True)

    if render is not None:
        sim_params.render = render

    vehicles = VehicleParams()
    vehicles.add(
        veh_id="human",
        routing_controller=(GridRouter, {}),
        num_vehicles=tot_cars)

    env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS)

    tl_logic = TrafficLightParams(baseline=False)
    phases = [{
        "duration": "31",
        "minDur": "8",
        "maxDur": "45",
        "state": "GrGrGrGrGrGr"
    }, {
        "duration": "6",
        "minDur": "3",
        "maxDur": "6",
        "state": "yryryryryryr"
    }, {
        "duration": "31",
        "minDur": "8",
        "maxDur": "45",
        "state": "rGrGrGrGrGrG"
    }, {
        "duration": "6",
        "minDur": "3",
        "maxDur": "6",
        "state": "ryryryryryry"
    }]
    tl_logic.add("center0", phases=phases, programID=1)
    tl_logic.add("center1", phases=phases, programID=1)
    tl_logic.add("center2", phases=phases, programID=1, tls_type="actuated")

    additional_net_params = {
        "grid_array": grid_array,
        "speed_limit": 35,
        "horizontal_lanes": 1,
        "vertical_lanes": 1
    }

    if USE_INFLOWS:
        initial_config, net_params = get_flow_params(
            col_num=n_columns,
            row_num=n_rows,
            additional_net_params=additional_net_params)
    else:
        initial_config, net_params = get_non_flow_params(
            enter_speed=v_enter,
            add_net_params=additional_net_params)

    scenario = SimpleGridScenario(
        name="grid-intersection",
        vehicles=vehicles,
        net_params=net_params,
        initial_config=initial_config,
        traffic_lights=tl_logic)

    env = AccelEnv(env_params, sim_params, scenario)

    return Experiment(env)