def setUp(self): self.sim_params = SumoParams(sim_step=0.5, restart_instance=True) vehicles = VehicleParams() vehicles.add(veh_id="human", num_vehicles=10) env_params = EnvParams( additional_params={ "max_accel": 3, "max_decel": 3, "lane_change_duration": 5, "disable_tb": True, "disable_ramp_metering": True, "target_velocity": 30, "add_rl_if_exit": True, } ) net_params = NetParams( no_internal_links=False, additional_params={"scaling": 1, "speed_limit": 23}) self.scenario = BottleneckScenario( name="bay_bridge_toll", vehicles=vehicles, net_params=net_params) self.env = BottleNeckAccelEnv( env_params, self.sim_params, self.scenario) self.env.reset()
class TestBottleneckAccelEnv(unittest.TestCase): """Tests BottleneckAccelEnv in flow/envs/bottleneck_env.py.""" def setUp(self): self.sim_params = SumoParams(sim_step=0.5, restart_instance=True) vehicles = VehicleParams() vehicles.add(veh_id="human", num_vehicles=10) env_params = EnvParams( additional_params={ "max_accel": 3, "max_decel": 3, "lane_change_duration": 5, "disable_tb": True, "disable_ramp_metering": True, "target_velocity": 30, "add_rl_if_exit": True, }) net_params = NetParams(additional_params={ "scaling": 1, "speed_limit": 23 }) self.scenario = BottleneckScenario(name="bay_bridge_toll", vehicles=vehicles, net_params=net_params) self.env = BottleNeckAccelEnv(env_params, self.sim_params, self.scenario) self.env.reset() def tearDown(self): self.env.terminate() del self.env 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, sim_params=self.sim_params, scenario=self.scenario, additional_params={ "max_accel": 3, "max_decel": 3, "lane_change_duration": 5, "disable_tb": True, "disable_ramp_metering": True, "target_velocity": 30, "add_rl_if_exit": True, })) def test_observation_action_space(self): """Tests the observation and action spaces upon initialization.""" # check the observation space self.assertTrue( test_space(self.env.observation_space, expected_size=12, expected_min=0, expected_max=1))