From f6daf016beb0b1e8efc310585f63acf06f1043fe Mon Sep 17 00:00:00 2001 From: nathanlct Date: Fri, 12 Jul 2019 00:21:15 -0700 Subject: [PATCH 01/23] better file names for environments --- docs/source/flow.envs.bay_bridge.rst | 2 +- docs/source/flow.envs.rst | 6 ++--- examples/aimsun/bottlenecks.py | 2 +- examples/aimsun/grid.py | 2 +- examples/rllab/green_wave.py | 2 +- examples/rllab/velocity_bottleneck.py | 2 +- examples/rllib/green_wave.py | 2 +- examples/rllib/velocity_bottleneck.py | 2 +- examples/sumo/bay_bridge.py | 2 +- examples/sumo/bay_bridge_toll.py | 2 +- examples/sumo/bottlenecks.py | 2 +- examples/sumo/figure_eight.py | 2 +- examples/sumo/grid.py | 2 +- examples/sumo/highway.py | 2 +- examples/sumo/loop_merge.py | 2 +- examples/sumo/minicity.py | 2 +- examples/sumo/sugiyama.py | 2 +- flow/benchmarks/bottleneck0.py | 2 +- flow/benchmarks/bottleneck1.py | 2 +- flow/benchmarks/bottleneck2.py | 2 +- flow/benchmarks/grid0.py | 2 +- flow/benchmarks/grid1.py | 2 +- flow/controllers/base_routing_controller.py | 2 +- flow/controllers/velocity_controllers.py | 2 +- flow/core/kernel/scenario/base.py | 2 +- flow/core/kernel/traffic_light/base.py | 2 +- flow/core/kernel/vehicle/base.py | 2 +- flow/envs/__init__.py | 22 +++++++++---------- flow/envs/{base_env.py => base.py} | 0 .../{bay_bridge/base.py => bay_bridge.py} | 0 flow/envs/bay_bridge/__init__.py | 1 - .../envs/{bottleneck_env.py => bottleneck.py} | 19 ++++++++-------- flow/envs/loop/{loop_accel.py => accel.py} | 2 +- ...{lane_changing.py => lane_change_accel.py} | 2 +- flow/envs/loop/wave_attenuation.py | 2 +- flow/envs/merge.py | 2 +- flow/envs/test.py | 2 +- ...reen_wave_env.py => traffic_light_grid.py} | 4 ++-- flow/multiagent_envs/loop/loop_accel.py | 2 +- flow/multiagent_envs/multiagent_env.py | 2 +- .../fast_tests/test_environment_base_class.py | 4 ++-- tests/fast_tests/test_environments.py | 17 +++++++------- tests/setup_scripts.py | 4 ++-- tests/slow_tests/test_benchmarks.py | 4 ++-- tests/stress_tests/stress_test_start.py | 2 +- tutorials/tutorial01_sumo.ipynb | 4 ++-- tutorials/tutorial02_aimsun.ipynb | 4 ++-- tutorials/tutorial06_scenarios.ipynb | 2 +- tutorials/tutorial08_network_templates.ipynb | 2 +- tutorials/tutorial10_controllers.ipynb | 2 +- tutorials/tutorial11_traffic_lights.ipynb | 4 ++-- tutorials/tutorial12_inflows.ipynb | 2 +- 52 files changed, 85 insertions(+), 84 deletions(-) rename flow/envs/{base_env.py => base.py} (100%) rename flow/envs/{bay_bridge/base.py => bay_bridge.py} (100%) delete mode 100644 flow/envs/bay_bridge/__init__.py rename flow/envs/{bottleneck_env.py => bottleneck.py} (98%) rename flow/envs/loop/{loop_accel.py => accel.py} (99%) rename flow/envs/loop/{lane_changing.py => lane_change_accel.py} (99%) rename flow/envs/{green_wave_env.py => traffic_light_grid.py} (99%) diff --git a/docs/source/flow.envs.bay_bridge.rst b/docs/source/flow.envs.bay_bridge.rst index 4c22ff837a..0b82b2dd5a 100644 --- a/docs/source/flow.envs.bay_bridge.rst +++ b/docs/source/flow.envs.bay_bridge.rst @@ -7,7 +7,7 @@ Submodules flow.envs.bay\_bridge.base module --------------------------------- -.. automodule:: flow.envs.bay_bridge.base +.. automodule:: flow.envs.bay_bridge :members: :undoc-members: :show-inheritance: diff --git a/docs/source/flow.envs.rst b/docs/source/flow.envs.rst index ff71f71901..ed136b19c1 100644 --- a/docs/source/flow.envs.rst +++ b/docs/source/flow.envs.rst @@ -14,7 +14,7 @@ Submodules flow.envs.base\_env module -------------------------- -.. automodule:: flow.envs.base_env +.. automodule:: flow.envs.base :members: :undoc-members: :show-inheritance: @@ -22,7 +22,7 @@ flow.envs.base\_env module flow.envs.bottleneck\_env module -------------------------------- -.. automodule:: flow.envs.bottleneck_env +.. automodule:: flow.envs.bottleneck :members: :undoc-members: :show-inheritance: @@ -30,7 +30,7 @@ flow.envs.bottleneck\_env module flow.envs.green\_wave\_env module --------------------------------- -.. automodule:: flow.envs.green_wave_env +.. automodule:: flow.envs.traffic_light_grid :members: :undoc-members: :show-inheritance: diff --git a/examples/aimsun/bottlenecks.py b/examples/aimsun/bottlenecks.py index 205e241c56..e9cbacfb53 100644 --- a/examples/aimsun/bottlenecks.py +++ b/examples/aimsun/bottlenecks.py @@ -6,7 +6,7 @@ from flow.core.params import TrafficLightParams from flow.scenarios.bottleneck import BottleneckScenario -from flow.envs.bottleneck_env import BottleneckEnv +from flow.envs.bottleneck import BottleneckEnv from flow.core.experiment import Experiment SCALING = 1 diff --git a/examples/aimsun/grid.py b/examples/aimsun/grid.py index 38eb623eeb..0b2028f028 100644 --- a/examples/aimsun/grid.py +++ b/examples/aimsun/grid.py @@ -3,7 +3,7 @@ from flow.core.params import AimsunParams, EnvParams, InitialConfig, NetParams from flow.core.params import VehicleParams from flow.core.params import TrafficLightParams -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.grid import SimpleGridScenario diff --git a/examples/rllab/green_wave.py b/examples/rllab/green_wave.py index 9430e70152..146f6e34c2 100644 --- a/examples/rllab/green_wave.py +++ b/examples/rllab/green_wave.py @@ -206,7 +206,7 @@ def run_task(*_): initial_config=initial_config, traffic_lights=tl_logic) - env_name = "PO_TrafficLightGridEnv" + env_name = "TrafficLightGridPOEnv" pass_params = (env_name, sim_params, vehicles, env_params, net_params, initial_config, scenario) diff --git a/examples/rllab/velocity_bottleneck.py b/examples/rllab/velocity_bottleneck.py index c5671ffc6a..6a8bcce4b3 100644 --- a/examples/rllab/velocity_bottleneck.py +++ b/examples/rllab/velocity_bottleneck.py @@ -87,7 +87,7 @@ flow_rate = 1500 * SCALING print('flow rate is ', flow_rate) -env_name = "DesiredVelocityEnv" +env_name = "BottleneckDesiredVelocityEnv" inflow = InFlows() inflow.add( diff --git a/examples/rllib/green_wave.py b/examples/rllib/green_wave.py index e24fed995c..e0dc1fa6e7 100644 --- a/examples/rllib/green_wave.py +++ b/examples/rllib/green_wave.py @@ -183,7 +183,7 @@ def get_non_flow_params(enter_speed, add_net_params): exp_tag='green_wave', # name of the flow environment the experiment is running on - env_name='PO_TrafficLightGridEnv', + env_name='TrafficLightGridPOEnv', # name of the scenario class the experiment is running on scenario='SimpleGridScenario', diff --git a/examples/rllib/velocity_bottleneck.py b/examples/rllib/velocity_bottleneck.py index 852adbf8e5..ae694146f6 100644 --- a/examples/rllib/velocity_bottleneck.py +++ b/examples/rllib/velocity_bottleneck.py @@ -112,7 +112,7 @@ exp_tag="DesiredVelocity", # name of the flow environment the experiment is running on - env_name="DesiredVelocityEnv", + env_name="BottleneckDesiredVelocityEnv", # name of the scenario class the experiment is running on scenario="BottleneckScenario", diff --git a/examples/sumo/bay_bridge.py b/examples/sumo/bay_bridge.py index 7b107255fc..1c20529df5 100644 --- a/examples/sumo/bay_bridge.py +++ b/examples/sumo/bay_bridge.py @@ -9,7 +9,7 @@ from flow.core.params import TrafficLightParams from flow.core.experiment import Experiment -from flow.envs.bay_bridge.base import BayBridgeEnv +from flow.envs.bay_bridge import BayBridgeEnv from flow.scenarios.bay_bridge import BayBridgeScenario, EDGES_DISTRIBUTION from flow.controllers import SimCarFollowingController, BayBridgeRouter diff --git a/examples/sumo/bay_bridge_toll.py b/examples/sumo/bay_bridge_toll.py index 5b4d4b4fe1..01902f6029 100644 --- a/examples/sumo/bay_bridge_toll.py +++ b/examples/sumo/bay_bridge_toll.py @@ -8,7 +8,7 @@ from flow.core.params import VehicleParams from flow.core.experiment import Experiment -from flow.envs.bay_bridge.base import BayBridgeEnv +from flow.envs.bay_bridge import BayBridgeEnv from flow.scenarios.bay_bridge_toll import BayBridgeTollScenario from flow.scenarios.bay_bridge_toll import EDGES_DISTRIBUTION diff --git a/examples/sumo/bottlenecks.py b/examples/sumo/bottlenecks.py index 1aa9e6dff7..9d8f71826c 100644 --- a/examples/sumo/bottlenecks.py +++ b/examples/sumo/bottlenecks.py @@ -7,7 +7,7 @@ from flow.scenarios.bottleneck import BottleneckScenario from flow.controllers import SimLaneChangeController, ContinuousRouter -from flow.envs.bottleneck_env import BottleneckEnv +from flow.envs.bottleneck import BottleneckEnv from flow.core.experiment import Experiment import logging diff --git a/examples/sumo/figure_eight.py b/examples/sumo/figure_eight.py index 8eb74b4bbf..f978673067 100755 --- a/examples/sumo/figure_eight.py +++ b/examples/sumo/figure_eight.py @@ -9,7 +9,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, \ SumoCarFollowingParams from flow.core.params import VehicleParams -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.figure_eight import Figure8Scenario, ADDITIONAL_NET_PARAMS diff --git a/examples/sumo/grid.py b/examples/sumo/grid.py index e92e0d811e..9b8d8013fa 100644 --- a/examples/sumo/grid.py +++ b/examples/sumo/grid.py @@ -6,7 +6,7 @@ from flow.core.params import TrafficLightParams from flow.core.params import SumoCarFollowingParams from flow.core.params import InFlows -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.grid import SimpleGridScenario diff --git a/examples/sumo/highway.py b/examples/sumo/highway.py index d8c675393b..e6971e38b5 100644 --- a/examples/sumo/highway.py +++ b/examples/sumo/highway.py @@ -5,7 +5,7 @@ from flow.core.params import SumoParams, EnvParams, \ NetParams, InitialConfig, InFlows from flow.core.params import VehicleParams -from flow.envs.loop.lane_changing import LaneChangeAccelEnv, \ +from flow.envs.loop.lane_change_accel import LaneChangeAccelEnv, \ ADDITIONAL_ENV_PARAMS from flow.scenarios.highway import HighwayScenario, ADDITIONAL_NET_PARAMS diff --git a/examples/sumo/loop_merge.py b/examples/sumo/loop_merge.py index 02b750e0a8..8bd8ca3e4a 100755 --- a/examples/sumo/loop_merge.py +++ b/examples/sumo/loop_merge.py @@ -6,7 +6,7 @@ from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.loop_merge import TwoLoopsOneMergingScenario, \ ADDITIONAL_NET_PARAMS diff --git a/examples/sumo/minicity.py b/examples/sumo/minicity.py index 6742f831ea..084d16c57a 100644 --- a/examples/sumo/minicity.py +++ b/examples/sumo/minicity.py @@ -5,7 +5,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig from flow.core.params import SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.minicity import MiniCityScenario from flow.controllers.routing_controllers import MinicityRouter import numpy as np diff --git a/examples/sumo/sugiyama.py b/examples/sumo/sugiyama.py index 724196c039..8268342aeb 100755 --- a/examples/sumo/sugiyama.py +++ b/examples/sumo/sugiyama.py @@ -8,7 +8,7 @@ from flow.core.params import SumoParams, EnvParams, \ InitialConfig, NetParams from flow.core.params import VehicleParams -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS diff --git a/flow/benchmarks/bottleneck0.py b/flow/benchmarks/bottleneck0.py index 3eb29bfa06..0742502364 100644 --- a/flow/benchmarks/bottleneck0.py +++ b/flow/benchmarks/bottleneck0.py @@ -99,7 +99,7 @@ exp_tag="bottleneck_0", # name of the flow environment the experiment is running on - env_name="DesiredVelocityEnv", + env_name="BottleneckDesiredVelocityEnv", # name of the scenario class the experiment is running on scenario="BottleneckScenario", diff --git a/flow/benchmarks/bottleneck1.py b/flow/benchmarks/bottleneck1.py index 6231ea6980..de338ff26f 100644 --- a/flow/benchmarks/bottleneck1.py +++ b/flow/benchmarks/bottleneck1.py @@ -99,7 +99,7 @@ exp_tag="bottleneck_1", # name of the flow environment the experiment is running on - env_name="DesiredVelocityEnv", + env_name="BottleneckDesiredVelocityEnv", # name of the scenario class the experiment is running on scenario="BottleneckScenario", diff --git a/flow/benchmarks/bottleneck2.py b/flow/benchmarks/bottleneck2.py index 3523d0a05f..7324a7adbf 100644 --- a/flow/benchmarks/bottleneck2.py +++ b/flow/benchmarks/bottleneck2.py @@ -99,7 +99,7 @@ exp_tag="bottleneck_2", # name of the flow environment the experiment is running on - env_name="DesiredVelocityEnv", + env_name="BottleneckDesiredVelocityEnv", # name of the scenario class the experiment is running on scenario="BottleneckScenario", diff --git a/flow/benchmarks/grid0.py b/flow/benchmarks/grid0.py index cdb1e67299..3c082c6c47 100644 --- a/flow/benchmarks/grid0.py +++ b/flow/benchmarks/grid0.py @@ -67,7 +67,7 @@ exp_tag="grid_0", # name of the flow environment the experiment is running on - env_name="PO_TrafficLightGridEnv", + env_name="TrafficLightGridPOEnv", # name of the scenario class the experiment is running on scenario="SimpleGridScenario", diff --git a/flow/benchmarks/grid1.py b/flow/benchmarks/grid1.py index a8029e642f..316240df11 100644 --- a/flow/benchmarks/grid1.py +++ b/flow/benchmarks/grid1.py @@ -67,7 +67,7 @@ exp_tag="grid_1", # name of the flow environment the experiment is running on - env_name="PO_TrafficLightGridEnv", + env_name="TrafficLightGridPOEnv", # name of the scenario class the experiment is running on scenario="SimpleGridScenario", diff --git a/flow/controllers/base_routing_controller.py b/flow/controllers/base_routing_controller.py index 7bf92bfd6f..f24e0b58de 100755 --- a/flow/controllers/base_routing_controller.py +++ b/flow/controllers/base_routing_controller.py @@ -26,7 +26,7 @@ def choose_route(self, env): Parameters ---------- env : flow.envs.Env - see flow/envs/base_env.py + see flow/envs/base.py Returns ------- diff --git a/flow/controllers/velocity_controllers.py b/flow/controllers/velocity_controllers.py index 07f6086c3a..e18a151185 100644 --- a/flow/controllers/velocity_controllers.py +++ b/flow/controllers/velocity_controllers.py @@ -49,7 +49,7 @@ def find_intersection_dist(self, env): Parameters ---------- env : flow.envs.Env - see flow/envs/base_env.py + see flow/envs/base.py Returns ------- diff --git a/flow/core/kernel/scenario/base.py b/flow/core/kernel/scenario/base.py index 946c48713c..06774ad57f 100644 --- a/flow/core/kernel/scenario/base.py +++ b/flow/core/kernel/scenario/base.py @@ -31,7 +31,7 @@ class KernelScenario(object): travel within the network, this can be done by calling the following command: - >>> from flow.envs.base_env import Env + >>> from flow.envs.base import Env >>> env = Env(...) >>> max_speed = env.k.scenario.max_speed() diff --git a/flow/core/kernel/traffic_light/base.py b/flow/core/kernel/traffic_light/base.py index c3fc95c6e1..c89cda9192 100644 --- a/flow/core/kernel/traffic_light/base.py +++ b/flow/core/kernel/traffic_light/base.py @@ -12,7 +12,7 @@ class KernelTrafficLight(object): certain traffic lights at a given time step. This can be done by calling the following method: - >>> from flow.envs.base_env import Env + >>> from flow.envs.base import Env >>> env = Env(...) >>> node_id = 'test_intersection' # name of the node >>> env.k.traffic_light.set_state(node_id, 'r') diff --git a/flow/core/kernel/vehicle/base.py b/flow/core/kernel/vehicle/base.py index b39849cbf9..b1db255aa8 100644 --- a/flow/core/kernel/vehicle/base.py +++ b/flow/core/kernel/vehicle/base.py @@ -26,7 +26,7 @@ class KernelVehicle(object): would like to get the speed of a vehicle from the environment, that can be done by calling: - >>> from flow.envs.base_env import Env + >>> from flow.envs.base import Env >>> env = Env(...) >>> veh_id = "test_car" # name of the vehicle >>> speed = env.k.vehicle.get_speed(veh_id) diff --git a/flow/envs/__init__.py b/flow/envs/__init__.py index 4d4e088858..c07362a853 100755 --- a/flow/envs/__init__.py +++ b/flow/envs/__init__.py @@ -1,13 +1,13 @@ """Contains all callable environments in Flow.""" -from flow.envs.base_env import Env -from flow.envs.bay_bridge.base import BayBridgeEnv -from flow.envs.bottleneck_env import BottleNeckAccelEnv, BottleneckEnv, \ - DesiredVelocityEnv -from flow.envs.green_wave_env import TrafficLightGridEnv, \ - PO_TrafficLightGridEnv, GreenWaveTestEnv -from flow.envs.loop.lane_changing import LaneChangeAccelEnv, \ +from flow.envs.base import Env +from flow.envs.bay_bridge import BayBridgeEnv +from flow.envs.bottleneck import BottleneckAccelEnv, BottleneckEnv, \ + BottleneckDesiredVelocityEnv +from flow.envs.traffic_light_grid import TrafficLightGridEnv, \ + TrafficLightGridPOEnv, GreenWaveTestEnv +from flow.envs.loop.lane_change_accel import LaneChangeAccelEnv, \ LaneChangeAccelPOEnv -from flow.envs.loop.loop_accel import AccelEnv +from flow.envs.loop.accel import AccelEnv from flow.envs.loop.wave_attenuation import WaveAttenuationEnv, \ WaveAttenuationPOEnv from flow.envs.merge import WaveAttenuationMergePOEnv @@ -17,7 +17,7 @@ 'Env', 'AccelEnv', 'LaneChangeAccelEnv', 'LaneChangeAccelPOEnv', 'GreenWaveTestEnv', 'GreenWaveTestEnv', 'WaveAttenuationMergePOEnv', 'BottleneckEnv', - 'BottleNeckAccelEnv', 'WaveAttenuationEnv', 'WaveAttenuationPOEnv', - 'TrafficLightGridEnv', 'PO_TrafficLightGridEnv', 'DesiredVelocityEnv', - 'TestEnv', 'BayBridgeEnv', + 'BottleneckAccelEnv', 'WaveAttenuationEnv', 'WaveAttenuationPOEnv', + 'TrafficLightGridEnv', 'TrafficLightGridPOEnv', + 'BottleneckDesiredVelocityEnv', 'TestEnv', 'BayBridgeEnv', ] diff --git a/flow/envs/base_env.py b/flow/envs/base.py similarity index 100% rename from flow/envs/base_env.py rename to flow/envs/base.py diff --git a/flow/envs/bay_bridge/base.py b/flow/envs/bay_bridge.py similarity index 100% rename from flow/envs/bay_bridge/base.py rename to flow/envs/bay_bridge.py diff --git a/flow/envs/bay_bridge/__init__.py b/flow/envs/bay_bridge/__init__.py deleted file mode 100644 index 7a671f6daa..0000000000 --- a/flow/envs/bay_bridge/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Empty init file to ensure documentation for Bay Bridge is created.""" diff --git a/flow/envs/bottleneck_env.py b/flow/envs/bottleneck.py similarity index 98% rename from flow/envs/bottleneck_env.py rename to flow/envs/bottleneck.py index c1d81e7d51..3d2513634e 100644 --- a/flow/envs/bottleneck_env.py +++ b/flow/envs/bottleneck.py @@ -21,7 +21,7 @@ from gym.spaces.box import Box from flow.core import rewards -from flow.envs.base_env import Env +from flow.envs.base import Env MAX_LANES = 4 # base number of largest number of lanes in the network EDGE_LIST = ["1", "2", "3", "4", "5"] # Edge 1 is before the toll booth @@ -371,8 +371,8 @@ def get_state(self): return np.asarray([1]) -class BottleNeckAccelEnv(BottleneckEnv): - """BottleNeckAccelEnv. +class BottleneckAccelEnv(BottleneckEnv): + """BottleneckAccelEnv. Environment used to train vehicles to effectively pass through a bottleneck. @@ -402,7 +402,7 @@ class BottleNeckAccelEnv(BottleneckEnv): """ def __init__(self, env_params, sim_params, scenario, simulator='traci'): - """Initialize BottleNeckAccelEnv.""" + """Initialize BottleneckAccelEnv.""" for p in ADDITIONAL_RL_ENV_PARAMS.keys(): if p not in env_params.additional_params: raise KeyError( @@ -601,8 +601,8 @@ def additional_command(self): pass -class DesiredVelocityEnv(BottleneckEnv): - """DesiredVelocityEnv. +class BottleneckDesiredVelocityEnv(BottleneckEnv): + """BottleneckDesiredVelocityEnv. Environment used to train vehicles to effectively pass through a bottleneck by specifying the velocity that RL vehicles should attempt to @@ -623,7 +623,7 @@ class DesiredVelocityEnv(BottleneckEnv): """ def __init__(self, env_params, sim_params, scenario, simulator='traci'): - """Initialize DesiredVelocityEnv.""" + """Initialize BottleneckDesiredVelocityEnv.""" super().__init__(env_params, sim_params, scenario, simulator) for p in ADDITIONAL_VSL_ENV_PARAMS.keys(): if p not in env_params.additional_params: @@ -633,8 +633,9 @@ def __init__(self, env_params, sim_params, scenario, simulator='traci'): # default (edge, segment, controlled) status add_env_params = self.env_params.additional_params default = [(str(i), 1, True) for i in range(1, 6)] - super(DesiredVelocityEnv, self).__init__(env_params, sim_params, - scenario) + super(BottleneckDesiredVelocityEnv, self).__init__(env_params, + sim_params, + scenario) self.segments = add_env_params.get("controlled_segments", default) # number of segments for each edge diff --git a/flow/envs/loop/loop_accel.py b/flow/envs/loop/accel.py similarity index 99% rename from flow/envs/loop/loop_accel.py rename to flow/envs/loop/accel.py index e0214e254b..d3a0c87453 100755 --- a/flow/envs/loop/loop_accel.py +++ b/flow/envs/loop/accel.py @@ -1,7 +1,7 @@ """Environment for training the acceleration behavior of vehicles in a loop.""" from flow.core import rewards -from flow.envs.base_env import Env +from flow.envs.base import Env from gym.spaces.box import Box diff --git a/flow/envs/loop/lane_changing.py b/flow/envs/loop/lane_change_accel.py similarity index 99% rename from flow/envs/loop/lane_changing.py rename to flow/envs/loop/lane_change_accel.py index f9754b74f1..634543e091 100755 --- a/flow/envs/loop/lane_changing.py +++ b/flow/envs/loop/lane_change_accel.py @@ -1,6 +1,6 @@ """Environments that can train both lane change and acceleration behaviors.""" -from flow.envs.loop.loop_accel import AccelEnv +from flow.envs.loop.accel import AccelEnv from flow.core import rewards from gym.spaces.box import Box diff --git a/flow/envs/loop/wave_attenuation.py b/flow/envs/loop/wave_attenuation.py index 6e54cd6af6..ff05d6408a 100644 --- a/flow/envs/loop/wave_attenuation.py +++ b/flow/envs/loop/wave_attenuation.py @@ -10,7 +10,7 @@ from flow.core.params import InitialConfig from flow.core.params import NetParams -from flow.envs.base_env import Env +from flow.envs.base import Env from gym.spaces.box import Box diff --git a/flow/envs/merge.py b/flow/envs/merge.py index 6b27e7f8e4..de4c92b7b0 100644 --- a/flow/envs/merge.py +++ b/flow/envs/merge.py @@ -5,7 +5,7 @@ TODO(ak): add paper after it has been published. """ -from flow.envs.base_env import Env +from flow.envs.base import Env from flow.core import rewards from gym.spaces.box import Box diff --git a/flow/envs/test.py b/flow/envs/test.py index e653eae8ac..813e4621ea 100644 --- a/flow/envs/test.py +++ b/flow/envs/test.py @@ -1,6 +1,6 @@ """Test environment used to run simulations in the absence of autonomy.""" -from flow.envs.base_env import Env +from flow.envs.base import Env from gym.spaces.box import Box import numpy as np diff --git a/flow/envs/green_wave_env.py b/flow/envs/traffic_light_grid.py similarity index 99% rename from flow/envs/green_wave_env.py rename to flow/envs/traffic_light_grid.py index 55bf7995b9..fd8a1af9e8 100644 --- a/flow/envs/green_wave_env.py +++ b/flow/envs/traffic_light_grid.py @@ -12,7 +12,7 @@ from gym.spaces.tuple_space import Tuple from flow.core import rewards -from flow.envs.base_env import Env +from flow.envs.base import Env ADDITIONAL_ENV_PARAMS = { # minimum switch time for each traffic light (in seconds) @@ -419,7 +419,7 @@ def k_closest_to_intersection(self, edges, k): return veh_ids_ordered[:k] -class PO_TrafficLightGridEnv(TrafficLightGridEnv): +class TrafficLightGridPOEnv(TrafficLightGridEnv): """Environment used to train traffic lights. Required from env_params: diff --git a/flow/multiagent_envs/loop/loop_accel.py b/flow/multiagent_envs/loop/loop_accel.py index d325de9d2f..2306799203 100644 --- a/flow/multiagent_envs/loop/loop_accel.py +++ b/flow/multiagent_envs/loop/loop_accel.py @@ -2,7 +2,7 @@ import numpy as np from flow.core import rewards -from flow.envs.loop.loop_accel import AccelEnv +from flow.envs.loop.accel import AccelEnv from flow.multiagent_envs.multiagent_env import MultiEnv diff --git a/flow/multiagent_envs/multiagent_env.py b/flow/multiagent_envs/multiagent_env.py index df2f6da54e..c57bd74db2 100644 --- a/flow/multiagent_envs/multiagent_env.py +++ b/flow/multiagent_envs/multiagent_env.py @@ -11,7 +11,7 @@ from ray.rllib.env import MultiAgentEnv -from flow.envs.base_env import Env +from flow.envs.base import Env from flow.utils.exceptions import FatalFlowError diff --git a/tests/fast_tests/test_environment_base_class.py b/tests/fast_tests/test_environment_base_class.py index 7d4d554352..a699a03e02 100644 --- a/tests/fast_tests/test_environment_base_class.py +++ b/tests/fast_tests/test_environment_base_class.py @@ -7,7 +7,7 @@ from flow.controllers.routing_controllers import ContinuousRouter from flow.controllers.car_following_models import IDMController from flow.controllers import RLController -from flow.envs.loop.loop_accel import ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import ADDITIONAL_ENV_PARAMS from flow.utils.exceptions import FatalFlowError from flow.envs import Env, TestEnv @@ -102,7 +102,7 @@ def test_emission(self): class TestApplyingActionsWithSumo(unittest.TestCase): """ Tests the apply_acceleration, apply_lane_change, and choose_routes - functions in base_env.py + functions in base.py """ def setUp(self): diff --git a/tests/fast_tests/test_environments.py b/tests/fast_tests/test_environments.py index 5a08030664..ce341614f3 100644 --- a/tests/fast_tests/test_environments.py +++ b/tests/fast_tests/test_environments.py @@ -12,7 +12,7 @@ from flow.scenarios.merge import ADDITIONAL_NET_PARAMS as MERGE_PARAMS from flow.envs import LaneChangeAccelEnv, LaneChangeAccelPOEnv, AccelEnv, \ WaveAttenuationEnv, WaveAttenuationPOEnv, WaveAttenuationMergePOEnv, \ - TestEnv, DesiredVelocityEnv, BottleneckEnv, BottleNeckAccelEnv + TestEnv, BottleneckDesiredVelocityEnv, BottleneckEnv, BottleneckAccelEnv from flow.envs.loop.wave_attenuation import v_eq_max_function @@ -720,7 +720,7 @@ def reward_fn(*_): class TestBottleneckEnv(unittest.TestCase): - """Tests the BottleneckEnv environment in flow/envs/bottleneck_env.py""" + """Tests the BottleneckEnv environment in flow/envs/bottleneck.py""" def setUp(self): self.sim_params = SumoParams(sim_step=0.5, restart_instance=True) @@ -795,7 +795,7 @@ def test_observation_action_space(self): class TestBottleneckAccelEnv(unittest.TestCase): - """Tests BottleneckAccelEnv in flow/envs/bottleneck_env.py.""" + """Tests BottleneckAccelEnv in flow/envs/bottleneck.py.""" def setUp(self): self.sim_params = SumoParams(sim_step=0.5, restart_instance=True) @@ -824,7 +824,7 @@ def setUp(self): vehicles=vehicles, net_params=net_params) - self.env = BottleNeckAccelEnv( + self.env = BottleneckAccelEnv( env_params, self.sim_params, self.scenario) self.env.reset() @@ -836,7 +836,7 @@ def test_additional_env_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - env_class=BottleNeckAccelEnv, + env_class=BottleneckAccelEnv, sim_params=self.sim_params, scenario=self.scenario, additional_params={ @@ -862,9 +862,10 @@ def test_observation_action_space(self): ) -class TestDesiredVelocityEnv(unittest.TestCase): +class TestBottleneckDesiredVelocityEnv(unittest.TestCase): - """Tests the DesiredVelocityEnv environment in flow/envs/bottleneck.py""" + """Tests the BottleneckDesiredVelocityEnv environment in + flow/envs/bottleneck.py""" def test_reset_inflows(self): """Tests that the inflow change within the expected range when calling @@ -917,7 +918,7 @@ def test_reset_inflows(self): vehicles=vehicles, net_params=net_params) - env = DesiredVelocityEnv(env_params, sim_params, scenario) + env = BottleneckDesiredVelocityEnv(env_params, sim_params, scenario) # reset the environment and get a new inflow rate env.reset() diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index 61c02b9cc8..1957fa7b4a 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -14,8 +14,8 @@ SumoCarFollowingParams from flow.core.params import TrafficLightParams from flow.core.params import VehicleParams -from flow.envs.green_wave_env import GreenWaveTestEnv -from flow.envs.loop.loop_accel import AccelEnv +from flow.envs.traffic_light_grid import GreenWaveTestEnv +from flow.envs.loop.accel import AccelEnv from flow.scenarios.figure_eight import Figure8Scenario from flow.scenarios.grid import SimpleGridScenario from flow.scenarios.highway import HighwayScenario diff --git a/tests/slow_tests/test_benchmarks.py b/tests/slow_tests/test_benchmarks.py index e2038a3068..96174b82cf 100644 --- a/tests/slow_tests/test_benchmarks.py +++ b/tests/slow_tests/test_benchmarks.py @@ -84,7 +84,7 @@ def ray_runner(self, num_runs, flow_params, version): def test_bottleneck0(self): """ Tests flow/benchmark/baselines/bottleneck0.py - env_name='DesiredVelocityEnv', + env_name='BottleneckDesiredVelocityEnv', """ # run the bottleneck to make sure it runs self.ray_runner(1, bottleneck0.flow_params, 0) @@ -140,7 +140,7 @@ def test_figure_eight2(self): def test_grid0(self): """ Tests flow/benchmark/baselines/grid0.py - env_name='PO_TrafficLightGridEnv', + env_name='TrafficLightGridPOEnv', """ # run the bottleneck to make sure it runs self.ray_runner(1, grid0.flow_params, 0) diff --git a/tests/stress_tests/stress_test_start.py b/tests/stress_tests/stress_test_start.py index f60f28f17c..c7b4a5d05f 100644 --- a/tests/stress_tests/stress_test_start.py +++ b/tests/stress_tests/stress_test_start.py @@ -3,7 +3,7 @@ from flow.core.params import SumoParams, EnvParams, \ InitialConfig, NetParams from flow.core.params import VehicleParams -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS import ray diff --git a/tutorials/tutorial01_sumo.ipynb b/tutorials/tutorial01_sumo.ipynb index 9e6e438fe4..849e29f06c 100644 --- a/tutorials/tutorial01_sumo.ipynb +++ b/tutorials/tutorial01_sumo.ipynb @@ -227,7 +227,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.loop_accel import AccelEnv" + "from flow.envs.loop.accel import AccelEnv" ] }, { @@ -273,7 +273,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.loop_accel import ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.loop.accel import ADDITIONAL_ENV_PARAMS\n", "\n", "print(ADDITIONAL_ENV_PARAMS)" ] diff --git a/tutorials/tutorial02_aimsun.ipynb b/tutorials/tutorial02_aimsun.ipynb index f8b52dbe2e..97fc59df5b 100644 --- a/tutorials/tutorial02_aimsun.ipynb +++ b/tutorials/tutorial02_aimsun.ipynb @@ -235,7 +235,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.loop_accel import AccelEnv" + "from flow.envs.loop.accel import AccelEnv" ] }, { @@ -281,7 +281,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.loop_accel import ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.loop.accel import ADDITIONAL_ENV_PARAMS\n", "\n", "print(ADDITIONAL_ENV_PARAMS)" ] diff --git a/tutorials/tutorial06_scenarios.ipynb b/tutorials/tutorial06_scenarios.ipynb index a5ef1ab350..de03227c07 100644 --- a/tutorials/tutorial06_scenarios.ipynb +++ b/tutorials/tutorial06_scenarios.ipynb @@ -409,7 +409,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", "\n", "env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS)" ] diff --git a/tutorials/tutorial08_network_templates.ipynb b/tutorials/tutorial08_network_templates.ipynb index 4c3f59ec63..f296e3578b 100644 --- a/tutorials/tutorial08_network_templates.ipynb +++ b/tutorials/tutorial08_network_templates.ipynb @@ -175,7 +175,7 @@ "\u001b[0;31mFatalTraCIError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;31m# run the simulation for 1000 steps\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0mexp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mExperiment\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0menv\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0menv\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 18\u001b[0;31m \u001b[0m_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mexp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1000\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m~/Documents/flow/flow/core/experiment.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, num_runs, num_steps, rl_actions, convert_to_csv)\u001b[0m\n\u001b[1;32m 104\u001b[0m \u001b[0mstate\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0menv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mj\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnum_steps\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 106\u001b[0;31m \u001b[0mstate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreward\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0m_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0menv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrl_actions\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstate\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 107\u001b[0m vel[j] = np.mean(\n\u001b[1;32m 108\u001b[0m self.env.k.vehicle.get_speed(self.env.k.vehicle.get_ids()))\n", - "\u001b[0;32m~/Documents/flow/flow/envs/base_env.py\u001b[0m in \u001b[0;36mstep\u001b[0;34m(self, rl_actions)\u001b[0m\n\u001b[1;32m 325\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 326\u001b[0m \u001b[0;31m# advance the simulation in the simulator by one step\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 327\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulation\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulation_step\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 328\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[0;31m# store new observations in the vehicles and traffic lights class\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m~/Documents/flow/flow/envs/base.py\u001b[0m in \u001b[0;36mstep\u001b[0;34m(self, rl_actions)\u001b[0m\n\u001b[1;32m 325\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 326\u001b[0m \u001b[0;31m# advance the simulation in the simulator by one step\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 327\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mk\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulation\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulation_step\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 328\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 329\u001b[0m \u001b[0;31m# store new observations in the vehicles and traffic lights class\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/Documents/flow/flow/core/kernel/simulation/traci.py\u001b[0m in \u001b[0;36msimulation_step\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 54\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0msimulation_step\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 55\u001b[0m \u001b[0;34m\"\"\"See parent class.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 56\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkernel_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msimulationStep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 57\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 58\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mupdate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreset\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/traci/connection.py\u001b[0m in \u001b[0;36msimulationStep\u001b[0;34m(self, step)\u001b[0m\n\u001b[1;32m 273\u001b[0m self._string += struct.pack(\"!BBi\", 1 +\n\u001b[1;32m 274\u001b[0m 1 + 4, tc.CMD_SIMSTEP, step)\n\u001b[0;32m--> 275\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_sendExact\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 276\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0msubscriptionResults\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_subscriptionMapping\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 277\u001b[0m \u001b[0msubscriptionResults\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python3.6/dist-packages/traci/connection.py\u001b[0m in \u001b[0;36m_sendExact\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 95\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_socket\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 96\u001b[0m \u001b[0;32mdel\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_socket\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 97\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mFatalTraCIError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"connection closed by SUMO\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 98\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mcommand\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_queue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 99\u001b[0m \u001b[0mprefix\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"!BBB\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", diff --git a/tutorials/tutorial10_controllers.ipynb b/tutorials/tutorial10_controllers.ipynb index b26dddad65..aba680bd84 100644 --- a/tutorials/tutorial10_controllers.ipynb +++ b/tutorials/tutorial10_controllers.ipynb @@ -23,7 +23,7 @@ "\n", "### 1.1 BaseController\n", "\n", - "Flow's `BaseController` class is an abstract class to use when implementing longitudinal controllers. It includes failsafe methods and the `get_action` method called by Flow's `core.base_env` module. `get_action` adds noise to actions and runs failsafes, if specified. `BaseController` does not implement `get_accel`; that method should be implemented in any controllers that are subclasses of `BaseController`. \n", + "Flow's `BaseController` class is an abstract class to use when implementing longitudinal controllers. It includes failsafe methods and the `get_action` method called by Flow's `core.base` module. `get_action` adds noise to actions and runs failsafes, if specified. `BaseController` does not implement `get_accel`; that method should be implemented in any controllers that are subclasses of `BaseController`. \n", "\n", "As such, any longitudinal controller must import `BaseController`. We also import NumPy in order to use some mathematical functions." ] diff --git a/tutorials/tutorial11_traffic_lights.ipynb b/tutorials/tutorial11_traffic_lights.ipynb index 1359d97f81..783d1b1494 100644 --- a/tutorials/tutorial11_traffic_lights.ipynb +++ b/tutorials/tutorial11_traffic_lights.ipynb @@ -18,8 +18,8 @@ "* Experiment script for RL: `examples/rllab/green_wave.py`\n", "* Experiment script for non-RL: `examples/sumo/grid.py`\n", "* Scenario: `grid.py` (class SimpleGridScenario)\n", - "* Environment for RL: `green_wave_env.py` (class TrafficLightGridEnv)\n", - "* Environment for non-RL: `loop_accel.py` (class AccelEnv)\n", + "* Environment for RL: `traffic_light_grid.py` (class TrafficLightGridEnv)\n", + "* Environment for non-RL: `accel.py` (class AccelEnv)\n", "\n", "There are two main classes of traffic lights that Sumo supports: actuated and static traffic lights. This tutorial will cover both types. Over the course of this tutorial, we'll discuss 4 different types of traffic lights to introduce into your road network: \n", "\n", diff --git a/tutorials/tutorial12_inflows.ipynb b/tutorials/tutorial12_inflows.ipynb index 2572f712f2..93c794b288 100644 --- a/tutorials/tutorial12_inflows.ipynb +++ b/tutorials/tutorial12_inflows.ipynb @@ -171,7 +171,7 @@ "outputs": [], "source": [ "from flow.core.params import SumoParams, EnvParams, InitialConfig\n", - "from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", "from flow.core.experiment import Experiment\n", "\n", "sumo_params = SumoParams(render=True,\n", From 55156a7d206e22672eb1b88be787d06932ecdf06 Mon Sep 17 00:00:00 2001 From: nathanlct Date: Fri, 12 Jul 2019 00:23:54 -0700 Subject: [PATCH 02/23] change base_scenario.py to base.py for consistency --- flow/core/kernel/scenario/base.py | 2 +- flow/envs/base.py | 4 ++-- flow/scenarios/__init__.py | 2 +- flow/scenarios/{base_scenario.py => base.py} | 0 flow/scenarios/bay_bridge.py | 2 +- flow/scenarios/bay_bridge_toll.py | 2 +- flow/scenarios/bottleneck.py | 2 +- flow/scenarios/figure_eight.py | 2 +- flow/scenarios/grid.py | 2 +- flow/scenarios/highway.py | 2 +- flow/scenarios/loop.py | 2 +- flow/scenarios/loop_merge.py | 2 +- flow/scenarios/merge.py | 2 +- flow/scenarios/minicity.py | 2 +- flow/scenarios/multi_loop.py | 2 +- tests/fast_tests/test_scenario_base_class.py | 4 ++-- 16 files changed, 17 insertions(+), 17 deletions(-) rename flow/scenarios/{base_scenario.py => base.py} (100%) diff --git a/flow/core/kernel/scenario/base.py b/flow/core/kernel/scenario/base.py index 06774ad57f..795ea555ec 100644 --- a/flow/core/kernel/scenario/base.py +++ b/flow/core/kernel/scenario/base.py @@ -17,7 +17,7 @@ class KernelScenario(object): components needed to simulate a traffic network. This may include network creating configuration files that support the generating of certain traffic networks in a simulator (e.g. sumo), or may be as simple as passing network - features from the scenario class (see flow/scenarios/base_scenario.py) and + features from the scenario class (see flow/scenarios/base.py) and transferring them to the simulator kernel later on. In addition to generating files for network initialization, the scenario diff --git a/flow/envs/base.py b/flow/envs/base.py index aef6c75338..ba0ddfd003 100755 --- a/flow/envs/base.py +++ b/flow/envs/base.py @@ -62,7 +62,7 @@ class Env(*classdef): sim_params : flow.core.params.SimParams see flow/core/params.py scenario : flow.scenarios.Scenario - see flow/scenarios/base_scenario.py + see flow/scenarios/base.py simulator : str the simulator used, one of {'traci', 'aimsun'} k : flow.core.kernel.Kernel @@ -107,7 +107,7 @@ def __init__(self, env_params, sim_params, scenario, simulator='traci'): sim_params : flow.core.params.SimParams see flow/core/params.py scenario : flow.scenarios.Scenario - see flow/scenarios/base_scenario.py + see flow/scenarios/base.py simulator : str the simulator used, one of {'traci', 'aimsun'}. Defaults to 'traci' diff --git a/flow/scenarios/__init__.py b/flow/scenarios/__init__.py index d4929f4fa7..f4001060a6 100644 --- a/flow/scenarios/__init__.py +++ b/flow/scenarios/__init__.py @@ -1,7 +1,7 @@ """Contains all available scenarios in Flow.""" # base scenario class -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario # custom scenarios from flow.scenarios.bay_bridge import BayBridgeScenario diff --git a/flow/scenarios/base_scenario.py b/flow/scenarios/base.py similarity index 100% rename from flow/scenarios/base_scenario.py rename to flow/scenarios/base.py diff --git a/flow/scenarios/bay_bridge.py b/flow/scenarios/bay_bridge.py index 7b09448c8c..818f431bc0 100644 --- a/flow/scenarios/bay_bridge.py +++ b/flow/scenarios/bay_bridge.py @@ -1,6 +1,6 @@ """Contains the Bay Bridge scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario # Use this to ensure that vehicles are only placed in the edges of the Bay # Bridge moving from Oakland to San Francisco. diff --git a/flow/scenarios/bay_bridge_toll.py b/flow/scenarios/bay_bridge_toll.py index a3c8f4fad8..fb06dd0598 100644 --- a/flow/scenarios/bay_bridge_toll.py +++ b/flow/scenarios/bay_bridge_toll.py @@ -1,6 +1,6 @@ """Contains the Bay Bridge toll scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario # Use this to ensure that vehicles are only placed in the edges of the Bay # Bridge moving from Oakland to San Francisco. diff --git a/flow/scenarios/bottleneck.py b/flow/scenarios/bottleneck.py index 1c5226a258..a9df6f98eb 100644 --- a/flow/scenarios/bottleneck.py +++ b/flow/scenarios/bottleneck.py @@ -2,7 +2,7 @@ from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario import numpy as np ADDITIONAL_NET_PARAMS = { diff --git a/flow/scenarios/figure_eight.py b/flow/scenarios/figure_eight.py index ed3567cd32..9cf3d72e73 100755 --- a/flow/scenarios/figure_eight.py +++ b/flow/scenarios/figure_eight.py @@ -5,7 +5,7 @@ from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario ADDITIONAL_NET_PARAMS = { # radius of the circular components diff --git a/flow/scenarios/grid.py b/flow/scenarios/grid.py index 0ca786bbee..8b938c56df 100644 --- a/flow/scenarios/grid.py +++ b/flow/scenarios/grid.py @@ -1,6 +1,6 @@ """Contains the grid scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams from collections import defaultdict diff --git a/flow/scenarios/highway.py b/flow/scenarios/highway.py index 6c412a6861..c68969e713 100644 --- a/flow/scenarios/highway.py +++ b/flow/scenarios/highway.py @@ -1,6 +1,6 @@ """Contains the highway scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams import numpy as np diff --git a/flow/scenarios/loop.py b/flow/scenarios/loop.py index 84411b767d..51ee2d04c3 100755 --- a/flow/scenarios/loop.py +++ b/flow/scenarios/loop.py @@ -1,6 +1,6 @@ """Contains the ring road scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams from numpy import pi, sin, cos, linspace diff --git a/flow/scenarios/loop_merge.py b/flow/scenarios/loop_merge.py index 0c4d52e9d9..cc275f2f4b 100644 --- a/flow/scenarios/loop_merge.py +++ b/flow/scenarios/loop_merge.py @@ -1,6 +1,6 @@ """Contains the loop merge scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams from numpy import pi, sin, cos, linspace diff --git a/flow/scenarios/merge.py b/flow/scenarios/merge.py index f34124ac33..b9f8497343 100644 --- a/flow/scenarios/merge.py +++ b/flow/scenarios/merge.py @@ -1,6 +1,6 @@ """Contains the merge scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams from numpy import pi, sin, cos diff --git a/flow/scenarios/minicity.py b/flow/scenarios/minicity.py index fd92c98208..661c92e691 100644 --- a/flow/scenarios/minicity.py +++ b/flow/scenarios/minicity.py @@ -2,7 +2,7 @@ from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario import numpy as np from numpy import linspace, pi, sin, cos diff --git a/flow/scenarios/multi_loop.py b/flow/scenarios/multi_loop.py index 06ba0213d0..b9a9470438 100644 --- a/flow/scenarios/multi_loop.py +++ b/flow/scenarios/multi_loop.py @@ -1,6 +1,6 @@ """Contains the ring road scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams from numpy import pi, sin, cos, linspace, ceil, sqrt diff --git a/tests/fast_tests/test_scenario_base_class.py b/tests/fast_tests/test_scenario_base_class.py index b1c71a2acd..34361f6779 100644 --- a/tests/fast_tests/test_scenario_base_class.py +++ b/tests/fast_tests/test_scenario_base_class.py @@ -94,7 +94,7 @@ def test_get_edge(self): class TestEvenStartPos(unittest.TestCase): """ - Tests the function gen_even_start_pos in base_scenario.py. This function + Tests the function gen_even_start_pos in scenarios/base.py. This function can be used on any scenario subclass, and therefore may be tested on any of these classes. In order to perform this testing, replace the scenario in setUp() with the scenario to be tested. @@ -492,7 +492,7 @@ def test_even_start_pos_internal(self): class TestRandomStartPos(unittest.TestCase): """ - Tests the function gen_random_start_pos in base_scenario.py. + Tests the function gen_random_start_pos in scenarios/base.py. """ def setUp_gen_start_pos(self, initial_config=InitialConfig()): From 3ffb685b325fee925719ce5616dc62c213373cbf Mon Sep 17 00:00:00 2001 From: nathanlct Date: Fri, 12 Jul 2019 00:29:05 -0700 Subject: [PATCH 03/23] change WaveAttenuationMergePOEnv to MergePOEnv for consistency --- examples/aimsun/merge.py | 4 ++-- examples/rllab/stabilizing_highway.py | 2 +- examples/rllib/stabilizing_highway.py | 2 +- examples/sumo/merge.py | 4 ++-- flow/benchmarks/merge0.py | 2 +- flow/benchmarks/merge1.py | 2 +- flow/benchmarks/merge2.py | 2 +- flow/envs/__init__.py | 4 ++-- flow/envs/merge.py | 2 +- tests/fast_tests/test_environments.py | 10 +++++----- tests/fast_tests/test_files/merge.json | 2 +- tests/fast_tests/test_util.py | 2 +- tests/slow_tests/test_benchmarks.py | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/aimsun/merge.py b/examples/aimsun/merge.py index 0d42bf1b65..e10dc0c4bb 100644 --- a/examples/aimsun/merge.py +++ b/examples/aimsun/merge.py @@ -9,7 +9,7 @@ from flow.core.experiment import Experiment from flow.scenarios.merge import MergeScenario, ADDITIONAL_NET_PARAMS from flow.controllers import IDMController -from flow.envs.merge import WaveAttenuationMergePOEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.merge import MergePOEnv, ADDITIONAL_ENV_PARAMS # inflow rate at the highway HIGHWAY_RATE = 2000 @@ -84,7 +84,7 @@ def merge_example(render=None): net_params=net_params, initial_config=initial_config) - env = WaveAttenuationMergePOEnv( + env = MergePOEnv( env_params, sim_params, scenario, simulator='aimsun') return Experiment(env) diff --git a/examples/rllab/stabilizing_highway.py b/examples/rllab/stabilizing_highway.py index eeb4fa2718..174f01511f 100644 --- a/examples/rllab/stabilizing_highway.py +++ b/examples/rllab/stabilizing_highway.py @@ -114,7 +114,7 @@ def run_task(_): net_params=net_params, initial_config=initial_config) - env_name = "WaveAttenuationMergePOEnv" + env_name = "MergePOEnv" pass_params = (env_name, sim_params, vehicles, env_params, net_params, initial_config, scenario) diff --git a/examples/rllib/stabilizing_highway.py b/examples/rllib/stabilizing_highway.py index 772ff2408b..74221cd19f 100644 --- a/examples/rllib/stabilizing_highway.py +++ b/examples/rllib/stabilizing_highway.py @@ -94,7 +94,7 @@ exp_tag="stabilizing_open_network_merges", # name of the flow environment the experiment is running on - env_name="WaveAttenuationMergePOEnv", + env_name="MergePOEnv", # name of the scenario class the experiment is running on scenario="MergeScenario", diff --git a/examples/sumo/merge.py b/examples/sumo/merge.py index 348764bb30..2fd9281e1f 100644 --- a/examples/sumo/merge.py +++ b/examples/sumo/merge.py @@ -11,7 +11,7 @@ from flow.core.experiment import Experiment from flow.scenarios.merge import MergeScenario, ADDITIONAL_NET_PARAMS from flow.controllers import IDMController -from flow.envs.merge import WaveAttenuationMergePOEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.merge import MergePOEnv, ADDITIONAL_ENV_PARAMS # inflow rate at the highway FLOW_RATE = 2000 @@ -88,7 +88,7 @@ def merge_example(render=None): net_params=net_params, initial_config=initial_config) - env = WaveAttenuationMergePOEnv(env_params, sim_params, scenario) + env = MergePOEnv(env_params, sim_params, scenario) return Experiment(env) diff --git a/flow/benchmarks/merge0.py b/flow/benchmarks/merge0.py index 7b69194fc8..47eb57e14f 100644 --- a/flow/benchmarks/merge0.py +++ b/flow/benchmarks/merge0.py @@ -76,7 +76,7 @@ exp_tag="merge_0", # name of the flow environment the experiment is running on - env_name="WaveAttenuationMergePOEnv", + env_name="MergePOEnv", # name of the scenario class the experiment is running on scenario="MergeScenario", diff --git a/flow/benchmarks/merge1.py b/flow/benchmarks/merge1.py index 103ec47d9d..894395a1a0 100644 --- a/flow/benchmarks/merge1.py +++ b/flow/benchmarks/merge1.py @@ -76,7 +76,7 @@ exp_tag="merge_1", # name of the flow environment the experiment is running on - env_name="WaveAttenuationMergePOEnv", + env_name="MergePOEnv", # name of the scenario class the experiment is running on scenario="MergeScenario", diff --git a/flow/benchmarks/merge2.py b/flow/benchmarks/merge2.py index 243714c778..26309f03e2 100644 --- a/flow/benchmarks/merge2.py +++ b/flow/benchmarks/merge2.py @@ -76,7 +76,7 @@ exp_tag="merge_2", # name of the flow environment the experiment is running on - env_name="WaveAttenuationMergePOEnv", + env_name="MergePOEnv", # name of the scenario class the experiment is running on scenario="MergeScenario", diff --git a/flow/envs/__init__.py b/flow/envs/__init__.py index c07362a853..a5ed79b111 100755 --- a/flow/envs/__init__.py +++ b/flow/envs/__init__.py @@ -10,13 +10,13 @@ from flow.envs.loop.accel import AccelEnv from flow.envs.loop.wave_attenuation import WaveAttenuationEnv, \ WaveAttenuationPOEnv -from flow.envs.merge import WaveAttenuationMergePOEnv +from flow.envs.merge import MergePOEnv from flow.envs.test import TestEnv __all__ = [ 'Env', 'AccelEnv', 'LaneChangeAccelEnv', 'LaneChangeAccelPOEnv', 'GreenWaveTestEnv', 'GreenWaveTestEnv', - 'WaveAttenuationMergePOEnv', 'BottleneckEnv', + 'MergePOEnv', 'BottleneckEnv', 'BottleneckAccelEnv', 'WaveAttenuationEnv', 'WaveAttenuationPOEnv', 'TrafficLightGridEnv', 'TrafficLightGridPOEnv', 'BottleneckDesiredVelocityEnv', 'TestEnv', 'BayBridgeEnv', diff --git a/flow/envs/merge.py b/flow/envs/merge.py index de4c92b7b0..362763131d 100644 --- a/flow/envs/merge.py +++ b/flow/envs/merge.py @@ -25,7 +25,7 @@ } -class WaveAttenuationMergePOEnv(Env): +class MergePOEnv(Env): """Partially observable merge environment. This environment is used to train autonomous vehicles to attenuate the diff --git a/tests/fast_tests/test_environments.py b/tests/fast_tests/test_environments.py index ce341614f3..ea09b010e7 100644 --- a/tests/fast_tests/test_environments.py +++ b/tests/fast_tests/test_environments.py @@ -11,7 +11,7 @@ from flow.scenarios.loop import ADDITIONAL_NET_PARAMS as LOOP_PARAMS from flow.scenarios.merge import ADDITIONAL_NET_PARAMS as MERGE_PARAMS from flow.envs import LaneChangeAccelEnv, LaneChangeAccelPOEnv, AccelEnv, \ - WaveAttenuationEnv, WaveAttenuationPOEnv, WaveAttenuationMergePOEnv, \ + WaveAttenuationEnv, WaveAttenuationPOEnv, MergePOEnv, \ TestEnv, BottleneckDesiredVelocityEnv, BottleneckEnv, BottleneckAccelEnv from flow.envs.loop.wave_attenuation import v_eq_max_function @@ -597,7 +597,7 @@ def test_reward(self): ) -class TestWaveAttenuationMergePOEnv(unittest.TestCase): +class TestMergePOEnv(unittest.TestCase): def setUp(self): vehicles = VehicleParams() @@ -628,7 +628,7 @@ def test_additional_env_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - env_class=WaveAttenuationMergePOEnv, + env_class=MergePOEnv, sim_params=self.sim_params, scenario=self.scenario, additional_params={ @@ -643,7 +643,7 @@ def test_additional_env_params(self): def test_observation_action_space(self): """Tests the observation and action spaces upon initialization.""" # create the environment - env = WaveAttenuationMergePOEnv( + env = MergePOEnv( sim_params=self.sim_params, scenario=self.scenario, env_params=self.env_params @@ -665,7 +665,7 @@ def test_observed(self): """Ensures that the observed ids are returning the correct vehicles.""" self.assertTrue( test_observed( - env_class=WaveAttenuationMergePOEnv, + env_class=MergePOEnv, sim_params=self.sim_params, scenario=self.scenario, env_params=self.env_params, diff --git a/tests/fast_tests/test_files/merge.json b/tests/fast_tests/test_files/merge.json index 04a993a2bd..71f5cc9ab9 100644 --- a/tests/fast_tests/test_files/merge.json +++ b/tests/fast_tests/test_files/merge.json @@ -12,7 +12,7 @@ "sims_per_step": 2, "warmup_steps": 0 }, - "env_name": "WaveAttenuationMergePOEnv", + "env_name": "MergePOEnv", "exp_tag": "merge_0", "initial": { "additional_params": {}, diff --git a/tests/fast_tests/test_util.py b/tests/fast_tests/test_util.py index a9f01302bc..b8088c78ca 100644 --- a/tests/fast_tests/test_util.py +++ b/tests/fast_tests/test_util.py @@ -218,7 +218,7 @@ def test_encoder_and_get_flow_params(self): flow_params = dict( exp_tag="merge_0", - env_name="WaveAttenuationMergePOEnv", + env_name="MergePOEnv", scenario="MergeScenario", sim=SumoParams( restart_instance=True, diff --git a/tests/slow_tests/test_benchmarks.py b/tests/slow_tests/test_benchmarks.py index 96174b82cf..4c4b1d1203 100644 --- a/tests/slow_tests/test_benchmarks.py +++ b/tests/slow_tests/test_benchmarks.py @@ -159,7 +159,7 @@ def test_grid1(self): def test_merge0(self): """ Tests flow/benchmark/baselines/merge{0,1,2}.py - env_name='WaveAttenuationMergePOEnv', + env_name='MergePOEnv', """ # run the bottleneck to make sure it runs self.ray_runner(1, merge0.flow_params, 0) From 5a6f57632e364c1702e8e971e8135094566eed2f Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sun, 18 Aug 2019 16:48:51 -0700 Subject: [PATCH 04/23] changed "loop" to "ring" in envs --- docs/source/examples.rst | 2 +- examples/aimsun/grid.py | 2 +- examples/aimsun/stabilizing_the_ring.py | 2 +- examples/aimsun/sugiyama.py | 2 +- examples/rllab/stabilizing_the_ring.py | 2 +- examples/sumo/figure_eight.py | 2 +- examples/sumo/highway.py | 2 +- examples/sumo/loop_merge.py | 2 +- examples/sumo/minicity.py | 2 +- examples/sumo/sugiyama.py | 2 +- flow/core/kernel/scenario/data.json | 889 ++++++++++++++++++ flow/envs/__init__.py | 6 +- flow/envs/{loop => ring}/__init__.py | 0 flow/envs/{loop => ring}/accel.py | 0 flow/envs/{loop => ring}/lane_change_accel.py | 2 +- flow/envs/{loop => ring}/wave_attenuation.py | 0 .../grid/grid_trafficlight_timing.py | 240 +++++ flow/multiagent_envs/loop/loop_accel.py | 2 +- .../fast_tests/test_environment_base_class.py | 2 +- tests/fast_tests/test_environments.py | 2 +- tests/setup_scripts.py | 2 +- tests/stress_tests/stress_test_start.py | 2 +- tutorials/tutorial01_sumo.ipynb | 4 +- tutorials/tutorial02_aimsun.ipynb | 4 +- tutorials/tutorial06_scenarios.ipynb | 2 +- tutorials/tutorial12_inflows.ipynb | 2 +- 26 files changed, 1154 insertions(+), 25 deletions(-) create mode 100644 flow/core/kernel/scenario/data.json rename flow/envs/{loop => ring}/__init__.py (100%) rename flow/envs/{loop => ring}/accel.py (100%) rename flow/envs/{loop => ring}/lane_change_accel.py (99%) rename flow/envs/{loop => ring}/wave_attenuation.py (100%) create mode 100644 flow/multiagent_envs/grid/grid_trafficlight_timing.py diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 590acd2c95..1f4e85a178 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -19,7 +19,7 @@ A few points of clarification: Figure Eight ------------ -The figure-eight is a closed-loop version of an intersection. The goal is to maximize +The figure-eight is a closed-ring version of an intersection. The goal is to maximize the system-wide velocity for fourteen vehicles, which necessitates spacing the vehicles so that they don't run into conflicts at the merging points. The scenario is fully observed: all vehicles diff --git a/examples/aimsun/grid.py b/examples/aimsun/grid.py index 0b2028f028..902727a9e8 100644 --- a/examples/aimsun/grid.py +++ b/examples/aimsun/grid.py @@ -3,7 +3,7 @@ from flow.core.params import AimsunParams, EnvParams, InitialConfig, NetParams from flow.core.params import VehicleParams from flow.core.params import TrafficLightParams -from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.grid import SimpleGridScenario diff --git a/examples/aimsun/stabilizing_the_ring.py b/examples/aimsun/stabilizing_the_ring.py index e97c559e15..68a40c9ceb 100644 --- a/examples/aimsun/stabilizing_the_ring.py +++ b/examples/aimsun/stabilizing_the_ring.py @@ -6,7 +6,7 @@ from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy -from flow.scenarios.loop import LoopScenario +from flow.scenarios.ring import LoopScenario from flow.controllers import RLController, IDMController, ContinuousRouter from flow.core.params import VehicleParams from flow.core.params import AimsunParams, EnvParams, NetParams, InitialConfig diff --git a/examples/aimsun/sugiyama.py b/examples/aimsun/sugiyama.py index d5fd7b6749..231526ac66 100644 --- a/examples/aimsun/sugiyama.py +++ b/examples/aimsun/sugiyama.py @@ -8,7 +8,7 @@ from flow.core.params import AimsunParams, EnvParams, InitialConfig, NetParams from flow.core.params import VehicleParams from flow.envs import TestEnv -from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS +from flow.scenarios.ring import LoopScenario, ADDITIONAL_NET_PARAMS def sugiyama_example(render=None): diff --git a/examples/rllab/stabilizing_the_ring.py b/examples/rllab/stabilizing_the_ring.py index 7a3c2614ce..3c3b7064a2 100644 --- a/examples/rllab/stabilizing_the_ring.py +++ b/examples/rllab/stabilizing_the_ring.py @@ -6,7 +6,7 @@ from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline from rllab.policies.gaussian_gru_policy import GaussianGRUPolicy -from flow.scenarios.loop import LoopScenario +from flow.scenarios.ring import LoopScenario from flow.controllers import RLController, IDMController, ContinuousRouter from flow.core.params import VehicleParams from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig diff --git a/examples/sumo/figure_eight.py b/examples/sumo/figure_eight.py index f978673067..cef0b4d647 100755 --- a/examples/sumo/figure_eight.py +++ b/examples/sumo/figure_eight.py @@ -9,7 +9,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, \ SumoCarFollowingParams from flow.core.params import VehicleParams -from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.figure_eight import Figure8Scenario, ADDITIONAL_NET_PARAMS diff --git a/examples/sumo/highway.py b/examples/sumo/highway.py index e6971e38b5..9476902e7e 100644 --- a/examples/sumo/highway.py +++ b/examples/sumo/highway.py @@ -5,7 +5,7 @@ from flow.core.params import SumoParams, EnvParams, \ NetParams, InitialConfig, InFlows from flow.core.params import VehicleParams -from flow.envs.loop.lane_change_accel import LaneChangeAccelEnv, \ +from flow.envs.ring.lane_change_accel import LaneChangeAccelEnv, \ ADDITIONAL_ENV_PARAMS from flow.scenarios.highway import HighwayScenario, ADDITIONAL_NET_PARAMS diff --git a/examples/sumo/loop_merge.py b/examples/sumo/loop_merge.py index 8bd8ca3e4a..8a80d212ed 100755 --- a/examples/sumo/loop_merge.py +++ b/examples/sumo/loop_merge.py @@ -6,7 +6,7 @@ from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams -from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.loop_merge import TwoLoopsOneMergingScenario, \ ADDITIONAL_NET_PARAMS diff --git a/examples/sumo/minicity.py b/examples/sumo/minicity.py index 084d16c57a..d6f4672452 100644 --- a/examples/sumo/minicity.py +++ b/examples/sumo/minicity.py @@ -5,7 +5,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig from flow.core.params import SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams -from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.minicity import MiniCityScenario from flow.controllers.routing_controllers import MinicityRouter import numpy as np diff --git a/examples/sumo/sugiyama.py b/examples/sumo/sugiyama.py index 8268342aeb..fc0f7a1880 100755 --- a/examples/sumo/sugiyama.py +++ b/examples/sumo/sugiyama.py @@ -8,7 +8,7 @@ from flow.core.params import SumoParams, EnvParams, \ InitialConfig, NetParams from flow.core.params import VehicleParams -from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS diff --git a/flow/core/kernel/scenario/data.json b/flow/core/kernel/scenario/data.json new file mode 100644 index 0000000000..8879c15f77 --- /dev/null +++ b/flow/core/kernel/scenario/data.json @@ -0,0 +1,889 @@ +{ + "centroid_config_name": null, + "connections": { + "center0": [ + { + "from": "bot0_0", + "fromLane": "0", + "signal_group": 1, + "to": "bot0_1", + "toLane": "0" + }, + { + "from": "top0_1", + "fromLane": "0", + "signal_group": 1, + "to": "top0_0", + "toLane": "0" + }, + { + "from": "right0_0", + "fromLane": "0", + "signal_group": 2, + "to": "right1_0", + "toLane": "0" + }, + { + "from": "left1_0", + "fromLane": "0", + "signal_group": 2, + "to": "left0_0", + "toLane": "0" + } + ], + "center1": [ + { + "from": "bot0_1", + "fromLane": "0", + "signal_group": 1, + "to": "bot0_2", + "toLane": "0" + }, + { + "from": "top0_2", + "fromLane": "0", + "signal_group": 1, + "to": "top0_1", + "toLane": "0" + }, + { + "from": "right0_1", + "fromLane": "0", + "signal_group": 2, + "to": "right1_1", + "toLane": "0" + }, + { + "from": "left1_1", + "fromLane": "0", + "signal_group": 2, + "to": "left0_1", + "toLane": "0" + } + ], + "center2": [ + { + "from": "bot0_2", + "fromLane": "0", + "signal_group": 1, + "to": "bot0_3", + "toLane": "0" + }, + { + "from": "top0_3", + "fromLane": "0", + "signal_group": 1, + "to": "top0_2", + "toLane": "0" + }, + { + "from": "right0_2", + "fromLane": "0", + "signal_group": 2, + "to": "right1_2", + "toLane": "0" + }, + { + "from": "left1_2", + "fromLane": "0", + "signal_group": 2, + "to": "left0_2", + "toLane": "0" + } + ], + "center3": [ + { + "from": "bot1_0", + "fromLane": "0", + "signal_group": 1, + "to": "bot1_1", + "toLane": "0" + }, + { + "from": "top1_1", + "fromLane": "0", + "signal_group": 1, + "to": "top1_0", + "toLane": "0" + }, + { + "from": "right1_0", + "fromLane": "0", + "signal_group": 2, + "to": "right2_0", + "toLane": "0" + }, + { + "from": "left2_0", + "fromLane": "0", + "signal_group": 2, + "to": "left1_0", + "toLane": "0" + } + ], + "center4": [ + { + "from": "bot1_1", + "fromLane": "0", + "signal_group": 1, + "to": "bot1_2", + "toLane": "0" + }, + { + "from": "top1_2", + "fromLane": "0", + "signal_group": 1, + "to": "top1_1", + "toLane": "0" + }, + { + "from": "right1_1", + "fromLane": "0", + "signal_group": 2, + "to": "right2_1", + "toLane": "0" + }, + { + "from": "left2_1", + "fromLane": "0", + "signal_group": 2, + "to": "left1_1", + "toLane": "0" + } + ], + "center5": [ + { + "from": "bot1_2", + "fromLane": "0", + "signal_group": 1, + "to": "bot1_3", + "toLane": "0" + }, + { + "from": "top1_3", + "fromLane": "0", + "signal_group": 1, + "to": "top1_2", + "toLane": "0" + }, + { + "from": "right1_2", + "fromLane": "0", + "signal_group": 2, + "to": "right2_2", + "toLane": "0" + }, + { + "from": "left2_2", + "fromLane": "0", + "signal_group": 2, + "to": "left1_2", + "toLane": "0" + } + ] + }, + "edges": [ + { + "from": "center1", + "id": "top0_1", + "length": 300, + "priority": 78, + "to": "center0", + "type": "horizontal" + }, + { + "from": "center0", + "id": "bot0_1", + "length": 300, + "priority": 78, + "to": "center1", + "type": "horizontal" + }, + { + "from": "center2", + "id": "top0_2", + "length": 300, + "priority": 78, + "to": "center1", + "type": "horizontal" + }, + { + "from": "center1", + "id": "bot0_2", + "length": 300, + "priority": 78, + "to": "center2", + "type": "horizontal" + }, + { + "from": "center4", + "id": "top1_1", + "length": 300, + "priority": 78, + "to": "center3", + "type": "horizontal" + }, + { + "from": "center3", + "id": "bot1_1", + "length": 300, + "priority": 78, + "to": "center4", + "type": "horizontal" + }, + { + "from": "center5", + "id": "top1_2", + "length": 300, + "priority": 78, + "to": "center4", + "type": "horizontal" + }, + { + "from": "center4", + "id": "bot1_2", + "length": 300, + "priority": 78, + "to": "center5", + "type": "horizontal" + }, + { + "from": "center0", + "id": "right1_0", + "length": 300, + "priority": 78, + "to": "center3", + "type": "vertical" + }, + { + "from": "center3", + "id": "left1_0", + "length": 300, + "priority": 78, + "to": "center0", + "type": "vertical" + }, + { + "from": "center1", + "id": "right1_1", + "length": 300, + "priority": 78, + "to": "center4", + "type": "vertical" + }, + { + "from": "center4", + "id": "left1_1", + "length": 300, + "priority": 78, + "to": "center1", + "type": "vertical" + }, + { + "from": "center2", + "id": "right1_2", + "length": 300, + "priority": 78, + "to": "center5", + "type": "vertical" + }, + { + "from": "center5", + "id": "left1_2", + "length": 300, + "priority": 78, + "to": "center2", + "type": "vertical" + }, + { + "from": "bot_col_short0", + "id": "right0_0", + "length": 300, + "priority": 78, + "to": "center0", + "type": "vertical" + }, + { + "from": "center0", + "id": "left0_0", + "length": 500, + "priority": 78, + "to": "bot_col_long0", + "type": "vertical" + }, + { + "from": "top_col_short0", + "id": "left2_0", + "length": 300, + "priority": 78, + "to": "center3", + "type": "vertical" + }, + { + "from": "center3", + "id": "right2_0", + "length": 500, + "priority": 78, + "to": "top_col_long0", + "type": "vertical" + }, + { + "from": "bot_col_short1", + "id": "right0_1", + "length": 300, + "priority": 78, + "to": "center1", + "type": "vertical" + }, + { + "from": "center1", + "id": "left0_1", + "length": 500, + "priority": 78, + "to": "bot_col_long1", + "type": "vertical" + }, + { + "from": "top_col_short1", + "id": "left2_1", + "length": 300, + "priority": 78, + "to": "center4", + "type": "vertical" + }, + { + "from": "center4", + "id": "right2_1", + "length": 500, + "priority": 78, + "to": "top_col_long1", + "type": "vertical" + }, + { + "from": "bot_col_short2", + "id": "right0_2", + "length": 300, + "priority": 78, + "to": "center2", + "type": "vertical" + }, + { + "from": "center2", + "id": "left0_2", + "length": 500, + "priority": 78, + "to": "bot_col_long2", + "type": "vertical" + }, + { + "from": "top_col_short2", + "id": "left2_2", + "length": 300, + "priority": 78, + "to": "center5", + "type": "vertical" + }, + { + "from": "center5", + "id": "right2_2", + "length": 500, + "priority": 78, + "to": "top_col_long2", + "type": "vertical" + }, + { + "from": "left_row_short0", + "id": "bot0_0", + "length": 300, + "priority": 78, + "to": "center0", + "type": "horizontal" + }, + { + "from": "center0", + "id": "top0_0", + "length": 500, + "priority": 78, + "to": "left_row_long0", + "type": "horizontal" + }, + { + "from": "right_row_short0", + "id": "top0_3", + "length": 300, + "priority": 78, + "to": "center2", + "type": "horizontal" + }, + { + "from": "center2", + "id": "bot0_3", + "length": 500, + "priority": 78, + "to": "right_row_long0", + "type": "horizontal" + }, + { + "from": "left_row_short1", + "id": "bot1_0", + "length": 300, + "priority": 78, + "to": "center3", + "type": "horizontal" + }, + { + "from": "center3", + "id": "top1_0", + "length": 500, + "priority": 78, + "to": "left_row_long1", + "type": "horizontal" + }, + { + "from": "right_row_short1", + "id": "top1_3", + "length": 300, + "priority": 78, + "to": "center5", + "type": "horizontal" + }, + { + "from": "center5", + "id": "bot1_3", + "length": 500, + "priority": 78, + "to": "right_row_long1", + "type": "horizontal" + } + ], + "experiment_name": "Micro SRC Experiment 867", + "inflows": { + "_InFlows__flows": [], + "num_flows": 0 + }, + "nodes": [ + { + "id": "center0", + "radius": 6.199999999999999, + "type": "traffic_light", + "x": 0, + "y": 0 + }, + { + "id": "center1", + "radius": 6.199999999999999, + "type": "traffic_light", + "x": 300, + "y": 0 + }, + { + "id": "center2", + "radius": 6.199999999999999, + "type": "traffic_light", + "x": 600, + "y": 0 + }, + { + "id": "center3", + "radius": 6.199999999999999, + "type": "traffic_light", + "x": 0, + "y": 300 + }, + { + "id": "center4", + "radius": 6.199999999999999, + "type": "traffic_light", + "x": 300, + "y": 300 + }, + { + "id": "center5", + "radius": 6.199999999999999, + "type": "traffic_light", + "x": 600, + "y": 300 + }, + { + "id": "bot_col_short0", + "type": "priority", + "x": 0, + "y": -300 + }, + { + "id": "bot_col_long0", + "type": "priority", + "x": 0, + "y": -500 + }, + { + "id": "top_col_short0", + "type": "priority", + "x": 0, + "y": 600 + }, + { + "id": "top_col_long0", + "type": "priority", + "x": 0, + "y": 800 + }, + { + "id": "bot_col_short1", + "type": "priority", + "x": 300, + "y": -300 + }, + { + "id": "bot_col_long1", + "type": "priority", + "x": 300, + "y": -500 + }, + { + "id": "top_col_short1", + "type": "priority", + "x": 300, + "y": 600 + }, + { + "id": "top_col_long1", + "type": "priority", + "x": 300, + "y": 800 + }, + { + "id": "bot_col_short2", + "type": "priority", + "x": 600, + "y": -300 + }, + { + "id": "bot_col_long2", + "type": "priority", + "x": 600, + "y": -500 + }, + { + "id": "top_col_short2", + "type": "priority", + "x": 600, + "y": 600 + }, + { + "id": "top_col_long2", + "type": "priority", + "x": 600, + "y": 800 + }, + { + "id": "left_row_short0", + "type": "priority", + "x": -300, + "y": 0 + }, + { + "id": "left_row_long0", + "type": "priority", + "x": -500, + "y": 0 + }, + { + "id": "right_row_short0", + "type": "priority", + "x": 900, + "y": 0 + }, + { + "id": "right_row_long0", + "type": "priority", + "x": 1100, + "y": 0 + }, + { + "id": "left_row_short1", + "type": "priority", + "x": -300, + "y": 300 + }, + { + "id": "left_row_long1", + "type": "priority", + "x": -500, + "y": 300 + }, + { + "id": "right_row_short1", + "type": "priority", + "x": 900, + "y": 300 + }, + { + "id": "right_row_long1", + "type": "priority", + "x": 1100, + "y": 300 + } + ], + "osm_path": null, + "render": true, + "replication_name": "Replication 870", + "scenario_name": "Dynamic Scenario 866", + "sim_step": 0.5, + "subnetwork_name": null, + "traffic_lights": { + "_TrafficLightParams__tls_properties": { + "center0": { + "id": "center0", + "phases": [ + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "GGGrrrGGGrrr", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "yyyrrryyyrrr", + "yellow": "3" + }, + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "rrrGGGrrrGGG", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "rrryyyrrryyy", + "yellow": "3" + } + ], + "programID": 1, + "type": "static" + }, + "center1": { + "id": "center1", + "phases": [ + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "GGGrrrGGGrrr", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "yyyrrryyyrrr", + "yellow": "3" + }, + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "rrrGGGrrrGGG", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "rrryyyrrryyy", + "yellow": "3" + } + ], + "programID": 1, + "type": "static" + }, + "center2": { + "detector-gap": 0.6, + "id": "center2", + "max-gap": 3.0, + "phases": [ + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "GGGrrrGGGrrr", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "yyyrrryyyrrr", + "yellow": "3" + }, + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "rrrGGGrrrGGG", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "rrryyyrrryyy", + "yellow": "3" + } + ], + "programID": 1, + "show-detectors": true, + "type": "actuated" + }, + "center3": { + "id": "center3", + "phases": [ + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "GGGrrrGGGrrr", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "yyyrrryyyrrr", + "yellow": "3" + }, + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "rrrGGGrrrGGG", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "rrryyyrrryyy", + "yellow": "3" + } + ], + "programID": 1, + "type": "static" + }, + "center4": { + "id": "center4", + "phases": [ + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "GGGrrrGGGrrr", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "yyyrrryyyrrr", + "yellow": "3" + }, + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "rrrGGGrrrGGG", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "rrryyyrrryyy", + "yellow": "3" + } + ], + "programID": 1, + "type": "static" + }, + "center5": { + "detector-gap": 0.6, + "id": "center5", + "max-gap": 3.0, + "phases": [ + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "GGGrrrGGGrrr", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "yyyrrryyyrrr", + "yellow": "3" + }, + { + "duration": "31", + "maxDur": "45", + "minDur": "8", + "state": "rrrGGGrrrGGG", + "yellow": "3" + }, + { + "duration": "6", + "maxDur": "6", + "minDur": "3", + "state": "rrryyyrrryyy", + "yellow": "3" + } + ], + "programID": 1, + "show-detectors": true, + "type": "actuated" + } + }, + "baseline": false + }, + "types": [ + { + "id": "horizontal", + "numLanes": 1, + "speed": 35 + }, + { + "id": "vertical", + "numLanes": 1, + "speed": 35 + } + ], + "vehicle_types": [ + { + "type_params": { + "accel": 2.6, + "carFollowModel": "IDM", + "decel": 4.5, + "impatience": 0.5, + "laneChangeModel": "LC2013", + "lcCooperative": "1.0", + "lcKeepRight": "1.0", + "lcSpeedGain": "1.0", + "lcStrategic": "1.0", + "maxSpeed": 30, + "minGap": 2.5, + "sigma": 0.5, + "speedDev": 0.1, + "speedFactor": 1.0, + "tau": 1.0 + }, + "veh_id": "human" + } + ] +} \ No newline at end of file diff --git a/flow/envs/__init__.py b/flow/envs/__init__.py index a5ed79b111..0f7ecdfcc8 100755 --- a/flow/envs/__init__.py +++ b/flow/envs/__init__.py @@ -5,10 +5,10 @@ BottleneckDesiredVelocityEnv from flow.envs.traffic_light_grid import TrafficLightGridEnv, \ TrafficLightGridPOEnv, GreenWaveTestEnv -from flow.envs.loop.lane_change_accel import LaneChangeAccelEnv, \ +from flow.envs.ring.lane_change_accel import LaneChangeAccelEnv, \ LaneChangeAccelPOEnv -from flow.envs.loop.accel import AccelEnv -from flow.envs.loop.wave_attenuation import WaveAttenuationEnv, \ +from flow.envs.ring.accel import AccelEnv +from flow.envs.ring.wave_attenuation import WaveAttenuationEnv, \ WaveAttenuationPOEnv from flow.envs.merge import MergePOEnv from flow.envs.test import TestEnv diff --git a/flow/envs/loop/__init__.py b/flow/envs/ring/__init__.py similarity index 100% rename from flow/envs/loop/__init__.py rename to flow/envs/ring/__init__.py diff --git a/flow/envs/loop/accel.py b/flow/envs/ring/accel.py similarity index 100% rename from flow/envs/loop/accel.py rename to flow/envs/ring/accel.py diff --git a/flow/envs/loop/lane_change_accel.py b/flow/envs/ring/lane_change_accel.py similarity index 99% rename from flow/envs/loop/lane_change_accel.py rename to flow/envs/ring/lane_change_accel.py index 634543e091..09f7db3565 100755 --- a/flow/envs/loop/lane_change_accel.py +++ b/flow/envs/ring/lane_change_accel.py @@ -1,6 +1,6 @@ """Environments that can train both lane change and acceleration behaviors.""" -from flow.envs.loop.accel import AccelEnv +from flow.envs.ring.accel import AccelEnv from flow.core import rewards from gym.spaces.box import Box diff --git a/flow/envs/loop/wave_attenuation.py b/flow/envs/ring/wave_attenuation.py similarity index 100% rename from flow/envs/loop/wave_attenuation.py rename to flow/envs/ring/wave_attenuation.py diff --git a/flow/multiagent_envs/grid/grid_trafficlight_timing.py b/flow/multiagent_envs/grid/grid_trafficlight_timing.py new file mode 100644 index 0000000000..71f928e8e3 --- /dev/null +++ b/flow/multiagent_envs/grid/grid_trafficlight_timing.py @@ -0,0 +1,240 @@ +"""Environment for training the timinig of the traffic lights in a grid scenario.""" + +import numpy as np +from flow.core import rewards +from flow.multiagent_envs.multiagent_env import MultiEnv + + +# todo for Ashkan: This needs to be defined for multi-agent RL in grid scenario +from gym.spaces.discrete import Discrete +from gym.spaces.box import Box +from gym.spaces.tuple_space import Tuple +from flow.envs.green_wave_env import TrafficLightGridEnv + +ADDITIONAL_ENV_PARAMS = { + # minimum switch time for each traffic light (in seconds) + "switch_time": 2.0, + # whether the traffic lights should be actuated by sumo or RL + # options are "controlled" and "actuated" + "tl_type": "controlled", + # determines whether the action space is meant to be discrete or continuous + "discrete": False, +} + + + + +class MultiAgentGrid(TrafficLightGridEnv, MultiEnv): + """Grid multi agent env. + """ + + def __init__(self, env_params, sim_params, scenario, simulator='traci'): + + super().__init__(env_params, sim_params, scenario, simulator) + self.NUM_FOG_NODES = len(self.k.traffic_light.get_ids()) + self.agent_name_prefix = 'intersection' + + + @property + def action_space(self): + """See class definition.""" + if self.discrete: + # each intersection is an agent, and the action is simply 0 or 1. 0 means no change in the traffic light + # and 1 means switch the direction + return Discrete(2) + else: + return Box( + low=0, + high=1, + shape=(1,), + dtype=np.float32) + + @property + def observation_space(self): + """ + Partially and locally observed state space. + + Velocities, distance to intersections, and traffic light state. + """ + self.num_closest_vehicles_onbound = 3 # number of observed vehicles per bound + self.num_inbounds = 4 + speed = Box( + low=0, + high=1, + shape=(self.num_inbounds * self.num_closest_vehicles_onbound,), + dtype=np.float32) + dist_to_intersec = Box( + low=0, + high=1, + shape=(self.num_inbounds * self.num_closest_vehicles_onbound,), + dtype=np.float32) + traffic_lights = Box( + low=0, + high=3, + shape=(1,), # the state of this intersection. 4 possibilities. Either left-right, or top-bottom traffic is passing, or it's the yellow light between them + dtype=np.float32) + return Tuple((speed, dist_to_intersec, traffic_lights)) + + def get_state(self): + """ + Returns for the self.num_closest_vehicles_onbound number of vehicles on each bound, + closest to each traffic light, its velocity, distance to intersection. And also + returns the state of the 4 traffic lights in the intersection. This is partially observed + """ + + max_speed = max( + self.k.scenario.speed_limit(edge) + for edge in self.k.scenario.get_edge_list()) + + max_dist = max(self.scenario.short_length, self.scenario.long_length, + self.scenario.inner_length) + agent_state_dict = {} + i = 0 + for intersection, edges in self.scenario.get_node_mapping(): + i = i + 1 + agent_id = self.agent_name_prefix + str(i) + observed_vehicle_ids = self.k_closest_to_intersection_edge(edges, self.num_closest_vehicles_onbound) + + speeds = [] + dist_to_intersec = [] + traffic_light_states = [] + + for veh_id in observed_vehicle_ids: + if veh_id == 0: + dist_to_intersec.append(-1) + speeds.append(-1) + else: + dist_to_intersec.append( + (self.k.scenario.edge_length( + self.k.vehicle.get_edge(veh_id)) + - self.k.vehicle.get_position(veh_id)) / max_dist + ) + speeds.append( + self.k.vehicle.get_speed(veh_id) / max_speed + ) + + traffic_light_states_chars = self.k.traffic_light.get_state(intersection) + + + if traffic_light_states_chars == 'GrGr' : + traffic_light_states.append(1) + elif traffic_light_states_chars == 'rGrG': + traffic_light_states.append(0) + elif traffic_light_states_chars == 'yryr' : + traffic_light_states.append(2) + else: # ryry + traffic_light_states.append(3) + + + # construct the state (observation) for each agent + observation = np.array( + np.concatenate([ + speeds, dist_to_intersec, traffic_light_states # or: speeds, dist_to_intersec, self.last_change.flatten().tolist() + ])) + # observation = np.ndarray.flatten(observation) + + # each intersection is an agent, so we will make a dictionary that maps form "self.agent_name_prefix+'i'" to the state of that agent. + agent_state_dict.update({agent_id: observation}) + + return agent_state_dict + + def _apply_rl_actions(self, rl_actions): + + for agent_name in rl_actions: + action = rl_actions[agent_name] + # check if the action space is discrete + + if self.discrete: + # convert single value (Discrete) to list of 0's and 1's + action = [int(x) for x in list('{0:0b}'.format(action))] + else: + # convert values less than 0.5 to zero and above to 1. 0's indicate + # that should not switch the direction + action = action > 0.5 + agent_num = agent_name[len(self.agent_name_prefix) : len(agent_name)] # agent_id = '15' if agent_name is 'intersection15' + tl_num = int(agent_num, 10) - 1 # the index of traffic lights starts from 0 + + # check if our timer has exceeded the yellow phase, meaning it + # should switch to red + if self.currently_yellow[tl_num] == 1: # currently yellow + self.last_change[tl_num] += self.sim_step + if self.last_change[tl_num] >= self.min_switch_time: # check if our timer has exceeded the yellow phase, meaning it + # should switch to red + if self.direction[tl_num] == 0: + self.k.traffic_light.set_state( + node_id='center{}'.format(tl_num), + state="GrGr") + else: + self.k.traffic_light.set_state( + node_id='center{}'.format(tl_num), + state='rGrG') + self.currently_yellow[tl_num] = 0 + else: + if action: + if self.direction[tl_num] == 0: + self.k.traffic_light.set_state( + node_id='center{}'.format(tl_num), + state='yryr') + else: + self.k.traffic_light.set_state( + node_id='center{}'.format(tl_num), + state='ryry') + self.last_change[tl_num] = 0.0 + self.direction[tl_num] = not self.direction[tl_num] + self.currently_yellow[tl_num] = 1 + + + def compute_reward(self, rl_actions, **kwargs): + """Each agents receives a reward that is with regards + to the delay of the vehicles it observers + """ + # in the warmup steps + if rl_actions is None: + return {} + i = 0 + agent_reward_dict = {} + for intersection, edges in self.scenario.get_node_mapping(): + i = i + 1 + agent_id = self.agent_name_prefix + str(i) + + observed_vehicle_ids = self.k_closest_to_intersection_edge(edges, self.num_closest_vehicles_onbound) + # construct the reward for each agent + observed_vehicle_ids = [id for id in observed_vehicle_ids if id] + reward = np.mean(self.k.vehicle.get_speed(observed_vehicle_ids)) # or: reward = - rewards.avg_delay_specified_vehicles(self, observed_vehicle_ids) + # each intersection is an agent, so we will make a dictionary that maps form "self.agent_name_prefix+'i'" to the reward of that agent. + agent_reward_dict.update({agent_id: reward}) + + if self.env_params.evaluate: + return agent_reward_dict + else: + reward = rewards.desired_velocity(self, fail=kwargs['fail']) + return agent_reward_dict + + def additional_command(self): + pass + + def k_closest_to_intersection_edge(self, edges, k): + """ + Return the veh_id of the 4*k closest vehicles to an intersection for + each edge (k closest vehicles on each edge). + """ + if k < 0: + raise IndexError("k must be greater than 0") + ids = [] + + def sort_lambda(veh_id): + return self.get_distance_to_intersection(veh_id) + + for edge in edges: + vehicles = self.k.vehicle.get_ids_by_edge(edge) + veh_ids_per_bound = sorted( + vehicles, + key=sort_lambda + ) + if len(veh_ids_per_bound) >= k: # we have more than k vehicles, and we need to cut + ids += veh_ids_per_bound[:k] + else: # we have less than k vehicles, and we need to pad + padding = k - len(veh_ids_per_bound) + ids += (veh_ids_per_bound + [0]*padding) + + return ids diff --git a/flow/multiagent_envs/loop/loop_accel.py b/flow/multiagent_envs/loop/loop_accel.py index 2306799203..c477b8ba5b 100644 --- a/flow/multiagent_envs/loop/loop_accel.py +++ b/flow/multiagent_envs/loop/loop_accel.py @@ -2,7 +2,7 @@ import numpy as np from flow.core import rewards -from flow.envs.loop.accel import AccelEnv +from flow.envs.ring.accel import AccelEnv from flow.multiagent_envs.multiagent_env import MultiEnv diff --git a/tests/fast_tests/test_environment_base_class.py b/tests/fast_tests/test_environment_base_class.py index a699a03e02..572936c92d 100644 --- a/tests/fast_tests/test_environment_base_class.py +++ b/tests/fast_tests/test_environment_base_class.py @@ -7,7 +7,7 @@ from flow.controllers.routing_controllers import ContinuousRouter from flow.controllers.car_following_models import IDMController from flow.controllers import RLController -from flow.envs.loop.accel import ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import ADDITIONAL_ENV_PARAMS from flow.utils.exceptions import FatalFlowError from flow.envs import Env, TestEnv diff --git a/tests/fast_tests/test_environments.py b/tests/fast_tests/test_environments.py index ea09b010e7..4957c90200 100644 --- a/tests/fast_tests/test_environments.py +++ b/tests/fast_tests/test_environments.py @@ -13,7 +13,7 @@ from flow.envs import LaneChangeAccelEnv, LaneChangeAccelPOEnv, AccelEnv, \ WaveAttenuationEnv, WaveAttenuationPOEnv, MergePOEnv, \ TestEnv, BottleneckDesiredVelocityEnv, BottleneckEnv, BottleneckAccelEnv -from flow.envs.loop.wave_attenuation import v_eq_max_function +from flow.envs.ring.wave_attenuation import v_eq_max_function os.environ["TEST_FLAG"] = "True" diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index 1957fa7b4a..dab5d74336 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -15,7 +15,7 @@ from flow.core.params import TrafficLightParams from flow.core.params import VehicleParams from flow.envs.traffic_light_grid import GreenWaveTestEnv -from flow.envs.loop.accel import AccelEnv +from flow.envs.ring.accel import AccelEnv from flow.scenarios.figure_eight import Figure8Scenario from flow.scenarios.grid import SimpleGridScenario from flow.scenarios.highway import HighwayScenario diff --git a/tests/stress_tests/stress_test_start.py b/tests/stress_tests/stress_test_start.py index c7b4a5d05f..588383658b 100644 --- a/tests/stress_tests/stress_test_start.py +++ b/tests/stress_tests/stress_test_start.py @@ -3,7 +3,7 @@ from flow.core.params import SumoParams, EnvParams, \ InitialConfig, NetParams from flow.core.params import VehicleParams -from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS import ray diff --git a/tutorials/tutorial01_sumo.ipynb b/tutorials/tutorial01_sumo.ipynb index 849e29f06c..97fdb5b854 100644 --- a/tutorials/tutorial01_sumo.ipynb +++ b/tutorials/tutorial01_sumo.ipynb @@ -227,7 +227,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.accel import AccelEnv" + "from flow.envs.ring.accel import AccelEnv" ] }, { @@ -273,7 +273,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.accel import ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.ring.accel import ADDITIONAL_ENV_PARAMS\n", "\n", "print(ADDITIONAL_ENV_PARAMS)" ] diff --git a/tutorials/tutorial02_aimsun.ipynb b/tutorials/tutorial02_aimsun.ipynb index 97fc59df5b..a64e8640c2 100644 --- a/tutorials/tutorial02_aimsun.ipynb +++ b/tutorials/tutorial02_aimsun.ipynb @@ -235,7 +235,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.accel import AccelEnv" + "from flow.envs.ring.accel import AccelEnv" ] }, { @@ -281,7 +281,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.accel import ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.ring.accel import ADDITIONAL_ENV_PARAMS\n", "\n", "print(ADDITIONAL_ENV_PARAMS)" ] diff --git a/tutorials/tutorial06_scenarios.ipynb b/tutorials/tutorial06_scenarios.ipynb index de03227c07..20917b2dba 100644 --- a/tutorials/tutorial06_scenarios.ipynb +++ b/tutorials/tutorial06_scenarios.ipynb @@ -409,7 +409,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", "\n", "env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS)" ] diff --git a/tutorials/tutorial12_inflows.ipynb b/tutorials/tutorial12_inflows.ipynb index 93c794b288..8b108b8791 100644 --- a/tutorials/tutorial12_inflows.ipynb +++ b/tutorials/tutorial12_inflows.ipynb @@ -171,7 +171,7 @@ "outputs": [], "source": [ "from flow.core.params import SumoParams, EnvParams, InitialConfig\n", - "from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", "from flow.core.experiment import Experiment\n", "\n", "sumo_params = SumoParams(render=True,\n", From a7dfbe9e7379f10de0563a9ab553ea6148b48f83 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sun, 18 Aug 2019 16:53:31 -0700 Subject: [PATCH 05/23] Renamed "loop" to "ring" in scenarios --- .../{multi_loop.py => multi_ring.py} | 10 ++--- flow/scenarios/{loop.py => ring.py} | 8 ++-- .../{loop_merge.py => ring_merge.py} | 38 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) rename flow/scenarios/{multi_loop.py => multi_ring.py} (97%) rename flow/scenarios/{loop.py => ring.py} (97%) rename flow/scenarios/{loop_merge.py => ring_merge.py} (90%) diff --git a/flow/scenarios/multi_loop.py b/flow/scenarios/multi_ring.py similarity index 97% rename from flow/scenarios/multi_loop.py rename to flow/scenarios/multi_ring.py index b9a9470438..01fac17f16 100644 --- a/flow/scenarios/multi_loop.py +++ b/flow/scenarios/multi_ring.py @@ -21,10 +21,10 @@ VEHICLE_LENGTH = 5 # length of vehicles in the network, in meters -class MultiLoopScenario(Scenario): +class MultiRingScenario(Scenario): """Ring road scenario. - This network is similar to `LoopScenario`, but generates multiple separate + This network is similar to `RingScenario`, but generates multiple separate ring roads in the same simulation. Requires from net_params: @@ -40,9 +40,9 @@ class MultiLoopScenario(Scenario): >>> from flow.core.params import NetParams >>> from flow.core.params import VehicleParams >>> from flow.core.params import InitialConfig - >>> from flow.scenarios import MultiLoopScenario + >>> from flow.scenarios import MultiRingScenario >>> - >>> scenario = MultiLoopScenario( + >>> scenario = MultiRingScenario( >>> name='multi_ring_road', >>> vehicles=VehicleParams(), >>> net_params=NetParams( @@ -64,7 +64,7 @@ def __init__(self, net_params, initial_config=InitialConfig(), traffic_lights=TrafficLightParams()): - """Initialize a loop scenario.""" + """Initialize a ring scenario.""" for p in ADDITIONAL_NET_PARAMS.keys(): if p not in net_params.additional_params: raise KeyError('Network parameter "{}" not supplied'.format(p)) diff --git a/flow/scenarios/loop.py b/flow/scenarios/ring.py similarity index 97% rename from flow/scenarios/loop.py rename to flow/scenarios/ring.py index 51ee2d04c3..202e9fed0b 100755 --- a/flow/scenarios/loop.py +++ b/flow/scenarios/ring.py @@ -17,7 +17,7 @@ } -class LoopScenario(Scenario): +class RingScenario(Scenario): """Ring road scenario. This network consists of nodes at the top, bottom, left, and right @@ -37,9 +37,9 @@ class LoopScenario(Scenario): >>> from flow.core.params import NetParams >>> from flow.core.params import VehicleParams >>> from flow.core.params import InitialConfig - >>> from flow.scenarios import LoopScenario + >>> from flow.scenarios import RingScenario >>> - >>> scenario = LoopScenario( + >>> scenario = RingScenario( >>> name='ring_road', >>> vehicles=VehicleParams(), >>> net_params=NetParams( @@ -60,7 +60,7 @@ def __init__(self, net_params, initial_config=InitialConfig(), traffic_lights=TrafficLightParams()): - """Initialize a loop scenario.""" + """Initialize a ring scenario.""" for p in ADDITIONAL_NET_PARAMS.keys(): if p not in net_params.additional_params: raise KeyError('Network parameter "{}" not supplied'.format(p)) diff --git a/flow/scenarios/loop_merge.py b/flow/scenarios/ring_merge.py similarity index 90% rename from flow/scenarios/loop_merge.py rename to flow/scenarios/ring_merge.py index cc275f2f4b..7d7a339b26 100644 --- a/flow/scenarios/loop_merge.py +++ b/flow/scenarios/ring_merge.py @@ -1,4 +1,4 @@ -"""Contains the loop merge scenario class.""" +"""Contains the ring merge scenario class.""" from flow.scenarios.base import Scenario from flow.core.params import InitialConfig @@ -6,13 +6,13 @@ from numpy import pi, sin, cos, linspace ADDITIONAL_NET_PARAMS = { - # radius of the loops + # radius of the rings "ring_radius": 50, - # length of the straight edges connected the outer loop to the inner loop + # length of the straight edges connected the outer ring to the inner ring "lane_length": 75, - # number of lanes in the inner loop + # number of lanes in the inner ring "inner_lanes": 3, - # number of lanes in the outer loop + # number of lanes in the outer ring "outer_lanes": 2, # max speed limit in the network "speed_limit": 30, @@ -21,20 +21,20 @@ } -class TwoLoopsOneMergingScenario(Scenario): - """Two loop merge scenario. +class TwoRingsOneMergingScenario(Scenario): + """Two ring merge scenario. - This network is expected to simulate a closed loop representation of a + This network is expected to simulate a closed ring representation of a merge. It consists of two rings that merge together for half the length of the smaller ring. Requires from net_params: - * **ring_radius** : radius of the loops - * **lane_length** : length of the straight edges connected the outer loop - to the inner loop - * **inner_lanes** : number of lanes in the inner loop - * **outer_lanes** : number of lanes in the outer loop + * **ring_radius** : radius of the rings + * **lane_length** : length of the straight edges connected the outer ring + to the inner ring + * **inner_lanes** : number of lanes in the inner ring + * **outer_lanes** : number of lanes in the outer ring * **speed_limit** : max speed limit in the network * **resolution** : resolution of the curved portions @@ -43,10 +43,10 @@ class TwoLoopsOneMergingScenario(Scenario): >>> from flow.core.params import NetParams >>> from flow.core.params import VehicleParams >>> from flow.core.params import InitialConfig - >>> from flow.scenarios import TwoLoopsOneMergingScenario + >>> from flow.scenarios import TwoRingsOneMergingScenario >>> - >>> scenario = TwoLoopsOneMergingScenario( - >>> name='two_loops_merge', + >>> scenario = TwoRingsOneMergingScenario( + >>> name='two_rings_merge', >>> vehicles=VehicleParams(), >>> net_params=NetParams( >>> additional_params={ @@ -68,7 +68,7 @@ def __init__(self, net_params, initial_config=InitialConfig(), traffic_lights=TrafficLightParams()): - """Initialize a two loop scenario.""" + """Initialize a two ring scenario.""" for p in ADDITIONAL_NET_PARAMS.keys(): if p not in net_params.additional_params: raise KeyError('Network parameter "{}" not supplied'.format(p)) @@ -93,8 +93,8 @@ def __init__(self, self.n_outer_vehicles = num_vehicles - num_merge_vehicles radius = net_params.additional_params["ring_radius"] - length_loop = 2 * pi * radius - self.length_loop = length_loop + length_ring = 2 * pi * radius + self.length_ring = length_ring super().__init__(name, vehicles, net_params, initial_config, traffic_lights) From cd379da908f1d9e2f320840e405d6fe095611de9 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sun, 18 Aug 2019 17:17:57 -0700 Subject: [PATCH 06/23] More rename "loop" to "ring" --- examples/README.md | 4 ++-- examples/aimsun/stabilizing_the_ring.py | 4 ++-- examples/rllab/cooperative_merge.py | 4 ++-- examples/rllib/cooperative_merge.py | 2 +- examples/sumo/{loop_merge.py => ring_merge.py} | 12 ++++++------ examples/sumo/sugiyama.py | 4 ++-- flow/controllers/routing_controllers.py | 2 +- flow/envs/ring/__init__.py | 2 +- flow/envs/ring/accel.py | 2 +- flow/multiagent_envs/__init__.py | 4 ++-- flow/multiagent_envs/{loop => ring}/__init__.py | 0 .../{loop/loop_accel.py => ring/accel.py} | 2 +- .../{loop => ring}/wave_attenuation.py | 0 flow/scenarios/__init__.py | 8 ++++---- flow/scenarios/base.py | 8 ++++---- flow/scenarios/figure_eight.py | 2 +- flow/utils/aimsun/run.py | 2 +- flow/utils/shflags | 2 +- tests/fast_tests/test_environments.py | 4 ++-- tests/fast_tests/test_examples.py | 8 ++++---- .../test_files/{loop_230.json => ring_230.json} | 0 .../{loop_230_emission.csv => ring_230_emission.csv} | 0 tests/fast_tests/test_scenario_base_class.py | 2 +- tests/fast_tests/test_scenarios.py | 6 +++--- tests/fast_tests/test_visualizers.py | 4 ++-- tests/setup_scripts.py | 2 +- tests/stress_tests/stress_test_start.py | 2 +- tutorials/tutorial01_sumo.ipynb | 4 ++-- tutorials/tutorial02_aimsun.ipynb | 4 ++-- tutorials/tutorial03_rllib.ipynb | 2 +- tutorials/tutorial04_rllab.ipynb | 4 ++-- tutorials/tutorial06_scenarios.ipynb | 2 +- tutorials/tutorial09_environments.ipynb | 4 ++-- 33 files changed, 56 insertions(+), 56 deletions(-) rename examples/sumo/{loop_merge.py => ring_merge.py} (91%) rename flow/multiagent_envs/{loop => ring}/__init__.py (100%) rename flow/multiagent_envs/{loop/loop_accel.py => ring/accel.py} (99%) rename flow/multiagent_envs/{loop => ring}/wave_attenuation.py (100%) rename tests/fast_tests/test_files/{loop_230.json => ring_230.json} (100%) rename tests/fast_tests/test_files/{loop_230_emission.csv => ring_230_emission.csv} (100%) diff --git a/examples/README.md b/examples/README.md index e12da40a85..5f000ed179 100644 --- a/examples/README.md +++ b/examples/README.md @@ -77,11 +77,11 @@ Example of an open multi-lane network with human-driven vehicles. ![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/highway.gif) -### loop_merges.py +### ring_merge.py Example of ring road with larger merging ring. -![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/loop_merge.gif) +![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/ring_merge.gif) ### merge.py diff --git a/examples/aimsun/stabilizing_the_ring.py b/examples/aimsun/stabilizing_the_ring.py index 68a40c9ceb..9939228cc6 100644 --- a/examples/aimsun/stabilizing_the_ring.py +++ b/examples/aimsun/stabilizing_the_ring.py @@ -6,7 +6,7 @@ from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy -from flow.scenarios.ring import LoopScenario +from flow.scenarios.ring import RingScenario from flow.controllers import RLController, IDMController, ContinuousRouter from flow.core.params import VehicleParams from flow.core.params import AimsunParams, EnvParams, NetParams, InitialConfig @@ -53,7 +53,7 @@ def run_task(*_): initial_config = InitialConfig(spacing="uniform", bunching=50) print("XXX name", exp_tag) - scenario = LoopScenario( + scenario = RingScenario( exp_tag, vehicles, net_params, diff --git a/examples/rllab/cooperative_merge.py b/examples/rllab/cooperative_merge.py index e64fee4a2e..cacb6050f3 100644 --- a/examples/rllab/cooperative_merge.py +++ b/examples/rllab/cooperative_merge.py @@ -1,4 +1,4 @@ -"""Trains vehicles to facilitate cooperative merging in a loop merge. +"""Trains vehicles to facilitate cooperative merging in a ring merge. This example consists of 1 learning agent and 6 additional vehicles in an inner ring, and 10 vehicles in an outer ring attempting to merge into the inner ring. @@ -16,7 +16,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams -from flow.scenarios.loop_merge import TwoLoopsOneMergingScenario, \ +from flow.scenarios.ring_merge import TwoLoopsOneMergingScenario, \ ADDITIONAL_NET_PARAMS HORIZON = 300 diff --git a/examples/rllib/cooperative_merge.py b/examples/rllib/cooperative_merge.py index 3b189b6b09..107350dafe 100644 --- a/examples/rllib/cooperative_merge.py +++ b/examples/rllib/cooperative_merge.py @@ -1,4 +1,4 @@ -"""Trains vehicles to facilitate cooperative merging in a loop merge. +"""Trains vehicles to facilitate cooperative merging in a ring merge. This examples consists of 1 learning agent and 6 additional vehicles in an inner ring, and 10 vehicles in an outer ring attempting to diff --git a/examples/sumo/loop_merge.py b/examples/sumo/ring_merge.py similarity index 91% rename from examples/sumo/loop_merge.py rename to examples/sumo/ring_merge.py index 8a80d212ed..b8a1170ae1 100755 --- a/examples/sumo/loop_merge.py +++ b/examples/sumo/ring_merge.py @@ -7,13 +7,13 @@ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.loop_merge import TwoLoopsOneMergingScenario, \ +from flow.scenarios.ring_merge import TwoLoopsOneMergingScenario, \ ADDITIONAL_NET_PARAMS -def loop_merge_example(render=None): +def ring_merge_example(render=None): """ - Perform a simulation of vehicles on a loop merge. + Perform a simulation of vehicles on a ring merge. Parameters ---------- @@ -24,7 +24,7 @@ def loop_merge_example(render=None): ------- exp: flow.core.experiment.Experiment A non-rl experiment demonstrating the performance of human-driven - vehicles on a loop merge. + vehicles on a ring merge. """ sim_params = SumoParams( sim_step=0.1, emission_path="./data/", render=True) @@ -74,7 +74,7 @@ def loop_merge_example(render=None): x0=50, spacing="uniform", additional_params={"merge_bunching": 0}) scenario = TwoLoopsOneMergingScenario( - name="two-loop-one-merging", + name="two-ring-one-merging", vehicles=vehicles, net_params=net_params, initial_config=initial_config) @@ -86,7 +86,7 @@ def loop_merge_example(render=None): if __name__ == "__main__": # import the experiment variable - exp = loop_merge_example() + exp = ring() # run for a set number of rollouts / time steps exp.run(1, 1500, convert_to_csv=True) diff --git a/examples/sumo/sugiyama.py b/examples/sumo/sugiyama.py index fc0f7a1880..8c3019ffd5 100755 --- a/examples/sumo/sugiyama.py +++ b/examples/sumo/sugiyama.py @@ -9,7 +9,7 @@ InitialConfig, NetParams from flow.core.params import VehicleParams from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS +from flow.scenarios.ring import RingScenario, ADDITIONAL_NET_PARAMS def sugiyama_example(render=None): @@ -46,7 +46,7 @@ def sugiyama_example(render=None): initial_config = InitialConfig(bunching=20) - scenario = LoopScenario( + scenario = RingScenario( name="sugiyama", vehicles=vehicles, net_params=net_params, diff --git a/flow/controllers/routing_controllers.py b/flow/controllers/routing_controllers.py index 3eb747e587..e85f91eb88 100755 --- a/flow/controllers/routing_controllers.py +++ b/flow/controllers/routing_controllers.py @@ -7,7 +7,7 @@ class ContinuousRouter(BaseRouter): - """A router used to continuously re-route of the vehicle in a closed loop. + """A router used to continuously re-route of the vehicle in a closed ring. This class is useful if vehicles are expected to continuously follow the same route, and repeat said route once it reaches its end. diff --git a/flow/envs/ring/__init__.py b/flow/envs/ring/__init__.py index 0aa374f9b8..ae058bd162 100644 --- a/flow/envs/ring/__init__.py +++ b/flow/envs/ring/__init__.py @@ -1 +1 @@ -"""Empty init file to ensure documentation for the loop env is created.""" +"""Empty init file to ensure documentation for the ring env is created.""" diff --git a/flow/envs/ring/accel.py b/flow/envs/ring/accel.py index d3a0c87453..c8a8807d7b 100755 --- a/flow/envs/ring/accel.py +++ b/flow/envs/ring/accel.py @@ -1,4 +1,4 @@ -"""Environment for training the acceleration behavior of vehicles in a loop.""" +"""Environment for training the acceleration behavior of vehicles in a ring.""" from flow.core import rewards from flow.envs.base import Env diff --git a/flow/multiagent_envs/__init__.py b/flow/multiagent_envs/__init__.py index e0d3fe90c7..bdc9660c78 100644 --- a/flow/multiagent_envs/__init__.py +++ b/flow/multiagent_envs/__init__.py @@ -1,8 +1,8 @@ """Empty init file to ensure documentation for multi-agent envs is created.""" from flow.multiagent_envs.multiagent_env import MultiEnv -from flow.multiagent_envs.loop.wave_attenuation import \ +from flow.multiagent_envs.ring.wave_attenuation import \ MultiWaveAttenuationPOEnv -from flow.multiagent_envs.loop.loop_accel import MultiAgentAccelEnv +from flow.multiagent_envs.ring.accel import MultiAgentAccelEnv __all__ = ['MultiEnv', 'MultiAgentAccelEnv', 'MultiWaveAttenuationPOEnv'] diff --git a/flow/multiagent_envs/loop/__init__.py b/flow/multiagent_envs/ring/__init__.py similarity index 100% rename from flow/multiagent_envs/loop/__init__.py rename to flow/multiagent_envs/ring/__init__.py diff --git a/flow/multiagent_envs/loop/loop_accel.py b/flow/multiagent_envs/ring/accel.py similarity index 99% rename from flow/multiagent_envs/loop/loop_accel.py rename to flow/multiagent_envs/ring/accel.py index c477b8ba5b..59be6c8b35 100644 --- a/flow/multiagent_envs/loop/loop_accel.py +++ b/flow/multiagent_envs/ring/accel.py @@ -1,4 +1,4 @@ -"""Environment for training the acceleration behavior of vehicles in a loop.""" +"""Environment for training the acceleration behavior of vehicles in a ring.""" import numpy as np from flow.core import rewards diff --git a/flow/multiagent_envs/loop/wave_attenuation.py b/flow/multiagent_envs/ring/wave_attenuation.py similarity index 100% rename from flow/multiagent_envs/loop/wave_attenuation.py rename to flow/multiagent_envs/ring/wave_attenuation.py diff --git a/flow/scenarios/__init__.py b/flow/scenarios/__init__.py index f4001060a6..433bbd292f 100644 --- a/flow/scenarios/__init__.py +++ b/flow/scenarios/__init__.py @@ -10,15 +10,15 @@ from flow.scenarios.figure_eight import Figure8Scenario from flow.scenarios.grid import SimpleGridScenario from flow.scenarios.highway import HighwayScenario -from flow.scenarios.loop import LoopScenario +from flow.scenarios.ring import RingScenario from flow.scenarios.merge import MergeScenario -from flow.scenarios.loop_merge import TwoLoopsOneMergingScenario -from flow.scenarios.multi_loop import MultiLoopScenario +from flow.scenarios.ring_merge import TwoRingsOneMergingScenario +from flow.scenarios.multi_ring import MultiRingScenario from flow.scenarios.minicity import MiniCityScenario __all__ = [ "Scenario", "BayBridgeScenario", "BayBridgeTollScenario", "BottleneckScenario", "Figure8Scenario", "SimpleGridScenario", "HighwayScenario", "LoopScenario", "MergeScenario", - "TwoLoopsOneMergingScenario", "MultiLoopScenario", "MiniCityScenario" + "TwoRingsOneMergingScenario", "MultiRingScenario", "MiniCityScenario" ] diff --git a/flow/scenarios/base.py b/flow/scenarios/base.py index 377b7289fb..f90510395a 100755 --- a/flow/scenarios/base.py +++ b/flow/scenarios/base.py @@ -142,7 +142,7 @@ class file If the type variable is None, then no types are available within the scenario. Furthermore, a proper example of this variable being used can - be found under `specify_types` in flow/scenarios/loop.py. + be found under `specify_types` in flow/scenarios/ring.py. Note that, if the scenario is meant to generate the network from an OpenStreetMap or template file, this variable is set to None @@ -178,7 +178,7 @@ class file Example ------- The following examples are derived from the `LoopScenario` Scenario class - located in flow/scenarios/loop.py, and should serve as an example of the + located in flow/scenarios/ring.py, and should serve as an example of the types of outputs to be expected from the different variables of a scenario class. @@ -300,7 +300,7 @@ class file >>> print(scenario.edge_starts) >>> [('bottom', 0), ('right', 57.5), ('top', 115.0), ('left', 172.5)] - Finally, the loop scenario does not contain any junctions or intersections, + Finally, the ring scenario does not contain any junctions or intersections, and as a result the `internal_edge_starts` and `intersection_edge_starts` attributes are both set to None. For an example of a network with junctions and intersections, please refer to: flow/scenarios/figure_eight.py. @@ -557,7 +557,7 @@ def specify_routes(self, net_params): to the edge the vehicle begins on. Note that the edges must be connected for the route to be valid. - For example (from flow/scenarios/loop.py): + For example (from flow/scenarios/ring.py): >>> def specify_routes(self, net_params): >>> return { diff --git a/flow/scenarios/figure_eight.py b/flow/scenarios/figure_eight.py index 9cf3d72e73..54d4c5b2e0 100755 --- a/flow/scenarios/figure_eight.py +++ b/flow/scenarios/figure_eight.py @@ -25,7 +25,7 @@ class Figure8Scenario(Scenario): The figure eight network is an extension of the ring road network: Two rings, placed at opposite ends of the network, are connected by an intersection with road segments of length equal to the diameter of the - rings. Serves as a simulation of a closed loop intersection. + rings. Serves as a simulation of a closed ring intersection. Requires from net_params: diff --git a/flow/utils/aimsun/run.py b/flow/utils/aimsun/run.py index 4105082f24..adc9fa097a 100644 --- a/flow/utils/aimsun/run.py +++ b/flow/utils/aimsun/run.py @@ -126,7 +126,7 @@ def threaded_client(conn): # convert to integer data = int(data) - # if the simulation step is over, terminate the loop and let + # if the simulation step is over, terminate the ring and let # the step be executed if data == ac.SIMULATION_STEP: send_message(conn, in_format='i', values=(0,)) diff --git a/flow/utils/shflags b/flow/utils/shflags index 38495e1ddb..60e48b233c 100644 --- a/flow/utils/shflags +++ b/flow/utils/shflags @@ -511,7 +511,7 @@ _flags_getFlagInfo() { # See if the _flags_gFI_usName_ variable is a string as strings can be # empty... # Note: the DRY principle would say to have this function call itself for - # the next three lines, but doing so results in an infinite loop as an + # the next three lines, but doing so results in an infinite ring as an # invalid _flags_name_ will also not have the associated _type variable. # Because it doesn't (it will evaluate to an empty string) the logic will # try to find the _type variable of the _type variable, and so on. Not so diff --git a/tests/fast_tests/test_environments.py b/tests/fast_tests/test_environments.py index 4957c90200..1707fae676 100644 --- a/tests/fast_tests/test_environments.py +++ b/tests/fast_tests/test_environments.py @@ -8,7 +8,7 @@ from flow.core.params import NetParams, EnvParams, SumoParams, InFlows from flow.controllers import IDMController, RLController from flow.scenarios import LoopScenario, MergeScenario, BottleneckScenario -from flow.scenarios.loop import ADDITIONAL_NET_PARAMS as LOOP_PARAMS +from flow.scenarios.ring import ADDITIONAL_NET_PARAMS as LOOP_PARAMS from flow.scenarios.merge import ADDITIONAL_NET_PARAMS as MERGE_PARAMS from flow.envs import LaneChangeAccelEnv, LaneChangeAccelPOEnv, AccelEnv, \ WaveAttenuationEnv, WaveAttenuationPOEnv, MergePOEnv, \ @@ -684,7 +684,7 @@ def setUp(self): net_params = NetParams(additional_params=LOOP_PARAMS) env_params = EnvParams() sim_params = SumoParams() - scenario = LoopScenario("test_loop", + scenario = LoopScenario("test_ring", vehicles=vehicles, net_params=net_params) self.env = TestEnv(env_params, sim_params, scenario) diff --git a/tests/fast_tests/test_examples.py b/tests/fast_tests/test_examples.py index 95b4b26c90..eacd1e62ce 100644 --- a/tests/fast_tests/test_examples.py +++ b/tests/fast_tests/test_examples.py @@ -8,7 +8,7 @@ from examples.sumo.figure_eight import figure_eight_example from examples.sumo.grid import grid_example from examples.sumo.highway import highway_example -from examples.sumo.loop_merge import loop_merge_example +from examples.sumo.ring_merge import ring_merge_example from examples.sumo.merge import merge_example from examples.sumo.minicity import minicity_example from examples.sumo.sugiyama import sugiyama_example @@ -89,10 +89,10 @@ def test_sugiyama(self): # run the experiment for a few time steps to ensure it doesn't fail exp.run(1, 5) - def test_loop_merge(self): - """Verify that examples/sumo/two_loops_merge_straight.py is working.""" + def test_ring_merge(self): + """Verify that examples/sumo/two_rings_merge_straight.py is working.""" # import the experiment variable from the example - exp = loop_merge_example(render=False) + exp = ring_merge_example(render=False) # run the experiment for a few time steps to ensure it doesn't fail exp.run(1, 5) diff --git a/tests/fast_tests/test_files/loop_230.json b/tests/fast_tests/test_files/ring_230.json similarity index 100% rename from tests/fast_tests/test_files/loop_230.json rename to tests/fast_tests/test_files/ring_230.json diff --git a/tests/fast_tests/test_files/loop_230_emission.csv b/tests/fast_tests/test_files/ring_230_emission.csv similarity index 100% rename from tests/fast_tests/test_files/loop_230_emission.csv rename to tests/fast_tests/test_files/ring_230_emission.csv diff --git a/tests/fast_tests/test_scenario_base_class.py b/tests/fast_tests/test_scenario_base_class.py index 34361f6779..4d003a411e 100644 --- a/tests/fast_tests/test_scenario_base_class.py +++ b/tests/fast_tests/test_scenario_base_class.py @@ -8,7 +8,7 @@ from flow.core.params import VehicleParams from flow.core.params import EnvParams from flow.core.params import SumoParams -from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS +from flow.scenarios.ring import RingScenario, ADDITIONAL_NET_PARAMS from flow.envs import TestEnv from flow.scenarios import Scenario diff --git a/tests/fast_tests/test_scenarios.py b/tests/fast_tests/test_scenarios.py index 3b88118cba..3e82711efe 100644 --- a/tests/fast_tests/test_scenarios.py +++ b/tests/fast_tests/test_scenarios.py @@ -102,7 +102,7 @@ def test_additional_net_params(self): class TestLoopScenario(unittest.TestCase): - """Tests LoopScenario in flow/scenarios/loop.py.""" + """Tests LoopScenario in flow/scenarios/ring.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" @@ -121,7 +121,7 @@ def test_additional_net_params(self): class TestTwoLoopsOneMergingScenario(unittest.TestCase): - """Tests TwoLoopsOneMergingScenario in flow/scenarios/loop_merge.py.""" + """Tests TwoLoopsOneMergingScenario in flow/scenarios/ring_merge.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" @@ -163,7 +163,7 @@ def test_additional_net_params(self): class TestMultiLoopScenario(unittest.TestCase): - """Tests MultiLoopScenario in flow/scenarios/multi_loop.py.""" + """Tests MultiLoopScenario in flow/scenarios/multi_ring.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" diff --git a/tests/fast_tests/test_visualizers.py b/tests/fast_tests/test_visualizers.py index 21a2a1c4cc..e991163696 100644 --- a/tests/fast_tests/test_visualizers.py +++ b/tests/fast_tests/test_visualizers.py @@ -239,10 +239,10 @@ def test_time_space_diagram_merge(self): def test_time_space_diagram_ring_road(self): dir_path = os.path.dirname(os.path.realpath(__file__)) emission_data = tsd.import_data_from_emission( - os.path.join(dir_path, 'test_files/loop_230_emission.csv')) + os.path.join(dir_path, 'test_files/ring_230_emission.csv')) flow_params = tsd.get_flow_params( - os.path.join(dir_path, 'test_files/loop_230.json')) + os.path.join(dir_path, 'test_files/ring_230.json')) pos, speed, _ = tsd.get_time_space_data(emission_data, flow_params) expected_pos = np.array( diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index dab5d74336..e1ff48cc94 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -19,7 +19,7 @@ from flow.scenarios.figure_eight import Figure8Scenario from flow.scenarios.grid import SimpleGridScenario from flow.scenarios.highway import HighwayScenario -from flow.scenarios.loop import LoopScenario +from flow.scenarios.ring import RingScenario def ring_road_exp_setup(sim_params=None, diff --git a/tests/stress_tests/stress_test_start.py b/tests/stress_tests/stress_test_start.py index 588383658b..1e33926049 100644 --- a/tests/stress_tests/stress_test_start.py +++ b/tests/stress_tests/stress_test_start.py @@ -4,7 +4,7 @@ InitialConfig, NetParams from flow.core.params import VehicleParams from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS +from flow.scenarios.ring import RingScenario, ADDITIONAL_NET_PARAMS import ray diff --git a/tutorials/tutorial01_sumo.ipynb b/tutorials/tutorial01_sumo.ipynb index 97fdb5b854..0504fcebdc 100644 --- a/tutorials/tutorial01_sumo.ipynb +++ b/tutorials/tutorial01_sumo.ipynb @@ -23,7 +23,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.scenarios.loop import LoopScenario" + "from flow.scenarios.ring import RingScenario" ] }, { @@ -141,7 +141,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.scenarios.loop import ADDITIONAL_NET_PARAMS\n", + "from flow.scenarios.ring import ADDITIONAL_NET_PARAMS\n", "\n", "print(ADDITIONAL_NET_PARAMS)" ] diff --git a/tutorials/tutorial02_aimsun.ipynb b/tutorials/tutorial02_aimsun.ipynb index a64e8640c2..90372a0a71 100644 --- a/tutorials/tutorial02_aimsun.ipynb +++ b/tutorials/tutorial02_aimsun.ipynb @@ -27,7 +27,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.scenarios.loop import LoopScenario" + "from flow.scenarios.ring import RingScenario" ] }, { @@ -130,7 +130,7 @@ "metadata": {}, "outputs": [], "source": [ - "from flow.scenarios.loop import ADDITIONAL_NET_PARAMS\n", + "from flow.scenarios.ring import ADDITIONAL_NET_PARAMS\n", "\n", "print(ADDITIONAL_NET_PARAMS)" ] diff --git a/tutorials/tutorial03_rllib.ipynb b/tutorials/tutorial03_rllib.ipynb index f93462b44a..9c2ffb13fc 100644 --- a/tutorials/tutorial03_rllib.ipynb +++ b/tutorials/tutorial03_rllib.ipynb @@ -77,7 +77,7 @@ "name = \"training_example\"\n", "\n", "# network-specific parameters\n", - "from flow.scenarios.loop import ADDITIONAL_NET_PARAMS\n", + "from flow.scenarios.ring import ADDITIONAL_NET_PARAMS\n", "net_params = NetParams(additional_params=ADDITIONAL_NET_PARAMS)\n", "\n", "# initial configuration to vehicles\n", diff --git a/tutorials/tutorial04_rllab.ipynb b/tutorials/tutorial04_rllab.ipynb index 5285b2b839..80c7173a43 100644 --- a/tutorials/tutorial04_rllab.ipynb +++ b/tutorials/tutorial04_rllab.ipynb @@ -35,7 +35,7 @@ "outputs": [], "source": [ "# ring road scenario class\n", - "from flow.scenarios.loop import LoopScenario\n", + "from flow.scenarios.ring import LoopScenario\n", "\n", "# input parameter classes to the scenario class\n", "from flow.core.params import NetParams, InitialConfig\n", @@ -44,7 +44,7 @@ "name = \"training_example\"\n", "\n", "# network-specific parameters\n", - "from flow.scenarios.loop import ADDITIONAL_NET_PARAMS\n", + "from flow.scenarios.ring import ADDITIONAL_NET_PARAMS\n", "net_params = NetParams(additional_params=ADDITIONAL_NET_PARAMS)\n", "\n", "# initial configuration to vehicles\n", diff --git a/tutorials/tutorial06_scenarios.ipynb b/tutorials/tutorial06_scenarios.ipynb index 20917b2dba..9e46922252 100644 --- a/tutorials/tutorial06_scenarios.ipynb +++ b/tutorials/tutorial06_scenarios.ipynb @@ -52,7 +52,7 @@ "\n", "All of the functions mentioned above paragraph take in as input `net_params`, and output a list of dictionary elements, with each element providing the attributes of the component to be specified.\n", "\n", - "This tutorial will cover the first three methods. For examples of `specify_types` and `specify_routes`, refer to source code located in `flow/scenarios/loop.py` and `flow/scenarios/bridge_toll.py`, respectively." + "This tutorial will cover the first three methods. For examples of `specify_types` and `specify_routes`, refer to source code located in `flow/scenarios/ring.py` and `flow/scenarios/bridge_toll.py`, respectively." ] }, { diff --git a/tutorials/tutorial09_environments.ipynb b/tutorials/tutorial09_environments.ipynb index bf0a756771..595b0f0782 100644 --- a/tutorials/tutorial09_environments.ipynb +++ b/tutorials/tutorial09_environments.ipynb @@ -287,7 +287,7 @@ "from flow.core.params import SumoParams, EnvParams, \\\n", " InitialConfig, NetParams\n", "from flow.core.params import VehicleParams\n", - "from flow.scenarios.loop import LoopScenario, ADDITIONAL_NET_PARAMS\n", + "from flow.scenarios.ring import RingScenario, ADDITIONAL_NET_PARAMS\n", "\n", "sumo_params = SumoParams(sim_step=0.1, render=True)\n", "\n", @@ -360,7 +360,7 @@ "from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline\n", "from rllab.policies.gaussian_gru_policy import GaussianGRUPolicy\n", "\n", - "from flow.scenarios.loop import LoopScenario\n", + "from flow.scenarios.ring import RingScenario\n", "from flow.controllers import RLController, IDMController, ContinuousRouter\n", "from flow.core.params import VehicleParams\n", "from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig\n", From e8a3e5c7f8bb61d78b5a7d0c643c7210a7e337e8 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sun, 18 Aug 2019 17:54:44 -0700 Subject: [PATCH 07/23] Final commit for "loop" to "merge" --- docs/img/{loop_merge.gif => ring_merge.gif} | Bin examples/aimsun/sugiyama.py | 4 +-- examples/rllab/cooperative_merge.py | 4 +-- examples/rllab/stabilizing_the_ring.py | 4 +-- examples/rllib/cooperative_merge.py | 2 +- .../multiagent_stabilizing_the_ring.py | 2 +- examples/rllib/stabilizing_the_ring.py | 2 +- examples/sumo/ring_merge.py | 4 +-- flow/scenarios/__init__.py | 2 +- flow/scenarios/base.py | 6 ++-- flow/visualize/time_space_diagram.py | 4 +-- tests/fast_tests/test_environments.py | 34 +++++++++--------- tests/fast_tests/test_files/ring_230.json | 2 +- tests/fast_tests/test_params.py | 4 +-- tests/fast_tests/test_scenario_base_class.py | 2 +- tests/fast_tests/test_scenarios.py | 24 ++++++------- tests/setup_scripts.py | 4 +-- tests/stress_tests/stress_test_start.py | 2 +- tutorials/tutorial01_sumo.ipynb | 6 ++-- tutorials/tutorial02_aimsun.ipynb | 6 ++-- tutorials/tutorial03_rllib.ipynb | 4 +-- tutorials/tutorial04_rllab.ipynb | 6 ++-- tutorials/tutorial09_environments.ipynb | 4 +-- 23 files changed, 66 insertions(+), 66 deletions(-) rename docs/img/{loop_merge.gif => ring_merge.gif} (100%) diff --git a/docs/img/loop_merge.gif b/docs/img/ring_merge.gif similarity index 100% rename from docs/img/loop_merge.gif rename to docs/img/ring_merge.gif diff --git a/examples/aimsun/sugiyama.py b/examples/aimsun/sugiyama.py index 231526ac66..e97e19a20f 100644 --- a/examples/aimsun/sugiyama.py +++ b/examples/aimsun/sugiyama.py @@ -8,7 +8,7 @@ from flow.core.params import AimsunParams, EnvParams, InitialConfig, NetParams from flow.core.params import VehicleParams from flow.envs import TestEnv -from flow.scenarios.ring import LoopScenario, ADDITIONAL_NET_PARAMS +from flow.scenarios.ring import RingScenario, ADDITIONAL_NET_PARAMS def sugiyama_example(render=None): @@ -43,7 +43,7 @@ def sugiyama_example(render=None): initial_config = InitialConfig(bunching=20) - scenario = LoopScenario( + scenario = RingScenario( name="sugiyama", vehicles=vehicles, net_params=net_params, diff --git a/examples/rllab/cooperative_merge.py b/examples/rllab/cooperative_merge.py index cacb6050f3..39880a133f 100644 --- a/examples/rllab/cooperative_merge.py +++ b/examples/rllab/cooperative_merge.py @@ -16,7 +16,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams -from flow.scenarios.ring_merge import TwoLoopsOneMergingScenario, \ +from flow.scenarios.ring_merge import TwoRingsOneMergingScenario, \ ADDITIONAL_NET_PARAMS HORIZON = 300 @@ -86,7 +86,7 @@ def run_task(*_): initial_config = InitialConfig(x0=50, spacing="uniform") - scenario = TwoLoopsOneMergingScenario( + scenario = TwoRingsOneMergingScenario( name=exp_tag, vehicles=vehicles, net_params=net_params, diff --git a/examples/rllab/stabilizing_the_ring.py b/examples/rllab/stabilizing_the_ring.py index 3c3b7064a2..a6ade3c987 100644 --- a/examples/rllab/stabilizing_the_ring.py +++ b/examples/rllab/stabilizing_the_ring.py @@ -6,7 +6,7 @@ from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline from rllab.policies.gaussian_gru_policy import GaussianGRUPolicy -from flow.scenarios.ring import LoopScenario +from flow.scenarios.ring import RingScenario from flow.controllers import RLController, IDMController, ContinuousRouter from flow.core.params import VehicleParams from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig @@ -54,7 +54,7 @@ def run_task(*_): initial_config = InitialConfig(spacing="uniform", bunching=50) print("XXX name", exp_tag) - scenario = LoopScenario( + scenario = RingScenario( exp_tag, vehicles, net_params, diff --git a/examples/rllib/cooperative_merge.py b/examples/rllib/cooperative_merge.py index 107350dafe..f303033dda 100644 --- a/examples/rllib/cooperative_merge.py +++ b/examples/rllib/cooperative_merge.py @@ -88,7 +88,7 @@ env_name='AccelEnv', # name of the scenario class the experiment is running on - scenario='TwoLoopsOneMergingScenario', + scenario='TwoRingsOneMergingScenario', # simulator that is used by the experiment simulator='traci', diff --git a/examples/rllib/multiagent_exps/multiagent_stabilizing_the_ring.py b/examples/rllib/multiagent_exps/multiagent_stabilizing_the_ring.py index d8e621f04b..2b79b3bb25 100644 --- a/examples/rllib/multiagent_exps/multiagent_stabilizing_the_ring.py +++ b/examples/rllib/multiagent_exps/multiagent_stabilizing_the_ring.py @@ -61,7 +61,7 @@ env_name='MultiWaveAttenuationPOEnv', # name of the scenario class the experiment is running on - scenario='MultiLoopScenario', + scenario='MultiRingScenario', # simulator that is used by the experiment simulator='traci', diff --git a/examples/rllib/stabilizing_the_ring.py b/examples/rllib/stabilizing_the_ring.py index 859e112c9b..4c5393f09f 100644 --- a/examples/rllib/stabilizing_the_ring.py +++ b/examples/rllib/stabilizing_the_ring.py @@ -50,7 +50,7 @@ env_name="WaveAttenuationPOEnv", # name of the scenario class the experiment is running on - scenario="LoopScenario", + scenario="RingScenario", # simulator that is used by the experiment simulator='traci', diff --git a/examples/sumo/ring_merge.py b/examples/sumo/ring_merge.py index b8a1170ae1..8e8d19edaa 100755 --- a/examples/sumo/ring_merge.py +++ b/examples/sumo/ring_merge.py @@ -7,7 +7,7 @@ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.ring_merge import TwoLoopsOneMergingScenario, \ +from flow.scenarios.ring_merge import TwoRingsOneMergingScenario, \ ADDITIONAL_NET_PARAMS @@ -73,7 +73,7 @@ def ring_merge_example(render=None): initial_config = InitialConfig( x0=50, spacing="uniform", additional_params={"merge_bunching": 0}) - scenario = TwoLoopsOneMergingScenario( + scenario = TwoRingsOneMergingScenario( name="two-ring-one-merging", vehicles=vehicles, net_params=net_params, diff --git a/flow/scenarios/__init__.py b/flow/scenarios/__init__.py index 433bbd292f..03b2880c30 100644 --- a/flow/scenarios/__init__.py +++ b/flow/scenarios/__init__.py @@ -19,6 +19,6 @@ __all__ = [ "Scenario", "BayBridgeScenario", "BayBridgeTollScenario", "BottleneckScenario", "Figure8Scenario", "SimpleGridScenario", - "HighwayScenario", "LoopScenario", "MergeScenario", + "HighwayScenario", "RingScenario", "MergeScenario", "TwoRingsOneMergingScenario", "MultiRingScenario", "MiniCityScenario" ] diff --git a/flow/scenarios/base.py b/flow/scenarios/base.py index f90510395a..4c14a37855 100755 --- a/flow/scenarios/base.py +++ b/flow/scenarios/base.py @@ -177,7 +177,7 @@ class file Example ------- - The following examples are derived from the `LoopScenario` Scenario class + The following examples are derived from the `RingScenario` Scenario class located in flow/scenarios/ring.py, and should serve as an example of the types of outputs to be expected from the different variables of a scenario class. @@ -186,10 +186,10 @@ class file the following commands (note if this this unclear please refer to Tutorial 1): - >>> from flow.scenarios import LoopScenario + >>> from flow.scenarios import RingScenario >>> from flow.core.params import NetParams, VehicleParams >>> - >>> scenario = LoopScenario( + >>> scenario = RingScenario( >>> name='test', >>> vehicles=VehicleParams(), >>> net_params=NetParams( diff --git a/flow/visualize/time_space_diagram.py b/flow/visualize/time_space_diagram.py index 7c86799d03..286c6475ea 100644 --- a/flow/visualize/time_space_diagram.py +++ b/flow/visualize/time_space_diagram.py @@ -26,7 +26,7 @@ # scenarios that can be plotted by this method ACCEPTABLE_SCENARIOS = [ - 'LoopScenario', + 'RingScenario', 'Figure8Scenario', 'MergeScenario', ] @@ -120,7 +120,7 @@ def get_time_space_data(data, params): # switcher used to compute the positions based on the type of scenario switcher = { - 'LoopScenario': _ring_road, + 'RingScenario': _ring_road, 'MergeScenario': _merge, 'Figure8Scenario': _figure_eight } diff --git a/tests/fast_tests/test_environments.py b/tests/fast_tests/test_environments.py index 1707fae676..0d636caa4e 100644 --- a/tests/fast_tests/test_environments.py +++ b/tests/fast_tests/test_environments.py @@ -7,8 +7,8 @@ from flow.core.params import VehicleParams from flow.core.params import NetParams, EnvParams, SumoParams, InFlows from flow.controllers import IDMController, RLController -from flow.scenarios import LoopScenario, MergeScenario, BottleneckScenario -from flow.scenarios.ring import ADDITIONAL_NET_PARAMS as LOOP_PARAMS +from flow.scenarios import RingScenario, MergeScenario, BottleneckScenario +from flow.scenarios.ring import ADDITIONAL_NET_PARAMS as Ring_PARAMS from flow.scenarios.merge import ADDITIONAL_NET_PARAMS as MERGE_PARAMS from flow.envs import LaneChangeAccelEnv, LaneChangeAccelPOEnv, AccelEnv, \ WaveAttenuationEnv, WaveAttenuationPOEnv, MergePOEnv, \ @@ -27,10 +27,10 @@ def setUp(self): vehicles.add("human", acceleration_controller=(IDMController, {})) self.sim_params = SumoParams() - self.scenario = LoopScenario( + self.scenario = RingScenario( name="test_merge", vehicles=vehicles, - net_params=NetParams(additional_params=LOOP_PARAMS.copy()), + net_params=NetParams(additional_params=Ring_PARAMS.copy()), ) self.env_params = EnvParams( additional_params={ @@ -114,10 +114,10 @@ def setUp(self): vehicles.add("human", acceleration_controller=(IDMController, {})) self.sim_params = SumoParams() - self.scenario = LoopScenario( + self.scenario = RingScenario( name="test_merge", vehicles=vehicles, - net_params=NetParams(additional_params=LOOP_PARAMS.copy()), + net_params=NetParams(additional_params=Ring_PARAMS.copy()), ) self.env_params = EnvParams( additional_params={ @@ -196,10 +196,10 @@ def setUp(self): vehicles.add("human", acceleration_controller=(IDMController, {})) self.sim_params = SumoParams() - self.scenario = LoopScenario( + self.scenario = RingScenario( name="test_merge", vehicles=vehicles, - net_params=NetParams(additional_params=LOOP_PARAMS.copy()), + net_params=NetParams(additional_params=Ring_PARAMS.copy()), ) self.env_params = EnvParams( additional_params={ @@ -327,10 +327,10 @@ def setUp(self): self.sim_params = SumoParams( restart_instance=True ) - self.scenario = LoopScenario( + self.scenario = RingScenario( name="test_merge", vehicles=vehicles, - net_params=NetParams(additional_params=LOOP_PARAMS.copy()), + net_params=NetParams(additional_params=Ring_PARAMS.copy()), ) params = { "max_accel": 1, @@ -449,11 +449,11 @@ def test_reset_no_same_length(self): ) # reset the network several times and check its length - self.assertEqual(env.k.scenario.length(), LOOP_PARAMS["length"]) + self.assertEqual(env.k.scenario.length(), Ring_PARAMS["length"]) env.reset() - self.assertEqual(env.k.scenario.length(), LOOP_PARAMS["length"]) + self.assertEqual(env.k.scenario.length(), Ring_PARAMS["length"]) env.reset() - self.assertEqual(env.k.scenario.length(), LOOP_PARAMS["length"]) + self.assertEqual(env.k.scenario.length(), Ring_PARAMS["length"]) class TestWaveAttenuationPOEnv(unittest.TestCase): @@ -464,10 +464,10 @@ def setUp(self): vehicles.add("human", acceleration_controller=(IDMController, {})) self.sim_params = SumoParams() - self.scenario = LoopScenario( + self.scenario = RingScenario( name="test_merge", vehicles=vehicles, - net_params=NetParams(additional_params=LOOP_PARAMS.copy()), + net_params=NetParams(additional_params=Ring_PARAMS.copy()), ) self.env_params = EnvParams( additional_params={ @@ -681,10 +681,10 @@ class TestTestEnv(unittest.TestCase): def setUp(self): vehicles = VehicleParams() vehicles.add("test") - net_params = NetParams(additional_params=LOOP_PARAMS) + net_params = NetParams(additional_params=Ring_PARAMS) env_params = EnvParams() sim_params = SumoParams() - scenario = LoopScenario("test_ring", + scenario = RingScenario("test_ring", vehicles=vehicles, net_params=net_params) self.env = TestEnv(env_params, sim_params, scenario) diff --git a/tests/fast_tests/test_files/ring_230.json b/tests/fast_tests/test_files/ring_230.json index 7993a2826e..ba21a36e92 100644 --- a/tests/fast_tests/test_files/ring_230.json +++ b/tests/fast_tests/test_files/ring_230.json @@ -42,7 +42,7 @@ "osm_path": null, "template": null }, - "scenario": "LoopScenario", + "scenario": "RingScenario", "sim": { "emission_path": null, "lateral_resolution": null, diff --git a/tests/fast_tests/test_params.py b/tests/fast_tests/test_params.py index c7ecb3c321..de1b497dfb 100644 --- a/tests/fast_tests/test_params.py +++ b/tests/fast_tests/test_params.py @@ -2,7 +2,7 @@ from flow.core.params import EnvParams, SumoParams, SumoLaneChangeParams, \ SumoCarFollowingParams, VehicleParams, NetParams from flow.envs import Env -from flow.scenarios import LoopScenario +from flow.scenarios import RingScenario import os import numpy as np from gym.spaces import Box @@ -46,7 +46,7 @@ def test_clip_actions(self): "resolution": 40 } net_params = NetParams(additional_params=additional_net_params) - scenario = LoopScenario( + scenario = RingScenario( name="RingRoadTest", vehicles=vehicles, net_params=net_params) diff --git a/tests/fast_tests/test_scenario_base_class.py b/tests/fast_tests/test_scenario_base_class.py index 4d003a411e..700c0a9448 100644 --- a/tests/fast_tests/test_scenario_base_class.py +++ b/tests/fast_tests/test_scenario_base_class.py @@ -22,7 +22,7 @@ os.environ["TEST_FLAG"] = "True" -class NoRouteNetwork(LoopScenario): +class NoRouteNetwork(RingScenario): """A network with no routes. Used to check for default route assignment. diff --git a/tests/fast_tests/test_scenarios.py b/tests/fast_tests/test_scenarios.py index 3e82711efe..1e7009150a 100644 --- a/tests/fast_tests/test_scenarios.py +++ b/tests/fast_tests/test_scenarios.py @@ -3,11 +3,11 @@ from flow.core.params import VehicleParams from flow.core.params import NetParams from flow.scenarios import BottleneckScenario, Figure8Scenario, \ - SimpleGridScenario, HighwayScenario, LoopScenario, MergeScenario, \ - TwoLoopsOneMergingScenario, MiniCityScenario, MultiLoopScenario + SimpleGridScenario, HighwayScenario, RingScenario, MergeScenario, \ + TwoRingsOneMergingScenario, MiniCityScenario, MultiRingScenario __all__ = [ - "MultiLoopScenario", "MiniCityScenario" + "MultiRingScenario", "MiniCityScenario" ] os.environ["TEST_FLAG"] = "True" @@ -100,15 +100,15 @@ def test_additional_net_params(self): ) -class TestLoopScenario(unittest.TestCase): +class TestRingScenario(unittest.TestCase): - """Tests LoopScenario in flow/scenarios/ring.py.""" + """Tests RingScenario in flow/scenarios/ring.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - scenario_class=LoopScenario, + scenario_class=RingScenario, additional_params={ "length": 230, "lanes": 1, @@ -119,15 +119,15 @@ def test_additional_net_params(self): ) -class TestTwoLoopsOneMergingScenario(unittest.TestCase): +class TestTwoRingsOneMergingScenario(unittest.TestCase): - """Tests TwoLoopsOneMergingScenario in flow/scenarios/ring_merge.py.""" + """Tests TwoRingsOneMergingScenario in flow/scenarios/ring_merge.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - scenario_class=TwoLoopsOneMergingScenario, + scenario_class=TwoRingsOneMergingScenario, additional_params={ "ring_radius": 50, "lane_length": 75, @@ -161,15 +161,15 @@ def test_additional_net_params(self): ) -class TestMultiLoopScenario(unittest.TestCase): +class TestMultiRingScenario(unittest.TestCase): - """Tests MultiLoopScenario in flow/scenarios/multi_ring.py.""" + """Tests MultiRingScenario in flow/scenarios/multi_ring.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - scenario_class=MultiLoopScenario, + scenario_class=MultiRingScenario, additional_params={ "length": 230, "lanes": 1, diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index e1ff48cc94..0352177ef8 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -98,7 +98,7 @@ def ring_road_exp_setup(sim_params=None, traffic_lights = TrafficLightParams() # create the scenario - scenario = LoopScenario( + scenario = RingScenario( name="RingRoadTest", vehicles=vehicles, net_params=net_params, @@ -519,7 +519,7 @@ def variable_lanes_exp_setup(sim_params=None, return env, scenario -class VariableLanesScenario(LoopScenario): +class VariableLanesScenario(RingScenario): """Instantiate a ring road with variable number of lanes per edge.""" def specify_edges(self, net_params): diff --git a/tests/stress_tests/stress_test_start.py b/tests/stress_tests/stress_test_start.py index 1e33926049..45a82c0fa2 100644 --- a/tests/stress_tests/stress_test_start.py +++ b/tests/stress_tests/stress_test_start.py @@ -27,7 +27,7 @@ def start(): initial_config = InitialConfig(bunching=20) - scenario = LoopScenario( + scenario = RingScenario( name="sugiyama", vehicles=vehicles, net_params=net_params, diff --git a/tutorials/tutorial01_sumo.ipynb b/tutorials/tutorial01_sumo.ipynb index 0504fcebdc..f68df03e3c 100644 --- a/tutorials/tutorial01_sumo.ipynb +++ b/tutorials/tutorial01_sumo.ipynb @@ -14,7 +14,7 @@ "All simulations, both in the presence and absence of RL, require two components: a *scenario*, and an *environment*. Scenarios describe the features of the transportation network used in simulation. This includes the positions and properties of nodes and edges constituting the lanes and junctions, as well as properties of the vehicles, traffic lights, inflows, etc. in the network. Environments, on the other hand, initialize, reset, and advance simulations, and act the primary interface between the reinforcement learning algorithm and the scenario. Moreover, custom environments may be used to modify the dynamical features of an scenario.\n", "\n", "## 2. Setting up a Scenario\n", - "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. In order to recreate a ring road network, we begin by importing the scenario `LoopScenario`." + "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. In order to recreate a ring road network, we begin by importing the scenario `RingScenario`." ] }, { @@ -37,7 +37,7 @@ "* initial_config\n", "* traffic_lights\n", "\n", - "These parameters allow a single scenario to be recycled for a multitude of different network settings. For example, `LoopScenario` may be used to create ring roads of variable length with a variable number of lanes and vehicles.\n", + "These parameters allow a single scenario to be recycled for a multitude of different network settings. For example, `RingScenario` may be used to create ring roads of variable length with a variable number of lanes and vehicles.\n", "\n", "### 2.1 Name\n", "The `name` argument is a string variable depicting the name of the scenario. This has no effect on the type of network created." @@ -329,7 +329,7 @@ "outputs": [], "source": [ "# create the scenario object\n", - "scenario = LoopScenario(name=\"ring_example\",\n", + "scenario = RingScenario(name=\"ring_example\",\n", " vehicles=vehicles,\n", " net_params=net_params,\n", " initial_config=initial_config,\n", diff --git a/tutorials/tutorial02_aimsun.ipynb b/tutorials/tutorial02_aimsun.ipynb index 90372a0a71..d8221f6a8d 100644 --- a/tutorials/tutorial02_aimsun.ipynb +++ b/tutorials/tutorial02_aimsun.ipynb @@ -18,7 +18,7 @@ "All simulations, both in the presence and absence of RL, require two components: a *scenario*, and an *environment*. Scenarios describe the features of the transportation network used in simulation. This includes the positions and properties of nodes and edges constituting the lanes and junctions, as well as properties of the vehicles, traffic lights, inflows, etc. in the network. Environments, on the other hand, initialize, reset, and advance simulations, and act the primary interface between the reinforcement learning algorithm and the scenario. Moreover, custom environments may be used to modify the dynamical features of an scenario.\n", "\n", "## 2. Setting up a Scenario\n", - "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. In order to recreate a ring road network, we begin by importing the scenario `LoopScenario`." + "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. In order to recreate a ring road network, we begin by importing the scenario `RingScenario`." ] }, { @@ -41,7 +41,7 @@ "* initial_config\n", "* traffic_lights\n", "\n", - "These parameters allow a single scenario to be recycled for a multitude of different network settings. For example, `LoopScenario` may be used to create ring roads of variable length with a variable number of lanes and vehicles.\n", + "These parameters allow a single scenario to be recycled for a multitude of different network settings. For example, `RingScenario` may be used to create ring roads of variable length with a variable number of lanes and vehicles.\n", "\n", "### 2.1 Name\n", "The `name` argument is a string variable depicting the name of the scenario. This has no effect on the type of network created." @@ -338,7 +338,7 @@ "outputs": [], "source": [ "# create the scenario object\n", - "scenario = LoopScenario(name=\"ring_example\",\n", + "scenario = RingScenario(name=\"ring_example\",\n", " vehicles=vehicles,\n", " net_params=net_params,\n", " initial_config=initial_config,\n", diff --git a/tutorials/tutorial03_rllib.ipynb b/tutorials/tutorial03_rllib.ipynb index 9c2ffb13fc..fccdb25083 100644 --- a/tutorials/tutorial03_rllib.ipynb +++ b/tutorials/tutorial03_rllib.ipynb @@ -14,7 +14,7 @@ "All simulations, both in the presence and absence of RL, require two components: a *scenario*, and an *environment*. Scenarios describe the features of the transportation network used in simulation. This includes the positions and properties of nodes and edges constituting the lanes and junctions, as well as properties of the vehicles, traffic lights, inflows, etc... in the network. Environments, on the other hand, initialize, reset, and advance simulations, and act as the primary interface between the reinforcement learning algorithm and the scenario. Moreover, custom environments may be used to modify the dynamical features of an scenario. Finally, in the RL case, it is in the *environment* that the state/action spaces and the reward function are defined. \n", "\n", "## 2. Setting up a Scenario\n", - "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. For this exercise, which involves a single lane ring road, we will use the scenario `LoopScenario`.\n", + "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. For this exercise, which involves a single lane ring road, we will use the scenario `RingScenario`.\n", "\n", "### 2.1 Setting up Scenario Parameters\n", "\n", @@ -54,7 +54,7 @@ "outputs": [], "source": [ "# ring road scenario class\n", - "scenario_name = \"LoopScenario\"" + "scenario_name = \"RingScenario\"" ] }, { diff --git a/tutorials/tutorial04_rllab.ipynb b/tutorials/tutorial04_rllab.ipynb index 80c7173a43..501661517f 100644 --- a/tutorials/tutorial04_rllab.ipynb +++ b/tutorials/tutorial04_rllab.ipynb @@ -14,7 +14,7 @@ "All simulations, both in the presence and absence of RL, require two components: a *scenario*, and an *environment*. Scenarios describe the features of the transportation network used in simulation. This includes the positions and properties of nodes and edges constituting the lanes and junctions, as well as properties of the vehicles, traffic lights, inflows, etc... in the network. Environments, on the other hand, initialize, reset, and advance simulations, and act as the primary interface between the reinforcement learning algorithm and the scenario. Moreover, custom environments may be used to modify the dynamical features of an scenario. Finally, in the RL case, it is in the *environment* that the state/action spaces and the reward function are defined. \n", "\n", "## 2. Setting up a Scenario\n", - "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. For this exercise, which involves a single lane ring road, we will use the scenario `LoopScenario`.\n", + "Flow contains a plethora of pre-designed scenarios used to replicate highways, intersections, and merges in both closed and open settings. All these scenarios are located in flow/scenarios. For this exercise, which involves a single lane ring road, we will use the scenario `RingScenario`.\n", "\n", "### 2.1 Setting up Scenario Parameters\n", "\n", @@ -35,7 +35,7 @@ "outputs": [], "source": [ "# ring road scenario class\n", - "from flow.scenarios.ring import LoopScenario\n", + "from flow.scenarios.ring import RingScenario\n", "\n", "# input parameter classes to the scenario class\n", "from flow.core.params import NetParams, InitialConfig\n", @@ -138,7 +138,7 @@ "metadata": {}, "outputs": [], "source": [ - "scenario = LoopScenario(name=\"ring_example\",\n", + "scenario = RingScenario(name=\"ring_example\",\n", " vehicles=vehicles,\n", " net_params=net_params,\n", " initial_config=initial_config,\n", diff --git a/tutorials/tutorial09_environments.ipynb b/tutorials/tutorial09_environments.ipynb index 595b0f0782..c87013e878 100644 --- a/tutorials/tutorial09_environments.ipynb +++ b/tutorials/tutorial09_environments.ipynb @@ -304,7 +304,7 @@ "\n", "initial_config = InitialConfig(bunching=20)\n", "\n", - "scenario = LoopScenario(name=\"sugiyama\",\n", + "scenario = RingScenario(name=\"sugiyama\",\n", " vehicles=vehicles,\n", " net_params=net_params,\n", " initial_config=initial_config)\n", @@ -390,7 +390,7 @@ "\n", " initial_config = InitialConfig(bunching=20)\n", "\n", - " scenario = LoopScenario(name=\"sugiyama-training\",\n", + " scenario = RingScenario(name=\"sugiyama-training\",\n", " vehicles=vehicles,\n", " net_params=net_params,\n", " initial_config=initial_config)\n", From 6bae833087be637e7f9f6239987bfe865b5dff4b Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sun, 18 Aug 2019 22:21:34 -0700 Subject: [PATCH 08/23] merge multiagent_envs into envs --- docs/source/multiagent.rst | 2 +- flow/{multiagent_envs => envs/multiagent}/__init__.py | 6 +++--- .../multiagent_env.py => envs/multiagent/base.py} | 0 .../multiagent}/grid/grid_trafficlight_timing.py | 2 +- flow/{multiagent_envs => envs/multiagent}/ring/__init__.py | 0 flow/{multiagent_envs => envs/multiagent}/ring/accel.py | 2 +- .../multiagent}/ring/wave_attenuation.py | 2 +- flow/utils/registry.py | 2 +- flow/visualize/visualizer_rllib.py | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename flow/{multiagent_envs => envs/multiagent}/__init__.py (51%) rename flow/{multiagent_envs/multiagent_env.py => envs/multiagent/base.py} (100%) rename flow/{multiagent_envs => envs/multiagent}/grid/grid_trafficlight_timing.py (99%) rename flow/{multiagent_envs => envs/multiagent}/ring/__init__.py (100%) rename flow/{multiagent_envs => envs/multiagent}/ring/accel.py (97%) rename flow/{multiagent_envs => envs/multiagent}/ring/wave_attenuation.py (98%) diff --git a/docs/source/multiagent.rst b/docs/source/multiagent.rst index 1c73ed264d..cb2585a09b 100644 --- a/docs/source/multiagent.rst +++ b/docs/source/multiagent.rst @@ -16,7 +16,7 @@ The keys of the dictionary are IDs of the agent policies. A brief example of a multiagent env: :: - from flow.envs.multiagent_env import MultiEnv + from flow.envs.multiagent.base import MultiEnv class MultiAgentAccelEnv(AccelEnv, MultiEnv): """Example MultiAgent environment""" diff --git a/flow/multiagent_envs/__init__.py b/flow/envs/multiagent/__init__.py similarity index 51% rename from flow/multiagent_envs/__init__.py rename to flow/envs/multiagent/__init__.py index bdc9660c78..7d3d8bd5df 100644 --- a/flow/multiagent_envs/__init__.py +++ b/flow/envs/multiagent/__init__.py @@ -1,8 +1,8 @@ """Empty init file to ensure documentation for multi-agent envs is created.""" -from flow.multiagent_envs.multiagent_env import MultiEnv -from flow.multiagent_envs.ring.wave_attenuation import \ +from flow.envs.multiagent.base import MultiEnv +from flow.envs.multiagent.ring.wave_attenuation import \ MultiWaveAttenuationPOEnv -from flow.multiagent_envs.ring.accel import MultiAgentAccelEnv +from flow.envs.multiagent.ring.accel import MultiAgentAccelEnv __all__ = ['MultiEnv', 'MultiAgentAccelEnv', 'MultiWaveAttenuationPOEnv'] diff --git a/flow/multiagent_envs/multiagent_env.py b/flow/envs/multiagent/base.py similarity index 100% rename from flow/multiagent_envs/multiagent_env.py rename to flow/envs/multiagent/base.py diff --git a/flow/multiagent_envs/grid/grid_trafficlight_timing.py b/flow/envs/multiagent/grid/grid_trafficlight_timing.py similarity index 99% rename from flow/multiagent_envs/grid/grid_trafficlight_timing.py rename to flow/envs/multiagent/grid/grid_trafficlight_timing.py index 71f928e8e3..4c97264183 100644 --- a/flow/multiagent_envs/grid/grid_trafficlight_timing.py +++ b/flow/envs/multiagent/grid/grid_trafficlight_timing.py @@ -2,7 +2,7 @@ import numpy as np from flow.core import rewards -from flow.multiagent_envs.multiagent_env import MultiEnv +from flow.envs.multiagent.base import MultiEnv # todo for Ashkan: This needs to be defined for multi-agent RL in grid scenario diff --git a/flow/multiagent_envs/ring/__init__.py b/flow/envs/multiagent/ring/__init__.py similarity index 100% rename from flow/multiagent_envs/ring/__init__.py rename to flow/envs/multiagent/ring/__init__.py diff --git a/flow/multiagent_envs/ring/accel.py b/flow/envs/multiagent/ring/accel.py similarity index 97% rename from flow/multiagent_envs/ring/accel.py rename to flow/envs/multiagent/ring/accel.py index 59be6c8b35..ba2e32fed4 100644 --- a/flow/multiagent_envs/ring/accel.py +++ b/flow/envs/multiagent/ring/accel.py @@ -3,7 +3,7 @@ import numpy as np from flow.core import rewards from flow.envs.ring.accel import AccelEnv -from flow.multiagent_envs.multiagent_env import MultiEnv +from flow.envs.multiagent.base import MultiEnv class MultiAgentAccelEnv(AccelEnv, MultiEnv): diff --git a/flow/multiagent_envs/ring/wave_attenuation.py b/flow/envs/multiagent/ring/wave_attenuation.py similarity index 98% rename from flow/multiagent_envs/ring/wave_attenuation.py rename to flow/envs/multiagent/ring/wave_attenuation.py index 68bb5b21f3..89a71ee073 100644 --- a/flow/multiagent_envs/ring/wave_attenuation.py +++ b/flow/envs/multiagent/ring/wave_attenuation.py @@ -10,7 +10,7 @@ import numpy as np from gym.spaces.box import Box -from flow.multiagent_envs.multiagent_env import MultiEnv +from flow.envs.multiagent.base import MultiEnv ADDITIONAL_ENV_PARAMS = { # maximum acceleration of autonomous vehicles diff --git a/flow/utils/registry.py b/flow/utils/registry.py index 61a2f1f753..d225a070f8 100644 --- a/flow/utils/registry.py +++ b/flow/utils/registry.py @@ -92,7 +92,7 @@ def create_env(*_): if params['env_name'] in single_agent_envs: env_loc = 'flow.envs' else: - env_loc = 'flow.multiagent_envs' + env_loc = 'flow.envs.multiagent' try: register( diff --git a/flow/visualize/visualizer_rllib.py b/flow/visualize/visualizer_rllib.py index 1c1a69473e..4caf5f1924 100644 --- a/flow/visualize/visualizer_rllib.py +++ b/flow/visualize/visualizer_rllib.py @@ -135,7 +135,7 @@ def visualizer_rllib(args): # if flow_params['env_name'] in single_agent_envs: # env_loc = 'flow.envs' # else: - # env_loc = 'flow.multiagent_envs' + # env_loc = 'flow.envs.multiagent' # Start the environment with the gui turned on and a path for the # emission file From a12a6ddcc85d021ac78c2bae97ff79ab230489b6 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sun, 18 Aug 2019 22:51:04 -0700 Subject: [PATCH 09/23] changed all apperance of green wave to traffic light grid --- docs/source/examples.rst | 2 +- docs/source/flow.envs.rst | 2 +- examples/sumo/grid.py | 2 +- flow/core/kernel/vehicle/traci.py | 2 +- flow/envs/__init__.py | 4 ++-- .../grid_trafficlight_timing.py => traffic_light_grid.py} | 4 ++-- flow/envs/traffic_light_grid.py | 4 ++-- tests/setup_scripts.py | 4 ++-- tutorials/tutorial11_traffic_lights.ipynb | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) rename flow/envs/multiagent/{grid/grid_trafficlight_timing.py => traffic_light_grid.py} (98%) diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 1f4e85a178..48fd436ade 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -63,7 +63,7 @@ Flow comes with a New York City style, configurable grid of traffic lights where control both the traffic lights and the autonomous vehicles. The build-in reward is to minimize the total system delay. The number of rows and columns can be adjusted by changing the values in `N_ROWS` and `N_COLUMNS` and the inflows adjusted by changing `EDGE_INFLOW`. Relevant files are -`green_wave.py` in the examples folder and `grid_0.py` and `grid_1.py` in the benchmark folder. +`traffic_light_grid.py` in the examples folder and `grid_0.py` and `grid_1.py` in the benchmark folder. .. image:: ../img/grid-corl2018.png :width: 400 diff --git a/docs/source/flow.envs.rst b/docs/source/flow.envs.rst index ed136b19c1..fb383c11c0 100644 --- a/docs/source/flow.envs.rst +++ b/docs/source/flow.envs.rst @@ -27,7 +27,7 @@ flow.envs.bottleneck\_env module :undoc-members: :show-inheritance: -flow.envs.green\_wave\_env module +flow.envs.traffic\_light\_grid module --------------------------------- .. automodule:: flow.envs.traffic_light_grid diff --git a/examples/sumo/grid.py b/examples/sumo/grid.py index 9b8d8013fa..3be4cbf6a8 100644 --- a/examples/sumo/grid.py +++ b/examples/sumo/grid.py @@ -6,7 +6,7 @@ from flow.core.params import TrafficLightParams from flow.core.params import SumoCarFollowingParams from flow.core.params import InFlows -from flow.envs.loop.accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS from flow.scenarios.grid import SimpleGridScenario diff --git a/flow/core/kernel/vehicle/traci.py b/flow/core/kernel/vehicle/traci.py index 17e9828f75..4691fb25d3 100644 --- a/flow/core/kernel/vehicle/traci.py +++ b/flow/core/kernel/vehicle/traci.py @@ -138,7 +138,7 @@ def update(self, reset): if veh_id in self.get_ids(): # this occurs when a vehicle is actively being removed and # placed again in the network to ensure a constant number of - # total vehicles (e.g. GreenWaveEnv). In this case, the vehicle + # total vehicles (e.g. TrafficLightGridEnv). In this case, the vehicle # is already in the class; its state data just needs to be # updated pass diff --git a/flow/envs/__init__.py b/flow/envs/__init__.py index 0f7ecdfcc8..0c002016cd 100755 --- a/flow/envs/__init__.py +++ b/flow/envs/__init__.py @@ -4,7 +4,7 @@ from flow.envs.bottleneck import BottleneckAccelEnv, BottleneckEnv, \ BottleneckDesiredVelocityEnv from flow.envs.traffic_light_grid import TrafficLightGridEnv, \ - TrafficLightGridPOEnv, GreenWaveTestEnv + TrafficLightGridPOEnv, TrafficLightGridTestEnv from flow.envs.ring.lane_change_accel import LaneChangeAccelEnv, \ LaneChangeAccelPOEnv from flow.envs.ring.accel import AccelEnv @@ -15,7 +15,7 @@ __all__ = [ 'Env', 'AccelEnv', 'LaneChangeAccelEnv', - 'LaneChangeAccelPOEnv', 'GreenWaveTestEnv', 'GreenWaveTestEnv', + 'LaneChangeAccelPOEnv', 'TrafficLightGridTestEnv', 'MergePOEnv', 'BottleneckEnv', 'BottleneckAccelEnv', 'WaveAttenuationEnv', 'WaveAttenuationPOEnv', 'TrafficLightGridEnv', 'TrafficLightGridPOEnv', diff --git a/flow/envs/multiagent/grid/grid_trafficlight_timing.py b/flow/envs/multiagent/traffic_light_grid.py similarity index 98% rename from flow/envs/multiagent/grid/grid_trafficlight_timing.py rename to flow/envs/multiagent/traffic_light_grid.py index 4c97264183..55bd5f7f00 100644 --- a/flow/envs/multiagent/grid/grid_trafficlight_timing.py +++ b/flow/envs/multiagent/traffic_light_grid.py @@ -9,7 +9,7 @@ from gym.spaces.discrete import Discrete from gym.spaces.box import Box from gym.spaces.tuple_space import Tuple -from flow.envs.green_wave_env import TrafficLightGridEnv +from flow.envs.traffic_light_grid import TrafficLightGridEnv ADDITIONAL_ENV_PARAMS = { # minimum switch time for each traffic light (in seconds) @@ -24,7 +24,7 @@ -class MultiAgentGrid(TrafficLightGridEnv, MultiEnv): +class MultiAgentTrafficLightGrid(TrafficLightGridEnv, MultiEnv): """Grid multi agent env. """ diff --git a/flow/envs/traffic_light_grid.py b/flow/envs/traffic_light_grid.py index fd8a1af9e8..5415738f7e 100644 --- a/flow/envs/traffic_light_grid.py +++ b/flow/envs/traffic_light_grid.py @@ -571,11 +571,11 @@ def additional_command(self): [self.k.vehicle.set_observed(veh_id) for veh_id in self.observed_ids] -class GreenWaveTestEnv(TrafficLightGridEnv): +class TrafficLightGridTestEnv(TrafficLightGridEnv): """ Class for use in testing. - This class overrides RL methods of green wave so we can test + This class overrides RL methods of Traffic Light Grid so we can test construction without needing to specify RL methods """ diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index 0352177ef8..1571bd26ac 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -14,7 +14,7 @@ SumoCarFollowingParams from flow.core.params import TrafficLightParams from flow.core.params import VehicleParams -from flow.envs.traffic_light_grid import GreenWaveTestEnv +from flow.envs.traffic_light_grid import TrafficLightGridTestEnv from flow.envs.ring.accel import AccelEnv from flow.scenarios.figure_eight import Figure8Scenario from flow.scenarios.grid import SimpleGridScenario @@ -414,7 +414,7 @@ def grid_mxn_exp_setup(row_num=1, traffic_lights=tl_logic) # create the environment - env = GreenWaveTestEnv( + env = TrafficLightGridTestEnv( env_params=env_params, sim_params=sim_params, scenario=scenario) # reset the environment diff --git a/tutorials/tutorial11_traffic_lights.ipynb b/tutorials/tutorial11_traffic_lights.ipynb index 783d1b1494..d6c5121679 100644 --- a/tutorials/tutorial11_traffic_lights.ipynb +++ b/tutorials/tutorial11_traffic_lights.ipynb @@ -316,7 +316,7 @@ "metadata": {}, "source": [ "## 6. Controlling Your Traffic Lights via RL\n", - "This is where we switch from the `grid.py` experiment script to `green_wave.py`. \n", + "This is where we switch from the `grid.py` experiment script to `traffic_light_grid.py`. \n", "\n", "To control traffic lights via RL, no `tl_logic` element is necessary. This is because rllab is controlling all the parameters you were able to customize in the prior sections. Your `additional_net_params` should look something like this: " ] From 56f234a2c48834d3448a15d997a673093d7939f6 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sun, 18 Aug 2019 23:26:25 -0700 Subject: [PATCH 10/23] Fixed names for scenarios so that they match the environments. Everything is uniform now --- ...corl2018.png => figure_eight-corl2018.png} | Bin ...ring_merge.gif => two_rings_one_merge.gif} | Bin docs/source/examples.rst | 2 +- examples/README.md | 4 +-- examples/aimsun/figure_eight.py | 6 ++--- examples/aimsun/grid.py | 4 +-- examples/rllab/cooperative_merge.py | 4 +-- examples/rllab/figure_eight.py | 4 +-- examples/rllab/green_wave.py | 4 +-- examples/rllib/cooperative_merge.py | 2 +- examples/rllib/figure_eight.py | 2 +- examples/rllib/green_wave.py | 2 +- .../multiagent_figure_eight.py | 2 +- examples/sumo/figure_eight.py | 6 ++--- examples/sumo/grid.py | 4 +-- .../{ring_merge.py => two_rings_one_merge.py} | 6 ++--- flow/benchmarks/figureeight0.py | 2 +- flow/benchmarks/figureeight1.py | 2 +- flow/benchmarks/figureeight2.py | 2 +- flow/benchmarks/grid0.py | 2 +- flow/benchmarks/grid1.py | 2 +- flow/scenarios/__init__.py | 10 ++++---- flow/scenarios/figure_eight.py | 6 ++--- .../{grid.py => traffic_light_grid.py} | 6 ++--- .../{ring_merge.py => two_rings_one_merge.py} | 6 ++--- flow/visualize/time_space_diagram.py | 10 ++++---- tests/fast_tests/test_examples.py | 6 ++--- tests/fast_tests/test_files/fig8.json | 2 +- tests/fast_tests/test_scenarios.py | 24 +++++++++--------- tests/fast_tests/test_util.py | 2 +- tests/setup_scripts.py | 8 +++--- tutorials/tutorial11_traffic_lights.ipynb | 6 ++--- 32 files changed, 74 insertions(+), 74 deletions(-) rename docs/img/{figure8-corl2018.png => figure_eight-corl2018.png} (100%) rename docs/img/{ring_merge.gif => two_rings_one_merge.gif} (100%) rename examples/sumo/{ring_merge.py => two_rings_one_merge.py} (94%) rename flow/scenarios/{grid.py => traffic_light_grid.py} (99%) rename flow/scenarios/{ring_merge.py => two_rings_one_merge.py} (98%) diff --git a/docs/img/figure8-corl2018.png b/docs/img/figure_eight-corl2018.png similarity index 100% rename from docs/img/figure8-corl2018.png rename to docs/img/figure_eight-corl2018.png diff --git a/docs/img/ring_merge.gif b/docs/img/two_rings_one_merge.gif similarity index 100% rename from docs/img/ring_merge.gif rename to docs/img/two_rings_one_merge.gif diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 48fd436ade..52ed147936 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -32,7 +32,7 @@ is relatively light-weight and can be trained the quickest. It can serve both as that the training process is working correctly and as a study of the difficulty of controlling many vehicles simultaneously. -.. image:: ../img/figure8-corl2018.png +.. image:: ../img/figure_eight-corl2018.png :width: 400 :align: center diff --git a/examples/README.md b/examples/README.md index 5f000ed179..99ddc2bf10 100644 --- a/examples/README.md +++ b/examples/README.md @@ -77,11 +77,11 @@ Example of an open multi-lane network with human-driven vehicles. ![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/highway.gif) -### ring_merge.py +### two_rings_one_merge.py Example of ring road with larger merging ring. -![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/ring_merge.gif) +![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/two_rings_one_merge.gif) ### merge.py diff --git a/examples/aimsun/figure_eight.py b/examples/aimsun/figure_eight.py index 51639a6a0f..6f56d1a9ab 100644 --- a/examples/aimsun/figure_eight.py +++ b/examples/aimsun/figure_eight.py @@ -9,7 +9,7 @@ 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 Figure8Scenario, ADDITIONAL_NET_PARAMS +from flow.scenarios.figure_eight import FigureEightScenario, ADDITIONAL_NET_PARAMS def figure_eight_example(render=None): @@ -42,8 +42,8 @@ def figure_eight_example(render=None): net_params = NetParams( additional_params=ADDITIONAL_NET_PARAMS.copy()) - scenario = Figure8Scenario( - name="figure8", + scenario = figure_eight_example( + name="FigureEight", vehicles=vehicles, net_params=net_params) diff --git a/examples/aimsun/grid.py b/examples/aimsun/grid.py index 902727a9e8..c14f1591e8 100644 --- a/examples/aimsun/grid.py +++ b/examples/aimsun/grid.py @@ -4,7 +4,7 @@ from flow.core.params import VehicleParams from flow.core.params import TrafficLightParams from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.grid import SimpleGridScenario +from flow.scenarios.traffic_light_grid import TrafficLightGridScenario def grid_example(render=None): @@ -102,7 +102,7 @@ def grid_example(render=None): initial_config = InitialConfig(spacing='custom') - scenario = SimpleGridScenario( + scenario = TrafficLightGridScenario( name="grid-intersection", vehicles=vehicles, net_params=net_params, diff --git a/examples/rllab/cooperative_merge.py b/examples/rllab/cooperative_merge.py index 39880a133f..e8512c99ee 100644 --- a/examples/rllab/cooperative_merge.py +++ b/examples/rllab/cooperative_merge.py @@ -16,7 +16,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams -from flow.scenarios.ring_merge import TwoRingsOneMergingScenario, \ +from flow.scenarios.two_rings_one_merge import TwoRingsOneMergeScenario, \ ADDITIONAL_NET_PARAMS HORIZON = 300 @@ -86,7 +86,7 @@ def run_task(*_): initial_config = InitialConfig(x0=50, spacing="uniform") - scenario = TwoRingsOneMergingScenario( + scenario = TwoRingsOneMergeScenario( name=exp_tag, vehicles=vehicles, net_params=net_params, diff --git a/examples/rllab/figure_eight.py b/examples/rllab/figure_eight.py index 1fdb99dfba..f06427e05f 100644 --- a/examples/rllab/figure_eight.py +++ b/examples/rllab/figure_eight.py @@ -6,7 +6,7 @@ from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy -from flow.scenarios.figure_eight import Figure8Scenario +from flow.scenarios.figure_eight import FigureEightScenario from flow.controllers import RLController, IDMController, ContinuousRouter from flow.core.params import VehicleParams from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ @@ -63,7 +63,7 @@ def run_task(*_): initial_config = InitialConfig(spacing="uniform") print("XXX name", exp_tag) - scenario = Figure8Scenario( + scenario = FigureEightScenario( exp_tag, vehicles, net_params, diff --git a/examples/rllab/green_wave.py b/examples/rllab/green_wave.py index 146f6e34c2..433d456235 100644 --- a/examples/rllab/green_wave.py +++ b/examples/rllab/green_wave.py @@ -14,7 +14,7 @@ from flow.controllers import SimCarFollowingController, GridRouter -from flow.scenarios.grid import SimpleGridScenario +from flow.scenarios.traffic_light_grid import TrafficLightGridScenario # set to true if you would like to run the experiment with inflows of vehicles # from the edges, and false otherwise @@ -199,7 +199,7 @@ def run_task(*_): initial_config, net_params = get_non_flow_params( V_ENTER, additional_net_params) - scenario = SimpleGridScenario( + scenario = TrafficLightGridScenario( name="grid-intersection", vehicles=vehicles, net_params=net_params, diff --git a/examples/rllib/cooperative_merge.py b/examples/rllib/cooperative_merge.py index f303033dda..aa5af7e114 100644 --- a/examples/rllib/cooperative_merge.py +++ b/examples/rllib/cooperative_merge.py @@ -88,7 +88,7 @@ env_name='AccelEnv', # name of the scenario class the experiment is running on - scenario='TwoRingsOneMergingScenario', + scenario='TwoRingsOneMergeScenario', # simulator that is used by the experiment simulator='traci', diff --git a/examples/rllib/figure_eight.py b/examples/rllib/figure_eight.py index e128b04920..89ddaf0c2a 100644 --- a/examples/rllib/figure_eight.py +++ b/examples/rllib/figure_eight.py @@ -56,7 +56,7 @@ env_name='AccelEnv', # name of the scenario class the experiment is running on - scenario='Figure8Scenario', + scenario='FigureEightScenario', # simulator that is used by the experiment simulator='traci', diff --git a/examples/rllib/green_wave.py b/examples/rllib/green_wave.py index e0dc1fa6e7..edd0d0c9fb 100644 --- a/examples/rllib/green_wave.py +++ b/examples/rllib/green_wave.py @@ -186,7 +186,7 @@ def get_non_flow_params(enter_speed, add_net_params): env_name='TrafficLightGridPOEnv', # name of the scenario class the experiment is running on - scenario='SimpleGridScenario', + scenario='TrafficLightGridScenario', # simulator that is used by the experiment simulator='traci', diff --git a/examples/rllib/multiagent_exps/multiagent_figure_eight.py b/examples/rllib/multiagent_exps/multiagent_figure_eight.py index 8e736d843d..c63c1ff4e7 100644 --- a/examples/rllib/multiagent_exps/multiagent_figure_eight.py +++ b/examples/rllib/multiagent_exps/multiagent_figure_eight.py @@ -69,7 +69,7 @@ env_name='MultiAgentAccelEnv', # name of the scenario class the experiment is running on - scenario='Figure8Scenario', + scenario='FigureEightScenario', # simulator that is used by the experiment simulator='traci', diff --git a/examples/sumo/figure_eight.py b/examples/sumo/figure_eight.py index cef0b4d647..73fffa61fd 100755 --- a/examples/sumo/figure_eight.py +++ b/examples/sumo/figure_eight.py @@ -10,7 +10,7 @@ SumoCarFollowingParams from flow.core.params import VehicleParams from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.figure_eight import Figure8Scenario, ADDITIONAL_NET_PARAMS +from flow.scenarios.figure_eight import FigureEightScenario, ADDITIONAL_NET_PARAMS def figure_eight_example(render=None): @@ -52,8 +52,8 @@ def figure_eight_example(render=None): net_params = NetParams( no_internal_links=False, additional_params=additional_net_params) - scenario = Figure8Scenario( - name="figure8", + scenario = FigureEightScenario( + name="FigureEight", vehicles=vehicles, net_params=net_params) diff --git a/examples/sumo/grid.py b/examples/sumo/grid.py index 3be4cbf6a8..411294207d 100644 --- a/examples/sumo/grid.py +++ b/examples/sumo/grid.py @@ -7,7 +7,7 @@ from flow.core.params import SumoCarFollowingParams from flow.core.params import InFlows from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.grid import SimpleGridScenario +from flow.scenarios.traffic_light_grid import TrafficLightGridScenario def gen_edges(col_num, row_num): @@ -215,7 +215,7 @@ def grid_example(render=None, use_inflows=False): enter_speed=v_enter, add_net_params=additional_net_params) - scenario = SimpleGridScenario( + scenario = TrafficLightGridScenario( name="grid-intersection", vehicles=vehicles, net_params=net_params, diff --git a/examples/sumo/ring_merge.py b/examples/sumo/two_rings_one_merge.py similarity index 94% rename from examples/sumo/ring_merge.py rename to examples/sumo/two_rings_one_merge.py index 8e8d19edaa..82ba65b579 100755 --- a/examples/sumo/ring_merge.py +++ b/examples/sumo/two_rings_one_merge.py @@ -7,11 +7,11 @@ SumoCarFollowingParams, SumoLaneChangeParams from flow.core.params import VehicleParams from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.ring_merge import TwoRingsOneMergingScenario, \ +from flow.scenarios.two_rings_one_merge import TwoRingsOneMergeScenario, \ ADDITIONAL_NET_PARAMS -def ring_merge_example(render=None): +def two_rings_one_merge_example(render=None): """ Perform a simulation of vehicles on a ring merge. @@ -73,7 +73,7 @@ def ring_merge_example(render=None): initial_config = InitialConfig( x0=50, spacing="uniform", additional_params={"merge_bunching": 0}) - scenario = TwoRingsOneMergingScenario( + scenario = TwoRingsOneMergeScenario( name="two-ring-one-merging", vehicles=vehicles, net_params=net_params, diff --git a/flow/benchmarks/figureeight0.py b/flow/benchmarks/figureeight0.py index fd2a3fb3af..2159d2dde2 100644 --- a/flow/benchmarks/figureeight0.py +++ b/flow/benchmarks/figureeight0.py @@ -49,7 +49,7 @@ env_name="AccelEnv", # name of the scenario class the experiment is running on - scenario="Figure8Scenario", + scenario="FigureEightScenario", # simulator that is used by the experiment simulator='traci', diff --git a/flow/benchmarks/figureeight1.py b/flow/benchmarks/figureeight1.py index a54f5ebd36..8f3d34db5d 100644 --- a/flow/benchmarks/figureeight1.py +++ b/flow/benchmarks/figureeight1.py @@ -50,7 +50,7 @@ env_name="AccelEnv", # name of the scenario class the experiment is running on - scenario="Figure8Scenario", + scenario="FigureEightScenario", # simulator that is used by the experiment simulator='traci', diff --git a/flow/benchmarks/figureeight2.py b/flow/benchmarks/figureeight2.py index c0b6244ae4..0d13b8c182 100644 --- a/flow/benchmarks/figureeight2.py +++ b/flow/benchmarks/figureeight2.py @@ -38,7 +38,7 @@ env_name="AccelEnv", # name of the scenario class the experiment is running on - scenario="Figure8Scenario", + scenario="FigureEightScenario", # simulator that is used by the experiment simulator='traci', diff --git a/flow/benchmarks/grid0.py b/flow/benchmarks/grid0.py index 3c082c6c47..89403f77b0 100644 --- a/flow/benchmarks/grid0.py +++ b/flow/benchmarks/grid0.py @@ -70,7 +70,7 @@ env_name="TrafficLightGridPOEnv", # name of the scenario class the experiment is running on - scenario="SimpleGridScenario", + scenario="TrafficLightGridScenario", # simulator that is used by the experiment simulator='traci', diff --git a/flow/benchmarks/grid1.py b/flow/benchmarks/grid1.py index 316240df11..93b5bfb0b6 100644 --- a/flow/benchmarks/grid1.py +++ b/flow/benchmarks/grid1.py @@ -70,7 +70,7 @@ env_name="TrafficLightGridPOEnv", # name of the scenario class the experiment is running on - scenario="SimpleGridScenario", + scenario="TrafficLightGridScenario", # simulator that is used by the experiment simulator='traci', diff --git a/flow/scenarios/__init__.py b/flow/scenarios/__init__.py index 03b2880c30..8f8634aea3 100644 --- a/flow/scenarios/__init__.py +++ b/flow/scenarios/__init__.py @@ -7,18 +7,18 @@ from flow.scenarios.bay_bridge import BayBridgeScenario from flow.scenarios.bay_bridge_toll import BayBridgeTollScenario from flow.scenarios.bottleneck import BottleneckScenario -from flow.scenarios.figure_eight import Figure8Scenario -from flow.scenarios.grid import SimpleGridScenario +from flow.scenarios.figure_eight import FigureEightScenario +from flow.scenarios.traffic_light_grid import TrafficLightGridScenario from flow.scenarios.highway import HighwayScenario from flow.scenarios.ring import RingScenario from flow.scenarios.merge import MergeScenario -from flow.scenarios.ring_merge import TwoRingsOneMergingScenario +from flow.scenarios.two_rings_one_merge import TwoRingsOneMergeScenario from flow.scenarios.multi_ring import MultiRingScenario from flow.scenarios.minicity import MiniCityScenario __all__ = [ "Scenario", "BayBridgeScenario", "BayBridgeTollScenario", - "BottleneckScenario", "Figure8Scenario", "SimpleGridScenario", + "BottleneckScenario", "FigureEightScenario", "TrafficLightGridScenario", "HighwayScenario", "RingScenario", "MergeScenario", - "TwoRingsOneMergingScenario", "MultiRingScenario", "MiniCityScenario" + "TwoRingsOneMergeScenario", "MultiRingScenario", "MiniCityScenario" ] diff --git a/flow/scenarios/figure_eight.py b/flow/scenarios/figure_eight.py index 54d4c5b2e0..5a2269f5db 100755 --- a/flow/scenarios/figure_eight.py +++ b/flow/scenarios/figure_eight.py @@ -19,7 +19,7 @@ } -class Figure8Scenario(Scenario): +class FigureEightScenario(Scenario): """Figure eight scenario class. The figure eight network is an extension of the ring road network: Two @@ -43,9 +43,9 @@ class Figure8Scenario(Scenario): >>> from flow.core.params import NetParams >>> from flow.core.params import VehicleParams >>> from flow.core.params import InitialConfig - >>> from flow.scenarios import Figure8Scenario + >>> from flow.scenarios import FigureEightScenario >>> - >>> scenario = Figure8Scenario( + >>> scenario = FigureEightScenario( >>> name='figure_eight', >>> vehicles=VehicleParams(), >>> net_params=NetParams( diff --git a/flow/scenarios/grid.py b/flow/scenarios/traffic_light_grid.py similarity index 99% rename from flow/scenarios/grid.py rename to flow/scenarios/traffic_light_grid.py index 8b938c56df..b01d94afd9 100644 --- a/flow/scenarios/grid.py +++ b/flow/scenarios/traffic_light_grid.py @@ -40,7 +40,7 @@ } -class SimpleGridScenario(Scenario): +class TrafficLightGridScenario(Scenario): """Grid scenario class. The grid scenario consists of m vertical lanes and n horizontal lanes, @@ -78,9 +78,9 @@ class SimpleGridScenario(Scenario): >>> from flow.core.params import NetParams >>> from flow.core.params import VehicleParams >>> from flow.core.params import InitialConfig - >>> from flow.scenarios import SimpleGridScenario + >>> from flow.scenarios import TrafficLightGridScenario >>> - >>> scenario = SimpleGridScenario( + >>> scenario = TrafficLightGridScenario( >>> name='grid', >>> vehicles=VehicleParams(), >>> net_params=NetParams( diff --git a/flow/scenarios/ring_merge.py b/flow/scenarios/two_rings_one_merge.py similarity index 98% rename from flow/scenarios/ring_merge.py rename to flow/scenarios/two_rings_one_merge.py index 7d7a339b26..c16bf13e7f 100644 --- a/flow/scenarios/ring_merge.py +++ b/flow/scenarios/two_rings_one_merge.py @@ -21,7 +21,7 @@ } -class TwoRingsOneMergingScenario(Scenario): +class TwoRingsOneMergeScenario(Scenario): """Two ring merge scenario. This network is expected to simulate a closed ring representation of a @@ -43,9 +43,9 @@ class TwoRingsOneMergingScenario(Scenario): >>> from flow.core.params import NetParams >>> from flow.core.params import VehicleParams >>> from flow.core.params import InitialConfig - >>> from flow.scenarios import TwoRingsOneMergingScenario + >>> from flow.scenarios import TwoRingsOneMergeScenario >>> - >>> scenario = TwoRingsOneMergingScenario( + >>> scenario = TwoRingsOneMergeScenario( >>> name='two_rings_merge', >>> vehicles=VehicleParams(), >>> net_params=NetParams( diff --git a/flow/visualize/time_space_diagram.py b/flow/visualize/time_space_diagram.py index 286c6475ea..d9e42a3cf6 100644 --- a/flow/visualize/time_space_diagram.py +++ b/flow/visualize/time_space_diagram.py @@ -27,7 +27,7 @@ # scenarios that can be plotted by this method ACCEPTABLE_SCENARIOS = [ 'RingScenario', - 'Figure8Scenario', + 'FigureEightScenario', 'MergeScenario', ] @@ -122,7 +122,7 @@ def get_time_space_data(data, params): switcher = { 'RingScenario': _ring_road, 'MergeScenario': _merge, - 'Figure8Scenario': _figure_eight + 'FigureEightScenario': _figure_eight } # Collect a list of all the unique times. @@ -353,14 +353,14 @@ def _figure_eight(data, params, all_time): speed[ind, i] = spd # reorganize data for space-time plot - figure8_len = 6*ring_edgelen + 2*intersection + 2*junction + 10*inner + figure_eight_len = 6*ring_edgelen + 2*intersection + 2*junction + 10*inner intersection_loc = [edgestarts[':center_1'] + intersection / 2, edgestarts[':center_0'] + intersection / 2] - pos[pos < intersection_loc[0]] += figure8_len + pos[pos < intersection_loc[0]] += figure_eight_len pos[np.logical_and(pos > intersection_loc[0], pos < intersection_loc[1])] \ += - intersection_loc[1] pos[pos > intersection_loc[1]] = \ - - pos[pos > intersection_loc[1]] + figure8_len + intersection_loc[0] + - pos[pos > intersection_loc[1]] + figure_eight_len + intersection_loc[0] return pos, speed diff --git a/tests/fast_tests/test_examples.py b/tests/fast_tests/test_examples.py index eacd1e62ce..9dde05acb2 100644 --- a/tests/fast_tests/test_examples.py +++ b/tests/fast_tests/test_examples.py @@ -8,7 +8,7 @@ from examples.sumo.figure_eight import figure_eight_example from examples.sumo.grid import grid_example from examples.sumo.highway import highway_example -from examples.sumo.ring_merge import ring_merge_example +from examples.sumo.two_rings_one_merge import two_rings_one_merge_example from examples.sumo.merge import merge_example from examples.sumo.minicity import minicity_example from examples.sumo.sugiyama import sugiyama_example @@ -89,10 +89,10 @@ def test_sugiyama(self): # run the experiment for a few time steps to ensure it doesn't fail exp.run(1, 5) - def test_ring_merge(self): + def test_two_rings_one_merge(self): """Verify that examples/sumo/two_rings_merge_straight.py is working.""" # import the experiment variable from the example - exp = ring_merge_example(render=False) + exp = two_rings_one_merge_example(render=False) # run the experiment for a few time steps to ensure it doesn't fail exp.run(1, 5) diff --git a/tests/fast_tests/test_files/fig8.json b/tests/fast_tests/test_files/fig8.json index bd76859d9f..06f96d3664 100644 --- a/tests/fast_tests/test_files/fig8.json +++ b/tests/fast_tests/test_files/fig8.json @@ -40,7 +40,7 @@ "osm_path": null, "template": null }, - "scenario": "Figure8Scenario", + "scenario": "FigureEightScenario", "sim": { "emission_path": null, "lateral_resolution": null, diff --git a/tests/fast_tests/test_scenarios.py b/tests/fast_tests/test_scenarios.py index 1e7009150a..bd651471fd 100644 --- a/tests/fast_tests/test_scenarios.py +++ b/tests/fast_tests/test_scenarios.py @@ -2,9 +2,9 @@ import os from flow.core.params import VehicleParams from flow.core.params import NetParams -from flow.scenarios import BottleneckScenario, Figure8Scenario, \ - SimpleGridScenario, HighwayScenario, RingScenario, MergeScenario, \ - TwoRingsOneMergingScenario, MiniCityScenario, MultiRingScenario +from flow.scenarios import BottleneckScenario, FigureEightScenario, \ + TrafficLightGridScenario, HighwayScenario, RingScenario, MergeScenario, \ + TwoRingsOneMergeScenario, MiniCityScenario, MultiRingScenario __all__ = [ "MultiRingScenario", "MiniCityScenario" @@ -30,15 +30,15 @@ def test_additional_net_params(self): ) -class TestFigure8Scenario(unittest.TestCase): +class TestFigureEightScenario(unittest.TestCase): - """Tests Figure8Scenario in flow/scenarios/figure_eight.py.""" + """Tests FigureEightScenario in flow/scenarios/figure_eight.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - scenario_class=Figure8Scenario, + scenario_class=FigureEightScenario, additional_params={ "radius_ring": 30, "lanes": 1, @@ -49,15 +49,15 @@ def test_additional_net_params(self): ) -class TestSimpleGridScenario(unittest.TestCase): +class TestTrafficLightGridScenario(unittest.TestCase): - """Tests SimpleGridScenario in flow/scenarios/grid.py.""" + """Tests TrafficLightGridScenario in flow/scenarios/grid.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - scenario_class=SimpleGridScenario, + scenario_class=TrafficLightGridScenario, additional_params={ "grid_array": { "row_num": 3, @@ -119,15 +119,15 @@ def test_additional_net_params(self): ) -class TestTwoRingsOneMergingScenario(unittest.TestCase): +class TestTwoRingsOneMergeScenario(unittest.TestCase): - """Tests TwoRingsOneMergingScenario in flow/scenarios/ring_merge.py.""" + """Tests TwoRingsOneMergeScenario in flow/scenarios/two_rings_one_merge.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" self.assertTrue( test_additional_params( - scenario_class=TwoRingsOneMergingScenario, + scenario_class=TwoRingsOneMergeScenario, additional_params={ "ring_radius": 50, "lane_length": 75, diff --git a/tests/fast_tests/test_util.py b/tests/fast_tests/test_util.py index b8088c78ca..3787b3b84d 100644 --- a/tests/fast_tests/test_util.py +++ b/tests/fast_tests/test_util.py @@ -105,7 +105,7 @@ def test_make_create_env(self): flow_params = dict( exp_tag="figure_eight_0", env_name="AccelEnv", - scenario="Figure8Scenario", + scenario="FigureEightScenario", simulator='traci', sim=SumoParams( sim_step=0.1, diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index 1571bd26ac..9a289e9725 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -16,8 +16,8 @@ from flow.core.params import VehicleParams from flow.envs.traffic_light_grid import TrafficLightGridTestEnv from flow.envs.ring.accel import AccelEnv -from flow.scenarios.figure_eight import Figure8Scenario -from flow.scenarios.grid import SimpleGridScenario +from flow.scenarios.figure_eight import FigureEightScenario +from flow.scenarios.traffic_light_grid import TrafficLightGridScenario from flow.scenarios.highway import HighwayScenario from flow.scenarios.ring import RingScenario @@ -192,7 +192,7 @@ def figure_eight_exp_setup(sim_params=None, traffic_lights = TrafficLightParams() # create the scenario - scenario = Figure8Scenario( + scenario = FigureEightScenario( name="FigureEightTest", vehicles=vehicles, net_params=net_params, @@ -406,7 +406,7 @@ def grid_mxn_exp_setup(row_num=1, spacing="custom", additional_params={"enter_speed": 30}) # create the scenario - scenario = SimpleGridScenario( + scenario = TrafficLightGridScenario( name="Grid1x1Test", vehicles=vehicles, net_params=net_params, diff --git a/tutorials/tutorial11_traffic_lights.ipynb b/tutorials/tutorial11_traffic_lights.ipynb index d6c5121679..cd1533645f 100644 --- a/tutorials/tutorial11_traffic_lights.ipynb +++ b/tutorials/tutorial11_traffic_lights.ipynb @@ -17,7 +17,7 @@ "\n", "* Experiment script for RL: `examples/rllab/green_wave.py`\n", "* Experiment script for non-RL: `examples/sumo/grid.py`\n", - "* Scenario: `grid.py` (class SimpleGridScenario)\n", + "* Scenario: `grid.py` (class TrafficLightGridScenario)\n", "* Environment for RL: `traffic_light_grid.py` (class TrafficLightGridEnv)\n", "* Environment for non-RL: `accel.py` (class AccelEnv)\n", "\n", @@ -40,7 +40,7 @@ "outputs": [], "source": [ "from flow.core.params import NetParams\n", - "from flow.scenarios.grid import SimpleGridScenario\n", + "from flow.scenarios.traffic_light_grid import TrafficLightGridScenario\n", "from flow.core.params import TrafficLightParams\n", "from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \\\n", " InFlows, SumoCarFollowingParams\n", @@ -156,7 +156,7 @@ "net_params = NetParams(no_internal_links=False,\n", " additional_params=additional_net_params)\n", "\n", - "scenario = SimpleGridScenario(name=\"grid\",\n", + "scenario = TrafficLightGridScenario(name=\"grid\",\n", " vehicles=VehicleParams(),\n", " net_params=net_params,\n", " initial_config=InitialConfig(),\n", From abcf6cf5b7d19c581900ea974e7e940865e39be4 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Tue, 20 Aug 2019 15:11:25 -0700 Subject: [PATCH 11/23] Removing cooperative_merge (later we called it "TwoRingsOneMerge" --- examples/README.md | 6 - examples/rllab/__init__.py | 1 - examples/rllab/cooperative_merge.py | 136 ------------- examples/rllab/figure_eight.py | 113 ----------- examples/rllab/green_wave.py | 249 ----------------------- examples/rllab/stabilizing_highway.py | 160 --------------- examples/rllab/stabilizing_the_ring.py | 107 ---------- examples/rllab/velocity_bottleneck.py | 175 ---------------- examples/rllib/cooperative_merge.py | 200 ------------------ examples/sumo/two_rings_one_merge.py | 92 --------- flow/scenarios/__init__.py | 3 +- flow/scenarios/two_rings_one_merge.py | 268 ------------------------- tests/fast_tests/test_examples.py | 9 - tests/fast_tests/test_scenarios.py | 23 +-- 14 files changed, 2 insertions(+), 1540 deletions(-) delete mode 100644 examples/rllab/__init__.py delete mode 100644 examples/rllab/cooperative_merge.py delete mode 100644 examples/rllab/figure_eight.py delete mode 100644 examples/rllab/green_wave.py delete mode 100644 examples/rllab/stabilizing_highway.py delete mode 100644 examples/rllab/stabilizing_the_ring.py delete mode 100644 examples/rllab/velocity_bottleneck.py delete mode 100644 examples/rllib/cooperative_merge.py delete mode 100755 examples/sumo/two_rings_one_merge.py delete mode 100644 flow/scenarios/two_rings_one_merge.py diff --git a/examples/README.md b/examples/README.md index 99ddc2bf10..c6897a8496 100644 --- a/examples/README.md +++ b/examples/README.md @@ -77,12 +77,6 @@ Example of an open multi-lane network with human-driven vehicles. ![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/highway.gif) -### two_rings_one_merge.py - -Example of ring road with larger merging ring. - -![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/two_rings_one_merge.gif) - ### merge.py Example of a merge network with human-driven vehicles. diff --git a/examples/rllab/__init__.py b/examples/rllab/__init__.py deleted file mode 100644 index d48602a8b3..0000000000 --- a/examples/rllab/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Empty init file to ensure that the examples documentation builds.""" diff --git a/examples/rllab/cooperative_merge.py b/examples/rllab/cooperative_merge.py deleted file mode 100644 index e8512c99ee..0000000000 --- a/examples/rllab/cooperative_merge.py +++ /dev/null @@ -1,136 +0,0 @@ -"""Trains vehicles to facilitate cooperative merging in a ring merge. - -This example consists of 1 learning agent and 6 additional vehicles in an inner -ring, and 10 vehicles in an outer ring attempting to merge into the inner ring. -""" - -from rllab.algos.trpo import TRPO -from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline -from rllab.envs.gym_env import GymEnv -from rllab.envs.normalized_env import normalize -from rllab.misc.instrument import run_experiment_lite -from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy - -from flow.controllers import RLController, IDMController, \ - SimLaneChangeController, ContinuousRouter -from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ - SumoCarFollowingParams, SumoLaneChangeParams -from flow.core.params import VehicleParams -from flow.scenarios.two_rings_one_merge import TwoRingsOneMergeScenario, \ - ADDITIONAL_NET_PARAMS - -HORIZON = 300 - - -def run_task(*_): - """Implement the run_task method needed to run experiments with rllab.""" - sim_params = SumoParams(sim_step=0.2, render=True) - - # note that the vehicles are added sequentially by the scenario, - # so place the merging vehicles after the vehicles in the ring - vehicles = VehicleParams() - # Inner ring vehicles - vehicles.add( - veh_id="human", - acceleration_controller=(IDMController, { - "noise": 0.2 - }), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=6, - car_following_params=SumoCarFollowingParams(minGap=0.0, tau=0.5), - lane_change_params=SumoLaneChangeParams()) - - # A single learning agent in the inner ring - vehicles.add( - veh_id="rl", - acceleration_controller=(RLController, {}), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=1, - car_following_params=SumoCarFollowingParams( - minGap=0.01, - tau=0.5, - speed_mode="obey_safe_speed" - ), - lane_change_params=SumoLaneChangeParams()) - - # Outer ring vehicles - vehicles.add( - veh_id="merge-human", - acceleration_controller=(IDMController, { - "noise": 0.2 - }), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=10, - car_following_params=SumoCarFollowingParams(minGap=0.0, tau=0.5), - lane_change_params=SumoLaneChangeParams()) - - env_params = EnvParams( - horizon=HORIZON, - additional_params={ - "target_velocity": 10, - "max_accel": 3, - "max_decel": 3, - "sort_vehicles": False - }) - - additional_net_params = ADDITIONAL_NET_PARAMS.copy() - additional_net_params["ring_radius"] = 50 - additional_net_params["inner_lanes"] = 1 - additional_net_params["outer_lanes"] = 1 - additional_net_params["lane_length"] = 75 - net_params = NetParams( - no_internal_links=False, additional_params=additional_net_params) - - initial_config = InitialConfig(x0=50, spacing="uniform") - - scenario = TwoRingsOneMergeScenario( - name=exp_tag, - vehicles=vehicles, - net_params=net_params, - initial_config=initial_config) - - env_name = "AccelEnv" - pass_params = (env_name, sim_params, vehicles, env_params, net_params, - initial_config, scenario) - - env = GymEnv(env_name, record_video=False, register_params=pass_params) - horizon = env.horizon - env = normalize(env) - - policy = GaussianMLPPolicy(env_spec=env.spec, hidden_sizes=(100, 50, 25)) - - baseline = LinearFeatureBaseline(env_spec=env.spec) - - algo = TRPO( - env=env, - policy=policy, - baseline=baseline, - batch_size=64 * 3 * horizon, - max_path_length=horizon, - # whole_paths=True, - n_itr=1000, - discount=0.999, - # step_size=0.01, - ) - algo.train() - - -exp_tag = "cooperative_merge_example" # experiment prefix - -for seed in [1]: # , 5, 10, 56, 73]: - run_experiment_lite( - run_task, - # Number of parallel workers for sampling - n_parallel=1, - # Only keep the snapshot parameters for the last iteration - snapshot_mode="all", - # Specifies the seed for the experiment. If this is not provided, a - # random seed will be used - seed=seed, - mode="local", # "ec2" - exp_prefix=exp_tag, - # plot=True, - ) diff --git a/examples/rllab/figure_eight.py b/examples/rllab/figure_eight.py deleted file mode 100644 index f06427e05f..0000000000 --- a/examples/rllab/figure_eight.py +++ /dev/null @@ -1,113 +0,0 @@ -"""Trains a percentage of AVs to increase traveling speeds in a figure 8.""" - -from rllab.envs.normalized_env import normalize -from rllab.misc.instrument import run_experiment_lite -from rllab.algos.trpo import TRPO -from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline -from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy - -from flow.scenarios.figure_eight import FigureEightScenario -from flow.controllers import RLController, IDMController, ContinuousRouter -from flow.core.params import VehicleParams -from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ - SumoCarFollowingParams -from rllab.envs.gym_env import GymEnv - -HORIZON = 1500 - - -def run_task(*_): - """Implement the run_task method needed to run experiments with rllab.""" - sim_params = SumoParams(sim_step=0.1, render=True) - - vehicles = VehicleParams() - vehicles.add( - veh_id="rl", - acceleration_controller=(RLController, {}), - routing_controller=(ContinuousRouter, {}), - car_following_params=SumoCarFollowingParams( - speed_mode="obey_safe_speed", - decel=1.5, - ), - num_vehicles=1) - vehicles.add( - veh_id="idm", - acceleration_controller=(IDMController, { - "noise": 0.2 - }), - routing_controller=(ContinuousRouter, {}), - car_following_params=SumoCarFollowingParams( - speed_mode="obey_safe_speed", - decel=1.5, - ), - num_vehicles=13) - - additional_env_params = { - "target_velocity": 20, - "max_accel": 3, - "max_decel": 3, - "sort_vehicles": False - } - env_params = EnvParams( - horizon=HORIZON, additional_params=additional_env_params) - - additional_net_params = { - "radius_ring": 30, - "lanes": 1, - "speed_limit": 30, - "resolution": 40 - } - net_params = NetParams( - no_internal_links=False, additional_params=additional_net_params) - - initial_config = InitialConfig(spacing="uniform") - - print("XXX name", exp_tag) - scenario = FigureEightScenario( - exp_tag, - vehicles, - net_params, - initial_config=initial_config) - - env_name = "AccelEnv" - pass_params = (env_name, sim_params, vehicles, env_params, net_params, - initial_config, scenario) - - env = GymEnv(env_name, record_video=False, register_params=pass_params) - horizon = env.horizon - env = normalize(env) - - policy = GaussianMLPPolicy(env_spec=env.spec, hidden_sizes=(16, 16)) - - baseline = LinearFeatureBaseline(env_spec=env.spec) - - algo = TRPO( - env=env, - policy=policy, - baseline=baseline, - batch_size=15000, - max_path_length=horizon, - n_itr=500, - # whole_paths=True, - discount=0.999, - # step_size=v["step_size"], - ) - algo.train(), - - -exp_tag = "figure-eight-control" - -for seed in [5]: # , 20, 68]: - run_experiment_lite( - run_task, - # Number of parallel workers for sampling - n_parallel=1, - # Keeps the snapshot parameters for all iterations - snapshot_mode="all", - # Specifies the seed for the experiment. If this is not provided, a - # random seed will be used - seed=seed, - mode="local", - exp_prefix=exp_tag, - # plot=True, - ) diff --git a/examples/rllab/green_wave.py b/examples/rllab/green_wave.py deleted file mode 100644 index 433d456235..0000000000 --- a/examples/rllab/green_wave.py +++ /dev/null @@ -1,249 +0,0 @@ -"""Green wave training experiment.""" -from rllab.envs.normalized_env import normalize -from rllab.misc.instrument import run_experiment_lite -from rllab.algos.trpo import TRPO -from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline -from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy -from rllab.envs.gym_env import GymEnv - -from flow.core.params import VehicleParams -from flow.core.params import TrafficLightParams -from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \ - InFlows -from flow.core.params import SumoCarFollowingParams - -from flow.controllers import SimCarFollowingController, GridRouter - -from flow.scenarios.traffic_light_grid import TrafficLightGridScenario - -# set to true if you would like to run the experiment with inflows of vehicles -# from the edges, and false otherwise -USE_INFLOWS = False -# inflow rate of vehicles at every edge (only if USE_INFLOWS is set to True) -EDGE_INFLOW = 300 - - -def gen_edges(col_num, row_num): - """Define the names of all edges in the network. - - Parameters - ---------- - col_num : int - number of columns of edges in the grid - row_num : int - number of rows of edges in the grid - - Returns - ------- - list of str - names of every edge to be generated. - """ - edges = [] - for i in range(col_num): - edges += ["left" + str(row_num) + '_' + str(i)] - edges += ["right" + '0' + '_' + str(i)] - - # build the left and then the right edges - for i in range(row_num): - edges += ["bot" + str(i) + '_' + '0'] - edges += ["top" + str(i) + '_' + str(col_num)] - - return edges - - -def get_flow_params(v_enter, vehs_per_hour, col_num, row_num, add_net_params): - """Define the network and initial params in the presence of inflows. - - Parameters - ---------- - v_enter : float - entering speed of inflow vehicles - vehs_per_hour : float - vehicle inflow rate (in veh/hr) - col_num : int - number of columns of edges in the grid - row_num : int - number of rows of edges in the grid - add_net_params : dict - additional network-specific parameters (unique to the grid) - - Returns - ------- - flow.core.params.InitialConfig - parameters specifying the initial configuration of vehicles in the - network - flow.core.params.NetParams - network-specific parameters used to generate the scenario - """ - initial_config = InitialConfig( - spacing="custom", lanes_distribution=float("inf"), shuffle=True) - - inflow = InFlows() - outer_edges = gen_edges(col_num, row_num) - for i in range(len(outer_edges)): - inflow.add( - veh_type="idm", - edge=outer_edges[i], - vehs_per_hour=vehs_per_hour, - departLane="free", - departSpeed=v_enter) - - net_params = NetParams( - inflows=inflow, - no_internal_links=False, - additional_params=add_net_params) - - return initial_config, net_params - - -def get_non_flow_params(enter_speed, add_net_params): - """Define the network and initial params in the absence of inflows. - - Note that when a vehicle leaves a network in this case, it is immediately - returns to the start of the row/column it was traversing, and in the same - direction as it was before. - - Parameters - ---------- - enter_speed : float - initial speed of vehicles as they enter the network. - add_net_params : dict - additional network-specific parameters (unique to the grid) - - Returns - ------- - flow.core.params.InitialConfig - parameters specifying the initial configuration of vehicles in the - network - flow.core.params.NetParams - network-specific parameters used to generate the scenario - """ - additional_init_params = {'enter_speed': enter_speed} - initial_config = InitialConfig( - spacing='custom', additional_params=additional_init_params) - net_params = NetParams( - no_internal_links=False, additional_params=add_net_params) - - return initial_config, net_params - - -def run_task(*_): - """Implement the run_task method needed to run experiments with rllab.""" - V_ENTER = 30 - INNER_LENGTH = 300 - LONG_LENGTH = 100 - SHORT_LENGTH = 300 - N_ROWS = 3 - N_COLUMNS = 3 - NUM_CARS_LEFT = 1 - NUM_CARS_RIGHT = 1 - NUM_CARS_TOP = 1 - NUM_CARS_BOT = 1 - tot_cars = (NUM_CARS_LEFT + NUM_CARS_RIGHT) * N_COLUMNS \ - + (NUM_CARS_BOT + NUM_CARS_TOP) * N_ROWS - - grid_array = { - "short_length": SHORT_LENGTH, - "inner_length": INNER_LENGTH, - "long_length": LONG_LENGTH, - "row_num": N_ROWS, - "col_num": N_COLUMNS, - "cars_left": NUM_CARS_LEFT, - "cars_right": NUM_CARS_RIGHT, - "cars_top": NUM_CARS_TOP, - "cars_bot": NUM_CARS_BOT - } - - sim_params = SumoParams(sim_step=1, render=True) - - vehicles = VehicleParams() - vehicles.add( - veh_id="idm", - acceleration_controller=(SimCarFollowingController, {}), - car_following_params=SumoCarFollowingParams( - min_gap=2.5, - tau=1.1, - max_speed=V_ENTER, - decel=7.5, # avoid collisions at emergency stops - speed_mode="all_checks" - ), - routing_controller=(GridRouter, {}), - num_vehicles=tot_cars) - - tl_logic = TrafficLightParams(baseline=False) - - additional_env_params = { - "target_velocity": 50, - "switch_time": 3.0, - "num_observed": 2, - "discrete": False, - "tl_type": "controlled" - } - env_params = EnvParams(additional_params=additional_env_params) - - additional_net_params = { - "speed_limit": 35, - "grid_array": grid_array, - "horizontal_lanes": 1, - "vertical_lanes": 1 - } - - if USE_INFLOWS: - initial_config, net_params = get_flow_params( - v_enter=V_ENTER, - vehs_per_hour=EDGE_INFLOW, - col_num=N_COLUMNS, - row_num=N_ROWS, - add_net_params=additional_net_params) - else: - initial_config, net_params = get_non_flow_params( - V_ENTER, additional_net_params) - - scenario = TrafficLightGridScenario( - name="grid-intersection", - vehicles=vehicles, - net_params=net_params, - initial_config=initial_config, - traffic_lights=tl_logic) - - env_name = "TrafficLightGridPOEnv" - pass_params = (env_name, sim_params, vehicles, env_params, net_params, - initial_config, scenario) - - env = GymEnv(env_name, record_video=False, register_params=pass_params) - horizon = env.horizon - env = normalize(env) - - policy = GaussianMLPPolicy(env_spec=env.spec, hidden_sizes=(32, 32)) - - baseline = LinearFeatureBaseline(env_spec=env.spec) - - algo = TRPO( - env=env, - policy=policy, - baseline=baseline, - batch_size=40000, - max_path_length=horizon, - # whole_paths=True, - n_itr=800, - discount=0.999, - # step_size=0.01, - ) - algo.train() - - -for seed in [6]: # , 7, 8]: - run_experiment_lite( - run_task, - # Number of parallel workers for sampling - n_parallel=1, - # n_parallel=1, - # Only keep the snapshot parameters for the last iteration - snapshot_mode="all", - # Specifies the seed for the experiment. If this is not provided, a - # random seed will be used - seed=seed, - mode="local", # "local_docker", "ec2" - exp_prefix="green-wave", - # plot=True, - ) diff --git a/examples/rllab/stabilizing_highway.py b/examples/rllab/stabilizing_highway.py deleted file mode 100644 index 174f01511f..0000000000 --- a/examples/rllab/stabilizing_highway.py +++ /dev/null @@ -1,160 +0,0 @@ -"""Trains cooperative merging behavior in an open merge network. - -Trains a small percentage of rl vehicles to dissipate shockwaves caused by -merges in an open network. -""" - -from rllab.envs.normalized_env import normalize -from rllab.misc.instrument import run_experiment_lite -from rllab.algos.trpo import TRPO -from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline -from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy -from rllab.envs.gym_env import GymEnv - -from flow.scenarios.merge import MergeScenario, ADDITIONAL_NET_PARAMS -from flow.controllers import RLController, IDMController -from flow.core.params import VehicleParams -from flow.core.params import SumoParams, InFlows, EnvParams, NetParams, \ - InitialConfig, SumoCarFollowingParams - -# experiment number -# - 0: 10% RL penetration, 5 max controllable vehicles -# - 1: 25% RL penetration, 13 max controllable vehicles -# - 2: 33% RL penetration, 17 max controllable vehicles -EXP_NUM = 0 - -# time horizon of a single rollout -HORIZON = 600 -# number of rollouts per training iteration -N_ROLLOUTS = 20 -# number of parallel workers -N_CPUS = 1 - -# inflow rate at the highway -FLOW_RATE = 2000 -# percent of autonomous vehicles -RL_PENETRATION = [0.1, 0.25, 0.33][EXP_NUM] -# num_rl term (see ADDITIONAL_ENV_PARAMs) -NUM_RL = [5, 13, 17][EXP_NUM] - - -def run_task(_): - """Implement the run_task method needed to run experiments with rllab.""" - sim_params = SumoParams( - render=True, sim_step=0.2, restart_instance=True) - - # RL vehicles constitute 5% of the total number of vehicles - vehicles = VehicleParams() - vehicles.add( - veh_id="human", - acceleration_controller=(IDMController, { - "noise": 0.2 - }), - car_following_params=SumoCarFollowingParams( - speed_mode="obey_safe_speed", - ), - num_vehicles=5) - vehicles.add( - veh_id="rl", - acceleration_controller=(RLController, {}), - car_following_params=SumoCarFollowingParams( - speed_mode="obey_safe_speed", - ), - num_vehicles=0) - - # Vehicles are introduced from both sides of merge, with RL vehicles - # entering from the highway portion as well - inflow = InFlows() - inflow.add( - veh_type="human", - edge="inflow_highway", - vehs_per_hour=(1 - RL_PENETRATION) * FLOW_RATE, - departLane="free", - departSpeed=10) - inflow.add( - veh_type="rl", - edge="inflow_highway", - vehs_per_hour=RL_PENETRATION * FLOW_RATE, - departLane="free", - departSpeed=10) - inflow.add( - veh_type="human", - edge="inflow_merge", - vehs_per_hour=100, - departLane="free", - departSpeed=7.5) - - additional_env_params = { - "target_velocity": 25, - "num_rl": NUM_RL, - "max_accel": 1.5, - "max_decel": 1.5 - } - env_params = EnvParams( - horizon=HORIZON, - sims_per_step=5, - warmup_steps=0, - additional_params=additional_env_params) - - additional_net_params = ADDITIONAL_NET_PARAMS.copy() - additional_net_params["merge_lanes"] = 1 - additional_net_params["highway_lanes"] = 1 - additional_net_params["pre_merge_length"] = 500 - net_params = NetParams( - inflows=inflow, - no_internal_links=False, - additional_params=additional_net_params) - - initial_config = InitialConfig( - spacing="uniform", lanes_distribution=float("inf")) - - scenario = MergeScenario( - name="merge-rl", - vehicles=vehicles, - net_params=net_params, - initial_config=initial_config) - - env_name = "MergePOEnv" - pass_params = (env_name, sim_params, vehicles, env_params, net_params, - initial_config, scenario) - - env = GymEnv(env_name, record_video=False, register_params=pass_params) - env = normalize(env) - - policy = GaussianMLPPolicy( - env_spec=env.spec, - hidden_sizes=(32, 32, 32), - ) - - baseline = LinearFeatureBaseline(env_spec=env.spec) - - algo = TRPO( - env=env, - policy=policy, - baseline=baseline, - batch_size=HORIZON * N_ROLLOUTS, - max_path_length=HORIZON, - n_itr=1000, - # whole_paths=True, - discount=0.999, - ) - algo.train(), - - -exp_tag = "stabilizing_highway_%.3f" % RL_PENETRATION - -for seed in [5]: # , 20, 68, 72, 125]: - run_experiment_lite( - run_task, - # Number of parallel workers for sampling - n_parallel=N_CPUS, - # Keeps the snapshot parameters for all iterations - snapshot_mode="all", - # Specifies the seed for the experiment. If this is not provided, a - # random seed will be used - seed=seed, - mode="local", - exp_prefix=exp_tag, - # plot=True, - sync_s3_pkl=True, - ) diff --git a/examples/rllab/stabilizing_the_ring.py b/examples/rllab/stabilizing_the_ring.py deleted file mode 100644 index a6ade3c987..0000000000 --- a/examples/rllab/stabilizing_the_ring.py +++ /dev/null @@ -1,107 +0,0 @@ -"""Train a single AV to stabilize a variable density ring road.""" - -from rllab.envs.normalized_env import normalize -from rllab.misc.instrument import run_experiment_lite -from rllab.algos.trpo import TRPO -from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline -from rllab.policies.gaussian_gru_policy import GaussianGRUPolicy - -from flow.scenarios.ring import RingScenario -from flow.controllers import RLController, IDMController, ContinuousRouter -from flow.core.params import VehicleParams -from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig -from rllab.envs.gym_env import GymEnv - -HORIZON = 3000 - - -def run_task(*_): - """Implement the run_task method needed to run experiments with rllab.""" - sim_params = SumoParams(sim_step=0.1, render=False, seed=0) - - vehicles = VehicleParams() - vehicles.add( - veh_id="rl", - acceleration_controller=(RLController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=1) - vehicles.add( - veh_id="idm", - acceleration_controller=(IDMController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=21) - - additional_env_params = { - "ring_length": [220, 270], - "max_accel": 1, - "max_decel": 1 - } - env_params = EnvParams( - horizon=HORIZON, - additional_params=additional_env_params, - warmup_steps=750, - clip_actions=False - ) - - additional_net_params = { - "length": 260, - "lanes": 1, - "speed_limit": 30, - "resolution": 40 - } - net_params = NetParams(additional_params=additional_net_params) - - initial_config = InitialConfig(spacing="uniform", bunching=50) - - print("XXX name", exp_tag) - scenario = RingScenario( - exp_tag, - vehicles, - net_params, - initial_config=initial_config) - - env_name = "WaveAttenuationPOEnv" - pass_params = (env_name, sim_params, vehicles, env_params, net_params, - initial_config, scenario) - - env = GymEnv(env_name, record_video=False, register_params=pass_params) - horizon = env.horizon - env = normalize(env) - - policy = GaussianGRUPolicy( - env_spec=env.spec, - hidden_sizes=(5, ), - ) - - baseline = LinearFeatureBaseline(env_spec=env.spec) - - algo = TRPO( - env=env, - policy=policy, - baseline=baseline, - batch_size=60000, - max_path_length=horizon, - n_itr=500, - # whole_paths=True, - discount=0.999, - # step_size=v["step_size"], - ) - algo.train(), - - -exp_tag = "stabilizing-the-ring" - -for seed in [5]: # , 20, 68]: - run_experiment_lite( - run_task, - # Number of parallel workers for sampling - n_parallel=1, - # Keeps the snapshot parameters for all iterations - snapshot_mode="all", - # Specifies the seed for the experiment. If this is not provided, a - # random seed will be used - seed=seed, - mode="local", - exp_prefix=exp_tag, - # plot=True, - ) diff --git a/examples/rllab/velocity_bottleneck.py b/examples/rllab/velocity_bottleneck.py deleted file mode 100644 index 6a8bcce4b3..0000000000 --- a/examples/rllab/velocity_bottleneck.py +++ /dev/null @@ -1,175 +0,0 @@ -"""Bottleneck decongestion example. - -Bottleneck in which the actions are specifying a desired velocity -in a segment of space -""" -from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ - InFlows, SumoCarFollowingParams, SumoLaneChangeParams -from flow.core.params import VehicleParams -from flow.core.params import TrafficLightParams - -from flow.scenarios.bottleneck import BottleneckScenario -from flow.controllers.lane_change_controllers import SimLaneChangeController -from flow.controllers.routing_controllers import ContinuousRouter -from flow.controllers.rlcontroller import RLController - -from rllab.envs.gym_env import GymEnv -from rllab.envs.normalized_env import normalize -from rllab.misc.instrument import run_experiment_lite -from rllab.algos.ppo import PPO -from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline -from rllab.policies.gaussian_gru_policy import GaussianGRUPolicy - -SCALING = 1 -NUM_LANES = 4 * SCALING # number of lanes in the widest highway -DISABLE_TB = True -DISABLE_RAMP_METER = True -AV_FRAC = .1 -N_CPUS = 32 -i = 0 - -sim_params = SumoParams( - sim_step=0.5, render=False, restart_instance=True) - -vehicles = VehicleParams() - -vehicles.add( - veh_id="human", - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - car_following_params=SumoCarFollowingParams( - speed_mode=9, - ), - lane_change_params=SumoLaneChangeParams( - lane_change_mode=0, # 1621,#0b100000101, - - ), - num_vehicles=1 * SCALING) -vehicles.add( - veh_id="av", - acceleration_controller=(RLController, { - "fail_safe": "instantaneous" - }), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - car_following_params=SumoCarFollowingParams( - speed_mode=9, - ), - lane_change_params=SumoLaneChangeParams( - lane_change_mode=0, - ), - num_vehicles=1 * SCALING) - -horizon = 1000 -# edge name, how many segments to observe/control, whether the segment is -# controlled -controlled_segments = [("1", 1, False), ("2", 2, True), ("3", 2, True), - ("4", 2, True), ("5", 1, False)] -num_observed_segments = [("1", 1), ("2", 3), ("3", 3), ("4", 3), ("5", 1)] -additional_env_params = { - "target_velocity": 40, - "disable_tb": True, - "disable_ramp_metering": True, - "controlled_segments": controlled_segments, - "symmetric": False, - "observed_segments": num_observed_segments, - "reset_inflow": False, - "lane_change_duration": 5, - "max_accel": 3, - "max_decel": 3, - "inflow_range": [1000, 2000] -} -env_params = EnvParams( - additional_params=additional_env_params, - warmup_steps=40, - sims_per_step=2, - horizon=horizon) - -flow_rate = 1500 * SCALING -print('flow rate is ', flow_rate) -env_name = "BottleneckDesiredVelocityEnv" - -inflow = InFlows() -inflow.add( - veh_type="human", - edge="1", - vehs_per_hour=flow_rate * (1 - AV_FRAC), - departLane="random", - departSpeed=10) -inflow.add( - veh_type="av", - name="av", - edge="1", - vehs_per_hour=flow_rate * (AV_FRAC), - departLane="random", - departSpeed=10) - -traffic_lights = TrafficLightParams() -if not DISABLE_TB: - traffic_lights.add(node_id="2") -if not DISABLE_RAMP_METER: - traffic_lights.add(node_id="3") - -additional_net_params = {"scaling": SCALING, "speed_limit": 23} -net_params = NetParams( - inflows=inflow, - no_internal_links=False, - additional_params=additional_net_params) - -initial_config = InitialConfig( - spacing="uniform", - min_gap=5, - lanes_distribution=float("inf"), - edges_distribution=["2", "3", "4", "5"]) -scenario = BottleneckScenario( - name="bay_bridge_toll", - vehicles=vehicles, - net_params=net_params, - initial_config=initial_config, - traffic_lights=traffic_lights) - - -def run_task(*_): - """Implement the run_task method needed to run experiments with rllab.""" - pass_params = (env_name, sim_params, vehicles, env_params, net_params, - initial_config, scenario) - - env = GymEnv(env_name, record_video=False, register_params=pass_params) - horizon = env.horizon - env = normalize(env) - - policy = GaussianGRUPolicy(env_spec=env.spec, hidden_sizes=(64, )) - - baseline = LinearFeatureBaseline(env_spec=env.spec) - - algo = PPO( - env=env, - policy=policy, - baseline=baseline, - batch_size=horizon * 32 * 2, - max_path_length=horizon, - # whole_paths=True, - n_itr=400, - discount=0.999, - # step_size=0.01, - ) - algo.train() - - -# for _ in range(2): -exp_tag = "VSLLaneInflowDensityLearning" # experiment prefix -for seed in [2]: # , 1, 5, 10, 73]: - run_experiment_lite( - run_task, - # Number of parallel workers for sampling - n_parallel=1, - # Only keep the snapshot parameters for the last iteration - snapshot_mode="all", - # Specifies the seed for the experiment. If this is not provided, a - # random seed will be used - seed=seed, - mode="local", - exp_prefix=exp_tag, - # plot=True, - sync_s3_pkl=True - ) diff --git a/examples/rllib/cooperative_merge.py b/examples/rllib/cooperative_merge.py deleted file mode 100644 index aa5af7e114..0000000000 --- a/examples/rllib/cooperative_merge.py +++ /dev/null @@ -1,200 +0,0 @@ -"""Trains vehicles to facilitate cooperative merging in a ring merge. - -This examples consists of 1 learning agent and 6 additional vehicles in an -inner ring, and 10 vehicles in an outer ring attempting to -merge into the inner ring. -""" - -import json - -import ray -try: - from ray.rllib.agents.agent import get_agent_class -except ImportError: - from ray.rllib.agents.registry import get_agent_class -from ray.tune import run_experiments -from ray.tune.registry import register_env - -from flow.controllers import RLController -from flow.controllers import IDMController -from flow.controllers import ContinuousRouter -from flow.controllers import SimLaneChangeController -from flow.core.params import SumoCarFollowingParams -from flow.core.params import SumoLaneChangeParams -from flow.core.params import SumoParams -from flow.core.params import EnvParams -from flow.core.params import InitialConfig -from flow.core.params import NetParams - -from flow.utils.registry import make_create_env -from flow.utils.rllib import FlowParamsEncoder -from flow.core.params import VehicleParams - -# time horizon of a single rollout -HORIZON = 100 -# number of rollouts per training iteration -N_ROLLOUTS = 10 -# number of parallel workers -N_CPUS = 2 - -RING_RADIUS = 100 -NUM_MERGE_HUMANS = 9 -NUM_MERGE_RL = 1 - -# note that the vehicles are added sequentially by the scenario, -# so place the merging vehicles after the vehicles in the ring -vehicles = VehicleParams() -# Inner ring vehicles -vehicles.add( - veh_id='human', - acceleration_controller=(IDMController, { - 'noise': 0.2 - }), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=6, - car_following_params=SumoCarFollowingParams(minGap=0.0, tau=0.5), - lane_change_params=SumoLaneChangeParams()) -# A single learning agent in the inner ring -vehicles.add( - veh_id='rl', - acceleration_controller=(RLController, {}), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=1, - car_following_params=SumoCarFollowingParams( - minGap=0.01, - tau=0.5, - speed_mode="obey_safe_speed", - ), - lane_change_params=SumoLaneChangeParams()) -# Outer ring vehicles -vehicles.add( - veh_id='merge-human', - acceleration_controller=(IDMController, { - 'noise': 0.2 - }), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=10, - car_following_params=SumoCarFollowingParams(minGap=0.0, tau=0.5), - lane_change_params=SumoLaneChangeParams()) - -flow_params = dict( - # name of the experiment - exp_tag='cooperative_merge', - - # name of the flow environment the experiment is running on - env_name='AccelEnv', - - # name of the scenario class the experiment is running on - scenario='TwoRingsOneMergeScenario', - - # simulator that is used by the experiment - simulator='traci', - - # sumo-related parameters (see flow.core.params.SumoParams) - sim=SumoParams( - sim_step=0.1, - render=False, - ), - - # environment related parameters (see flow.core.params.EnvParams) - env=EnvParams( - horizon=HORIZON, - additional_params={ - "target_velocity": 10, - "max_accel": 3, - "max_decel": 3, - "sort_vehicles": False - }, - ), - - # network-related parameters (see flow.core.params.NetParams and the - # scenario's documentation or ADDITIONAL_NET_PARAMS component) - net=NetParams( - no_internal_links=False, - additional_params={ - 'ring_radius': 50, - 'lane_length': 75, - 'inner_lanes': 1, - 'outer_lanes': 1, - 'speed_limit': 30, - 'resolution': 40, - }, - ), - - # 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( - x0=50, - spacing='uniform', - additional_params={ - 'merge_bunching': 0, - }, - ), -) - - -def setup_exps(): - """Return the relevant components of an RLlib experiment. - - Returns - ------- - str - name of the training algorithm - str - name of the gym environment to be trained - dict - training configuration parameters - """ - alg_run = 'PPO' - - agent_cls = get_agent_class(alg_run) - config = agent_cls._default_config.copy() - config['num_workers'] = N_CPUS - config['train_batch_size'] = HORIZON * N_ROLLOUTS - config['gamma'] = 0.999 # discount rate - config['model'].update({'fcnet_hiddens': [16, 16, 16]}) - config['use_gae'] = True - config['lambda'] = 0.97 - config['kl_target'] = 0.02 - config['num_sgd_iter'] = 10 - config['clip_actions'] = False # FIXME(ev) temporary ray bug - config['horizon'] = HORIZON - - # save the flow params for replay - flow_json = json.dumps( - flow_params, cls=FlowParamsEncoder, sort_keys=True, indent=4) - config['env_config']['flow_params'] = flow_json - config['env_config']['run'] = alg_run - - create_env, gym_name = make_create_env(params=flow_params, version=0) - - # Register as rllib env - register_env(gym_name, create_env) - return alg_run, gym_name, config - - -if __name__ == '__main__': - alg_run, gym_name, config = setup_exps() - ray.init(num_cpus=N_CPUS+1, redirect_output=False) - trials = run_experiments({ - flow_params['exp_tag']: { - 'run': alg_run, - 'env': gym_name, - 'config': { - **config - }, - 'checkpoint_freq': 20, - "checkpoint_at_end": True, - 'max_failures': 999, - 'stop': { - 'training_iteration': 200, - }, - } - }) diff --git a/examples/sumo/two_rings_one_merge.py b/examples/sumo/two_rings_one_merge.py deleted file mode 100755 index 82ba65b579..0000000000 --- a/examples/sumo/two_rings_one_merge.py +++ /dev/null @@ -1,92 +0,0 @@ -"""Example of ring road with larger merging ring.""" - -from flow.controllers import IDMController, SimLaneChangeController, \ - ContinuousRouter -from flow.core.experiment import Experiment -from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \ - SumoCarFollowingParams, SumoLaneChangeParams -from flow.core.params import VehicleParams -from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS -from flow.scenarios.two_rings_one_merge import TwoRingsOneMergeScenario, \ - ADDITIONAL_NET_PARAMS - - -def two_rings_one_merge_example(render=None): - """ - Perform a simulation of vehicles on a ring merge. - - 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 merge. - """ - sim_params = SumoParams( - sim_step=0.1, emission_path="./data/", render=True) - - if render is not None: - sim_params.render = render - - # note that the vehicles are added sequentially by the scenario, - # so place the merging vehicles after the vehicles in the ring - vehicles = VehicleParams() - vehicles.add( - veh_id="idm", - acceleration_controller=(IDMController, {}), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=7, - car_following_params=SumoCarFollowingParams( - minGap=0.0, - tau=0.5, - speed_mode="obey_safe_speed", - ), - lane_change_params=SumoLaneChangeParams()) - vehicles.add( - veh_id="merge-idm", - acceleration_controller=(IDMController, {}), - lane_change_controller=(SimLaneChangeController, {}), - routing_controller=(ContinuousRouter, {}), - num_vehicles=10, - car_following_params=SumoCarFollowingParams( - minGap=0.01, - tau=0.5, - speed_mode="obey_safe_speed", - ), - lane_change_params=SumoLaneChangeParams()) - - env_params = EnvParams(additional_params=ADDITIONAL_ENV_PARAMS) - - additional_net_params = ADDITIONAL_NET_PARAMS.copy() - additional_net_params["ring_radius"] = 50 - additional_net_params["inner_lanes"] = 1 - additional_net_params["outer_lanes"] = 1 - additional_net_params["lane_length"] = 75 - net_params = NetParams( - no_internal_links=False, additional_params=additional_net_params) - - initial_config = InitialConfig( - x0=50, spacing="uniform", additional_params={"merge_bunching": 0}) - - scenario = TwoRingsOneMergeScenario( - name="two-ring-one-merging", - vehicles=vehicles, - net_params=net_params, - initial_config=initial_config) - - env = AccelEnv(env_params, sim_params, scenario) - - return Experiment(env) - - -if __name__ == "__main__": - # import the experiment variable - exp = ring() - - # run for a set number of rollouts / time steps - exp.run(1, 1500, convert_to_csv=True) diff --git a/flow/scenarios/__init__.py b/flow/scenarios/__init__.py index 8f8634aea3..737b598855 100644 --- a/flow/scenarios/__init__.py +++ b/flow/scenarios/__init__.py @@ -12,7 +12,6 @@ from flow.scenarios.highway import HighwayScenario from flow.scenarios.ring import RingScenario from flow.scenarios.merge import MergeScenario -from flow.scenarios.two_rings_one_merge import TwoRingsOneMergeScenario from flow.scenarios.multi_ring import MultiRingScenario from flow.scenarios.minicity import MiniCityScenario @@ -20,5 +19,5 @@ "Scenario", "BayBridgeScenario", "BayBridgeTollScenario", "BottleneckScenario", "FigureEightScenario", "TrafficLightGridScenario", "HighwayScenario", "RingScenario", "MergeScenario", - "TwoRingsOneMergeScenario", "MultiRingScenario", "MiniCityScenario" + "MultiRingScenario", "MiniCityScenario" ] diff --git a/flow/scenarios/two_rings_one_merge.py b/flow/scenarios/two_rings_one_merge.py deleted file mode 100644 index c16bf13e7f..0000000000 --- a/flow/scenarios/two_rings_one_merge.py +++ /dev/null @@ -1,268 +0,0 @@ -"""Contains the ring merge scenario class.""" - -from flow.scenarios.base import Scenario -from flow.core.params import InitialConfig -from flow.core.params import TrafficLightParams -from numpy import pi, sin, cos, linspace - -ADDITIONAL_NET_PARAMS = { - # radius of the rings - "ring_radius": 50, - # length of the straight edges connected the outer ring to the inner ring - "lane_length": 75, - # number of lanes in the inner ring - "inner_lanes": 3, - # number of lanes in the outer ring - "outer_lanes": 2, - # max speed limit in the network - "speed_limit": 30, - # resolution of the curved portions - "resolution": 40, -} - - -class TwoRingsOneMergeScenario(Scenario): - """Two ring merge scenario. - - This network is expected to simulate a closed ring representation of a - merge. It consists of two rings that merge together for half the length of - the smaller ring. - - Requires from net_params: - - * **ring_radius** : radius of the rings - * **lane_length** : length of the straight edges connected the outer ring - to the inner ring - * **inner_lanes** : number of lanes in the inner ring - * **outer_lanes** : number of lanes in the outer ring - * **speed_limit** : max speed limit in the network - * **resolution** : resolution of the curved portions - - Usage - ----- - >>> from flow.core.params import NetParams - >>> from flow.core.params import VehicleParams - >>> from flow.core.params import InitialConfig - >>> from flow.scenarios import TwoRingsOneMergeScenario - >>> - >>> scenario = TwoRingsOneMergeScenario( - >>> name='two_rings_merge', - >>> vehicles=VehicleParams(), - >>> net_params=NetParams( - >>> additional_params={ - >>> 'ring_radius': 50, - >>> 'lane_length': 75, - >>> 'inner_lanes': 3, - >>> 'outer_lanes': 2, - >>> 'speed_limit': 30, - >>> 'resolution': 40 - >>> }, - >>> no_internal_links=False # we want junctions - >>> ) - >>> ) - """ - - def __init__(self, - name, - vehicles, - net_params, - initial_config=InitialConfig(), - traffic_lights=TrafficLightParams()): - """Initialize a two ring scenario.""" - for p in ADDITIONAL_NET_PARAMS.keys(): - if p not in net_params.additional_params: - raise KeyError('Network parameter "{}" not supplied'.format(p)) - - radius = net_params.additional_params["ring_radius"] - x = net_params.additional_params["lane_length"] - - self.inner_lanes = net_params.additional_params["inner_lanes"] - self.outer_lanes = net_params.additional_params["outer_lanes"] - - self.junction_length = 0.3 - self.intersection_length = 25.5 # calibrate when the radius changes - - net_params.additional_params["length"] = \ - 2 * x + 2 * pi * radius + \ - 2 * self.intersection_length + 2 * self.junction_length - - num_vehicles = vehicles.num_vehicles - num_merge_vehicles = sum("merge" in vehicles.get_type(veh_id) - for veh_id in vehicles.ids) - self.n_inner_vehicles = num_merge_vehicles - self.n_outer_vehicles = num_vehicles - num_merge_vehicles - - radius = net_params.additional_params["ring_radius"] - length_ring = 2 * pi * radius - self.length_ring = length_ring - - super().__init__(name, vehicles, net_params, initial_config, - traffic_lights) - - def specify_nodes(self, net_params): - """See parent class.""" - r = net_params.additional_params["ring_radius"] - x = net_params.additional_params["lane_length"] - - nodes = [{ - "id": "top_left", - "x": 0, - "y": r, - "type": "priority" - }, { - "id": "bottom_left", - "x": 0, - "y": -r, - "type": "priority" - }, { - "id": "top_right", - "x": x, - "y": r, - "type": "priority" - }, { - "id": "bottom_right", - "x": x, - "y": -r, - "type": "priority" - }] - - return nodes - - def specify_edges(self, net_params): - """See parent class.""" - r = net_params.additional_params["ring_radius"] - x = net_params.additional_params["lane_length"] - - ring_edgelen = pi * r - resolution = 40 - - edges = [{ - "id": - "center", - "from": - "bottom_left", - "to": - "top_left", - "type": - "edgeType", - "length": - ring_edgelen, - "priority": - 46, - "shape": - [ - (r * cos(t), r * sin(t)) - for t in linspace(-pi / 2, pi / 2, resolution) - ], - "numLanes": - self.inner_lanes - }, { - "id": "top", - "from": "top_right", - "to": "top_left", - "type": "edgeType", - "length": x, - "priority": 46, - "numLanes": self.outer_lanes - }, { - "id": "bottom", - "from": "bottom_left", - "to": "bottom_right", - "type": "edgeType", - "length": x, - "numLanes": self.outer_lanes - }, { - "id": - "left", - "from": - "top_left", - "to": - "bottom_left", - "type": - "edgeType", - "length": - ring_edgelen, - "shape": - [ - (r * cos(t), r * sin(t)) - for t in linspace(pi / 2, 3 * pi / 2, resolution) - ], - "numLanes": - self.inner_lanes - }, { - "id": - "right", - "from": - "bottom_right", - "to": - "top_right", - "type": - "edgeType", - "length": - ring_edgelen, - "shape": - [ - (x + r * cos(t), r * sin(t)) - for t in linspace(-pi / 2, pi / 2, resolution) - ], - "numLanes": - self.outer_lanes - }] - - return edges - - def specify_types(self, net_params): - """See parent class.""" - speed_limit = net_params.additional_params["speed_limit"] - - types = [{"id": "edgeType", "speed": speed_limit}] - return types - - def specify_routes(self, net_params): - """See parent class.""" - rts = { - "top": ["top", "left", "bottom", "right", "top"], - "bottom": ["bottom", "right", "top", "left", "bottom"], - "right": ["right", "top", "left", "bottom"], - "left": ["left", "center", "left"], - "center": ["center", "left", "center"] - } - - return rts - - def specify_edge_starts(self): - """See parent class.""" - r = self.net_params.additional_params["ring_radius"] - lane_length = self.net_params.additional_params["lane_length"] - - ring_edgelen = pi * r - - edgestarts = [ - ("left", self.intersection_length), - ("center", ring_edgelen + 2 * self.intersection_length), - ("bottom", 2 * ring_edgelen + 2 * self.intersection_length), - ("right", 2 * ring_edgelen + lane_length + - 2 * self.intersection_length + self.junction_length), - ("top", 3 * ring_edgelen + lane_length + - 2 * self.intersection_length + 2 * self.junction_length) - ] - - return edgestarts - - def specify_internal_edge_starts(self): - """See parent class.""" - r = self.net_params.additional_params["ring_radius"] - lane_length = self.net_params.additional_params["lane_length"] - - ring_edgelen = pi * r - - internal_edgestarts = [ - (":top_left", 0), (":bottom_left", - ring_edgelen + self.intersection_length), - (":bottom_right", - 2 * ring_edgelen + lane_length + 2 * self.intersection_length), - (":top_right", 3 * ring_edgelen + lane_length + - 2 * self.intersection_length + self.junction_length) - ] - - return internal_edgestarts diff --git a/tests/fast_tests/test_examples.py b/tests/fast_tests/test_examples.py index 9dde05acb2..5accf890d5 100644 --- a/tests/fast_tests/test_examples.py +++ b/tests/fast_tests/test_examples.py @@ -8,7 +8,6 @@ from examples.sumo.figure_eight import figure_eight_example from examples.sumo.grid import grid_example from examples.sumo.highway import highway_example -from examples.sumo.two_rings_one_merge import two_rings_one_merge_example from examples.sumo.merge import merge_example from examples.sumo.minicity import minicity_example from examples.sumo.sugiyama import sugiyama_example @@ -89,14 +88,6 @@ def test_sugiyama(self): # run the experiment for a few time steps to ensure it doesn't fail exp.run(1, 5) - def test_two_rings_one_merge(self): - """Verify that examples/sumo/two_rings_merge_straight.py is working.""" - # import the experiment variable from the example - exp = two_rings_one_merge_example(render=False) - - # run the experiment for a few time steps to ensure it doesn't fail - exp.run(1, 5) - def test_bay_bridge(self): """Verifies that examples/sumo/bay_bridge.py is working.""" # import the experiment variable from the example diff --git a/tests/fast_tests/test_scenarios.py b/tests/fast_tests/test_scenarios.py index bd651471fd..6d84b8532c 100644 --- a/tests/fast_tests/test_scenarios.py +++ b/tests/fast_tests/test_scenarios.py @@ -4,7 +4,7 @@ from flow.core.params import NetParams from flow.scenarios import BottleneckScenario, FigureEightScenario, \ TrafficLightGridScenario, HighwayScenario, RingScenario, MergeScenario, \ - TwoRingsOneMergeScenario, MiniCityScenario, MultiRingScenario + MiniCityScenario, MultiRingScenario __all__ = [ "MultiRingScenario", "MiniCityScenario" @@ -119,27 +119,6 @@ def test_additional_net_params(self): ) -class TestTwoRingsOneMergeScenario(unittest.TestCase): - - """Tests TwoRingsOneMergeScenario in flow/scenarios/two_rings_one_merge.py.""" - - def test_additional_net_params(self): - """Ensures that not returning the correct params leads to an error.""" - self.assertTrue( - test_additional_params( - scenario_class=TwoRingsOneMergeScenario, - additional_params={ - "ring_radius": 50, - "lane_length": 75, - "inner_lanes": 3, - "outer_lanes": 2, - "speed_limit": 30, - "resolution": 40 - } - ) - ) - - class TestMergeScenario(unittest.TestCase): """Tests MergeScenario in flow/scenarios/merge.py.""" From 55171fcde1e53b16776c5ad8412fa78678e1b4e5 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Tue, 20 Aug 2019 23:25:18 -0700 Subject: [PATCH 12/23] Refactoring new files that are added after pulling from master --- docs/source/flow.envs.bay_bridge.rst | 2 +- examples/README.md | 2 +- examples/aimsun/small_template.py | 2 +- .../multiagent_exps/multiagent_highway.py | 2 +- .../multiagent_traffic_light_grid.py | 2 +- .../{green_wave.py => traffic_light_grid.py} | 4 +-- examples/stable_baselines/figure_eight.py | 2 +- .../stable_baselines/stabilizing_highway.py | 2 +- .../stable_baselines/stabilizing_the_ring.py | 2 +- .../{green_wave.py => traffic_light_grid.py} | 10 +++---- .../stable_baselines/velocity_bottleneck.py | 2 +- examples/sumo/highway_ramps.py | 2 +- .../sumo/{grid.py => traffic_light_grid.py} | 2 +- flow/envs/multiagent/highway.py | 2 +- flow/envs/multiagent/traffic_light_grid.py | 10 +++---- flow/envs/traffic_light_grid.py | 2 +- flow/scenarios/highway_ramps.py | 2 +- tests/fast_tests/test_examples.py | 28 ++++++++----------- tests/fast_tests/test_scenarios.py | 2 +- tutorials/tutorial10_traffic_lights.ipynb | 14 +++++----- tutorials/tutorial11_inflows.ipynb | 2 +- tutorials/tutorial12_inflows.ipynb | 2 +- tutorials/tutorial14_bottlenecks.ipynb | 6 ++-- 23 files changed, 50 insertions(+), 56 deletions(-) rename examples/rllib/{green_wave.py => traffic_light_grid.py} (99%) rename examples/stable_baselines/{green_wave.py => traffic_light_grid.py} (97%) rename examples/sumo/{grid.py => traffic_light_grid.py} (99%) diff --git a/docs/source/flow.envs.bay_bridge.rst b/docs/source/flow.envs.bay_bridge.rst index 0b82b2dd5a..fdbed4bdf4 100644 --- a/docs/source/flow.envs.bay_bridge.rst +++ b/docs/source/flow.envs.bay_bridge.rst @@ -4,7 +4,7 @@ flow.envs.bay\_bridge package Submodules ---------- -flow.envs.bay\_bridge.base module +flow.envs.bay\_bridge module --------------------------------- .. automodule:: flow.envs.bay_bridge diff --git a/examples/README.md b/examples/README.md index 29a4eeb86a..4bd247d4aa 100644 --- a/examples/README.md +++ b/examples/README.md @@ -61,7 +61,7 @@ average speed of vehicles in the network. ![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/figure_eight.gif) -### grid.py +### traffic_light_grid.py Performs a simulation of vehicles on a grid. diff --git a/examples/aimsun/small_template.py b/examples/aimsun/small_template.py index 040c126b34..32e89e43b7 100644 --- a/examples/aimsun/small_template.py +++ b/examples/aimsun/small_template.py @@ -4,7 +4,7 @@ from flow.core.params import AimsunParams, EnvParams, NetParams from flow.core.params import VehicleParams from flow.envs import TestEnv -from flow.scenarios.loop import Scenario +from flow.scenarios.ring import Scenario from flow.core.params import InFlows import flow.config as config import os diff --git a/examples/rllib/multiagent_exps/multiagent_highway.py b/examples/rllib/multiagent_exps/multiagent_highway.py index 08732e9a84..a15580d6eb 100644 --- a/examples/rllib/multiagent_exps/multiagent_highway.py +++ b/examples/rllib/multiagent_exps/multiagent_highway.py @@ -22,7 +22,7 @@ from flow.utils.registry import make_create_env from flow.utils.rllib import FlowParamsEncoder -from flow.envs.loop.loop_accel import ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import ADDITIONAL_ENV_PARAMS from flow.scenarios.highway_ramps import ADDITIONAL_NET_PARAMS diff --git a/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py b/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py index ca9a75df36..c52e23193e 100644 --- a/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py +++ b/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py @@ -95,7 +95,7 @@ def make_flow_params(n_rows, n_columns, edge_inflow): env_name='MultiTrafficLightGridPOEnv', # name of the scenario class the experiment is running on - scenario="SimpleGridScenario", + scenario="TrafficLightGridScenario", # simulator that is used by the experiment simulator='traci', diff --git a/examples/rllib/green_wave.py b/examples/rllib/traffic_light_grid.py similarity index 99% rename from examples/rllib/green_wave.py rename to examples/rllib/traffic_light_grid.py index af327763a2..6d370a1439 100644 --- a/examples/rllib/green_wave.py +++ b/examples/rllib/traffic_light_grid.py @@ -1,4 +1,4 @@ -"""Grid/green wave example.""" +"""Traffic Light Grid example.""" import json @@ -178,7 +178,7 @@ def get_non_flow_params(enter_speed, add_net_params): flow_params = dict( # name of the experiment - exp_tag='green_wave', + exp_tag='traffic_light_grid', # name of the flow environment the experiment is running on env_name='TrafficLightGridPOEnv', diff --git a/examples/stable_baselines/figure_eight.py b/examples/stable_baselines/figure_eight.py index 6695cc9e55..b46095305f 100644 --- a/examples/stable_baselines/figure_eight.py +++ b/examples/stable_baselines/figure_eight.py @@ -54,7 +54,7 @@ env_name='AccelEnv', # name of the scenario class the experiment is running on - scenario='Figure8Scenario', + scenario='FigureEightScenario', # simulator that is used by the experiment simulator='traci', diff --git a/examples/stable_baselines/stabilizing_highway.py b/examples/stable_baselines/stabilizing_highway.py index 0baff4dd12..0b9c8af4b6 100644 --- a/examples/stable_baselines/stabilizing_highway.py +++ b/examples/stable_baselines/stabilizing_highway.py @@ -90,7 +90,7 @@ exp_tag="stabilizing_open_network_merges", # name of the flow environment the experiment is running on - env_name="WaveAttenuationMergePOEnv", + env_name="MergePOEnv", # name of the scenario class the experiment is running on scenario="MergeScenario", diff --git a/examples/stable_baselines/stabilizing_the_ring.py b/examples/stable_baselines/stabilizing_the_ring.py index dd4d170077..74bd2f9672 100644 --- a/examples/stable_baselines/stabilizing_the_ring.py +++ b/examples/stable_baselines/stabilizing_the_ring.py @@ -46,7 +46,7 @@ env_name="WaveAttenuationPOEnv", # name of the scenario class the experiment is running on - scenario="LoopScenario", + scenario="RingScenario", # simulator that is used by the experiment simulator='traci', diff --git a/examples/stable_baselines/green_wave.py b/examples/stable_baselines/traffic_light_grid.py similarity index 97% rename from examples/stable_baselines/green_wave.py rename to examples/stable_baselines/traffic_light_grid.py index 768284d40b..10d7cc19d4 100644 --- a/examples/stable_baselines/green_wave.py +++ b/examples/stable_baselines/traffic_light_grid.py @@ -1,4 +1,4 @@ -"""Grid/green wave example.""" +"""Traffic Light Grid example.""" import argparse import json @@ -172,13 +172,13 @@ def get_non_flow_params(enter_speed, add_net_params): flow_params = dict( # name of the experiment - exp_tag='green_wave', + exp_tag='traffic_light_grid', # name of the flow environment the experiment is running on - env_name='PO_TrafficLightGridEnv', + env_name='TrafficLightGridPOEnv', # name of the scenario class the experiment is running on - scenario='SimpleGridScenario', + scenario='TrafficLightGridScenario', # simulator that is used by the experiment simulator='traci', @@ -266,7 +266,7 @@ def run_model(num_cpus=1, rollout_size=50, num_steps=50, use_inflows=False): parser.add_argument('--num_cpus', type=int, default=1, help='How many CPUs to use') parser.add_argument('--num_steps', type=int, default=5000, help='How many total steps to perform learning over') parser.add_argument('--rollout_size', type=int, default=1000, help='How many steps are in a training batch.') - parser.add_argument('--result_name', type=str, default='green_wave', help='Name of saved model') + parser.add_argument('--result_name', type=str, default='traffic_light_grid', help='Name of saved model') parser.add_argument('--use_inflows', action='store_true') args = parser.parse_args() model = run_model(args.num_cpus, args.rollout_size, args.num_steps, args.use_inflows) diff --git a/examples/stable_baselines/velocity_bottleneck.py b/examples/stable_baselines/velocity_bottleneck.py index 1cebe2eb0a..dea86a3a5c 100644 --- a/examples/stable_baselines/velocity_bottleneck.py +++ b/examples/stable_baselines/velocity_bottleneck.py @@ -108,7 +108,7 @@ exp_tag="DesiredVelocity", # name of the flow environment the experiment is running on - env_name="DesiredVelocityEnv", + env_name="BottleneckDesiredVelocityEnv", # name of the scenario class the experiment is running on scenario="BottleneckScenario", diff --git a/examples/sumo/highway_ramps.py b/examples/sumo/highway_ramps.py index 4db47be76f..40663dcd01 100644 --- a/examples/sumo/highway_ramps.py +++ b/examples/sumo/highway_ramps.py @@ -7,7 +7,7 @@ from flow.core.experiment import Experiment from flow.scenarios.highway_ramps import HighwayRampsScenario, \ ADDITIONAL_NET_PARAMS -from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS +from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS additional_net_params = ADDITIONAL_NET_PARAMS.copy() diff --git a/examples/sumo/grid.py b/examples/sumo/traffic_light_grid.py similarity index 99% rename from examples/sumo/grid.py rename to examples/sumo/traffic_light_grid.py index 34d13bba4d..91e256c517 100644 --- a/examples/sumo/grid.py +++ b/examples/sumo/traffic_light_grid.py @@ -1,4 +1,4 @@ -"""Grid example.""" +"""Traffic Light Grid example.""" from flow.controllers import GridRouter from flow.core.experiment import Experiment from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams diff --git a/flow/envs/multiagent/highway.py b/flow/envs/multiagent/highway.py index cd38ff22e8..493bc226a9 100644 --- a/flow/envs/multiagent/highway.py +++ b/flow/envs/multiagent/highway.py @@ -2,7 +2,7 @@ import numpy as np from gym.spaces.box import Box from flow.core.rewards import desired_velocity -from flow.multiagent_envs.multiagent_env import MultiEnv +from flow.envs.multiagent.base import MultiEnv ADDITIONAL_ENV_PARAMS = { diff --git a/flow/envs/multiagent/traffic_light_grid.py b/flow/envs/multiagent/traffic_light_grid.py index 9c5b42102a..d89975f65f 100644 --- a/flow/envs/multiagent/traffic_light_grid.py +++ b/flow/envs/multiagent/traffic_light_grid.py @@ -9,8 +9,8 @@ from gym.spaces.discrete import Discrete from flow.core import rewards -from flow.envs.green_wave_env import PO_TrafficLightGridEnv -from flow.multiagent_envs.multiagent_env import MultiEnv +from flow.envs.traffic_light_grid import TrafficLightGridPOEnv +from flow.envs.multiagent import MultiEnv ADDITIONAL_ENV_PARAMS = { # num of nearby lights the agent can observe {0, ..., num_traffic_lights-1} @@ -23,8 +23,8 @@ ID_IDX = 1 -class MultiTrafficLightGridPOEnv(PO_TrafficLightGridEnv, MultiEnv): - """Multiagent shared model version of PO_TrafficLightGridEnv. +class MultiTrafficLightGridPOEnv(TrafficLightGridPOEnv, MultiEnv): + """Multiagent shared model version of TrafficLightGridPOEnv. Required from env_params: See parent class @@ -107,7 +107,7 @@ def get_state(self): max_dist = max(grid_array["short_length"], grid_array["long_length"], grid_array["inner_length"]) - # TODO(cathywu) refactor PO_TrafficLightGridEnv with convenience + # TODO(cathywu) refactor TrafficLightGridPOEnv with convenience # methods for observations, but remember to flatten for single-agent # Observed vehicle information diff --git a/flow/envs/traffic_light_grid.py b/flow/envs/traffic_light_grid.py index 6895ad39b6..1facf63688 100644 --- a/flow/envs/traffic_light_grid.py +++ b/flow/envs/traffic_light_grid.py @@ -388,7 +388,7 @@ def _get_relative_node(self, agent_id, direction): --- 0 --- 1 --- 2 --- | | | - See flow.scenarios.grid for more information. + See flow.scenarios.traffic_light_grid for more information. Example of function usage: - Seeking the "top" direction to ":center0" would return 3. diff --git a/flow/scenarios/highway_ramps.py b/flow/scenarios/highway_ramps.py index 7799ff97e5..74f5ae25e2 100644 --- a/flow/scenarios/highway_ramps.py +++ b/flow/scenarios/highway_ramps.py @@ -1,6 +1,6 @@ """Contains the highway with ramps scenario class.""" -from flow.scenarios.base_scenario import Scenario +from flow.scenarios.base import Scenario from flow.core.params import InitialConfig, TrafficLightParams from collections import defaultdict from numpy import pi, sin, cos diff --git a/tests/fast_tests/test_examples.py b/tests/fast_tests/test_examples.py index b2d5fe9a93..a506485de7 100644 --- a/tests/fast_tests/test_examples.py +++ b/tests/fast_tests/test_examples.py @@ -4,9 +4,8 @@ import ray from ray.tune import run_experiments -from examples.rllib.cooperative_merge import setup_exps as coop_setup from examples.rllib.figure_eight import setup_exps as figure_eight_setup -from examples.rllib.green_wave import setup_exps as green_wave_setup +from examples.rllib.traffic_light_grid import setup_exps as traffic_light_grid_setup from examples.rllib.stabilizing_highway import setup_exps as highway_setup from examples.rllib.stabilizing_the_ring import setup_exps as ring_setup from examples.rllib.velocity_bottleneck import setup_exps as bottleneck_setup @@ -24,7 +23,7 @@ as multi_highway_setup from examples.stable_baselines.figure_eight import run_model as run_figure_eight -from examples.stable_baselines.green_wave import run_model as run_green_wave +from examples.stable_baselines.traffic_light_grid import run_model as run_traffic_light_grid from examples.stable_baselines.stabilizing_highway import run_model as run_stabilizing_highway from examples.stable_baselines.stabilizing_the_ring import run_model as run_stabilizing_ring from examples.stable_baselines.velocity_bottleneck import run_model as run_velocity_bottleneck @@ -34,10 +33,9 @@ from examples.sumo.bottlenecks import bottleneck_example from examples.sumo.density_exp import run_bottleneck from examples.sumo.figure_eight import figure_eight_example -from examples.sumo.grid import grid_example +from examples.sumo.traffic_light_grid import grid_example from examples.sumo.highway import highway_example from examples.sumo.highway_ramps import highway_ramps_example -from examples.sumo.loop_merge import loop_merge_example from examples.sumo.merge import merge_example from examples.sumo.minicity import minicity_example from examples.sumo.sugiyama import sugiyama_example @@ -70,8 +68,8 @@ def test_figure_eight(self): # run the experiment for a few time steps to ensure it doesn't fail exp.run(1, 5) - def test_grid(self): - """Verifies that examples/sumo/grid.py is working.""" + def test_traffic_light_grid(self): + """Verifies that examples/sumo/traffic_light_grid.py is working.""" # test the example in the absence of inflows exp = grid_example(render=False, use_inflows=False) exp.run(1, 5) @@ -159,8 +157,8 @@ class TestStableBaselineExamples(unittest.TestCase): This is done by running each experiment in that folder for five time-steps and confirming that it completes one rollout with two workers. """ - def test_run_green_wave(self): - run_green_wave(num_steps=5) + def test_run_traffic_light_grid(self): + run_traffic_light_grid(num_steps=5) def test_run_figure_eight(self): run_figure_eight(num_steps=5) @@ -186,22 +184,18 @@ def setUp(self): if not ray.is_initialized(): ray.init(num_cpus=1) - def test_coop_merge(self): - alg_run, env_name, config = coop_setup() - self.run_exp(alg_run, env_name, config) - def test_figure_eight(self): alg_run, env_name, config = figure_eight_setup() self.run_exp(alg_run, env_name, config) - def test_green_wave(self): + def test_traffic_light_grid(self): # test the example in the absence of inflows - alg_run, env_name, config = green_wave_setup(use_inflows=False) + alg_run, env_name, config = traffic_light_grid_setup(use_inflows=False) self.run_exp(alg_run, env_name, config) - def test_green_wave_inflows(self): + def test_traffic_light_grid_inflows(self): # test the example in the presence of inflows - alg_run, env_name, config = green_wave_setup(use_inflows=True) + alg_run, env_name, config = traffic_light_grid_setup(use_inflows=True) self.run_exp(alg_run, env_name, config) def test_stabilizing_highway(self): diff --git a/tests/fast_tests/test_scenarios.py b/tests/fast_tests/test_scenarios.py index 6d84b8532c..2aa6eac1d7 100644 --- a/tests/fast_tests/test_scenarios.py +++ b/tests/fast_tests/test_scenarios.py @@ -51,7 +51,7 @@ def test_additional_net_params(self): class TestTrafficLightGridScenario(unittest.TestCase): - """Tests TrafficLightGridScenario in flow/scenarios/grid.py.""" + """Tests TrafficLightGridScenario in flow/scenarios/traffic_light_grid.py.""" def test_additional_net_params(self): """Ensures that not returning the correct params leads to an error.""" diff --git a/tutorials/tutorial10_traffic_lights.ipynb b/tutorials/tutorial10_traffic_lights.ipynb index ade0becbd8..31b7741881 100644 --- a/tutorials/tutorial10_traffic_lights.ipynb +++ b/tutorials/tutorial10_traffic_lights.ipynb @@ -15,11 +15,11 @@ "source": [ "This tutorial walks through how to add traffic lights to experiments. This tutorial will use the following files:\n", "\n", - "* Experiment script for RL version of traffic lights in grid: `examples/rllib/green_wave.py`\n", - "* Experiment script for non-RL version of traffic lights in grid: `examples/sumo/grid.py`\n", - "* Scenario: `grid.py` (class SimpleGridScenario)\n", - "* Environment for RL version of traffic lights in grid: `green_wave_env.py` (class TrafficLightGridEnv)\n", - "* Environment for non-RL version of traffic lights in grid: `loop_accel.py` (class AccelEnv)\n", + "* Experiment script for RL version of traffic lights in grid:\n", + "* Experiment script for non-RL version of traffic lights in grid:\n", + "* Scenario: `traffic_light_grid.py` (class TrafficLightGridScenario)\n", + "* Environment for RL version of traffic lights in grid (class TrafficLightGridEnv)\n", + "* Environment for non-RL version of traffic lights in grid (class AccelEnv)\n", "\n", "There are two main classes of traffic lights that Sumo supports: (1) actuated and (2) static traffic lights. This tutorial will cover both types. Moreover, in this tutorial, we'll discuss another type of traffic light. In total, we have 4 types of traffic lights in the Flow:\n", "\n", @@ -40,7 +40,7 @@ "outputs": [], "source": [ "from flow.core.params import NetParams\n", - "from flow.scenarios.grid import SimpleGridScenario\n", + "from flow.scenarios.traffic_light_grid import TrafficLightGridScenario\n", "from flow.core.params import TrafficLightParams\n", "from flow.core.params import SumoParams, EnvParams, InitialConfig, NetParams, \\\n", " InFlows, SumoCarFollowingParams\n", @@ -198,7 +198,7 @@ "net_params = NetParams(no_internal_links=False,\n", " additional_params=additional_net_params)\n", "\n", - "scenario = SimpleGridScenario(name=\"grid\",\n", + "scenario = TrafficLightGridScenario(name=\"grid\",\n", " vehicles=VehicleParams(),\n", " net_params=net_params,\n", " initial_config=InitialConfig(),\n", diff --git a/tutorials/tutorial11_inflows.ipynb b/tutorials/tutorial11_inflows.ipynb index 2572f712f2..8b108b8791 100644 --- a/tutorials/tutorial11_inflows.ipynb +++ b/tutorials/tutorial11_inflows.ipynb @@ -171,7 +171,7 @@ "outputs": [], "source": [ "from flow.core.params import SumoParams, EnvParams, InitialConfig\n", - "from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", "from flow.core.experiment import Experiment\n", "\n", "sumo_params = SumoParams(render=True,\n", diff --git a/tutorials/tutorial12_inflows.ipynb b/tutorials/tutorial12_inflows.ipynb index 6e8b28f1a3..872f73d99d 100644 --- a/tutorials/tutorial12_inflows.ipynb +++ b/tutorials/tutorial12_inflows.ipynb @@ -416,7 +416,7 @@ "from flow.controllers import IDMController\n", "from flow.scenarios import MergeScenario\n", "from flow.scenarios.merge import ADDITIONAL_NET_PARAMS\n", - "from flow.envs.loop.loop_accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", + "from flow.envs.ring.accel import AccelEnv, ADDITIONAL_ENV_PARAMS\n", "\n", "\n", "# create a vehicle type\n", diff --git a/tutorials/tutorial14_bottlenecks.ipynb b/tutorials/tutorial14_bottlenecks.ipynb index b73675795d..a5efef5cdd 100644 --- a/tutorials/tutorial14_bottlenecks.ipynb +++ b/tutorials/tutorial14_bottlenecks.ipynb @@ -52,7 +52,7 @@ "\n", "from flow.scenarios.bottleneck import BottleneckScenario\n", "from flow.controllers import SimLaneChangeController, ContinuousRouter\n", - "from flow.envs.bottleneck_env import BottleneckEnv\n", + "from flow.envs.bottleneck import BottleneckEnv\n", "from flow.core.experiment import Experiment\n", "\n", "import logging\n", @@ -225,7 +225,7 @@ "metadata": {}, "source": [ "## Adding a tollbooth\n", - "On the segment indicated in Fig. 4, we have set up a series of rules that allow users to mimic the effect of a tollbooth. If *disable_tb=False*, cars that approach the toll-booth have their color changed to blue to indicate that they are in the toll-booth region. Their lane changing is disabled. As they come to the front of the toll-booth, we sample from a gaussian to determine how long they should be held at the toll booth. The holding process is imitated by a red light that remains red for the duration of the holding time. As indicated in the figure, the outer lanes are fast-trak lanes; their mean holding time is set to be lower than the holding time of the other toll-booth lanes. For the exact values of the holding parameters, please refer to the *BottleneckEnv* class in *flow/envs/bottleneck_env.py*\n", + "On the segment indicated in Fig. 4, we have set up a series of rules that allow users to mimic the effect of a tollbooth. If *disable_tb=False*, cars that approach the toll-booth have their color changed to blue to indicate that they are in the toll-booth region. Their lane changing is disabled. As they come to the front of the toll-booth, we sample from a gaussian to determine how long they should be held at the toll booth. The holding process is imitated by a red light that remains red for the duration of the holding time. As indicated in the figure, the outer lanes are fast-trak lanes; their mean holding time is set to be lower than the holding time of the other toll-booth lanes. For the exact values of the holding parameters, please refer to the *BottleneckEnv* class in *flow/envs/bottleneck.py*\n", "\n", "\n", "\n", @@ -330,7 +330,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "For a reference on all of the different parameters that can be used to modify the ALINEA algorithm, please refer to the documentation in *BottleneckEnv* in *flow/envs/bottleneck_env.py*" + "For a reference on all of the different parameters that can be used to modify the ALINEA algorithm, please refer to the documentation in *BottleneckEnv* in *flow/envs/bottleneck.py*" ] }, { From 31bf7bf77e7a616ceca58d79b2ada693bb2ab207 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Wed, 21 Aug 2019 00:04:55 -0700 Subject: [PATCH 13/23] Change 'grid' to 'traffic_light_grid' across all files --- examples/README.md | 2 +- examples/aimsun/grid.py | 10 ++++----- .../multiagent_traffic_light_grid.py | 10 ++++----- examples/rllib/traffic_light_grid.py | 14 ++++++------ .../stable_baselines/traffic_light_grid.py | 14 ++++++------ examples/sumo/traffic_light_grid.py | 22 +++++++++---------- flow/benchmarks/README.md | 12 +++++----- flow/controllers/routing_controllers.py | 2 +- flow/envs/multiagent/traffic_light_grid.py | 2 +- flow/envs/traffic_light_grid.py | 18 +++++++-------- flow/scenarios/traffic_light_grid.py | 22 +++++++++---------- tests/fast_tests/test_collisions.py | 6 ++--- tests/fast_tests/test_examples.py | 6 ++--- tests/fast_tests/test_green_wave.py | 10 ++++----- tests/fast_tests/test_traffic_lights.py | 8 +++---- tests/setup_scripts.py | 12 +++++----- tutorials/tutorial05_scenarios.ipynb | 2 +- tutorials/tutorial10_traffic_lights.ipynb | 6 ++--- 18 files changed, 89 insertions(+), 89 deletions(-) diff --git a/examples/README.md b/examples/README.md index 4bd247d4aa..f612bb1fb1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -63,7 +63,7 @@ average speed of vehicles in the network. ### traffic_light_grid.py -Performs a simulation of vehicles on a grid. +Performs a simulation of vehicles on a traffic light grid. ![](https://raw.githubusercontent.com/flow-project/flow/master/docs/img/grid.gif) diff --git a/examples/aimsun/grid.py b/examples/aimsun/grid.py index baeaf092a6..442d30ca25 100644 --- a/examples/aimsun/grid.py +++ b/examples/aimsun/grid.py @@ -1,4 +1,4 @@ -"""Grid example.""" +"""Traffic Light Grid example.""" from flow.core.experiment import Experiment from flow.core.params import AimsunParams, EnvParams, InitialConfig, NetParams from flow.core.params import VehicleParams @@ -7,9 +7,9 @@ from flow.scenarios.traffic_light_grid import TrafficLightGridScenario -def grid_example(render=None): +def traffic_light_grid_example(render=None): """ - Perform a simulation of vehicles on a grid. + Perform a simulation of vehicles on a traffic light grid. Parameters ---------- @@ -20,7 +20,7 @@ def grid_example(render=None): ------- exp: flow.core.experiment.Experiment A non-rl experiment demonstrating the performance of human-driven - vehicles and balanced traffic lights on a grid. + vehicles and balanced traffic lights on a traffic light grid. """ inner_length = 300 long_length = 500 @@ -115,7 +115,7 @@ def grid_example(render=None): if __name__ == "__main__": # import the experiment variable - exp = grid_example() + exp = traffic_light_grid_example() # run for a set number of rollouts / time steps exp.run(1, 1500) diff --git a/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py b/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py index c52e23193e..b3030e5172 100644 --- a/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py +++ b/examples/rllib/multiagent_exps/multiagent_traffic_light_grid.py @@ -27,7 +27,7 @@ # Environment parameters HORIZON = 400 # time horizon of a single rollout V_ENTER = 30 # enter speed for departing vehicles -INNER_LENGTH = 300 # length of inner edges in the grid network +INNER_LENGTH = 300 # length of inner edges in the traffic light grid network LONG_LENGTH = 100 # length of final edge in route SHORT_LENGTH = 300 # length of edges that vehicles start on # number of vehicles originating in the left, right, top, and bottom edges @@ -41,9 +41,9 @@ def make_flow_params(n_rows, n_columns, edge_inflow): Parameters ---------- n_rows : int - number of rows in the grid + number of rows in the traffic light grid n_columns : int - number of columns in the grid + number of columns in the traffic light grid edge_inflow : float @@ -243,9 +243,9 @@ def policy_mapping_fn(_): parser.add_argument('--algo', type=str, default='PPO', help="RL method to use (PPO)") parser.add_argument('--num_rows', type=int, default=3, - help="The number of rows in the grid network.") + help="The number of rows in the traffic light grid network.") parser.add_argument('--num_cols', type=int, default=3, - help="The number of columns in the grid network.") + help="The number of columns in the traffic light grid network.") parser.add_argument('--inflow_rate', type=int, default=300, help="The inflow rate (veh/hr) per edge.") args = parser.parse_args() diff --git a/examples/rllib/traffic_light_grid.py b/examples/rllib/traffic_light_grid.py index 6d370a1439..867a474f51 100644 --- a/examples/rllib/traffic_light_grid.py +++ b/examples/rllib/traffic_light_grid.py @@ -26,14 +26,14 @@ def gen_edges(col_num, row_num): - """Generate the names of the outer edges in the grid network. + """Generate the names of the outer edges in the traffic light grid network. Parameters ---------- col_num : int - number of columns in the grid + number of columns in the traffic light grid row_num : int - number of rows in the grid + number of rows in the traffic light grid Returns ------- @@ -59,11 +59,11 @@ def get_flow_params(col_num, row_num, additional_net_params): Parameters ---------- col_num : int - number of columns in the grid + number of columns in the traffic light grid row_num : int - number of rows in the grid + number of rows in the traffic light grid additional_net_params : dict - network-specific parameters that are unique to the grid + network-specific parameters that are unique to the traffic light grid Returns ------- @@ -105,7 +105,7 @@ def get_non_flow_params(enter_speed, add_net_params): enter_speed : float initial speed of vehicles as they enter the network. add_net_params: dict - additional network-specific parameters (unique to the grid) + additional network-specific parameters (unique to the traffic light grid) Returns ------- diff --git a/examples/stable_baselines/traffic_light_grid.py b/examples/stable_baselines/traffic_light_grid.py index 10d7cc19d4..e88d84ea85 100644 --- a/examples/stable_baselines/traffic_light_grid.py +++ b/examples/stable_baselines/traffic_light_grid.py @@ -19,14 +19,14 @@ def gen_edges(col_num, row_num): - """Generate the names of the outer edges in the grid network. + """Generate the names of the outer edges in the traffic light grid network. Parameters ---------- col_num : int - number of columns in the grid + number of columns in the traffic light grid row_num : int - number of rows in the grid + number of rows in the traffic light grid Returns ------- @@ -52,11 +52,11 @@ def get_inflow_params(col_num, row_num, additional_net_params): Parameters ---------- col_num : int - number of columns in the grid + number of columns in the traffic light grid row_num : int - number of rows in the grid + number of rows in the traffic light grid additional_net_params : dict - network-specific parameters that are unique to the grid + network-specific parameters that are unique to the traffic light grid Returns ------- @@ -98,7 +98,7 @@ def get_non_flow_params(enter_speed, add_net_params): enter_speed : float initial speed of vehicles as they enter the network. add_net_params: dict - additional network-specific parameters (unique to the grid) + additional network-specific parameters (unique to the traffic light grid) Returns ------- diff --git a/examples/sumo/traffic_light_grid.py b/examples/sumo/traffic_light_grid.py index 91e256c517..2206f18fd2 100644 --- a/examples/sumo/traffic_light_grid.py +++ b/examples/sumo/traffic_light_grid.py @@ -11,14 +11,14 @@ def gen_edges(col_num, row_num): - """Generate the names of the outer edges in the grid network. + """Generate the names of the outer edges in the traffic light grid network. Parameters ---------- col_num : int - number of columns in the grid + number of columns in the traffic light grid row_num : int - number of rows in the grid + number of rows in the traffic light grid Returns ------- @@ -46,11 +46,11 @@ def get_flow_params(col_num, row_num, additional_net_params): Parameters ---------- col_num : int - number of columns in the grid + number of columns in the traffic light grid row_num : int - number of rows in the grid + number of rows in the traffic light grid additional_net_params : dict - network-specific parameters that are unique to the grid + network-specific parameters that are unique to the traffic light grid Returns ------- @@ -92,7 +92,7 @@ def get_non_flow_params(enter_speed, add_net_params): enter_speed : float initial speed of vehicles as they enter the network. add_net_params: dict - additional network-specific parameters (unique to the grid) + additional network-specific parameters (unique to the traffic light grid) Returns ------- @@ -110,9 +110,9 @@ def get_non_flow_params(enter_speed, add_net_params): return initial, net -def grid_example(render=None, use_inflows=False): +def traffic_light_grid_example(render=None, use_inflows=False): """ - Perform a simulation of vehicles on a grid. + Perform a simulation of vehicles on a traffic light grid. Parameters ---------- @@ -126,7 +126,7 @@ def grid_example(render=None, use_inflows=False): ------- exp: flow.core.experiment.Experiment A non-rl experiment demonstrating the performance of human-driven - vehicles and balanced traffic lights on a grid. + vehicles and balanced traffic lights on a traffic light grid. """ v_enter = 10 inner_length = 300 @@ -227,7 +227,7 @@ def grid_example(render=None, use_inflows=False): if __name__ == "__main__": # import the experiment variable - exp = grid_example() + exp = traffic_light_grid_example() # run for a set number of rollouts / time steps exp.run(1, 1500) diff --git a/flow/benchmarks/README.md b/flow/benchmarks/README.md index f7851a51c6..963ad5b706 100644 --- a/flow/benchmarks/README.md +++ b/flow/benchmarks/README.md @@ -25,13 +25,13 @@ tasked with the objective of dissipating the formation and propagation of - `flow.benchmarks.merge1` 25% CAV penetration rate, S=(65,), A=(13,), T=750. - `flow.benchmarks.merge2` 33.3% CAV penetration rate, S=(85,), A=(17,), T=750. -**Grid (improving traffic signal timing schedules):** Traffic lights in a an -idealized representation of a city with a grid-like structure such as Manhattan -are controlled in intervals of 2 seconds, with the objective of minimizing -delays for drivers. -- `flow.benchmarks.grid0` 3x3 grid (9 traffic lights), +**Traffic Light Grid (improving traffic signal timing schedules):** Traffic +lights in a an idealized representation of a city with a grid-like structure +such as Manhattan are controlled in intervals of 2 seconds, with the objective +of minimizing delays for drivers. +- `flow.benchmarks.grid0` 3x3 traffic light grid (9 traffic lights), inflow = 300 veh/hour/lane S=(339,), A=(9,), T=400. -- `flow.benchmarks.grid1` 5x5 grid (25 traffic lights), +- `flow.benchmarks.grid1` 5x5 traffic light grid (25 traffic lights), inflow = 300 veh/hour/lane S=(915,), A=(25,), T=400. **Bottleneck (maximizing throughput in a bottleneck structure):** The goal of diff --git a/flow/controllers/routing_controllers.py b/flow/controllers/routing_controllers.py index 6fa6a0bad4..ca273289e4 100755 --- a/flow/controllers/routing_controllers.py +++ b/flow/controllers/routing_controllers.py @@ -83,7 +83,7 @@ def choose_route(self, env): class GridRouter(BaseRouter): - """A router used to re-route a vehicle within a grid environment. + """A router used to re-route a vehicle in a traffic light grid environment. Usage ----- diff --git a/flow/envs/multiagent/traffic_light_grid.py b/flow/envs/multiagent/traffic_light_grid.py index d89975f65f..7701e56d6e 100644 --- a/flow/envs/multiagent/traffic_light_grid.py +++ b/flow/envs/multiagent/traffic_light_grid.py @@ -1,7 +1,7 @@ """Multi-agent environments for scenarios with traffic lights. These environments are used to train traffic lights to regulate traffic flow -through an n x m grid. +through an n x m traffic light grid. """ import numpy as np diff --git a/flow/envs/traffic_light_grid.py b/flow/envs/traffic_light_grid.py index 1facf63688..55753de684 100644 --- a/flow/envs/traffic_light_grid.py +++ b/flow/envs/traffic_light_grid.py @@ -1,7 +1,7 @@ """Environments for scenarios with traffic lights. These environments are used to train traffic lights to regulate traffic flow -through an n x m grid. +through an n x m traffic light grid. """ import numpy as np @@ -71,14 +71,14 @@ class TrafficLightGridEnv(Env): Attributes ---------- grid_array : dict - Array containing information on the grid, such as the length of roads, - row_num, col_num, number of initial cars + Array containing information on the traffic light grid, such as the + length of roads, row_num, col_num, number of initial cars rows : int - Number of rows in this grid scenario + Number of rows in this traffic light grid scenario cols : int - Number of columns in this grid scenario + Number of columns in this traffic light grid scenario num_traffic_lights : int - Number of intersection in this grid scenario + Number of intersection in this traffic light grid scenario tl_type : str Type of traffic lights, either 'actuated' or 'static' steps : int @@ -379,8 +379,8 @@ def _split_edge(self, edge): def _get_relative_node(self, agent_id, direction): """Yield node number of traffic light agent in a given direction. - For example, the nodes in a grid with 2 rows and 3 columns are - indexed as follows: + For example, the nodes in a traffic light grid with 2 rows and 3 + columns are indexed as follows: | | | --- 3 --- 4 --- 5 --- @@ -727,7 +727,7 @@ class TrafficLightGridTestEnv(TrafficLightGridEnv): """ Class for use in testing. - This class overrides RL methods of Traffic Light Grid so we can test + This class overrides RL methods of traffic light grid so we can test construction without needing to specify RL methods """ diff --git a/flow/scenarios/traffic_light_grid.py b/flow/scenarios/traffic_light_grid.py index ecab5c0149..fce7842086 100644 --- a/flow/scenarios/traffic_light_grid.py +++ b/flow/scenarios/traffic_light_grid.py @@ -1,4 +1,4 @@ -"""Contains the grid scenario class.""" +"""Contains the traffic light grid scenario class.""" from flow.scenarios.base import Scenario from flow.core.params import InitialConfig @@ -6,13 +6,13 @@ from collections import defaultdict ADDITIONAL_NET_PARAMS = { - # dictionary of grid array data + # dictionary of traffic light grid array data "grid_array": { # number of horizontal rows of edges "row_num": 3, # number of vertical columns of edges "col_num": 2, - # length of inner edges in the grid network + # length of inner edges in the traffic light grid network "inner_length": None, # length of edges where vehicles enter the network "short_length": None, @@ -41,11 +41,11 @@ class TrafficLightGridScenario(Scenario): - """Grid scenario class. + """Traffic Light Grid scenario class. - The grid scenario consists of m vertical lanes and n horizontal lanes, - with a total of nxm intersections where the vertical and horizontal - edges meet. + The traffic light grid scenario consists of m vertical lanes and n + horizontal lanes, with a total of nxm intersections where the vertical + and horizontal edges meet. Requires from net_params: @@ -53,7 +53,7 @@ class TrafficLightGridScenario(Scenario): * **row_num** : number of horizontal rows of edges * **col_num** : number of vertical columns of edges - * **inner_length** : length of inner edges in the grid network + * **inner_length** : length of inner edges in traffic light grid network * **short_length** : length of edges that vehicles start on * **long_length** : length of final edge in route * **cars_top** : number of cars starting at the edges heading to the top @@ -110,7 +110,7 @@ def __init__(self, net_params, initial_config=InitialConfig(), traffic_lights=TrafficLightParams()): - """Initialize an n*m grid scenario.""" + """Initialize an n*m traffic light grid scenario.""" optional = ["tl_logic"] for p in ADDITIONAL_NET_PARAMS.keys(): if p not in net_params.additional_params and p not in optional: @@ -218,8 +218,8 @@ def _inner_nodes(self): are numbered from bottom left, increasing first across the columns and then across the rows. - For example, the nodes in a grid with 2 rows and 3 columns would be - indexed as follows: + For example, the nodes in a traffic light grid with 2 rows and 3 columns + would be indexed as follows: | | | --- 3 --- 4 --- 5 --- diff --git a/tests/fast_tests/test_collisions.py b/tests/fast_tests/test_collisions.py index d094a87ac5..357e98df1a 100644 --- a/tests/fast_tests/test_collisions.py +++ b/tests/fast_tests/test_collisions.py @@ -7,7 +7,7 @@ from flow.controllers.car_following_models import SimCarFollowingController from flow.controllers.routing_controllers import GridRouter -from tests.setup_scripts import grid_mxn_exp_setup +from tests.setup_scripts import traffic_light_grid_mxn_exp_setup class TestCollisions(unittest.TestCase): @@ -50,7 +50,7 @@ def test_collide(self): net_params = NetParams(additional_params=additional_net_params) - env, _ = grid_mxn_exp_setup( + env, _ = traffic_light_grid_mxn_exp_setup( row_num=1, col_num=1, sim_params=sim_params, @@ -111,7 +111,7 @@ def test_collide_inflows(self): inflows=inflows, additional_params=additional_net_params) - env, _ = grid_mxn_exp_setup( + env, _ = traffic_light_grid_mxn_exp_setup( row_num=1, col_num=1, sim_params=sim_params, diff --git a/tests/fast_tests/test_examples.py b/tests/fast_tests/test_examples.py index a506485de7..be9dcc9bf2 100644 --- a/tests/fast_tests/test_examples.py +++ b/tests/fast_tests/test_examples.py @@ -33,7 +33,7 @@ from examples.sumo.bottlenecks import bottleneck_example from examples.sumo.density_exp import run_bottleneck from examples.sumo.figure_eight import figure_eight_example -from examples.sumo.traffic_light_grid import grid_example +from examples.sumo.traffic_light_grid import traffic_light_grid_example from examples.sumo.highway import highway_example from examples.sumo.highway_ramps import highway_ramps_example from examples.sumo.merge import merge_example @@ -71,11 +71,11 @@ def test_figure_eight(self): def test_traffic_light_grid(self): """Verifies that examples/sumo/traffic_light_grid.py is working.""" # test the example in the absence of inflows - exp = grid_example(render=False, use_inflows=False) + exp = traffic_light_grid_example(render=False, use_inflows=False) exp.run(1, 5) # test the example in the presence of inflows - exp = grid_example(render=False, use_inflows=True) + exp = traffic_light_grid_example(render=False, use_inflows=True) exp.run(1, 5) def test_highway(self): diff --git a/tests/fast_tests/test_green_wave.py b/tests/fast_tests/test_green_wave.py index 74ed94fb44..22de10f378 100644 --- a/tests/fast_tests/test_green_wave.py +++ b/tests/fast_tests/test_green_wave.py @@ -2,13 +2,13 @@ from flow.core.experiment import Experiment -from tests.setup_scripts import grid_mxn_exp_setup +from tests.setup_scripts import traffic_light_grid_mxn_exp_setup class Test1x1Environment(unittest.TestCase): def setUp(self): - # create the environment and scenario classes for a grid network - self.env, _ = grid_mxn_exp_setup() + # create the environment and scenario classes for a traffic light grid network + self.env, _ = traffic_light_grid_mxn_exp_setup() self.env.reset() # instantiate an experiment class @@ -93,8 +93,8 @@ def test_get_distance_to_intersection(self): class Test2x2Environment(unittest.TestCase): def setUp(self): - # create the environment and scenario classes for a grid network - self.env, _ = grid_mxn_exp_setup(row_num=2, col_num=2) + # create the environment and scenario classes for a traffic light grid network + self.env, _ = traffic_light_grid_mxn_exp_setup(row_num=2, col_num=2) self.env.reset() # instantiate an experiment class diff --git a/tests/fast_tests/test_traffic_lights.py b/tests/fast_tests/test_traffic_lights.py index 5686938fc1..263ca55f2d 100644 --- a/tests/fast_tests/test_traffic_lights.py +++ b/tests/fast_tests/test_traffic_lights.py @@ -1,7 +1,7 @@ import unittest import os -from tests.setup_scripts import ring_road_exp_setup, grid_mxn_exp_setup +from tests.setup_scripts import ring_road_exp_setup, traffic_light_grid_mxn_exp_setup from flow.core.params import VehicleParams from flow.core.params import NetParams from flow.core.params import SumoCarFollowingParams @@ -153,7 +153,7 @@ def setUp(self): min_gap=2.5, tau=1.1), num_vehicles=16) - self.env, scenario = grid_mxn_exp_setup( + self.env, scenario = traffic_light_grid_mxn_exp_setup( row_num=1, col_num=3, vehicles=vehicles) def tearDown(self): @@ -228,7 +228,7 @@ def setUp(self): min_gap=2.5, tau=1.1), num_vehicles=16) - env, scenario = grid_mxn_exp_setup( + env, scenario = traffic_light_grid_mxn_exp_setup( row_num=1, col_num=3, vehicles=vehicles) self.exp = Experiment(env) @@ -285,7 +285,7 @@ def setUp(self): file="testindividuallights.xml", freq=100) - env, scenario = grid_mxn_exp_setup( + env, scenario = traffic_light_grid_mxn_exp_setup( row_num=1, col_num=4, tl_logic=tl_logic) self.exp = Experiment(env) diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index eaab93e3cb..5a12613710 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -302,7 +302,7 @@ def highway_exp_setup(sim_params=None, return env, scenario -def grid_mxn_exp_setup(row_num=1, +def traffic_light_grid_mxn_exp_setup(row_num=1, col_num=1, sim_params=None, vehicles=None, @@ -311,14 +311,14 @@ def grid_mxn_exp_setup(row_num=1, initial_config=None, tl_logic=None): """ - Create an environment and scenario pair for grid 1x1 test experiments. + Create an environment and scenario pair for traffic light grid 1x1 test experiments. Parameters ---------- row_num: int, optional - number of horizontal rows of edges in the grid network + number of horizontal rows of edges in the traffic light grid network col_num: int, optional - number of vertical columns of edges in the grid network + number of vertical columns of edges in the traffic light grid network sim_params : flow.core.params.SumoParams sumo-related configuration parameters, defaults to a time step of 1s and no sumo-imposed failsafe on human or rl vehicles @@ -330,8 +330,8 @@ def grid_mxn_exp_setup(row_num=1, environment-specific parameters, defaults to a environment with failsafes, where other parameters do not matter for non-rl runs net_params : flow.core.params.NetParams - network-specific configuration parameters, defaults to a 1x1 grid - with traffic lights on + network-specific configuration parameters, defaults to a 1x1 traffic + light grid with traffic lights on initial_config : flow.core.params.InitialConfig specifies starting positions of vehicles, defaults to evenly distributed vehicles across the length of the network diff --git a/tutorials/tutorial05_scenarios.ipynb b/tutorials/tutorial05_scenarios.ipynb index 9e46922252..0c1a7fe051 100644 --- a/tutorials/tutorial05_scenarios.ipynb +++ b/tutorials/tutorial05_scenarios.ipynb @@ -6,7 +6,7 @@ "source": [ "# Tutorial 06: Creating Custom Scenarios\n", "\n", - "This tutorial walks you through the process of generating custom scenarios. Scenarios define the network geometry of a task, as well as the constituents of the network, e.g. vehicles, traffic lights, etc... Various scenarios are available in Flow, depicting a diverse set of open and closed traffic networks such as ring roads, intersections/grids, straight highway merges, and more. \n", + "This tutorial walks you through the process of generating custom scenarios. Scenarios define the network geometry of a task, as well as the constituents of the network, e.g. vehicles, traffic lights, etc... Various scenarios are available in Flow, depicting a diverse set of open and closed traffic networks such as ring roads, intersections, traffic light grids, straight highway merges, and more. \n", "\n", "In this exercise, we will recreate the ring road network, seen in the figure below.\n", "\n", diff --git a/tutorials/tutorial10_traffic_lights.ipynb b/tutorials/tutorial10_traffic_lights.ipynb index 31b7741881..cc168eba21 100644 --- a/tutorials/tutorial10_traffic_lights.ipynb +++ b/tutorials/tutorial10_traffic_lights.ipynb @@ -59,10 +59,10 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "There are a few unique additions to `additional_net_params` in the grid envirinments to be aware of. They are the following 2 items:\n", + "There are a few unique additions to `additional_net_params` in the traffic light grid envirinments to be aware of. They are the following 2 items:\n", "\n", "#### grid_array\n", - "`grid_array` passes information on the road network to the scenario, specifying the parameters you see below: `row_num`, `col_num`, `inner_length`, `short_length`, `long_length`, `cars_top`, `cars_bot`, `cars_left`, `cars_right`. This is required for any grid experiment.\n", + "`grid_array` passes information on the road network to the scenario, specifying the parameters you see below: `row_num`, `col_num`, `inner_length`, `short_length`, `long_length`, `cars_top`, `cars_bot`, `cars_left`, `cars_right`. This is required for any traffic light grid experiment.\n", "\n", "\n" ] @@ -74,7 +74,7 @@ "#### tl_logic\n", "`tl_logic` should be used for users who want to exert more control over individual traffic lights. `tl_logic` simply tells the env whether the traffic lights are controlled by RL or whether a default pattern or SUMO actuation is to be used. Use \"actuated\" if you want SUMO to control the traffic lights. \n", "\n", - "For this tutorial, we will assume the following parameters for the `grid_array`, which specifies a grid network with 2 rows and 3 columns. `traffic_lights` should be set to `True` for every experiment in this tutorial." + "For this tutorial, we will assume the following parameters for the `grid_array`, which specifies a traffic light grid network with 2 rows and 3 columns. `traffic_lights` should be set to `True` for every experiment in this tutorial." ] }, { From 0bd22fccd6834125d537f6a72c88320692e8db6b Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Wed, 21 Aug 2019 23:39:06 -0700 Subject: [PATCH 14/23] addressed flake8 issues --- examples/aimsun/figure_eight.py | 2 +- flow/envs/multiagent/__init__.py | 2 -- flow/scenarios/traffic_light_grid.py | 1 + tests/setup_scripts.py | 14 +++++++------- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/aimsun/figure_eight.py b/examples/aimsun/figure_eight.py index 6f56d1a9ab..058af88af7 100644 --- a/examples/aimsun/figure_eight.py +++ b/examples/aimsun/figure_eight.py @@ -42,7 +42,7 @@ def figure_eight_example(render=None): net_params = NetParams( additional_params=ADDITIONAL_NET_PARAMS.copy()) - scenario = figure_eight_example( + scenario = FigureEightScenario( name="FigureEight", vehicles=vehicles, net_params=net_params) diff --git a/flow/envs/multiagent/__init__.py b/flow/envs/multiagent/__init__.py index 9c5b7c64de..4c43611aa6 100644 --- a/flow/envs/multiagent/__init__.py +++ b/flow/envs/multiagent/__init__.py @@ -8,7 +8,5 @@ from flow.envs.multiagent.traffic_light_grid import MultiTrafficLightGridPOEnv from flow.envs.multiagent.highway import MultiAgentHighwayPOEnv -from flow.envs.multiagent.ring.accel import MultiAgentAccelEnv - __all__ = ['MultiEnv', 'MultiAgentAccelEnv', 'MultiWaveAttenuationPOEnv', 'MultiTrafficLightGridPOEnv', 'MultiAgentHighwayPOEnv'] diff --git a/flow/scenarios/traffic_light_grid.py b/flow/scenarios/traffic_light_grid.py index fce7842086..c9af6073eb 100644 --- a/flow/scenarios/traffic_light_grid.py +++ b/flow/scenarios/traffic_light_grid.py @@ -4,6 +4,7 @@ from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams from collections import defaultdict +import numpy as np ADDITIONAL_NET_PARAMS = { # dictionary of traffic light grid array data diff --git a/tests/setup_scripts.py b/tests/setup_scripts.py index 5a12613710..82ee29b8f3 100644 --- a/tests/setup_scripts.py +++ b/tests/setup_scripts.py @@ -303,13 +303,13 @@ def highway_exp_setup(sim_params=None, def traffic_light_grid_mxn_exp_setup(row_num=1, - col_num=1, - sim_params=None, - vehicles=None, - env_params=None, - net_params=None, - initial_config=None, - tl_logic=None): + col_num=1, + sim_params=None, + vehicles=None, + env_params=None, + net_params=None, + initial_config=None, + tl_logic=None): """ Create an environment and scenario pair for traffic light grid 1x1 test experiments. From 54d08b1574a5e774c38aab766b0774676cdf0be0 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Sat, 24 Aug 2019 11:07:29 -0700 Subject: [PATCH 15/23] Fixed test_visualiszer.py errors --- tests/data/rllib_data/multi_agent/params.json | 2 +- tests/data/rllib_data/single_agent/params.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/data/rllib_data/multi_agent/params.json b/tests/data/rllib_data/multi_agent/params.json index d32656fa7a..981780b3ad 100644 --- a/tests/data/rllib_data/multi_agent/params.json +++ b/tests/data/rllib_data/multi_agent/params.json @@ -16,7 +16,7 @@ "entropy_coeff": 0.0, "env": "MultiWaveAttenuationPOEnv-v0", "env_config": { - "flow_params": "{\n \"env\": {\n \"additional_params\": {\n \"max_accel\": 1,\n \"max_decel\": 1,\n \"ring_length\": [\n 230,\n 230\n ],\n \"target_velocity\": 4\n },\n \"clip_actions\": true,\n \"evaluate\": false,\n \"horizon\": 3000,\n \"sims_per_step\": 1,\n \"warmup_steps\": 750\n },\n \"env_name\": \"MultiWaveAttenuationPOEnv\",\n \"exp_tag\": \"lord_of_numrings1\",\n \"initial\": {\n \"additional_params\": {},\n \"bunching\": 20.0,\n \"edges_distribution\": \"all\",\n \"lanes_distribution\": Infinity,\n \"min_gap\": 0,\n \"perturbation\": 0.0,\n \"shuffle\": false,\n \"spacing\": \"custom\",\n \"x0\": 0\n },\n \"net\": {\n \"additional_params\": {\n \"lanes\": 1,\n \"length\": 230,\n \"num_rings\": 1,\n \"resolution\": 40,\n \"speed_limit\": 30\n },\n \"inflows\": {\n \"_InFlows__flows\": []\n },\n \"osm_path\": null,\n \"template\": null\n },\n \"scenario\": \"MultiLoopScenario\",\n \"sim\": {\n \"color_vehicles\": true,\n \"emission_path\": null,\n \"lateral_resolution\": null,\n \"no_step_log\": true,\n \"num_clients\": 1,\n \"overtake_right\": false,\n \"port\": null,\n \"print_warnings\": true,\n \"pxpm\": 2,\n \"render\": false,\n \"restart_instance\": false,\n \"save_render\": false,\n \"seed\": null,\n \"show_radius\": false,\n \"sight_radius\": 25,\n \"sim_step\": 0.1,\n \"teleport_time\": -1\n },\n \"simulator\": \"traci\",\n \"veh\": [\n {\n \"acceleration_controller\": [\n \"IDMController\",\n {\n \"noise\": 0.2\n }\n ],\n \"car_following_params\": {\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n },\n \"speed_mode\": 25\n },\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"lane_change_params\": {\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n },\n \"lane_change_mode\": 512\n },\n \"num_vehicles\": 21,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"veh_id\": \"human_0\"\n },\n {\n \"acceleration_controller\": [\n \"RLController\",\n {}\n ],\n \"car_following_params\": {\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n },\n \"speed_mode\": 25\n },\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"lane_change_params\": {\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n },\n \"lane_change_mode\": 512\n },\n \"num_vehicles\": 1,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"veh_id\": \"rl_0\"\n }\n ]\n}", + "flow_params": "{\n \"env\": {\n \"additional_params\": {\n \"max_accel\": 1,\n \"max_decel\": 1,\n \"ring_length\": [\n 230,\n 230\n ],\n \"target_velocity\": 4\n },\n \"clip_actions\": true,\n \"evaluate\": false,\n \"horizon\": 3000,\n \"sims_per_step\": 1,\n \"warmup_steps\": 750\n },\n \"env_name\": \"MultiWaveAttenuationPOEnv\",\n \"exp_tag\": \"lord_of_numrings1\",\n \"initial\": {\n \"additional_params\": {},\n \"bunching\": 20.0,\n \"edges_distribution\": \"all\",\n \"lanes_distribution\": Infinity,\n \"min_gap\": 0,\n \"perturbation\": 0.0,\n \"shuffle\": false,\n \"spacing\": \"custom\",\n \"x0\": 0\n },\n \"net\": {\n \"additional_params\": {\n \"lanes\": 1,\n \"length\": 230,\n \"num_rings\": 1,\n \"resolution\": 40,\n \"speed_limit\": 30\n },\n \"inflows\": {\n \"_InFlows__flows\": []\n },\n \"osm_path\": null,\n \"template\": null\n },\n \"scenario\": \"MultiRingScenario\",\n \"sim\": {\n \"color_vehicles\": true,\n \"emission_path\": null,\n \"lateral_resolution\": null,\n \"no_step_log\": true,\n \"num_clients\": 1,\n \"overtake_right\": false,\n \"port\": null,\n \"print_warnings\": true,\n \"pxpm\": 2,\n \"render\": false,\n \"restart_instance\": false,\n \"save_render\": false,\n \"seed\": null,\n \"show_radius\": false,\n \"sight_radius\": 25,\n \"sim_step\": 0.1,\n \"teleport_time\": -1\n },\n \"simulator\": \"traci\",\n \"veh\": [\n {\n \"acceleration_controller\": [\n \"IDMController\",\n {\n \"noise\": 0.2\n }\n ],\n \"car_following_params\": {\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n },\n \"speed_mode\": 25\n },\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"lane_change_params\": {\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n },\n \"lane_change_mode\": 512\n },\n \"num_vehicles\": 21,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"veh_id\": \"human_0\"\n },\n {\n \"acceleration_controller\": [\n \"RLController\",\n {}\n ],\n \"car_following_params\": {\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n },\n \"speed_mode\": 25\n },\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"lane_change_params\": {\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n },\n \"lane_change_mode\": 512\n },\n \"num_vehicles\": 1,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"veh_id\": \"rl_0\"\n }\n ]\n}", "run": "PPO" }, "gamma": 0.999, diff --git a/tests/data/rllib_data/single_agent/params.json b/tests/data/rllib_data/single_agent/params.json index 26991e86a0..f2c6dfe589 100644 --- a/tests/data/rllib_data/single_agent/params.json +++ b/tests/data/rllib_data/single_agent/params.json @@ -16,7 +16,7 @@ "entropy_coeff": 0.0, "env": "AccelEnv-v0", "env_config": { - "flow_params": "{\n \"simulator\": \"traci\",\n \"env\": {\n \"additional_params\": {\n \"max_accel\": 3,\n \"max_decel\": 3,\n \"sort_vehicles\": false,\n \"target_velocity\": 20\n },\n \"clip_actions\": false,\n \"evaluate\": false,\n \"horizon\": 1500,\n \"sims_per_step\": 1,\n \"warmup_steps\": 0\n },\n \"env_name\": \"AccelEnv\",\n \"exp_tag\": \"to_visualize\",\n \"initial\": {\n \"additional_params\": {},\n \"bunching\": 0,\n \"edges_distribution\": \"all\",\n \"lanes_distribution\": Infinity,\n \"min_gap\": 0,\n \"perturbation\": 0.0,\n \"shuffle\": false,\n \"spacing\": \"uniform\",\n \"x0\": 0\n },\n \"net\": {\n \"additional_params\": {\n \"lanes\": 1,\n \"radius_ring\": 30,\n \"resolution\": 40,\n \"speed_limit\": 30\n },\n \"inflows\": {\n \"_InFlows__flows\": [],\n \"num_flows\": 0\n },\n \"template\": null,\n \"osm_path\": null\n },\n \"scenario\": \"Figure8Scenario\",\n \"sim\": {\n \"emission_path\": null,\n \"lateral_resolution\": null,\n \"no_step_log\": true,\n \"num_clients\": 1,\n \"overtake_right\": false,\n \"port\": null,\n \"print_warnings\": true,\n \"render\": false,\n \"restart_instance\": false,\n \"seed\": null,\n \"sim_step\": 0.1,\n \"teleport_time\": -1\n },\n \"veh\": [\n {\n \"acceleration_controller\": [\n \"IDMController\",\n {\n \"noise\": 0.2\n }\n ],\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"num_vehicles\": 13,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"car_following_params\": {\n \"speed_mode\": 1,\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n }\n },\n \"lane_change_params\": {\n \"lane_change_mode\": 512,\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n }\n },\n \"veh_id\": \"human\"\n },\n {\n \"acceleration_controller\": [\n \"RLController\",\n {}\n ],\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"num_vehicles\": 1,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"car_following_params\": {\n \"speed_mode\": 1,\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n }\n },\n \"lane_change_params\": {\n \"lane_change_mode\": 512,\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n }\n },\n \"veh_id\": \"rl\"\n }\n ]\n}", + "flow_params": "{\n \"simulator\": \"traci\",\n \"env\": {\n \"additional_params\": {\n \"max_accel\": 3,\n \"max_decel\": 3,\n \"sort_vehicles\": false,\n \"target_velocity\": 20\n },\n \"clip_actions\": false,\n \"evaluate\": false,\n \"horizon\": 1500,\n \"sims_per_step\": 1,\n \"warmup_steps\": 0\n },\n \"env_name\": \"AccelEnv\",\n \"exp_tag\": \"to_visualize\",\n \"initial\": {\n \"additional_params\": {},\n \"bunching\": 0,\n \"edges_distribution\": \"all\",\n \"lanes_distribution\": Infinity,\n \"min_gap\": 0,\n \"perturbation\": 0.0,\n \"shuffle\": false,\n \"spacing\": \"uniform\",\n \"x0\": 0\n },\n \"net\": {\n \"additional_params\": {\n \"lanes\": 1,\n \"radius_ring\": 30,\n \"resolution\": 40,\n \"speed_limit\": 30\n },\n \"inflows\": {\n \"_InFlows__flows\": [],\n \"num_flows\": 0\n },\n \"template\": null,\n \"osm_path\": null\n },\n \"scenario\": \"FigureEightScenario\",\n \"sim\": {\n \"emission_path\": null,\n \"lateral_resolution\": null,\n \"no_step_log\": true,\n \"num_clients\": 1,\n \"overtake_right\": false,\n \"port\": null,\n \"print_warnings\": true,\n \"render\": false,\n \"restart_instance\": false,\n \"seed\": null,\n \"sim_step\": 0.1,\n \"teleport_time\": -1\n },\n \"veh\": [\n {\n \"acceleration_controller\": [\n \"IDMController\",\n {\n \"noise\": 0.2\n }\n ],\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"num_vehicles\": 13,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"car_following_params\": {\n \"speed_mode\": 1,\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n }\n },\n \"lane_change_params\": {\n \"lane_change_mode\": 512,\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n }\n },\n \"veh_id\": \"human\"\n },\n {\n \"acceleration_controller\": [\n \"RLController\",\n {}\n ],\n \"initial_speed\": 0,\n \"lane_change_controller\": [\n \"SimLaneChangeController\",\n {}\n ],\n \"num_vehicles\": 1,\n \"routing_controller\": [\n \"ContinuousRouter\",\n {}\n ],\n \"car_following_params\": {\n \"speed_mode\": 1,\n \"controller_params\": {\n \"accel\": 2.6,\n \"carFollowModel\": \"IDM\",\n \"decel\": 4.5,\n \"impatience\": 0.5,\n \"maxSpeed\": 30,\n \"minGap\": 2.5,\n \"sigma\": 0.5,\n \"speedDev\": 0.1,\n \"speedFactor\": 1.0,\n \"tau\": 1.0\n }\n },\n \"lane_change_params\": {\n \"lane_change_mode\": 512,\n \"controller_params\": {\n \"laneChangeModel\": \"LC2013\",\n \"lcCooperative\": \"1.0\",\n \"lcKeepRight\": \"1.0\",\n \"lcSpeedGain\": \"1.0\",\n \"lcStrategic\": \"1.0\"\n }\n },\n \"veh_id\": \"rl\"\n }\n ]\n}", "run": "PPO" }, "gamma": 0.999, From 26ed2cf447a0b5d7e3cc3bf164ea5f3b247248a4 Mon Sep 17 00:00:00 2001 From: Ashkan Y Date: Wed, 28 Aug 2019 20:04:08 -0700 Subject: [PATCH 16/23] Remove data.json --- flow/core/kernel/scenario/data.json | 889 ---------------------------- 1 file changed, 889 deletions(-) delete mode 100644 flow/core/kernel/scenario/data.json diff --git a/flow/core/kernel/scenario/data.json b/flow/core/kernel/scenario/data.json deleted file mode 100644 index 8879c15f77..0000000000 --- a/flow/core/kernel/scenario/data.json +++ /dev/null @@ -1,889 +0,0 @@ -{ - "centroid_config_name": null, - "connections": { - "center0": [ - { - "from": "bot0_0", - "fromLane": "0", - "signal_group": 1, - "to": "bot0_1", - "toLane": "0" - }, - { - "from": "top0_1", - "fromLane": "0", - "signal_group": 1, - "to": "top0_0", - "toLane": "0" - }, - { - "from": "right0_0", - "fromLane": "0", - "signal_group": 2, - "to": "right1_0", - "toLane": "0" - }, - { - "from": "left1_0", - "fromLane": "0", - "signal_group": 2, - "to": "left0_0", - "toLane": "0" - } - ], - "center1": [ - { - "from": "bot0_1", - "fromLane": "0", - "signal_group": 1, - "to": "bot0_2", - "toLane": "0" - }, - { - "from": "top0_2", - "fromLane": "0", - "signal_group": 1, - "to": "top0_1", - "toLane": "0" - }, - { - "from": "right0_1", - "fromLane": "0", - "signal_group": 2, - "to": "right1_1", - "toLane": "0" - }, - { - "from": "left1_1", - "fromLane": "0", - "signal_group": 2, - "to": "left0_1", - "toLane": "0" - } - ], - "center2": [ - { - "from": "bot0_2", - "fromLane": "0", - "signal_group": 1, - "to": "bot0_3", - "toLane": "0" - }, - { - "from": "top0_3", - "fromLane": "0", - "signal_group": 1, - "to": "top0_2", - "toLane": "0" - }, - { - "from": "right0_2", - "fromLane": "0", - "signal_group": 2, - "to": "right1_2", - "toLane": "0" - }, - { - "from": "left1_2", - "fromLane": "0", - "signal_group": 2, - "to": "left0_2", - "toLane": "0" - } - ], - "center3": [ - { - "from": "bot1_0", - "fromLane": "0", - "signal_group": 1, - "to": "bot1_1", - "toLane": "0" - }, - { - "from": "top1_1", - "fromLane": "0", - "signal_group": 1, - "to": "top1_0", - "toLane": "0" - }, - { - "from": "right1_0", - "fromLane": "0", - "signal_group": 2, - "to": "right2_0", - "toLane": "0" - }, - { - "from": "left2_0", - "fromLane": "0", - "signal_group": 2, - "to": "left1_0", - "toLane": "0" - } - ], - "center4": [ - { - "from": "bot1_1", - "fromLane": "0", - "signal_group": 1, - "to": "bot1_2", - "toLane": "0" - }, - { - "from": "top1_2", - "fromLane": "0", - "signal_group": 1, - "to": "top1_1", - "toLane": "0" - }, - { - "from": "right1_1", - "fromLane": "0", - "signal_group": 2, - "to": "right2_1", - "toLane": "0" - }, - { - "from": "left2_1", - "fromLane": "0", - "signal_group": 2, - "to": "left1_1", - "toLane": "0" - } - ], - "center5": [ - { - "from": "bot1_2", - "fromLane": "0", - "signal_group": 1, - "to": "bot1_3", - "toLane": "0" - }, - { - "from": "top1_3", - "fromLane": "0", - "signal_group": 1, - "to": "top1_2", - "toLane": "0" - }, - { - "from": "right1_2", - "fromLane": "0", - "signal_group": 2, - "to": "right2_2", - "toLane": "0" - }, - { - "from": "left2_2", - "fromLane": "0", - "signal_group": 2, - "to": "left1_2", - "toLane": "0" - } - ] - }, - "edges": [ - { - "from": "center1", - "id": "top0_1", - "length": 300, - "priority": 78, - "to": "center0", - "type": "horizontal" - }, - { - "from": "center0", - "id": "bot0_1", - "length": 300, - "priority": 78, - "to": "center1", - "type": "horizontal" - }, - { - "from": "center2", - "id": "top0_2", - "length": 300, - "priority": 78, - "to": "center1", - "type": "horizontal" - }, - { - "from": "center1", - "id": "bot0_2", - "length": 300, - "priority": 78, - "to": "center2", - "type": "horizontal" - }, - { - "from": "center4", - "id": "top1_1", - "length": 300, - "priority": 78, - "to": "center3", - "type": "horizontal" - }, - { - "from": "center3", - "id": "bot1_1", - "length": 300, - "priority": 78, - "to": "center4", - "type": "horizontal" - }, - { - "from": "center5", - "id": "top1_2", - "length": 300, - "priority": 78, - "to": "center4", - "type": "horizontal" - }, - { - "from": "center4", - "id": "bot1_2", - "length": 300, - "priority": 78, - "to": "center5", - "type": "horizontal" - }, - { - "from": "center0", - "id": "right1_0", - "length": 300, - "priority": 78, - "to": "center3", - "type": "vertical" - }, - { - "from": "center3", - "id": "left1_0", - "length": 300, - "priority": 78, - "to": "center0", - "type": "vertical" - }, - { - "from": "center1", - "id": "right1_1", - "length": 300, - "priority": 78, - "to": "center4", - "type": "vertical" - }, - { - "from": "center4", - "id": "left1_1", - "length": 300, - "priority": 78, - "to": "center1", - "type": "vertical" - }, - { - "from": "center2", - "id": "right1_2", - "length": 300, - "priority": 78, - "to": "center5", - "type": "vertical" - }, - { - "from": "center5", - "id": "left1_2", - "length": 300, - "priority": 78, - "to": "center2", - "type": "vertical" - }, - { - "from": "bot_col_short0", - "id": "right0_0", - "length": 300, - "priority": 78, - "to": "center0", - "type": "vertical" - }, - { - "from": "center0", - "id": "left0_0", - "length": 500, - "priority": 78, - "to": "bot_col_long0", - "type": "vertical" - }, - { - "from": "top_col_short0", - "id": "left2_0", - "length": 300, - "priority": 78, - "to": "center3", - "type": "vertical" - }, - { - "from": "center3", - "id": "right2_0", - "length": 500, - "priority": 78, - "to": "top_col_long0", - "type": "vertical" - }, - { - "from": "bot_col_short1", - "id": "right0_1", - "length": 300, - "priority": 78, - "to": "center1", - "type": "vertical" - }, - { - "from": "center1", - "id": "left0_1", - "length": 500, - "priority": 78, - "to": "bot_col_long1", - "type": "vertical" - }, - { - "from": "top_col_short1", - "id": "left2_1", - "length": 300, - "priority": 78, - "to": "center4", - "type": "vertical" - }, - { - "from": "center4", - "id": "right2_1", - "length": 500, - "priority": 78, - "to": "top_col_long1", - "type": "vertical" - }, - { - "from": "bot_col_short2", - "id": "right0_2", - "length": 300, - "priority": 78, - "to": "center2", - "type": "vertical" - }, - { - "from": "center2", - "id": "left0_2", - "length": 500, - "priority": 78, - "to": "bot_col_long2", - "type": "vertical" - }, - { - "from": "top_col_short2", - "id": "left2_2", - "length": 300, - "priority": 78, - "to": "center5", - "type": "vertical" - }, - { - "from": "center5", - "id": "right2_2", - "length": 500, - "priority": 78, - "to": "top_col_long2", - "type": "vertical" - }, - { - "from": "left_row_short0", - "id": "bot0_0", - "length": 300, - "priority": 78, - "to": "center0", - "type": "horizontal" - }, - { - "from": "center0", - "id": "top0_0", - "length": 500, - "priority": 78, - "to": "left_row_long0", - "type": "horizontal" - }, - { - "from": "right_row_short0", - "id": "top0_3", - "length": 300, - "priority": 78, - "to": "center2", - "type": "horizontal" - }, - { - "from": "center2", - "id": "bot0_3", - "length": 500, - "priority": 78, - "to": "right_row_long0", - "type": "horizontal" - }, - { - "from": "left_row_short1", - "id": "bot1_0", - "length": 300, - "priority": 78, - "to": "center3", - "type": "horizontal" - }, - { - "from": "center3", - "id": "top1_0", - "length": 500, - "priority": 78, - "to": "left_row_long1", - "type": "horizontal" - }, - { - "from": "right_row_short1", - "id": "top1_3", - "length": 300, - "priority": 78, - "to": "center5", - "type": "horizontal" - }, - { - "from": "center5", - "id": "bot1_3", - "length": 500, - "priority": 78, - "to": "right_row_long1", - "type": "horizontal" - } - ], - "experiment_name": "Micro SRC Experiment 867", - "inflows": { - "_InFlows__flows": [], - "num_flows": 0 - }, - "nodes": [ - { - "id": "center0", - "radius": 6.199999999999999, - "type": "traffic_light", - "x": 0, - "y": 0 - }, - { - "id": "center1", - "radius": 6.199999999999999, - "type": "traffic_light", - "x": 300, - "y": 0 - }, - { - "id": "center2", - "radius": 6.199999999999999, - "type": "traffic_light", - "x": 600, - "y": 0 - }, - { - "id": "center3", - "radius": 6.199999999999999, - "type": "traffic_light", - "x": 0, - "y": 300 - }, - { - "id": "center4", - "radius": 6.199999999999999, - "type": "traffic_light", - "x": 300, - "y": 300 - }, - { - "id": "center5", - "radius": 6.199999999999999, - "type": "traffic_light", - "x": 600, - "y": 300 - }, - { - "id": "bot_col_short0", - "type": "priority", - "x": 0, - "y": -300 - }, - { - "id": "bot_col_long0", - "type": "priority", - "x": 0, - "y": -500 - }, - { - "id": "top_col_short0", - "type": "priority", - "x": 0, - "y": 600 - }, - { - "id": "top_col_long0", - "type": "priority", - "x": 0, - "y": 800 - }, - { - "id": "bot_col_short1", - "type": "priority", - "x": 300, - "y": -300 - }, - { - "id": "bot_col_long1", - "type": "priority", - "x": 300, - "y": -500 - }, - { - "id": "top_col_short1", - "type": "priority", - "x": 300, - "y": 600 - }, - { - "id": "top_col_long1", - "type": "priority", - "x": 300, - "y": 800 - }, - { - "id": "bot_col_short2", - "type": "priority", - "x": 600, - "y": -300 - }, - { - "id": "bot_col_long2", - "type": "priority", - "x": 600, - "y": -500 - }, - { - "id": "top_col_short2", - "type": "priority", - "x": 600, - "y": 600 - }, - { - "id": "top_col_long2", - "type": "priority", - "x": 600, - "y": 800 - }, - { - "id": "left_row_short0", - "type": "priority", - "x": -300, - "y": 0 - }, - { - "id": "left_row_long0", - "type": "priority", - "x": -500, - "y": 0 - }, - { - "id": "right_row_short0", - "type": "priority", - "x": 900, - "y": 0 - }, - { - "id": "right_row_long0", - "type": "priority", - "x": 1100, - "y": 0 - }, - { - "id": "left_row_short1", - "type": "priority", - "x": -300, - "y": 300 - }, - { - "id": "left_row_long1", - "type": "priority", - "x": -500, - "y": 300 - }, - { - "id": "right_row_short1", - "type": "priority", - "x": 900, - "y": 300 - }, - { - "id": "right_row_long1", - "type": "priority", - "x": 1100, - "y": 300 - } - ], - "osm_path": null, - "render": true, - "replication_name": "Replication 870", - "scenario_name": "Dynamic Scenario 866", - "sim_step": 0.5, - "subnetwork_name": null, - "traffic_lights": { - "_TrafficLightParams__tls_properties": { - "center0": { - "id": "center0", - "phases": [ - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "GGGrrrGGGrrr", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "yyyrrryyyrrr", - "yellow": "3" - }, - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "rrrGGGrrrGGG", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "rrryyyrrryyy", - "yellow": "3" - } - ], - "programID": 1, - "type": "static" - }, - "center1": { - "id": "center1", - "phases": [ - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "GGGrrrGGGrrr", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "yyyrrryyyrrr", - "yellow": "3" - }, - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "rrrGGGrrrGGG", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "rrryyyrrryyy", - "yellow": "3" - } - ], - "programID": 1, - "type": "static" - }, - "center2": { - "detector-gap": 0.6, - "id": "center2", - "max-gap": 3.0, - "phases": [ - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "GGGrrrGGGrrr", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "yyyrrryyyrrr", - "yellow": "3" - }, - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "rrrGGGrrrGGG", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "rrryyyrrryyy", - "yellow": "3" - } - ], - "programID": 1, - "show-detectors": true, - "type": "actuated" - }, - "center3": { - "id": "center3", - "phases": [ - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "GGGrrrGGGrrr", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "yyyrrryyyrrr", - "yellow": "3" - }, - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "rrrGGGrrrGGG", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "rrryyyrrryyy", - "yellow": "3" - } - ], - "programID": 1, - "type": "static" - }, - "center4": { - "id": "center4", - "phases": [ - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "GGGrrrGGGrrr", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "yyyrrryyyrrr", - "yellow": "3" - }, - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "rrrGGGrrrGGG", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "rrryyyrrryyy", - "yellow": "3" - } - ], - "programID": 1, - "type": "static" - }, - "center5": { - "detector-gap": 0.6, - "id": "center5", - "max-gap": 3.0, - "phases": [ - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "GGGrrrGGGrrr", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "yyyrrryyyrrr", - "yellow": "3" - }, - { - "duration": "31", - "maxDur": "45", - "minDur": "8", - "state": "rrrGGGrrrGGG", - "yellow": "3" - }, - { - "duration": "6", - "maxDur": "6", - "minDur": "3", - "state": "rrryyyrrryyy", - "yellow": "3" - } - ], - "programID": 1, - "show-detectors": true, - "type": "actuated" - } - }, - "baseline": false - }, - "types": [ - { - "id": "horizontal", - "numLanes": 1, - "speed": 35 - }, - { - "id": "vertical", - "numLanes": 1, - "speed": 35 - } - ], - "vehicle_types": [ - { - "type_params": { - "accel": 2.6, - "carFollowModel": "IDM", - "decel": 4.5, - "impatience": 0.5, - "laneChangeModel": "LC2013", - "lcCooperative": "1.0", - "lcKeepRight": "1.0", - "lcSpeedGain": "1.0", - "lcStrategic": "1.0", - "maxSpeed": 30, - "minGap": 2.5, - "sigma": 0.5, - "speedDev": 0.1, - "speedFactor": 1.0, - "tau": 1.0 - }, - "veh_id": "human" - } - ] -} \ No newline at end of file From beb2d93c7eb639037542954d137c7e64fbe77a53 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 9 Sep 2019 12:43:47 -0700 Subject: [PATCH 17/23] added deprecation support - added a deprecation function for classes and functions - renames deprecation_warning ->deprecated_attribute - added deprecation warnings for all old names of environments - updated version to 0.5.0.dev --- flow/core/params.py | 40 +++++++------- flow/envs/__init__.py | 33 +++++++++--- flow/envs/base_env.py | 11 ++++ flow/envs/bottleneck_env.py | 26 +++++++++ flow/envs/green_wave_env.py | 26 +++++++++ flow/envs/loop/lane_changing.py | 19 +++++++ flow/envs/loop/loop_accel.py | 12 +++++ flow/envs/loop/wave_attenuation.py | 19 +++++++ flow/utils/flow_warnings.py | 84 +++++++++++++++++++++++++++++- flow/version.py | 2 +- tests/fast_tests/test_util.py | 6 +-- 11 files changed, 247 insertions(+), 31 deletions(-) create mode 100644 flow/envs/base_env.py create mode 100644 flow/envs/bottleneck_env.py create mode 100644 flow/envs/green_wave_env.py create mode 100644 flow/envs/loop/lane_changing.py create mode 100644 flow/envs/loop/loop_accel.py create mode 100644 flow/envs/loop/wave_attenuation.py diff --git a/flow/core/params.py b/flow/core/params.py index 021f0340cf..e0d331f5a4 100755 --- a/flow/core/params.py +++ b/flow/core/params.py @@ -3,7 +3,7 @@ import logging import collections -from flow.utils.flow_warnings import deprecation_warning +from flow.utils.flow_warnings import deprecated_attribute from flow.controllers.car_following_models import SimCarFollowingController from flow.controllers.rlcontroller import RLController from flow.controllers.lane_change_controllers import SimLaneChangeController @@ -828,27 +828,27 @@ def __init__( """Instantiate SumoCarFollowingParams.""" # check for deprecations (minGap) if "minGap" in kwargs: - deprecation_warning(self, "minGap", "min_gap") + deprecated_attribute(self, "minGap", "min_gap") min_gap = kwargs["minGap"] # check for deprecations (maxSpeed) if "maxSpeed" in kwargs: - deprecation_warning(self, "maxSpeed", "max_speed") + deprecated_attribute(self, "maxSpeed", "max_speed") max_speed = kwargs["maxSpeed"] # check for deprecations (speedFactor) if "speedFactor" in kwargs: - deprecation_warning(self, "speedFactor", "speed_factor") + deprecated_attribute(self, "speedFactor", "speed_factor") speed_factor = kwargs["speedFactor"] # check for deprecations (speedDev) if "speedDev" in kwargs: - deprecation_warning(self, "speedDev", "speed_dev") + deprecated_attribute(self, "speedDev", "speed_dev") speed_dev = kwargs["speedDev"] # check for deprecations (carFollowModel) if "carFollowModel" in kwargs: - deprecation_warning(self, "carFollowModel", "car_follow_model") + deprecated_attribute(self, "carFollowModel", "car_follow_model") car_follow_model = kwargs["carFollowModel"] # create a controller_params dict with all the specified parameters @@ -952,69 +952,69 @@ def __init__(self, """Instantiate SumoLaneChangeParams.""" # check for deprecations (lcStrategic) if "lcStrategic" in kwargs: - deprecation_warning(self, "lcStrategic", "lc_strategic") + deprecated_attribute(self, "lcStrategic", "lc_strategic") lc_strategic = kwargs["lcStrategic"] # check for deprecations (lcCooperative) if "lcCooperative" in kwargs: - deprecation_warning(self, "lcCooperative", "lc_cooperative") + deprecated_attribute(self, "lcCooperative", "lc_cooperative") lc_cooperative = kwargs["lcCooperative"] # check for deprecations (lcSpeedGain) if "lcSpeedGain" in kwargs: - deprecation_warning(self, "lcSpeedGain", "lc_speed_gain") + deprecated_attribute(self, "lcSpeedGain", "lc_speed_gain") lc_speed_gain = kwargs["lcSpeedGain"] # check for deprecations (lcKeepRight) if "lcKeepRight" in kwargs: - deprecation_warning(self, "lcKeepRight", "lc_keep_right") + deprecated_attribute(self, "lcKeepRight", "lc_keep_right") lc_keep_right = kwargs["lcKeepRight"] # check for deprecations (lcLookaheadLeft) if "lcLookaheadLeft" in kwargs: - deprecation_warning(self, "lcLookaheadLeft", "lc_look_ahead_left") + deprecated_attribute(self, "lcLookaheadLeft", "lc_look_ahead_left") lc_look_ahead_left = kwargs["lcLookaheadLeft"] # check for deprecations (lcSpeedGainRight) if "lcSpeedGainRight" in kwargs: - deprecation_warning(self, "lcSpeedGainRight", + deprecated_attribute(self, "lcSpeedGainRight", "lc_speed_gain_right") lc_speed_gain_right = kwargs["lcSpeedGainRight"] # check for deprecations (lcSublane) if "lcSublane" in kwargs: - deprecation_warning(self, "lcSublane", "lc_sublane") + deprecated_attribute(self, "lcSublane", "lc_sublane") lc_sublane = kwargs["lcSublane"] # check for deprecations (lcPushy) if "lcPushy" in kwargs: - deprecation_warning(self, "lcPushy", "lc_pushy") + deprecated_attribute(self, "lcPushy", "lc_pushy") lc_pushy = kwargs["lcPushy"] # check for deprecations (lcPushyGap) if "lcPushyGap" in kwargs: - deprecation_warning(self, "lcPushyGap", "lc_pushy_gap") + deprecated_attribute(self, "lcPushyGap", "lc_pushy_gap") lc_pushy_gap = kwargs["lcPushyGap"] # check for deprecations (lcAssertive) if "lcAssertive" in kwargs: - deprecation_warning(self, "lcAssertive", "lc_assertive") + deprecated_attribute(self, "lcAssertive", "lc_assertive") lc_assertive = kwargs["lcAssertive"] # check for deprecations (lcImpatience) if "lcImpatience" in kwargs: - deprecation_warning(self, "lcImpatience", "lc_impatience") + deprecated_attribute(self, "lcImpatience", "lc_impatience") lc_impatience = kwargs["lcImpatience"] # check for deprecations (lcTimeToImpatience) if "lcTimeToImpatience" in kwargs: - deprecation_warning(self, "lcTimeToImpatience", + deprecated_attribute(self, "lcTimeToImpatience", "lc_time_to_impatience") lc_time_to_impatience = kwargs["lcTimeToImpatience"] # check for deprecations (lcAccelLat) if "lcAccelLat" in kwargs: - deprecation_warning(self, "lcAccelLat", "lc_accel_lat") + deprecated_attribute(self, "lcAccelLat", "lc_accel_lat") lc_accel_lat = kwargs["lcAccelLat"] # check for valid model @@ -1154,7 +1154,7 @@ def add(self, """ # check for deprecations def deprecate(old, new): - deprecation_warning(self, old, new) + deprecated_attribute(self, old, new) new_val = kwargs[old] del kwargs[old] return new_val diff --git a/flow/envs/__init__.py b/flow/envs/__init__.py index 0c002016cd..5befe6a33b 100755 --- a/flow/envs/__init__.py +++ b/flow/envs/__init__.py @@ -13,11 +13,32 @@ from flow.envs.merge import MergePOEnv from flow.envs.test import TestEnv +# deprecated classes whose names have changed +from flow.envs.bottleneck_env import BottleNeckAccelEnv +from flow.envs.bottleneck_env import DesiredVelocityEnv +from flow.envs.green_wave_env import PO_TrafficLightGridEnv +from flow.envs.green_wave_env import GreenWaveTestEnv + + __all__ = [ - 'Env', 'AccelEnv', 'LaneChangeAccelEnv', - 'LaneChangeAccelPOEnv', 'TrafficLightGridTestEnv', - 'MergePOEnv', 'BottleneckEnv', - 'BottleneckAccelEnv', 'WaveAttenuationEnv', 'WaveAttenuationPOEnv', - 'TrafficLightGridEnv', 'TrafficLightGridPOEnv', - 'BottleneckDesiredVelocityEnv', 'TestEnv', 'BayBridgeEnv', + 'Env', + 'AccelEnv', + 'LaneChangeAccelEnv', + 'LaneChangeAccelPOEnv', + 'TrafficLightGridTestEnv', + 'MergePOEnv', + 'BottleneckEnv', + 'BottleneckAccelEnv', + 'WaveAttenuationEnv', + 'WaveAttenuationPOEnv', + 'TrafficLightGridEnv', + 'TrafficLightGridPOEnv', + 'BottleneckDesiredVelocityEnv', + 'TestEnv', + 'BayBridgeEnv', + # deprecated classes + 'BottleNeckAccelEnv', + 'DesiredVelocityEnv', + 'PO_TrafficLightGridEnv', + 'GreenWaveTestEnv', ] diff --git a/flow/envs/base_env.py b/flow/envs/base_env.py new file mode 100644 index 0000000000..1de94994a5 --- /dev/null +++ b/flow/envs/base_env.py @@ -0,0 +1,11 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/base.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.base import Env as BaseEnv + + +@deprecated('flow.envs.base_env', 'flow.envs.base.Env') +class Env(BaseEnv): + pass diff --git a/flow/envs/bottleneck_env.py b/flow/envs/bottleneck_env.py new file mode 100644 index 0000000000..8bc5863678 --- /dev/null +++ b/flow/envs/bottleneck_env.py @@ -0,0 +1,26 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/bottleneck.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.bottleneck import BottleneckEnv as BEnv +from flow.envs.bottleneck import BottleneckAccelEnv as BAEnv +from flow.envs.bottleneck import BottleneckDesiredVelocityEnv as BDVEnv + + +@deprecated('flow.envs.bottleneck_env', + 'flow.envs.bottleneck.BottleneckEnv') +class BottleneckEnv(BEnv): + pass + + +@deprecated('flow.envs.bottleneck_env', + 'flow.envs.bottleneck.BottleneckAccelEnv') +class BottleNeckAccelEnv(BAEnv): + pass + + +@deprecated('flow.envs.bottleneck_env', + 'flow.envs.bottleneck.BottleneckDesiredVelocityEnv') +class DesiredVelocityEnv(BDVEnv): + pass diff --git a/flow/envs/green_wave_env.py b/flow/envs/green_wave_env.py new file mode 100644 index 0000000000..91297ad7d6 --- /dev/null +++ b/flow/envs/green_wave_env.py @@ -0,0 +1,26 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/traffic_light_grid.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.traffic_light_grid import TrafficLightGridEnv as TLGEnv +from flow.envs.traffic_light_grid import TrafficLightGridPOEnv as TLGPOEnv +from flow.envs.traffic_light_grid import TrafficLightGridTestEnv as TLGTEnv + + +@deprecated('flow.envs.green_wave_env', + 'flow.envs.traffic_light_grid.TrafficLightGridEnv') +class TrafficLightGridEnv(TLGEnv): + pass + + +@deprecated('flow.envs.green_wave_env', + 'flow.envs.traffic_light_grid.TrafficLightGridPOEnv') +class PO_TrafficLightGridEnv(TLGPOEnv): + pass + + +@deprecated('flow.envs.green_wave_env', + 'flow.envs.traffic_light_grid.TrafficLightGridTestEnv') +class GreenWaveTestEnv(TLGTEnv): + pass diff --git a/flow/envs/loop/lane_changing.py b/flow/envs/loop/lane_changing.py new file mode 100644 index 0000000000..7aba482e8d --- /dev/null +++ b/flow/envs/loop/lane_changing.py @@ -0,0 +1,19 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/ring/lane_change_accel.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.ring.lane_change_accel import LaneChangeAccelEnv as LCEnv +from flow.envs.ring.lane_change_accel import LaneChangeAccelPOEnv as LCPOEnv + + +@deprecated('flow.envs.loop.lane_changing', + 'flow.envs.ring.lane_change_accel.LaneChangeAccelEnv') +class LaneChangeAccelEnv(LCEnv): + pass + + +@deprecated('flow.envs.loop.lane_changing', + 'flow.envs.ring.lane_change_accel.LaneChangeAccelPOEnv') +class LaneChangeAccelPOEnv(LCPOEnv): + pass diff --git a/flow/envs/loop/loop_accel.py b/flow/envs/loop/loop_accel.py new file mode 100644 index 0000000000..92c586f8e3 --- /dev/null +++ b/flow/envs/loop/loop_accel.py @@ -0,0 +1,12 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/ring/accel.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.ring.accel import AccelEnv as AEnv + + +@deprecated('flow.envs.loop.accel', + 'flow.envs.ring.accel.AccelEnv') +class AccelEnv(AEnv): + pass diff --git a/flow/envs/loop/wave_attenuation.py b/flow/envs/loop/wave_attenuation.py new file mode 100644 index 0000000000..41cda18c73 --- /dev/null +++ b/flow/envs/loop/wave_attenuation.py @@ -0,0 +1,19 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/ring/wave_attenuation.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.ring.wave_attenuation import WaveAttenuationEnv as WAEnv +from flow.envs.ring.wave_attenuation import WaveAttenuationPOEnv as WAPOEnv + + +@deprecated('flow.envs.loop.wave_attenuation', + 'flow.envs.ring.wave_attenuation.WaveAttenuationEnv') +class WaveAttenuationEnv(WAEnv): + pass + + +@deprecated('flow.envs.loop.wave_attenuation', + 'flow.envs.ring.wave_attenuation.WaveAttenuationPOEnv') +class WaveAttenuationPOEnv(WAPOEnv): + pass diff --git a/flow/utils/flow_warnings.py b/flow/utils/flow_warnings.py index 066f61ffeb..efeae5217b 100644 --- a/flow/utils/flow_warnings.py +++ b/flow/utils/flow_warnings.py @@ -1,9 +1,13 @@ """Warnings that may be printed by Flow (e.g. deprecation warnings).""" +import functools +import inspect import warnings +string_types = (type(b''), type(u'')) -def deprecation_warning(obj, dep_from, dep_to): + +def deprecated_attribute(obj, dep_from, dep_to): """Print a deprecation warning. Parameters @@ -18,3 +22,81 @@ def deprecation_warning(obj, dep_from, dep_to): warnings.warn( "The attribute {} in {} is deprecated, use {} instead.".format( dep_from, obj.__class__.__name__, dep_to)) + + +def deprecated(base, new_path): + """Print a deprecation warning. + + This is a decorator which can be used to mark functions as deprecated. It + will result in a warning being emitted when the function is used. + """ + # if isinstance(base, string_types): + + # The @deprecated is used with a 'reason'. + # + # .. code-block:: python + # + # @deprecated("please, use another function") + # def old_function(x, y): + # pass + + def decorator(func1): + + if inspect.isclass(func1): + fmt1 = "The class {base}.{name} is deprecated, use " \ + "{new_path} instead." + else: + fmt1 = "The function {base}.{name} is deprecated, use " \ + "{new_path} instead." + + @functools.wraps(func1) + def new_func1(*args, **kwargs): + warnings.simplefilter('always', PendingDeprecationWarning) + warnings.warn( + fmt1.format( + base=base, + name=func1.__name__, + new_path=new_path + ), + category=PendingDeprecationWarning, + stacklevel=2 + ) + warnings.simplefilter('default', PendingDeprecationWarning) + return func1(*args, **kwargs) + + return new_func1 + + return decorator + # + # elif inspect.isclass(reason) or inspect.isfunction(reason): + # + # # The @deprecated is used without any 'reason'. + # # + # # .. code-block:: python + # # + # # @deprecated + # # def old_function(x, y): + # # pass + # + # func2 = reason + # + # if inspect.isclass(func2): + # fmt2 = "Call to deprecated class {name}." + # else: + # fmt2 = "Call to deprecated function {name}." + # + # @functools.wraps(func2) + # def new_func2(*args, **kwargs): + # warnings.simplefilter('always', DeprecationWarning) + # warnings.warn( + # fmt2.format(name=func2.__name__), + # category=DeprecationWarning, + # stacklevel=2 + # ) + # warnings.simplefilter('default', DeprecationWarning) + # return func2(*args, **kwargs) + # + # return new_func2 + # + # else: + # raise TypeError(repr(type(reason))) diff --git a/flow/version.py b/flow/version.py index 487c623aa3..7c9845e29b 100644 --- a/flow/version.py +++ b/flow/version.py @@ -1,3 +1,3 @@ """Specifies the current version number of Flow.""" -__version__ = "0.4.1" +__version__ = "0.5.0.dev" diff --git a/tests/fast_tests/test_util.py b/tests/fast_tests/test_util.py index 477692d953..3caf8d4e31 100644 --- a/tests/fast_tests/test_util.py +++ b/tests/fast_tests/test_util.py @@ -10,7 +10,7 @@ from flow.core.params import SumoParams, EnvParams, NetParams, InitialConfig, \ InFlows, SumoCarFollowingParams from flow.core.util import emission_to_csv -from flow.utils.flow_warnings import deprecation_warning +from flow.utils.flow_warnings import deprecated_attribute from flow.utils.registry import make_create_env from flow.utils.rllib import FlowParamsEncoder, get_flow_params @@ -59,7 +59,7 @@ def test_emission_to_csv(self): class TestWarnings(unittest.TestCase): """Tests warning functions located in flow.utils.warnings""" - def test_deprecation_warning(self): + def test_deprecated_attribute(self): # dummy class class Foo(object): pass @@ -71,7 +71,7 @@ class Foo(object): # check the deprecation warning is printing what is expected self.assertWarnsRegex( UserWarning, "The attribute bar_deprecated in Foo is deprecated, " - "use bar_new instead.", deprecation_warning, Foo(), dep_from, + "use bar_new instead.", deprecated_attribute, Foo(), dep_from, dep_to) From 3ddb3600d6ddaf8c691af8cb027a6146050a8689 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 9 Sep 2019 12:48:25 -0700 Subject: [PATCH 18/23] pep8 --- flow/core/params.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flow/core/params.py b/flow/core/params.py index e0d331f5a4..cc1181de26 100755 --- a/flow/core/params.py +++ b/flow/core/params.py @@ -978,7 +978,7 @@ def __init__(self, # check for deprecations (lcSpeedGainRight) if "lcSpeedGainRight" in kwargs: deprecated_attribute(self, "lcSpeedGainRight", - "lc_speed_gain_right") + "lc_speed_gain_right") lc_speed_gain_right = kwargs["lcSpeedGainRight"] # check for deprecations (lcSublane) @@ -1009,7 +1009,7 @@ def __init__(self, # check for deprecations (lcTimeToImpatience) if "lcTimeToImpatience" in kwargs: deprecated_attribute(self, "lcTimeToImpatience", - "lc_time_to_impatience") + "lc_time_to_impatience") lc_time_to_impatience = kwargs["lcTimeToImpatience"] # check for deprecations (lcAccelLat) From 7c96c41122640fb85df7cade3673b433ac4b43fc Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 9 Sep 2019 13:12:46 -0700 Subject: [PATCH 19/23] pydocstyle --- flow/envs/base_env.py | 2 ++ flow/envs/bottleneck_env.py | 6 ++++++ flow/envs/green_wave_env.py | 6 ++++++ flow/envs/loop/lane_changing.py | 4 ++++ flow/envs/loop/loop_accel.py | 2 ++ flow/envs/loop/wave_attenuation.py | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/flow/envs/base_env.py b/flow/envs/base_env.py index 1de94994a5..e92093b96c 100644 --- a/flow/envs/base_env.py +++ b/flow/envs/base_env.py @@ -8,4 +8,6 @@ @deprecated('flow.envs.base_env', 'flow.envs.base.Env') class Env(BaseEnv): + """See parent class.""" + pass diff --git a/flow/envs/bottleneck_env.py b/flow/envs/bottleneck_env.py index 8bc5863678..4106fd9ec0 100644 --- a/flow/envs/bottleneck_env.py +++ b/flow/envs/bottleneck_env.py @@ -11,16 +11,22 @@ @deprecated('flow.envs.bottleneck_env', 'flow.envs.bottleneck.BottleneckEnv') class BottleneckEnv(BEnv): + """See parent class.""" + pass @deprecated('flow.envs.bottleneck_env', 'flow.envs.bottleneck.BottleneckAccelEnv') class BottleNeckAccelEnv(BAEnv): + """See parent class.""" + pass @deprecated('flow.envs.bottleneck_env', 'flow.envs.bottleneck.BottleneckDesiredVelocityEnv') class DesiredVelocityEnv(BDVEnv): + """See parent class.""" + pass diff --git a/flow/envs/green_wave_env.py b/flow/envs/green_wave_env.py index 91297ad7d6..6b34e562e6 100644 --- a/flow/envs/green_wave_env.py +++ b/flow/envs/green_wave_env.py @@ -11,16 +11,22 @@ @deprecated('flow.envs.green_wave_env', 'flow.envs.traffic_light_grid.TrafficLightGridEnv') class TrafficLightGridEnv(TLGEnv): + """See parent class.""" + pass @deprecated('flow.envs.green_wave_env', 'flow.envs.traffic_light_grid.TrafficLightGridPOEnv') class PO_TrafficLightGridEnv(TLGPOEnv): + """See parent class.""" + pass @deprecated('flow.envs.green_wave_env', 'flow.envs.traffic_light_grid.TrafficLightGridTestEnv') class GreenWaveTestEnv(TLGTEnv): + """See parent class.""" + pass diff --git a/flow/envs/loop/lane_changing.py b/flow/envs/loop/lane_changing.py index 7aba482e8d..76f05e7bce 100644 --- a/flow/envs/loop/lane_changing.py +++ b/flow/envs/loop/lane_changing.py @@ -10,10 +10,14 @@ @deprecated('flow.envs.loop.lane_changing', 'flow.envs.ring.lane_change_accel.LaneChangeAccelEnv') class LaneChangeAccelEnv(LCEnv): + """See parent class.""" + pass @deprecated('flow.envs.loop.lane_changing', 'flow.envs.ring.lane_change_accel.LaneChangeAccelPOEnv') class LaneChangeAccelPOEnv(LCPOEnv): + """See parent class.""" + pass diff --git a/flow/envs/loop/loop_accel.py b/flow/envs/loop/loop_accel.py index 92c586f8e3..a8378a6ac4 100644 --- a/flow/envs/loop/loop_accel.py +++ b/flow/envs/loop/loop_accel.py @@ -9,4 +9,6 @@ @deprecated('flow.envs.loop.accel', 'flow.envs.ring.accel.AccelEnv') class AccelEnv(AEnv): + """See parent class.""" + pass diff --git a/flow/envs/loop/wave_attenuation.py b/flow/envs/loop/wave_attenuation.py index 41cda18c73..1be0bfa45e 100644 --- a/flow/envs/loop/wave_attenuation.py +++ b/flow/envs/loop/wave_attenuation.py @@ -10,10 +10,14 @@ @deprecated('flow.envs.loop.wave_attenuation', 'flow.envs.ring.wave_attenuation.WaveAttenuationEnv') class WaveAttenuationEnv(WAEnv): + """See parent class.""" + pass @deprecated('flow.envs.loop.wave_attenuation', 'flow.envs.ring.wave_attenuation.WaveAttenuationPOEnv') class WaveAttenuationPOEnv(WAPOEnv): + """See parent class.""" + pass From e85dff7a1db6c789007e77b517a928c63f25a04e Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 9 Sep 2019 15:27:04 -0700 Subject: [PATCH 20/23] added deprecation warnings to changed scenarios --- flow/scenarios/__init__.py | 25 +++++++++++++++++++++---- flow/scenarios/figure_eight.py | 7 +++++++ flow/scenarios/grid.py | 15 +++++++++++++++ flow/scenarios/loop.py | 15 +++++++++++++++ 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 flow/scenarios/grid.py create mode 100644 flow/scenarios/loop.py diff --git a/flow/scenarios/__init__.py b/flow/scenarios/__init__.py index 852d9c1f2a..b7e759c0c1 100644 --- a/flow/scenarios/__init__.py +++ b/flow/scenarios/__init__.py @@ -16,9 +16,26 @@ from flow.scenarios.minicity import MiniCityScenario from flow.scenarios.highway_ramps import HighwayRampsScenario +# deprecated classes whose names have changed +from flow.scenarios.figure_eight import Figure8Scenario +from flow.scenarios.loop import LoopScenario +from flow.scenarios.grid import SimpleGridScenario + __all__ = [ - "Scenario", "BayBridgeScenario", "BayBridgeTollScenario", - "BottleneckScenario", "FigureEightScenario", "TrafficLightGridScenario", - "HighwayScenario", "RingScenario", "MergeScenario", - "MultiRingScenario", "MiniCityScenario", "HighwayRampsScenario" + "Scenario", + "BayBridgeScenario", + "BayBridgeTollScenario", + "BottleneckScenario", + "FigureEightScenario", + "TrafficLightGridScenario", + "HighwayScenario", + "RingScenario", + "MergeScenario", + "MultiRingScenario", + "MiniCityScenario", + "HighwayRampsScenario", + # deprecated classes + "Figure8Scenario", + "LoopScenario", + "SimpleGridScenario", ] diff --git a/flow/scenarios/figure_eight.py b/flow/scenarios/figure_eight.py index 465f5456b3..b4e4b4cfcd 100755 --- a/flow/scenarios/figure_eight.py +++ b/flow/scenarios/figure_eight.py @@ -3,6 +3,7 @@ import numpy as np from numpy import pi, sin, cos, linspace +from flow.utils.flow_warnings import deprecated from flow.core.params import InitialConfig from flow.core.params import TrafficLightParams from flow.scenarios.base import Scenario @@ -261,3 +262,9 @@ def specify_internal_edge_starts(self): ] return internal_edgestarts + + +@deprecated('flow.scenarios.figure_eight', + 'flow.scenarios.figure_eight.FigureEightScenario') +class Figure8Scenario(FigureEightScenario): + pass diff --git a/flow/scenarios/grid.py b/flow/scenarios/grid.py new file mode 100644 index 0000000000..c0b7c28ba9 --- /dev/null +++ b/flow/scenarios/grid.py @@ -0,0 +1,15 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/scenarios/traffic_light_grid.py +""" +from flow.utils.flow_warnings import deprecated +from flow.scenarios.traffic_light_grid import TrafficLightGridScenario +from flow.scenarios.traffic_light_grid import ADDITIONAL_NET_PARAMS # noqa: F401 + + +@deprecated('flow.scenarios.grid', + 'flow.scenarios.traffic_light_grid.TrafficLightGridScenario') +class SimpleGridScenario(TrafficLightGridScenario): + """See parent class.""" + + pass diff --git a/flow/scenarios/loop.py b/flow/scenarios/loop.py new file mode 100644 index 0000000000..96839218ee --- /dev/null +++ b/flow/scenarios/loop.py @@ -0,0 +1,15 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/scenarios/ring.py +""" +from flow.utils.flow_warnings import deprecated +from flow.scenarios.ring import RingScenario +from flow.scenarios.ring import ADDITIONAL_NET_PARAMS # noqa: F401 + + +@deprecated('flow.scenarios.loop', + 'flow.scenarios.ring.RingScenario') +class LoopScenario(RingScenario): + """See parent class.""" + + pass From d334876b6be050a028c9ea7fa3168647f2ea1861 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 9 Sep 2019 15:35:31 -0700 Subject: [PATCH 21/23] added deprecation warning for the multiagnet environments --- flow/multiagent_envs/__iniy__.py | 16 ++++++++++++++++ flow/multiagent_envs/highway.py | 15 +++++++++++++++ flow/multiagent_envs/loop/loop_accel.py | 14 ++++++++++++++ flow/multiagent_envs/loop/wave_attenuation.py | 15 +++++++++++++++ flow/multiagent_envs/multiagent_env.py | 14 ++++++++++++++ flow/multiagent_envs/traffic_light_grid.py | 15 +++++++++++++++ 6 files changed, 89 insertions(+) create mode 100644 flow/multiagent_envs/__iniy__.py create mode 100644 flow/multiagent_envs/highway.py create mode 100644 flow/multiagent_envs/loop/loop_accel.py create mode 100644 flow/multiagent_envs/loop/wave_attenuation.py create mode 100644 flow/multiagent_envs/multiagent_env.py create mode 100644 flow/multiagent_envs/traffic_light_grid.py diff --git a/flow/multiagent_envs/__iniy__.py b/flow/multiagent_envs/__iniy__.py new file mode 100644 index 0000000000..e270fa3970 --- /dev/null +++ b/flow/multiagent_envs/__iniy__.py @@ -0,0 +1,16 @@ +"""Empty init file to ensure documentation for multi-agent envs is created.""" + +from flow.multiagent_envs.multiagent_env import MultiEnv +from flow.multiagent_envs.loop.wave_attenuation import \ + MultiWaveAttenuationPOEnv +from flow.multiagent_envs.loop.loop_accel import MultiAgentAccelEnv +from flow.multiagent_envs.traffic_light_grid import MultiTrafficLightGridPOEnv +from flow.multiagent_envs.highway import MultiAgentHighwayPOEnv + +__all__ = [ + 'MultiEnv', + 'MultiAgentAccelEnv', + 'MultiWaveAttenuationPOEnv', + 'MultiTrafficLightGridPOEnv', + 'MultiAgentHighwayPOEnv' +] diff --git a/flow/multiagent_envs/highway.py b/flow/multiagent_envs/highway.py new file mode 100644 index 0000000000..c95f8ad76c --- /dev/null +++ b/flow/multiagent_envs/highway.py @@ -0,0 +1,15 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/multiagent/highway.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.multiagent.highway import MultiAgentHighwayPOEnv as MAHPOEnv +from flow.envs.multiagent.highway import ADDITIONAL_ENV_PARAMS # noqa: F401 + + +@deprecated('flow.multiagent_envs.highway', + 'flow.envs.multiagent.highway.MultiAgentHighwayPOEnv') +class MultiAgentHighwayPOEnv(MAHPOEnv): + """See parent class.""" + + pass diff --git a/flow/multiagent_envs/loop/loop_accel.py b/flow/multiagent_envs/loop/loop_accel.py new file mode 100644 index 0000000000..f46e3e38dc --- /dev/null +++ b/flow/multiagent_envs/loop/loop_accel.py @@ -0,0 +1,14 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/multiagent/traffic_light_grid.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.multiagent.ring.accel import MultiAgentAccelEnv as MAAEnv + + +@deprecated('flow.multiagent_envs.loop.loop_accel', + 'flow.envs.multiagent.ring.accel.MultiAgentAccelEnv') +class MultiAgentAccelEnv(MAAEnv): + """See parent class.""" + + pass diff --git a/flow/multiagent_envs/loop/wave_attenuation.py b/flow/multiagent_envs/loop/wave_attenuation.py new file mode 100644 index 0000000000..98f36e2a70 --- /dev/null +++ b/flow/multiagent_envs/loop/wave_attenuation.py @@ -0,0 +1,15 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/multiagent/traffic_light_grid.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.multiagent.ring.wave_attenuation import MultiWaveAttenuationPOEnv as MWAPOEnv +from flow.envs.multiagent.ring.wave_attenuation import ADDITIONAL_ENV_PARAMS # noqa: F401 + + +@deprecated('flow.multiagent_envs.loop.wave_attenuation', + 'flow.envs.multiagent.ring.wave_attenuation.MultiWaveAttenuationPOEnv') +class MultiWaveAttenuationPOEnv(MWAPOEnv): + """See parent class.""" + + pass diff --git a/flow/multiagent_envs/multiagent_env.py b/flow/multiagent_envs/multiagent_env.py new file mode 100644 index 0000000000..15ff442a79 --- /dev/null +++ b/flow/multiagent_envs/multiagent_env.py @@ -0,0 +1,14 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/multiagent/base.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.multiagent.base import MultiEnv as MAEnv + + +@deprecated('flow.multiagent_envs.multiagent_env', + 'flow.envs.multiagent.base.MultiEnv') +class MultiEnv(MAEnv): + """See parent class.""" + + pass diff --git a/flow/multiagent_envs/traffic_light_grid.py b/flow/multiagent_envs/traffic_light_grid.py new file mode 100644 index 0000000000..0469485e75 --- /dev/null +++ b/flow/multiagent_envs/traffic_light_grid.py @@ -0,0 +1,15 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/envs/multiagent/traffic_light_grid.py +""" +from flow.utils.flow_warnings import deprecated +from flow.envs.multiagent.traffic_light_grid import MultiTrafficLightGridPOEnv as MTLGPOEnv +from flow.envs.multiagent.traffic_light_grid import ADDITIONAL_ENV_PARAMS # noqa: F401 + + +@deprecated('flow.multiagent_envs.traffic_light_grid', + 'flow.envs.multiagent.traffic_light_grid.MultiEnv') +class MultiTrafficLightGridPOEnv(MTLGPOEnv): + """See parent class.""" + + pass From 2d49cb6db43fbfa25e8f0110ad88192ec26414be Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Mon, 9 Sep 2019 15:40:18 -0700 Subject: [PATCH 22/23] pydocstyle --- flow/scenarios/figure_eight.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flow/scenarios/figure_eight.py b/flow/scenarios/figure_eight.py index b4e4b4cfcd..87b807d964 100755 --- a/flow/scenarios/figure_eight.py +++ b/flow/scenarios/figure_eight.py @@ -267,4 +267,6 @@ def specify_internal_edge_starts(self): @deprecated('flow.scenarios.figure_eight', 'flow.scenarios.figure_eight.FigureEightScenario') class Figure8Scenario(FigureEightScenario): + """See parent class.""" + pass From b3d8d304f3a7177cf4a66f96ab1b37260702a735 Mon Sep 17 00:00:00 2001 From: AboudyKreidieh Date: Tue, 10 Sep 2019 13:15:05 -0700 Subject: [PATCH 23/23] added two missing deprecated files --- flow/scenarios/__init__.py | 3 +++ flow/scenarios/base_scenario.py | 14 ++++++++++++++ flow/scenarios/multi_loop.py | 15 +++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 flow/scenarios/base_scenario.py create mode 100644 flow/scenarios/multi_loop.py diff --git a/flow/scenarios/__init__.py b/flow/scenarios/__init__.py index b7e759c0c1..eb2d50e0a9 100644 --- a/flow/scenarios/__init__.py +++ b/flow/scenarios/__init__.py @@ -20,6 +20,8 @@ from flow.scenarios.figure_eight import Figure8Scenario from flow.scenarios.loop import LoopScenario from flow.scenarios.grid import SimpleGridScenario +from flow.scenarios.multi_loop import MultiLoopScenario + __all__ = [ "Scenario", @@ -38,4 +40,5 @@ "Figure8Scenario", "LoopScenario", "SimpleGridScenario", + "MultiLoopScenario", ] diff --git a/flow/scenarios/base_scenario.py b/flow/scenarios/base_scenario.py new file mode 100644 index 0000000000..f753862a58 --- /dev/null +++ b/flow/scenarios/base_scenario.py @@ -0,0 +1,14 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/scenarios/base.py +""" +from flow.utils.flow_warnings import deprecated +from flow.scenarios.base import Scenario as Scen + + +@deprecated('flow.scenarios.base_scenario', + 'flow.scenarios.base.Scenario') +class Scenario(Scen): + """See parent class.""" + + pass diff --git a/flow/scenarios/multi_loop.py b/flow/scenarios/multi_loop.py new file mode 100644 index 0000000000..2b7c6666d1 --- /dev/null +++ b/flow/scenarios/multi_loop.py @@ -0,0 +1,15 @@ +"""Pending deprecation file. + +To view the actual content, go to: flow/scenarios/multi_ring.py +""" +from flow.utils.flow_warnings import deprecated +from flow.scenarios.multi_ring import MultiRingScenario +from flow.scenarios.multi_ring import ADDITIONAL_NET_PARAMS # noqa: F401 + + +@deprecated('flow.scenarios.multi_loop', + 'flow.scenarios.multi_ring.MultiRingScenario') +class MultiLoopScenario(MultiRingScenario): + """See parent class.""" + + pass