示例#1
0
 def setUp(self):
     env, scenario = ring_road_exp_setup()
     sim_params = SumoParams()  # FIXME: make ambiguous
     env_params = EnvParams()
     self.env = Env(sim_params=sim_params,
                    env_params=env_params,
                    scenario=scenario)
示例#2
0
class TestAbstractMethods(unittest.TestCase):
    """
    These series of tests are meant to ensure that the environment abstractions
    exist and are in fact abstract, i.e. they will raise errors if not
    implemented in a child class.
    """
    def setUp(self):
        env, scenario = ring_road_exp_setup()
        sim_params = SumoParams()  # FIXME: make ambiguous
        env_params = EnvParams()
        self.env = Env(sim_params=sim_params,
                       env_params=env_params,
                       scenario=scenario)

    def tearDown(self):
        self.env.terminate()
        self.env = None

    def test_get_state(self):
        """Checks that get_state raises an error."""
        self.assertRaises(NotImplementedError, self.env.get_state)

    def test_compute_reward(self):
        """Checks that compute_reward returns 0."""
        self.assertEqual(self.env.compute_reward([]), 0)

    def test__apply_rl_actions(self):
        self.assertRaises(NotImplementedError,
                          self.env._apply_rl_actions,
                          rl_actions=None)
示例#3
0
 def setUp(self):
     env, scenario = ring_road_exp_setup()
     sumo_params = SumoParams()
     env_params = EnvParams()
     self.env = Env(sumo_params=sumo_params,
                    env_params=env_params,
                    scenario=scenario)
示例#4
0
 def setUp(self):
     env, network = ring_road_exp_setup()
     sim_params = SumoParams()  # FIXME: make ambiguous
     env_params = EnvParams()
     self.env = Env(sim_params=sim_params,
                    env_params=env_params,
                    network=network)
class TestAbstractMethods(unittest.TestCase):
    """
    These series of tests are meant to ensure that the environment abstractions
    exist and are in fact abstract, i.e. they will raise errors if not
    implemented in a child class.
    """

    def setUp(self):
        env, scenario = ring_road_exp_setup()
        sumo_params = SumoParams()
        env_params = EnvParams()
        self.env = Env(sumo_params=sumo_params,
                       env_params=env_params,
                       scenario=scenario)

    def tearDown(self):
        self.env.terminate()
        self.env = None

    def test_get_state(self):
        """Checks that get_state raises an error."""
        try:
            self.env.get_state()
            raise AssertionError
        except NotImplementedError:
            return

    def test_action_space(self):
        try:
            self.env.action_space
            raise AssertionError
        except NotImplementedError:
            return

    def test_observation_space(self):
        try:
            self.env.observation_space
            raise AssertionError
        except NotImplementedError:
            return

    def test_compute_reward(self):
        """Checks that compute_reward returns 0."""
        self.assertEqual(self.env.compute_reward([]), 0)

    def test__apply_rl_actions(self):
        try:
            self.env._apply_rl_actions(None)
            raise AssertionError
        except NotImplementedError:
            return
示例#6
0
    def test_all(self):
        vehicles = Vehicles()
        vehicles.add("human", num_vehicles=10)
        # add an RL vehicle to ensure that its color will be distinct
        vehicles.add("rl", acceleration_controller=(RLController, {}),
                     num_vehicles=1)
        _, scenario = ring_road_exp_setup(vehicles=vehicles)

        # we will use the generic environment to ensure this applies to all
        # environments
        sumo_params = SumoParams()
        env_params = EnvParams()
        env = Env(sumo_params=sumo_params,
                  env_params=env_params,
                  scenario=scenario)

        # set one vehicle as observed
        env.vehicles.set_observed("human_0")

        # update the colors of all vehicles
        env.update_vehicle_colors()
        env.traci_connection.simulationStep()

        # check that, when rendering is off, the colors don't change (this
        # avoids unnecessary API calls)
        for veh_id in env.vehicles.get_ids():
            self.assertEqual(
                env.traci_connection.vehicle.getColor(veh_id), WHITE)

        # a little hack to ensure the colors change
        env.sumo_params.render = True

        # set one vehicle as observed
        env.vehicles.set_observed("human_0")

        # update the colors of all vehicles
        env.update_vehicle_colors()
        env.traci_connection.simulationStep()

        # check the colors of all vehicles
        for veh_id in env.vehicles.get_ids():
            if veh_id == "human_0":
                self.assertEqual(
                    env.traci_connection.vehicle.getColor(veh_id), CYAN)
            elif veh_id == "rl_0":
                self.assertEqual(
                    env.traci_connection.vehicle.getColor(veh_id), RED)
            else:
                self.assertEqual(
                    env.traci_connection.vehicle.getColor(veh_id), WHITE)
 def test_abstract_base_class(self):
     """Checks that instantiating abstract base class raises an error."""
     with self.assertRaises(TypeError):
         Env(sim_params=self.sim_params,
             env_params=self.env_params,
             network=self.network)