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()
def test_reset_inflows(self): """Tests that the inflow change within the expected range when calling reset.""" # set a random seed for inflows to be the same every time np.random.seed(seed=123) sim_params = SumoParams(sim_step=0.5, restart_instance=True) vehicles = VehicleParams() vehicles.add(veh_id="human") vehicles.add(veh_id="followerstopper") # 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)] env_params = EnvParams( additional_params={ "target_velocity": 40, "disable_tb": True, "disable_ramp_metering": True, "controlled_segments": controlled_segments, "symmetric": False, "observed_segments": num_observed_segments, "reset_inflow": True, # this must be set to True for the test "lane_change_duration": 5, "max_accel": 3, "max_decel": 3, "inflow_range": [1000, 2000] # this is what we're testing }) inflow = InFlows() inflow.add( veh_type="human", edge="1", vehs_per_hour=1500, # the initial inflow we're checking for departLane="random", departSpeed=10) net_params = NetParams(inflows=inflow, no_internal_links=False, additional_params={ "scaling": 1, "speed_limit": 23 }) scenario = BottleneckScenario(name="bay_bridge_toll", vehicles=vehicles, net_params=net_params) env = DesiredVelocityEnv(env_params, sim_params, scenario) # reset the environment and get a new inflow rate env.reset() expected_inflow = 1343.178 # just from checking the new inflow # check that the first inflow rate is approximately 1500 for _ in range(500): env.step(rl_actions=None) self.assertAlmostEqual( env.k.vehicle.get_inflow_rate(250) / expected_inflow, 1, 1) # reset the environment and get a new inflow rate env.reset() expected_inflow = 1729.050 # just from checking the new inflow # check that the new inflow rate is approximately as expected for _ in range(500): env.step(rl_actions=None) self.assertAlmostEqual( env.k.vehicle.get_inflow_rate(250) / expected_inflow, 1, 1)