def setUp(self): vehicles = VehicleParams() vehicles.add("test", num_vehicles=1) net_params = NetParams(additional_params=RING_PARAMS) env_params = EnvParams() sim_params = SumoParams() network = RingNetwork("test_ring", vehicles=vehicles, net_params=net_params) self.env = TestEnv(env_params, sim_params, network)
def setUp(self): vehicles = VehicleParams() vehicles.add("rl", acceleration_controller=(RLController, {}), num_vehicles=1) vehicles.add("human", acceleration_controller=(IDMController, {}), num_vehicles=1) self.sim_params = SumoParams(restart_instance=True) self.network = RingNetwork( name="test_merge", vehicles=vehicles, net_params=NetParams(additional_params=RING_PARAMS.copy()), ) params = {"max_accel": 1, "max_decel": 1, "ring_length": [220, 270]} self.env_params = EnvParams(additional_params=params)
def setUp(self): vehicles = VehicleParams() vehicles.add("rl", acceleration_controller=(RLController, {}), num_vehicles=1) vehicles.add("human", acceleration_controller=(IDMController, {}), num_vehicles=1) self.sim_params = SumoParams() self.network = RingNetwork( name="test_ring", vehicles=vehicles, net_params=NetParams(additional_params=RING_PARAMS.copy()), ) self.env_params = EnvParams(additional_params={ 'max_accel': 1, 'max_decel': 1, "target_velocity": 25 })
def setUp(self): vehicles = VehicleParams() vehicles.add("rl", acceleration_controller=(RLController, {}), num_vehicles=1) vehicles.add("human", acceleration_controller=(IDMController, {}), num_vehicles=1) self.sim_params = SumoParams() self.network = RingNetwork( name="test_merge", vehicles=vehicles, net_params=NetParams(additional_params=RING_PARAMS.copy()), ) self.env_params = EnvParams( additional_params={ "max_accel": 3, "max_decel": 3, "target_velocity": 10, "lane_change_duration": 5, "sort_vehicles": False } )
def test_clip_actions(self): """Test that the actions are clipped in the reward function.""" sim_params = SumoParams() vehicles = VehicleParams() additional_net_params = { "length": 230, "lanes": 1, "speed_limit": 30, "resolution": 40 } net_params = NetParams(additional_params=additional_net_params) network = RingNetwork(name="RingRoadTest", vehicles=vehicles, net_params=net_params) # when set to False env_params = EnvParams(clip_actions=False) env = RLActionsEnv(env_params=env_params, sim_params=sim_params, network=network) env.reset() _, ret, _, _ = env.step(rl_actions=[5]) self.assertEqual(np.mean(ret), 5) # when set to True env_params = EnvParams(clip_actions=True) env = RLActionsEnv(env_params=env_params, sim_params=sim_params, network=network) env.reset() _, ret, _, _ = env.step(rl_actions=[0.5]) self.assertEqual(ret, 0.5) _, ret, _, _ = env.step(rl_actions=[5]) self.assertEqual(ret, 1) _, ret, _, _ = env.step(rl_actions=[-5]) self.assertEqual(ret, -1)