当前位置: 首页>>代码示例>>Python>>正文


Python Mapper.map_rbgs方法代码示例

本文整理汇总了Python中mapper.Mapper.map_rbgs方法的典型用法代码示例。如果您正苦于以下问题:Python Mapper.map_rbgs方法的具体用法?Python Mapper.map_rbgs怎么用?Python Mapper.map_rbgs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mapper.Mapper的用法示例。


在下文中一共展示了Mapper.map_rbgs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Scheduler

# 需要导入模块: from mapper import Mapper [as 别名]
# 或者: from mapper.Mapper import map_rbgs [as 别名]
class Scheduler(StoppableThread):
    """
    The scheduler class. may use differents algorithms.
    """

    def __init__(self, station):
        # selection of the algorithm to use
        self.algorithm = getattr(settings, 'SCHEDULER_ALGORITHM')()
        self.station = station
        self.current_user_imsi = None
        self.last_user_imsi = None
        self.start_time = None
        self.iteration_time = None
        self.mapper = Mapper()
        self.rbgs = None
        return super(Scheduler, self).__init__()

    def run(self):
        self.it = 0
        for u in self.station.user_queues:
            self.station.users_rbgs_hist[u[0]] = []
        timeslot = getattr(settings, 'TIME_SLOT', 0.005)
        nb_iter = (
            getattr(settings, 'EXECUTION_TIME', 2.0) /
            timeslot
        )
        while self.it < nb_iter and not self.stop_request:
            start_time = time()
            self.action()
            end_time = time()
            diff_time = end_time - start_time
            if diff_time < timeslot:
                sleep(timeslot - diff_time)
            self.it = self.it + 1
            CallAfter(Publisher().sendMessage, "refresh", '')

    def action(self):
        # IF YOU WISH TO IMPLEMENT AN ALGORITHM
        # YOU DON'T HAVE TO EDIT THIS FUNCTION
        self.rbgs = []

        for u in self.station.user_queues:
            self.station.users_rbgs_hist[u[0]].append(0)
        # sending datas to the mapper
        for i in range(getattr(settings, 'NB_RBG', 25)):
            data = []

            # call of the scheduling algo to choose the user to consider
            self.current_user_imsi = self.algorithm.choose_user(
                self.station.user_queues, self.last_user_imsi,
                self.station.users_throughput)
            # gets the user queue of the choosed user
            user_queue = next(
                i for i in self.station.user_queues
                if i[0] == self.current_user_imsi
            )
            for i in range(
                getattr(settings, 'NB_RB_PER_RBG')
                * getattr(settings, 'NB_OFDM_SYMBOLS_PER_TIMESLOT', 7)
            ):
                if not user_queue[1].empty():
                    # gets a constellation/data from this queue
                    data.append(user_queue[1].get())

            self.last_user_imsi = self.current_user_imsi

            self.rbgs.append((self.current_user_imsi, data))

            self.station.users_rbgs_hist[
                self.current_user_imsi][self.it] += 1

        # here we send the rbgs array to the mapper
        self.mapper.map_rbgs(self.rbgs)

        for u in self.station.user_queues:
            self.station.record_throughput(
                u[0], self.compute_used_throughput(
                    u[0],
                    [i for i in range(len(self.rbgs))
                     if self.rbgs[i][0] == u[0]]
                )
            )
            self.station.record_th_throughput(
                u[0],
                self.compute_th_throughput(
                    u[0],
                    [i for i in range(len(self.rbgs))
                     if self.rbgs[i][0] == u[0]]
                )
            )

        return super(Scheduler, self).action()

    def compute_used_throughput(self, user_id, rbgs_indexes):
        """
        Returns the throughput of the user in this timeslot
        considering the RBGs he's got and the infomations the
        can give.
        /!\ Return strange values /!\
        """
#.........这里部分代码省略.........
开发者ID:bpetit,项目名称:lte_multiplexing_simulator,代码行数:103,代码来源:station.py


注:本文中的mapper.Mapper.map_rbgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。