Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions examples/exp_configs/non_rl/highway_single.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
"""Multi-agent highway with ramps example.

Trains a non-constant number of agents, all sharing the same policy, on the
highway with ramps network.
"""
from flow.controllers import BandoFTLController
"""Example of an open network with human-driven vehicles."""
from flow.controllers import IDMController
from flow.core.params import EnvParams
from flow.core.params import NetParams
from flow.core.params import InitialConfig
from flow.core.params import InFlows
from flow.core.params import VehicleParams
from flow.core.params import SumoParams
from flow.core.params import SumoLaneChangeParams
from flow.core.params import SumoCarFollowingParams
from flow.networks import HighwayNetwork
from flow.envs import TestEnv
from flow.networks.highway import ADDITIONAL_NET_PARAMS

TRAFFIC_SPEED = 11
END_SPEED = 16
TRAFFIC_FLOW = 2056
HORIZON = 3600
INCLUDE_NOISE = False
# the speed of vehicles entering the network
TRAFFIC_SPEED = 24.1
# the maximum speed at the downstream boundary edge
END_SPEED = 6.0
# the inflow rate of vehicles
TRAFFIC_FLOW = 2215
# the simulation time horizon (in steps)
HORIZON = 1500
# whether to include noise in the car-following models
INCLUDE_NOISE = True

additional_net_params = ADDITIONAL_NET_PARAMS.copy()
additional_net_params.update({
Expand All @@ -31,28 +33,30 @@
"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.
# whether to include a ghost edge. This edge is provided a different speed
# limit.
"use_ghost_edge": True,
# speed limit for the ghost edge
"ghost_speed_limit": END_SPEED
"ghost_speed_limit": END_SPEED,
# length of the downstream ghost edge with the reduced speed limit
"boundary_cell_length": 300,
})

vehicles = VehicleParams()
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(
lane_change_mode="strategic",
model="SL2015",
lc_sublane=2.0,
),
acceleration_controller=(BandoFTLController, {
'alpha': .5,
'beta': 20.0,
'h_st': 12.0,
'h_go': 50.0,
'v_max': 30.0,
'noise': 1.0 if INCLUDE_NOISE else 0.0,
}),
)

inflows = InFlows()
Expand All @@ -64,8 +68,6 @@
depart_speed=TRAFFIC_SPEED,
name="idm_highway_inflow")

# SET UP FLOW PARAMETERS

flow_params = dict(
# name of the experiment
exp_tag='highway-single',
Expand All @@ -82,14 +84,15 @@
# environment related parameters (see flow.core.params.EnvParams)
env=EnvParams(
horizon=HORIZON,
warmup_steps=0,
sims_per_step=1,
warmup_steps=500,
sims_per_step=3,
),

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

Expand Down
110 changes: 82 additions & 28 deletions examples/exp_configs/non_rl/i210_subnetwork.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""I-210 subnetwork example."""
import os

import numpy as np

from flow.controllers.car_following_models import IDMController
from flow.controllers import IDMController
from flow.controllers import I210Router
from flow.core.params import SumoParams
from flow.core.params import EnvParams
from flow.core.params import NetParams
Expand All @@ -15,7 +15,49 @@
from flow.envs import TestEnv
from flow.networks.i210_subnetwork import I210SubNetwork, EDGES_DISTRIBUTION

# create the base vehicle type that will be used for inflows
# =========================================================================== #
# Specify some configurable constants. #
# =========================================================================== #

# whether to include the upstream ghost edge in the network
WANT_GHOST_CELL = True
# whether to include the downstream slow-down edge in the network
WANT_DOWNSTREAM_BOUNDARY = True
# whether to include vehicles on the on-ramp
ON_RAMP = True
# the inflow rate of vehicles (in veh/hr)
INFLOW_RATE = 5 * 2215
# the speed of inflowing vehicles from the main edge (in m/s)
INFLOW_SPEED = 24.1

# =========================================================================== #
# Specify the path to the network template. #
# =========================================================================== #

if WANT_DOWNSTREAM_BOUNDARY:
NET_TEMPLATE = os.path.join(
config.PROJECT_PATH,
"examples/exp_configs/templates/sumo/i210_with_ghost_cell_with_"
"downstream.xml")
elif WANT_GHOST_CELL:
NET_TEMPLATE = os.path.join(
config.PROJECT_PATH,
"examples/exp_configs/templates/sumo/i210_with_ghost_cell.xml")
else:
NET_TEMPLATE = os.path.join(
config.PROJECT_PATH,
"examples/exp_configs/templates/sumo/test2.net.xml")

# If the ghost cell is not being used, remove it from the initial edges that
# vehicles can be placed on.
edges_distribution = EDGES_DISTRIBUTION.copy()
if not WANT_GHOST_CELL:
edges_distribution.remove("ghost0")

# =========================================================================== #
# Specify vehicle-specific information and inflows. #
# =========================================================================== #

vehicles = VehicleParams()
vehicles.add(
"human",
Expand All @@ -24,35 +66,39 @@
lane_change_mode="strategic",
),
acceleration_controller=(IDMController, {
"a": 0.3, "b": 2.0, "noise": 0.5
"a": 1.3,
"b": 2.0,
"noise": 0.3,
}),
routing_controller=(I210Router, {}) if ON_RAMP else None,
)

inflow = InFlows()
# main highway
inflow.add(
veh_type="human",
edge="119257914",
vehs_per_hour=8378,
departLane="random",
departSpeed=23)
edge="ghost0" if WANT_GHOST_CELL else "119257914",
vehs_per_hour=INFLOW_RATE,
departLane="best",
departSpeed=INFLOW_SPEED)
# on ramp
# inflow.add(
# veh_type="human",
# edge="27414345",
# vehs_per_hour=321,
# departLane="random",
# departSpeed=20)
# inflow.add(
# veh_type="human",
# edge="27414342#0",
# vehs_per_hour=421,
# departLane="random",
# departSpeed=20)

NET_TEMPLATE = os.path.join(
config.PROJECT_PATH,
"examples/exp_configs/templates/sumo/test2.net.xml")
if ON_RAMP:
inflow.add(
veh_type="human",
edge="27414345",
vehs_per_hour=500,
departLane="random",
departSpeed=10)
inflow.add(
veh_type="human",
edge="27414342#0",
vehs_per_hour=500,
departLane="random",
departSpeed=10)

# =========================================================================== #
# Generate the flow_params dict with all relevant simulation information. #
# =========================================================================== #

flow_params = dict(
# name of the experiment
Expand All @@ -69,22 +115,26 @@

# simulation-related parameters
sim=SumoParams(
sim_step=0.5,
sim_step=0.4,
render=False,
color_by_speed=True,
use_ballistic=True
),

# environment related parameters (see flow.core.params.EnvParams)
env=EnvParams(
horizon=4500,
horizon=10000,
),

# network-related parameters (see flow.core.params.NetParams and the
# network's documentation or ADDITIONAL_NET_PARAMS component)
net=NetParams(
inflows=inflow,
template=NET_TEMPLATE
template=NET_TEMPLATE,
additional_params={
"on_ramp": ON_RAMP,
"ghost_edge": WANT_GHOST_CELL,
}
),

# vehicles to be placed in the network at the start of a rollout (see
Expand All @@ -94,10 +144,14 @@
# parameters specifying the positioning of vehicles upon initialization/
# reset (see flow.core.params.InitialConfig)
initial=InitialConfig(
edges_distribution=EDGES_DISTRIBUTION,
edges_distribution=edges_distribution,
),
)

# =========================================================================== #
# Specify custom callable that is logged during simulation runtime. #
# =========================================================================== #

edge_id = "119257908#1-AddedOnRampEdge"
custom_callables = {
"avg_merge_speed": lambda env: np.nan_to_num(np.mean(
Expand Down
Loading