예제 #1
0
    def add(self, veh_id, type_id, edge, pos, lane, speed):
        """See parent class."""
        self.num_vehicles += 1
        self.__ids.append(veh_id)
        self.__vehicles[veh_id] = {}
        self.__vehicles[veh_id]["type_name"] = type_id

        # add vehicle in Aimsun
        # negative one means the first feasible turn TODO get route
        next_section = -1
        aimsun_id = self.kernel_api.add_vehicle(
            edge=self.master_kernel.scenario.aimsun_edge_name(edge),
            lane=lane,
            type_id=type_id,
            pos=pos,
            speed=speed,
            next_section=next_section)

        self.__vehicles[veh_id]['static_info'] =\
            self.kernel_api.get_vehicle_static_info(aimsun_id)
        self.__vehicles[veh_id]['tracking_info'] = InfVeh()

        # set the Aimsun/Flow vehicle ID converters
        self._id_aimsun2flow[aimsun_id] = veh_id
        self._id_flow2aimsun[veh_id] = aimsun_id

        # increment the number of vehicles of this type
        if type_id in self.num_type:
            self.num_type[type_id] += 1
            self.total_num_type[type_id] += 1
        else:
            self.num_type[type_id] = 1
            self.total_num_type[type_id] = 1
예제 #2
0
    def test_inf_veh(self):
        """Verify that the InfVeh object contains the expected attributes."""
        expected_variables = [
            'CurrentPos', 'distance2End', 'xCurrentPos', 'yCurrentPos',
            'zCurrentPos', 'xCurrentPosBack', 'yCurrentPosBack',
            'zCurrentPosBack', 'CurrentSpeed', 'TotalDistance',
            'SectionEntranceT', 'CurrentStopTime', 'stopped', 'idSection',
            'segment', 'numberLane', 'idJunction', 'idSectionFrom',
            'idLaneFrom', 'idSectionTo', 'idLaneTo'
        ]

        obj = InfVeh()

        for val in expected_variables:
            self.assertIn(val, obj.__dict__.keys())
예제 #3
0
    def _add_departed(self, aimsun_id):
        """See parent class."""
        # get vehicle information from API
        static_inf_veh = self.kernel_api.get_vehicle_static_info(aimsun_id)

        # get the vehicle's type
        type_id = self.kernel_api.get_vehicle_type_name(aimsun_id)

        self.kernel_api.set_vehicle_tracked(aimsun_id)

        # get the vehicle ID, or create a new vehicle ID if one doesn't exist
        # for the vehicle
        if aimsun_id not in self._id_aimsun2flow.keys():
            # get a new name for this vehicle
            if type_id not in self.num_type:
                self.num_type[type_id] = 0
                self.total_num_type[type_id] = 0
            veh_id = '{}_{}'.format(type_id, self.total_num_type[type_id])
            self.num_type[type_id] += 1
            self.total_num_type[type_id] += 1
            self.__ids.append(veh_id)
            self.__vehicles[veh_id] = {}
            # set the Aimsun/Flow vehicle ID converters
            self._id_aimsun2flow[aimsun_id] = veh_id
            self._id_flow2aimsun[veh_id] = aimsun_id
        else:
            veh_id = self._id_aimsun2flow[aimsun_id]

        # store the static info
        self.__vehicles[veh_id]["static_info"] = static_inf_veh
        self.__vehicles[veh_id]["type_name"] = type_id

        # store an empty tracking info object
        self.__vehicles[veh_id]['tracking_info'] = InfVeh()

        if type_id in self.type_parameters:
            # specify the acceleration controller class
            accel_controller = \
                self.type_parameters[type_id]["acceleration_controller"]
            car_following_params = \
                self.type_parameters[type_id]["car_following_params"]
            self.__vehicles[veh_id]["acc_controller"] = \
                accel_controller[0](veh_id,
                                    car_following_params=car_following_params,
                                    **accel_controller[1])

            # specify the lane-changing controller class
            lc_controller = \
                self.type_parameters[type_id]["lane_change_controller"]
            self.__vehicles[veh_id]["lane_changer"] = \
                lc_controller[0](veh_id=veh_id, **lc_controller[1])

            # specify the routing controller class
            rt_controller = self.type_parameters[type_id]["routing_controller"]
            if rt_controller is not None:
                self.__vehicles[veh_id]["router"] = \
                    rt_controller[0](veh_id=veh_id,
                                     router_params=rt_controller[1])
            else:
                self.__vehicles[veh_id]["router"] = None

            # FIXME should add RL controller to RL vehicle added by Aimsun via
            # load.py

            # add the vehicle's id to the list of vehicle ids
            if accel_controller[0] == RLController:
                self.__rl_ids.append(veh_id)
                self.num_rl_vehicles += 1
            else:
                self.__human_ids.append(veh_id)
                if accel_controller[0] != SimCarFollowingController:
                    self.__controlled_ids.append(veh_id)
                if lc_controller[0] != SimLaneChangeController:
                    self.__controlled_lc_ids.append(veh_id)

        # set the "last_lc" parameter of the vehicle
        self.__vehicles[veh_id]["last_lc"] = -float("inf")

        self.__human_ids.append(veh_id)  # FIXME not true for RL vehicles

        # make sure that the order of rl_ids is kept sorted
        self.__rl_ids.sort()