Skip to content

Commit 028e0e3

Browse files
Merge pull request berkeleyflow#62 from berkeleyflow/baselines
Baselines
2 parents 25edc0a + 302a918 commit 028e0e3

19 files changed

+940
-114
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""
2+
This script is used to quickly evaluate a baseline for bottleneck0.
3+
Baseline is no AVs.
4+
5+
Bottleneck in which the actions are specifying a desired velocity in a segment
6+
of space. The autonomous penetration rate in this example is 10%.
7+
8+
Action Dimension: (?, )
9+
10+
Observation Dimension: (?, )
11+
12+
Horizon: 1000 steps
13+
"""
14+
15+
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
16+
InFlows
17+
from flow.core.traffic_lights import TrafficLights
18+
from flow.core.vehicles import Vehicles
19+
from flow.controllers import ContinuousRouter
20+
from flow.envs.bottleneck_env import DesiredVelocityEnv
21+
from flow.core.experiment import SumoExperiment
22+
from flow.scenarios.bottleneck.scenario import BottleneckScenario
23+
from flow.scenarios.bottleneck.gen import BottleneckGenerator
24+
import numpy as np
25+
26+
# time horizon of a single rollout
27+
HORIZON = 1000
28+
29+
SCALING = 1
30+
NUM_LANES = 4 * SCALING # number of lanes in the widest highway
31+
DISABLE_TB = True
32+
DISABLE_RAMP_METER = True
33+
AV_FRAC = 0.10
34+
35+
vehicles = Vehicles()
36+
vehicles.add(veh_id="human",
37+
speed_mode=9,
38+
routing_controller=(ContinuousRouter, {}),
39+
lane_change_mode=0,
40+
num_vehicles=1 * SCALING)
41+
42+
controlled_segments = [("1", 1, False), ("2", 2, True), ("3", 2, True),
43+
("4", 2, True), ("5", 1, False)]
44+
num_observed_segments = [("1", 1), ("2", 3), ("3", 3),
45+
("4", 3), ("5", 1)]
46+
additional_env_params = {
47+
"target_velocity": 40,
48+
"disable_tb": True,
49+
"disable_ramp_metering": True,
50+
"controlled_segments": controlled_segments,
51+
"symmetric": False,
52+
"observed_segments": num_observed_segments,
53+
"reset_inflow": False,
54+
"lane_change_duration": 5,
55+
"max_accel": 3,
56+
"max_decel": 3,
57+
"inflow_range": [1000, 2000]
58+
}
59+
60+
# flow rate
61+
flow_rate = 1900 * SCALING
62+
63+
# percentage of flow coming out of each lane
64+
inflow = InFlows()
65+
inflow.add(veh_type="human", edge="1",
66+
vehs_per_hour=flow_rate,
67+
departLane="random", departSpeed=10)
68+
69+
traffic_lights = TrafficLights()
70+
if not DISABLE_TB:
71+
traffic_lights.add(node_id="2")
72+
if not DISABLE_RAMP_METER:
73+
traffic_lights.add(node_id="3")
74+
75+
additional_net_params = {"scaling": SCALING}
76+
net_params = NetParams(in_flows=inflow,
77+
no_internal_links=False,
78+
additional_params=additional_net_params)
79+
80+
sumo_params = SumoParams(
81+
sim_step=0.5,
82+
sumo_binary="sumo-gui",
83+
print_warnings=False,
84+
restart_instance=False,
85+
)
86+
87+
env_params = EnvParams(
88+
evaluate=True, # Set to True to evaluate traffic metrics
89+
warmup_steps=40,
90+
sims_per_step=1,
91+
horizon=HORIZON,
92+
additional_params=additional_env_params,
93+
)
94+
95+
initial_config = InitialConfig(
96+
spacing="uniform",
97+
min_gap=5,
98+
lanes_distribution=float("inf"),
99+
edges_distribution=["2", "3", "4", "5"],
100+
)
101+
102+
scenario = BottleneckScenario(name="bay_bridge_toll",
103+
generator_class=BottleneckGenerator,
104+
vehicles=vehicles,
105+
net_params=net_params,
106+
initial_config=initial_config,
107+
traffic_lights=traffic_lights)
108+
109+
env = DesiredVelocityEnv(env_params, sumo_params, scenario)
110+
111+
exp = SumoExperiment(env, scenario)
112+
113+
num_runs = 2
114+
results = exp.run(num_runs, HORIZON)
115+
avg_outflow = np.mean([outflow[-1] for outflow in results["per_step_returns"]])
116+
print('The average outflow over 500 seconds '
117+
'across {} runs is {}'.format(num_runs, avg_outflow))
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
"""
2+
This script is used to quickly evaluate a baseline for bottleneck0.
3+
Baseline is no AVs.
4+
5+
Bottleneck in which the actions are specifying a desired velocity in a segment
6+
of space. The autonomous penetration rate in this example is 25%.
7+
Humans are allowed to lane change
8+
9+
Action Dimension: (?, )
10+
11+
Observation Dimension: (?, )
12+
13+
Horizon: 1000 steps
14+
"""
15+
16+
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
17+
InFlows
18+
from flow.core.traffic_lights import TrafficLights
19+
from flow.core.vehicles import Vehicles
20+
from flow.controllers import ContinuousRouter
21+
from flow.envs.bottleneck_env import DesiredVelocityEnv
22+
from flow.core.experiment import SumoExperiment
23+
from flow.scenarios.bottleneck.scenario import BottleneckScenario
24+
from flow.scenarios.bottleneck.gen import BottleneckGenerator
25+
import numpy as np
26+
27+
# time horizon of a single rollout
28+
HORIZON = 1000
29+
30+
SCALING = 1
31+
NUM_LANES = 4 * SCALING # number of lanes in the widest highway
32+
DISABLE_TB = True
33+
DISABLE_RAMP_METER = True
34+
AV_FRAC = 0.25
35+
36+
vehicles = Vehicles()
37+
vehicles.add(veh_id="human",
38+
speed_mode=9,
39+
routing_controller=(ContinuousRouter, {}),
40+
lane_change_mode=1621,
41+
num_vehicles=1 * SCALING)
42+
43+
controlled_segments = [("1", 1, False), ("2", 2, True), ("3", 2, True),
44+
("4", 2, True), ("5", 1, False)]
45+
num_observed_segments = [("1", 1), ("2", 3), ("3", 3),
46+
("4", 3), ("5", 1)]
47+
additional_env_params = {
48+
"target_velocity": 40,
49+
"disable_tb": True,
50+
"disable_ramp_metering": True,
51+
"controlled_segments": controlled_segments,
52+
"symmetric": False,
53+
"observed_segments": num_observed_segments,
54+
"reset_inflow": False,
55+
"lane_change_duration": 5,
56+
"max_accel": 3,
57+
"max_decel": 3,
58+
"inflow_range": [1000, 2000]
59+
}
60+
61+
# flow rate
62+
flow_rate = 1900 * SCALING
63+
64+
# percentage of flow coming out of each lane
65+
inflow = InFlows()
66+
inflow.add(veh_type="human", edge="1",
67+
vehs_per_hour=flow_rate,
68+
departLane="random", departSpeed=10)
69+
70+
traffic_lights = TrafficLights()
71+
if not DISABLE_TB:
72+
traffic_lights.add(node_id="2")
73+
if not DISABLE_RAMP_METER:
74+
traffic_lights.add(node_id="3")
75+
76+
additional_net_params = {"scaling": SCALING}
77+
net_params = NetParams(in_flows=inflow,
78+
no_internal_links=False,
79+
additional_params=additional_net_params)
80+
81+
sumo_params = SumoParams(
82+
sim_step=0.5,
83+
sumo_binary="sumo-gui",
84+
print_warnings=False,
85+
restart_instance=False,
86+
)
87+
88+
env_params = EnvParams(
89+
evaluate=True, # Set to True to evaluate traffic metrics
90+
warmup_steps=40,
91+
sims_per_step=1,
92+
horizon=HORIZON,
93+
additional_params=additional_env_params,
94+
)
95+
96+
initial_config = InitialConfig(
97+
spacing="uniform",
98+
min_gap=5,
99+
lanes_distribution=float("inf"),
100+
edges_distribution=["2", "3", "4", "5"],
101+
)
102+
103+
scenario = BottleneckScenario(name="bay_bridge_toll",
104+
generator_class=BottleneckGenerator,
105+
vehicles=vehicles,
106+
net_params=net_params,
107+
initial_config=initial_config,
108+
traffic_lights=traffic_lights)
109+
110+
env = DesiredVelocityEnv(env_params, sumo_params, scenario)
111+
112+
exp = SumoExperiment(env, scenario)
113+
114+
num_runs = 2
115+
results = exp.run(num_runs, HORIZON)
116+
avg_outflow = np.mean([outflow[-1] for outflow in results["per_step_returns"]])
117+
print('The average outflow over 500 seconds '
118+
'across {} runs is {}'.format(num_runs, avg_outflow))
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""
2+
Script used to evaluate uncontrolled outflow performance of bottleneck2.
3+
Baseline is no AV control.
4+
5+
Bottleneck in which the actions are specifying a desired velocity in a segment
6+
of space. The autonomous penetration rate in this example is 10%.
7+
8+
Action Dimension: (40, )
9+
10+
Observation Dimension: (281, )
11+
12+
Horizon: 1000 steps
13+
"""
14+
15+
from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \
16+
InFlows
17+
from flow.core.traffic_lights import TrafficLights
18+
from flow.core.vehicles import Vehicles
19+
from flow.controllers import ContinuousRouter
20+
from flow.envs.bottleneck_env import DesiredVelocityEnv
21+
from flow.core.experiment import SumoExperiment
22+
from flow.scenarios.bottleneck.scenario import BottleneckScenario
23+
from flow.scenarios.bottleneck.gen import BottleneckGenerator
24+
import numpy as np
25+
26+
# time horizon of a single rollout
27+
HORIZON = 1000
28+
29+
SCALING = 2
30+
NUM_LANES = 4 * SCALING # number of lanes in the widest highway
31+
DISABLE_TB = True
32+
DISABLE_RAMP_METER = True
33+
AV_FRAC = .10
34+
35+
vehicles = Vehicles()
36+
vehicles.add(veh_id="human",
37+
speed_mode=9,
38+
routing_controller=(ContinuousRouter, {}),
39+
lane_change_mode=0,
40+
num_vehicles=1 * SCALING)
41+
42+
controlled_segments = [("1", 1, False), ("2", 2, True), ("3", 2, True),
43+
("4", 2, True), ("5", 1, False)]
44+
num_observed_segments = [("1", 1), ("2", 3), ("3", 3),
45+
("4", 3), ("5", 1)]
46+
additional_env_params = {
47+
"target_velocity": 40,
48+
"disable_tb": True,
49+
"disable_ramp_metering": True,
50+
"controlled_segments": controlled_segments,
51+
"symmetric": False,
52+
"observed_segments": num_observed_segments,
53+
"reset_inflow": False,
54+
"lane_change_duration": 5,
55+
"max_accel": 3,
56+
"max_decel": 3,
57+
"inflow_range": [1000, 2000]
58+
}
59+
60+
# flow rate
61+
flow_rate = 1900 * SCALING
62+
63+
# percentage of flow coming out of each lane
64+
inflow = InFlows()
65+
inflow.add(veh_type="human", edge="1",
66+
vehs_per_hour=flow_rate,
67+
departLane="random", departSpeed=10)
68+
69+
traffic_lights = TrafficLights()
70+
if not DISABLE_TB:
71+
traffic_lights.add(node_id="2")
72+
if not DISABLE_RAMP_METER:
73+
traffic_lights.add(node_id="3")
74+
75+
additional_net_params = {"scaling": SCALING}
76+
net_params = NetParams(in_flows=inflow,
77+
no_internal_links=False,
78+
additional_params=additional_net_params)
79+
80+
sumo_params = SumoParams(
81+
sim_step=0.5,
82+
sumo_binary="sumo-gui",
83+
print_warnings=False,
84+
restart_instance=False,
85+
)
86+
87+
env_params = EnvParams(
88+
evaluate=True, # Set to True to evaluate traffic metrics
89+
warmup_steps=40,
90+
sims_per_step=1,
91+
horizon=HORIZON,
92+
additional_params=additional_env_params,
93+
)
94+
95+
initial_config = InitialConfig(
96+
spacing="uniform",
97+
min_gap=5,
98+
lanes_distribution=float("inf"),
99+
edges_distribution=["2", "3", "4", "5"],
100+
)
101+
102+
scenario = BottleneckScenario(name="bay_bridge_toll",
103+
generator_class=BottleneckGenerator,
104+
vehicles=vehicles,
105+
net_params=net_params,
106+
initial_config=initial_config,
107+
traffic_lights=traffic_lights)
108+
109+
env = DesiredVelocityEnv(env_params, sumo_params, scenario)
110+
111+
exp = SumoExperiment(env, scenario)
112+
113+
num_runs = 2
114+
results = exp.run(num_runs, HORIZON)
115+
avg_outflow = np.mean([outflow[-1] for outflow in results["per_step_returns"]])
116+
print('The average outflow over 500 seconds '
117+
'across {} runs is {}'.format(num_runs, avg_outflow))

0 commit comments

Comments
 (0)