-
Notifications
You must be signed in to change notification settings - Fork 367
/
figure_eight.py
60 lines (45 loc) · 1.74 KB
/
figure_eight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Example of a figure 8 network with human-driven vehicles.
Right-of-way dynamics near the intersection causes vehicles to queue up on
either side of the intersection, leading to a significant reduction in the
average speed of vehicles in the network.
"""
from flow.controllers import IDMController
from flow.core.experiment import Experiment
from flow.core.params import AimsunParams, EnvParams, NetParams
from flow.core.params import VehicleParams
from flow.envs import TestEnv
from flow.scenarios.figure_eight import FigureEightScenario, ADDITIONAL_NET_PARAMS
def figure_eight_example(render=None):
"""Perform a simulation of vehicles on a figure eight.
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 figure eight.
"""
sim_params = AimsunParams(sim_step=0.5, render=False, emission_path='data')
if render is not None:
sim_params.render = render
vehicles = VehicleParams()
vehicles.add(
veh_id="human",
acceleration_controller=(IDMController, {}),
num_vehicles=14)
env_params = EnvParams()
net_params = NetParams(
additional_params=ADDITIONAL_NET_PARAMS.copy())
scenario = FigureEightScenario(
name="FigureEight",
vehicles=vehicles,
net_params=net_params)
env = TestEnv(env_params, sim_params, scenario, simulator='aimsun')
return Experiment(env)
if __name__ == "__main__":
# import the experiment variable
exp = figure_eight_example(render=True)
# run for a set number of rollouts / time steps
exp.run(1, 1500)