Example #1
0
    def test_add_vehicles_human(self):
        """
        Ensure that added human vehicles are placed in the current vehicle
        IDs, and that the number of vehicles is correct.
        """
        # generate a vehicles class
        vehicles = VehicleParams()

        # vehicles whose acceleration and LC are controlled by sumo
        vehicles.add("test_1", num_vehicles=1)

        # vehicles whose acceleration are controlled by sumo
        vehicles.add("test_2",
                     num_vehicles=2,
                     lane_change_controller=(StaticLaneChanger, {}))

        # vehicles whose LC are controlled by sumo
        vehicles.add("test_3",
                     num_vehicles=4,
                     acceleration_controller=(IDMController, {}))

        self.assertEqual(vehicles.num_vehicles, 7)
        self.assertEqual(len(vehicles.get_ids()), 7)
        self.assertEqual(len(vehicles.get_rl_ids()), 0)
        self.assertEqual(len(vehicles.get_human_ids()), 7)
        self.assertEqual(len(vehicles.get_controlled_ids()), 4)
        self.assertEqual(len(vehicles.get_controlled_lc_ids()), 2)
Example #2
0
    def test_add_vehicles_rl(self):
        """
        Ensure that added rl vehicles are placed in the current vehicle IDs,
        and that the number of vehicles is correct.
        """
        vehicles = VehicleParams()
        vehicles.add("test_rl",
                     num_vehicles=10,
                     acceleration_controller=(RLController, {}))

        self.assertEqual(vehicles.num_vehicles, 10)
        self.assertEqual(len(vehicles.get_ids()), 10)
        self.assertEqual(len(vehicles.get_rl_ids()), 10)
        self.assertEqual(len(vehicles.get_human_ids()), 0)
        self.assertEqual(len(vehicles.get_controlled_ids()), 0)
        self.assertEqual(len(vehicles.get_controlled_lc_ids()), 0)
Example #3
0
    def test_remove(self):
        """
        Check that there is no trace of the vehicle ID of the vehicle meant to
        be removed in the vehicles class.
        """
        # generate a vehicles class
        vehicles = VehicleParams()
        vehicles.add("test", num_vehicles=10)
        vehicles.add("test_rl",
                     num_vehicles=10,
                     acceleration_controller=(RLController, {}))

        # remove one human-driven vehicle and on rl vehicle
        vehicles.remove("test_0")
        vehicles.remove("test_rl_0")

        # ensure that the removed vehicle's ID is not in any lists of vehicles
        self.assertTrue("test_0" not in vehicles.get_ids(),
                        msg="vehicle still in get_ids()")
        self.assertTrue("test_0" not in vehicles.get_human_ids(),
                        msg="vehicle still in get_controlled_lc_ids()")
        self.assertTrue("test_0" not in vehicles.get_controlled_lc_ids(),
                        msg="vehicle still in get_controlled_lc_ids()")
        self.assertTrue("test_0" not in vehicles.get_controlled_ids(),
                        msg="vehicle still in get_controlled_ids()")
        self.assertTrue("test_rl_0" not in vehicles.get_ids(),
                        msg="RL vehicle still in get_ids()")
        self.assertTrue("test_rl_0" not in vehicles.get_rl_ids(),
                        msg="RL vehicle still in get_rl_ids()")

        # ensure that the vehicles are not storing extra information in the
        # vehicles.__vehicles dict
        error_state = vehicles.get_state('test_0', "type", error=None)
        self.assertIsNone(error_state)
        error_state_rl = vehicles.get_state('rl_test_0', "type", error=None)
        self.assertIsNone(error_state_rl)

        # ensure that the num_vehicles matches the actual number of vehicles
        self.assertEqual(vehicles.num_vehicles, len(vehicles.get_ids()))

        # ensures that then num_rl_vehicles matches the actual number of rl veh
        self.assertEqual(vehicles.num_rl_vehicles, len(vehicles.get_rl_ids()))