|
1 | 1 | """I-210 subnetwork example."""
|
2 | 2 | import os
|
3 |
| - |
4 | 3 | import numpy as np
|
5 | 4 |
|
6 |
| -from flow.controllers.car_following_models import IDMController |
| 5 | +from flow.controllers import IDMController |
| 6 | +from flow.controllers import I210Router |
7 | 7 | from flow.core.params import SumoParams
|
8 | 8 | from flow.core.params import EnvParams
|
9 | 9 | from flow.core.params import NetParams
|
|
15 | 15 | from flow.envs import TestEnv
|
16 | 16 | from flow.networks.i210_subnetwork import I210SubNetwork, EDGES_DISTRIBUTION
|
17 | 17 |
|
18 |
| -# create the base vehicle type that will be used for inflows |
| 18 | +# =========================================================================== # |
| 19 | +# Specify some configurable constants. # |
| 20 | +# =========================================================================== # |
| 21 | + |
| 22 | +# whether to include the upstream ghost edge in the network |
| 23 | +WANT_GHOST_CELL = True |
| 24 | +# whether to include the downstream slow-down edge in the network |
| 25 | +WANT_DOWNSTREAM_BOUNDARY = True |
| 26 | +# whether to include vehicles on the on-ramp |
| 27 | +ON_RAMP = True |
| 28 | +# the inflow rate of vehicles (in veh/hr) |
| 29 | +INFLOW_RATE = 5 * 2215 |
| 30 | +# the speed of inflowing vehicles from the main edge (in m/s) |
| 31 | +INFLOW_SPEED = 24.1 |
| 32 | + |
| 33 | +# =========================================================================== # |
| 34 | +# Specify the path to the network template. # |
| 35 | +# =========================================================================== # |
| 36 | + |
| 37 | +if WANT_DOWNSTREAM_BOUNDARY: |
| 38 | + NET_TEMPLATE = os.path.join( |
| 39 | + config.PROJECT_PATH, |
| 40 | + "examples/exp_configs/templates/sumo/i210_with_ghost_cell_with_" |
| 41 | + "downstream.xml") |
| 42 | +elif WANT_GHOST_CELL: |
| 43 | + NET_TEMPLATE = os.path.join( |
| 44 | + config.PROJECT_PATH, |
| 45 | + "examples/exp_configs/templates/sumo/i210_with_ghost_cell.xml") |
| 46 | +else: |
| 47 | + NET_TEMPLATE = os.path.join( |
| 48 | + config.PROJECT_PATH, |
| 49 | + "examples/exp_configs/templates/sumo/test2.net.xml") |
| 50 | + |
| 51 | +# If the ghost cell is not being used, remove it from the initial edges that |
| 52 | +# vehicles can be placed on. |
| 53 | +edges_distribution = EDGES_DISTRIBUTION.copy() |
| 54 | +if not WANT_GHOST_CELL: |
| 55 | + edges_distribution.remove("ghost0") |
| 56 | + |
| 57 | +# =========================================================================== # |
| 58 | +# Specify vehicle-specific information and inflows. # |
| 59 | +# =========================================================================== # |
| 60 | + |
19 | 61 | vehicles = VehicleParams()
|
20 | 62 | vehicles.add(
|
21 | 63 | "human",
|
|
24 | 66 | lane_change_mode="strategic",
|
25 | 67 | ),
|
26 | 68 | acceleration_controller=(IDMController, {
|
27 |
| - "a": 0.3, "b": 2.0, "noise": 0.5 |
| 69 | + "a": 1.3, |
| 70 | + "b": 2.0, |
| 71 | + "noise": 0.3, |
28 | 72 | }),
|
| 73 | + routing_controller=(I210Router, {}) if ON_RAMP else None, |
29 | 74 | )
|
30 | 75 |
|
31 | 76 | inflow = InFlows()
|
32 | 77 | # main highway
|
33 | 78 | inflow.add(
|
34 | 79 | veh_type="human",
|
35 |
| - edge="119257914", |
36 |
| - vehs_per_hour=8378, |
37 |
| - departLane="random", |
38 |
| - departSpeed=23) |
| 80 | + edge="ghost0" if WANT_GHOST_CELL else "119257914", |
| 81 | + vehs_per_hour=INFLOW_RATE, |
| 82 | + departLane="best", |
| 83 | + departSpeed=INFLOW_SPEED) |
39 | 84 | # on ramp
|
40 |
| -# inflow.add( |
41 |
| -# veh_type="human", |
42 |
| -# edge="27414345", |
43 |
| -# vehs_per_hour=321, |
44 |
| -# departLane="random", |
45 |
| -# departSpeed=20) |
46 |
| -# inflow.add( |
47 |
| -# veh_type="human", |
48 |
| -# edge="27414342#0", |
49 |
| -# vehs_per_hour=421, |
50 |
| -# departLane="random", |
51 |
| -# departSpeed=20) |
52 |
| - |
53 |
| -NET_TEMPLATE = os.path.join( |
54 |
| - config.PROJECT_PATH, |
55 |
| - "examples/exp_configs/templates/sumo/test2.net.xml") |
| 85 | +if ON_RAMP: |
| 86 | + inflow.add( |
| 87 | + veh_type="human", |
| 88 | + edge="27414345", |
| 89 | + vehs_per_hour=500, |
| 90 | + departLane="random", |
| 91 | + departSpeed=10) |
| 92 | + inflow.add( |
| 93 | + veh_type="human", |
| 94 | + edge="27414342#0", |
| 95 | + vehs_per_hour=500, |
| 96 | + departLane="random", |
| 97 | + departSpeed=10) |
| 98 | + |
| 99 | +# =========================================================================== # |
| 100 | +# Generate the flow_params dict with all relevant simulation information. # |
| 101 | +# =========================================================================== # |
56 | 102 |
|
57 | 103 | flow_params = dict(
|
58 | 104 | # name of the experiment
|
|
69 | 115 |
|
70 | 116 | # simulation-related parameters
|
71 | 117 | sim=SumoParams(
|
72 |
| - sim_step=0.5, |
| 118 | + sim_step=0.4, |
73 | 119 | render=False,
|
74 | 120 | color_by_speed=True,
|
75 | 121 | use_ballistic=True
|
76 | 122 | ),
|
77 | 123 |
|
78 | 124 | # environment related parameters (see flow.core.params.EnvParams)
|
79 | 125 | env=EnvParams(
|
80 |
| - horizon=4500, |
| 126 | + horizon=10000, |
81 | 127 | ),
|
82 | 128 |
|
83 | 129 | # network-related parameters (see flow.core.params.NetParams and the
|
84 | 130 | # network's documentation or ADDITIONAL_NET_PARAMS component)
|
85 | 131 | net=NetParams(
|
86 | 132 | inflows=inflow,
|
87 |
| - template=NET_TEMPLATE |
| 133 | + template=NET_TEMPLATE, |
| 134 | + additional_params={ |
| 135 | + "on_ramp": ON_RAMP, |
| 136 | + "ghost_edge": WANT_GHOST_CELL, |
| 137 | + } |
88 | 138 | ),
|
89 | 139 |
|
90 | 140 | # vehicles to be placed in the network at the start of a rollout (see
|
|
94 | 144 | # parameters specifying the positioning of vehicles upon initialization/
|
95 | 145 | # reset (see flow.core.params.InitialConfig)
|
96 | 146 | initial=InitialConfig(
|
97 |
| - edges_distribution=EDGES_DISTRIBUTION, |
| 147 | + edges_distribution=edges_distribution, |
98 | 148 | ),
|
99 | 149 | )
|
100 | 150 |
|
| 151 | +# =========================================================================== # |
| 152 | +# Specify custom callable that is logged during simulation runtime. # |
| 153 | +# =========================================================================== # |
| 154 | + |
101 | 155 | edge_id = "119257908#1-AddedOnRampEdge"
|
102 | 156 | custom_callables = {
|
103 | 157 | "avg_merge_speed": lambda env: np.nan_to_num(np.mean(
|
|
0 commit comments