Пример #1
0
class TestInstantaneousFailsafe(unittest.TestCase):
    """
    Tests that the instantaneous failsafe of the base acceleration controller
    does not allow vehicles to crash under situations where they otherwise
    would. This is tested on two crash-prone controllers: OVM and LinearOVM
    """
    def setUp_failsafe(self, vehicles):
        additional_env_params = {
            "target_velocity": 8,
            "max_accel": 3,
            "max_decel": 3,
            "sort_vehicles": False
        }
        env_params = EnvParams(additional_params=additional_env_params)

        additional_net_params = {
            "length": 100,
            "lanes": 1,
            "speed_limit": 30,
            "resolution": 40
        }
        net_params = NetParams(additional_params=additional_net_params)

        initial_config = InitialConfig(bunching=10)

        # create the environment and network classes for a ring road
        _, _, flow_params = ring_road_exp_setup(vehicles=vehicles,
                                                env_params=env_params,
                                                net_params=net_params,
                                                initial_config=initial_config)

        flow_params['env'].horizon = 200
        # instantiate an experiment class
        self.exp = Experiment(flow_params)

    def tearDown_failsafe(self):
        # free data used by the class
        self.exp = None

    def test_no_crash_OVM(self):
        vehicles = VehicleParams()
        vehicles.add(
            veh_id="test",
            acceleration_controller=(OVMController, {
                "fail_safe": "instantaneous"
            }),
            routing_controller=(ContinuousRouter, {}),
            num_vehicles=10,
        )

        self.setUp_failsafe(vehicles=vehicles)

        # run the experiment, see if it fails
        self.exp.run(1)

        self.tearDown_failsafe()

    def test_no_crash_LinearOVM(self):
        vehicles = VehicleParams()
        vehicles.add(veh_id="test",
                     acceleration_controller=(LinearOVM, {
                         "fail_safe": "instantaneous"
                     }),
                     routing_controller=(ContinuousRouter, {}),
                     num_vehicles=10)

        self.setUp_failsafe(vehicles=vehicles)

        # run the experiment, see if it fails
        self.exp.run(1)

        self.tearDown_failsafe()
    },
)

net_params = NetParams(
    inflows=inflow,
    #no_internal_links=False,
    additional_params=additional_net_params,
    template={
        "net": scenario_road_data["net"],  # see above
        "rou": scenario_road_data["rou"],  # see above 
    })

initial_config = InitialConfig(
    #scenario_road_data["edges_distribution"]
    edges_distribution=scenario_road_data["edges_distribution"], )
if __name__ == "__main__":
    scenario = i696Scenario(
        name='i696',
        vehicles=vehicles,
        net_params=net_params,
        initial_config=initial_config,
    )
    #env = AccelEnv(env_params,sumo_params,scenario)
    env = TestEnv(env_params, sumo_params, scenario)
    exp = Experiment(env)
    _ = exp.run(1, 2000)  #,convert_to_csv=True)
    #from IPython import embed
    #embed()
    with open("info.pkl", "wb") as f:
        pickle.dump(_, f)