Beispiel #1
0
def start():
    """Start a environment object with ray."""
    sim_params = SumoParams(sim_step=0.1, render=False)

    vehicles = VehicleParams()
    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)

    network = RingNetwork(
        name="ring",
        vehicles=vehicles,
        net_params=net_params,
        initial_config=initial_config)

    env = AccelEnv(env_params, sim_params, network)
    env._close()
Beispiel #2
0
    def setUp(self):
        vehicles = VehicleParams()
        vehicles.add("rl",
                     acceleration_controller=(RLController, {}),
                     num_vehicles=1)
        vehicles.add("human",
                     acceleration_controller=(IDMController, {}),
                     num_vehicles=1)

        self.sim_params = SumoParams(restart_instance=True)
        self.network = RingNetwork(
            name="test_merge",
            vehicles=vehicles,
            net_params=NetParams(additional_params=RING_PARAMS.copy()),
        )
        params = {"max_accel": 1, "max_decel": 1, "ring_length": [220, 270]}
        self.env_params = EnvParams(additional_params=params)
Beispiel #3
0
def sugiyama_example(render=None):
    """
    Perform a simulation of vehicles on a ring road.

    Parameters
    ----------
    render : bool, optional
        specifies whether to use the gui during execution

    Returns
    -------
    exp: flow.core.experiment.Experiment
        A non-rl experiment demonstrating the performance of human-driven
        vehicles on a ring road.
    """
    sim_params = SumoParams(sim_step=0.1, render=True)

    if render is not None:
        sim_params.render = render

    vehicles = VehicleParams()
    vehicles.add(veh_id="idm",
                 acceleration_controller=(IDMController, {}),
                 car_following_params=SumoCarFollowingParams(min_gap=0),
                 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)

    network = RingNetwork(name="sugiyama",
                          vehicles=vehicles,
                          net_params=net_params,
                          initial_config=initial_config)

    env = AccelEnv(env_params, sim_params, network)

    return Experiment(env)
Beispiel #4
0
    def setUp(self):
        vehicles = VehicleParams()
        vehicles.add("rl",
                     acceleration_controller=(RLController, {}),
                     num_vehicles=1)
        vehicles.add("human",
                     acceleration_controller=(IDMController, {}),
                     num_vehicles=1)

        self.sim_params = SumoParams()
        self.network = RingNetwork(
            name="test_ring",
            vehicles=vehicles,
            net_params=NetParams(additional_params=RING_PARAMS.copy()),
        )
        self.env_params = EnvParams(additional_params={
            'max_accel': 1,
            'max_decel': 1,
            "target_velocity": 25
        })
Beispiel #5
0
    def setUp(self):
        vehicles = VehicleParams()
        vehicles.add("rl", acceleration_controller=(RLController, {}),
                     num_vehicles=1)
        vehicles.add("human", acceleration_controller=(IDMController, {}),
                     num_vehicles=1)

        self.sim_params = SumoParams()
        self.network = RingNetwork(
            name="test_merge",
            vehicles=vehicles,
            net_params=NetParams(additional_params=RING_PARAMS.copy()),
        )
        self.env_params = EnvParams(
            additional_params={
                "max_accel": 3,
                "max_decel": 3,
                "target_velocity": 10,
                "lane_change_duration": 5,
                "sort_vehicles": False
            }
        )
Beispiel #6
0
def sugiyama_example(render=None):
    """Perform a simulation of vehicles on a ring road.

    Parameters
    ----------
    render : bool, optional
        specifies whether to use the gui during execution

    Returns
    -------
    exp: flow.core.experiment.Experiment
        A non-rl experiment demonstrating the performance of human-driven
        vehicles on a ring road.
    """
    sim_params = AimsunParams(sim_step=0.5, render=True, emission_path='data')

    if render is not None:
        sim_params.render = render

    vehicles = VehicleParams()
    vehicles.add(veh_id="idm",
                 acceleration_controller=(IDMController, {}),
                 num_vehicles=22)

    env_params = EnvParams()

    additional_net_params = ADDITIONAL_NET_PARAMS.copy()
    net_params = NetParams(additional_params=additional_net_params)

    initial_config = InitialConfig(bunching=20)

    network = RingNetwork(name="sugiyama",
                          vehicles=vehicles,
                          net_params=net_params,
                          initial_config=initial_config)

    env = TestEnv(env_params, sim_params, network, simulator='aimsun')

    return Experiment(env)
Beispiel #7
0
def get_flow_params(fixed_density,
                    stopping_penalty,
                    acceleration_penalty,
                    evaluate=False,
                    multiagent=False,
                    imitation=False):
    """Return the flow-specific parameters of the ring road network.

    This scenario consists of 50 (if density is fixed) or 50-75 vehicles (5 of
    which are automated) are placed on a sing-lane circular track of length
    1500m. In the absence of the automated vehicle, the human-driven vehicles
    exhibit stop-and-go instabilities brought about by the string-unstable
    characteristic of human car-following dynamics. Within this setting, the
    RL vehicles are tasked with dissipating the formation and propagation of
    stop-and-go waves via an objective function that rewards maximizing
    system-level speeds.

    Parameters
    ----------
    fixed_density : bool
        specifies whether the number of human-driven vehicles updates 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)
    """
    vehicles = VehicleParams()
    for i in range(NUM_AUTOMATED):
        vehicles.add(
            veh_id="human_{}".format(i),
            acceleration_controller=(IDMController, {
                "a": 1.3,
                "b": 2.0,
                "noise": 0.3 if INCLUDE_NOISE else 0.0
            }),
            routing_controller=(ContinuousRouter, {}),
            car_following_params=SumoCarFollowingParams(min_gap=0.5, ),
            lane_change_params=SumoLaneChangeParams(lane_change_mode=1621, ),
            num_vehicles=NUM_VEHICLES[0] - NUM_AUTOMATED if i == 0 else 0)
        vehicles.add(
            veh_id="rl_{}".format(i),
            acceleration_controller=(RLController, {}),
            routing_controller=(ContinuousRouter, {}),
            car_following_params=SumoCarFollowingParams(min_gap=0.5, ),
            lane_change_params=SumoLaneChangeParams(
                lane_change_mode=0,  # no lane changes by automated vehicles
            ),
            num_vehicles=NUM_AUTOMATED if i == 0 else 0)

    additional_net_params = ADDITIONAL_NET_PARAMS.copy()
    additional_net_params["length"] = RING_LENGTH
    additional_net_params["lanes"] = NUM_LANES

    if multiagent:
        if imitation:
            env_name = None  # FIXME
        else:
            env_name = AVClosedMultiAgentEnv
    else:
        if imitation:
            env_name = AVClosedEnv
        else:
            env_name = AVClosedImitationEnv

    return dict(
        # name of the experiment
        exp_tag='multilane-ring',

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

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

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

        # environment related parameters (see flow.core.params.EnvParams)
        env=EnvParams(
            horizon=1800,
            warmup_steps=50,
            sims_per_step=2,
            evaluate=evaluate,
            additional_params={
                "max_accel": 1,
                "max_decel": 1,
                "target_velocity": 30,  # FIXME
                "stopping_penalty": stopping_penalty,
                "acceleration_penalty": acceleration_penalty,
                "num_vehicles": None if fixed_density else NUM_VEHICLES,
                "even_distribution": False,
                "sort_vehicles": True,
                "expert_model": (IDMController, {
                    "a": 1.3,
                    "b": 2.0,
                }),
            },
        ),

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

        # 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(
            spacing="random",
            min_gap=0.5,
            shuffle=True,
        ),
    )
Beispiel #8
0
def get_flow_params(stopping_penalty,
                    acceleration_penalty,
                    scale=1,
                    evaluate=False,
                    multiagent=False):
    """Return the flow-specific parameters of the ring road network.

    This scenario consists of 50 (if density is fixed) or 50-75 vehicles (5 of
    which are automated) are placed on a sing-lane circular track of length
    1500m. In the absence of the automated vehicle, the human-driven vehicles
    exhibit stop-and-go instabilities brought about by the string-unstable
    characteristic of human car-following dynamics. Within this setting, the
    RL vehicles are tasked with dissipating the formation and propagation of
    stop-and-go waves via an objective function that rewards maximizing
    system-level speeds.

    Parameters
    ----------
    stopping_penalty : bool
        whether to include a stopping penalty
    acceleration_penalty : bool
        whether to include a regularizing penalty for accelerations by the AVs
    scale : int
        a scaling term for the number of AVs/humans and length of the ring
    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

    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 3000

    vehicles = VehicleParams()
    for i in range(scale):
        vehicles.add(veh_id="human_{}".format(i),
                     acceleration_controller=(IDMController, {
                         "a": 1.3,
                         "b": 2.0,
                         "noise": 0.2,
                     }),
                     routing_controller=(ContinuousRouter, {}),
                     car_following_params=SumoCarFollowingParams(
                         speed_mode=25,
                         min_gap=0.5,
                     ),
                     num_vehicles=21)
        vehicles.add(veh_id="rl_{}".format(i),
                     acceleration_controller=(RLController, {}),
                     routing_controller=(ContinuousRouter, {}),
                     car_following_params=SumoCarFollowingParams(
                         min_gap=0.5,
                         speed_mode=25,
                     ),
                     num_vehicles=1)

    additional_net_params = ADDITIONAL_NET_PARAMS.copy()
    additional_net_params["length"] = 260 * scale

    return dict(
        # name of the experiment
        exp_tag='ring',

        # name of the flow environment the experiment is running on
        env_name=AVClosedMultiAgentEnv if multiagent else AVClosedEnv,

        # 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(
            use_ballistic=True,
            render=False,
            sim_step=0.2,
        ),

        # environment related parameters (see flow.core.params.EnvParams)
        env=EnvParams(
            horizon=3000,
            warmup_steps=warmup_steps,
            sims_per_step=1,
            evaluate=evaluate,
            additional_params={
                "max_accel": 0.5,
                "stopping_penalty": stopping_penalty,
                "acceleration_penalty": acceleration_penalty,
                "use_follower_stopper": False,
                "obs_frames": 5,
                "ring_length": [250 * scale, 360 * scale],
                "expert_model": (IDMController, {
                    "a": 1.3,
                    "b": 2.0,
                }),
                "full_observation_fn": full_observation_fn,
            },
        ),

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

        # 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(
            min_gap=0.5,
            perturbation=0.5,
        ),
    )
Beispiel #9
0
    # 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(
        render=True,
        sim_step=0.1,
    ),

    # environment related parameters (see flow.core.params.EnvParams)
    env=EnvParams(
        horizon=1500,
        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(additional_params=ADDITIONAL_NET_PARAMS.copy(), ),

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

    # parameters specifying the positioning of vehicles upon initialization/
    # reset (see flow.core.params.InitialConfig)
    initial=InitialConfig(bunching=20, ),
)
Beispiel #10
0
from numpy import pi, sin, cos, linspace
from Network.custom_ring import RingNetwork_custom, ADDITIONAL_NET_PARAMS

vehicles = VehicleParams()

vehicles.add(veh_id="human",
             acceleration_controller=(IDMController, {}),
             routing_controller=(ContinuousRouter, {}),
             num_vehicles=14)
sim_params = SumoParams(sim_step=0.1, render=True)

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

env_params = EnvParams(horizon=1500, additional_params=ADDITIONAL_ENV_PARAMS)

additional_net_params = ADDITIONAL_NET_PARAMS.copy()

net_params = NetParams(additional_params=additional_net_params)

flow_params = dict(
    # name of the experiment
    exp_tag='custom_ring',
    # name of the flow environment the experiment is running on
    env_name=AccelEnv,
    # name of the network class the experiment is running on
    network=RingNetwork_custom,  # RingNetwork_custom
    # simulator that is used by the experiment
    simulator='traci',
    # sumo-related parameters (see flow.core.params.SumoParams)
    sim=SumoParams(
        render=True,
Beispiel #11
0
def get_flow_params(num_automated=5,
                    simulator="traci",
                    evaluate=False,
                    multiagent=False):
    """Return the flow-specific parameters of the ring road network.

    This scenario consists of 50-75 vehicles (50 of which are automated) are
    placed on a sing-lane circular track of length 1500 m. In the absence of
    the automated vehicle, the 22 human-driven vehicles exhibit stop-and-go
    instabilities brought about by the string-unstable characteristic of human
    car-following dynamics.

    Parameters
    ----------
    num_automated : int
        number of automated (RL) vehicles
    simulator : str
        the simulator used, one of {'traci', 'aimsun'}
    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

    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)
    """
    vehicles = VehicleParams()
    for i in range(num_automated):
        vehicles.add(
            veh_id="human_{}".format(i),
            acceleration_controller=(IDMController, {
                "a": 0.3,
                "b": 2.0,
                "noise": 0.5,
            }),
            routing_controller=(ContinuousRouter, {}),
            car_following_params=SumoCarFollowingParams(min_gap=0.5, ),
            lane_change_params=SumoLaneChangeParams(
                lane_change_mode="strategic", ),
            num_vehicles=NUM_VEHICLES - num_automated if i == 0 else 0)
        vehicles.add(
            veh_id="rl_{}".format(i),
            acceleration_controller=(RLController, {}),
            routing_controller=(ContinuousRouter, {}),
            car_following_params=SumoCarFollowingParams(min_gap=0.5, ),
            lane_change_params=SumoLaneChangeParams(
                lane_change_mode=0,  # no lane changes by automated vehicles
            ),
            num_vehicles=num_automated if i == 0 else 0)

    additional_net_params = ADDITIONAL_NET_PARAMS.copy()
    additional_net_params["length"] = RING_LENGTH
    additional_net_params["lanes"] = NUM_LANES

    return dict(
        # name of the experiment
        exp_tag='multilane-ring',

        # name of the flow environment the experiment is running on
        env_name=AVClosedMultiAgentEnv if multiagent else AVClosedEnv,

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

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

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

        # environment related parameters (see flow.core.params.EnvParams)
        env=EnvParams(
            horizon=1800,
            warmup_steps=50,
            sims_per_step=2,
            evaluate=evaluate,
            additional_params={
                "max_accel": 1,
                "max_decel": 1,
                "target_velocity": 30,
                "penalty_type": "acceleration",
                "penalty": 1,
                "num_vehicles": [50, 75],
                "even_distribution": False,
                "sort_vehicles": True,
            },
        ),

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

        # 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(
            spacing="random",
            min_gap=0.5,
            shuffle=True,
        ),
    )