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


Python Network.unpickleAndDecompress方法代码示例

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


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

示例1: exchange

# 需要导入模块: import Network [as 别名]
# 或者: from Network import unpickleAndDecompress [as 别名]
    def exchange(self):
        """ This is the main method, is where the individuals
        are exchanged """

        if not self.isReady():
            return

        # Client section --------------------------------------
        # How many will migrate ?
        pool = self.selectPool(self.getNumIndividuals())

        for individual in pool:
            # (code, group name, individual)
            networkObject = (Consts.CDefNetworkIndividual,
                             self.getGroupName(), individual)
            networkData = Network.pickleAndCompress(
                networkObject, self.getCompressionLevel())
            # Send the individuals to the topology
            self.clientThread.addData(networkData)

        # Server section --------------------------------------
        pool = []
        while self.serverThread.isReady():
            # (IP source, data)
            networkData = self.serverThread.popPool()
            networkObject = Network.unpickleAndDecompress(networkData[1])
            # (code, group name, individual)
            pool.append(networkObject)

        # No individuals received
        if len(pool) <= 0:
            return

        population = self.GAEngine.getPopulation()

        for i in xrange(self.getNumReplacement()):
            if len(pool) <= 0:
                break
            choice = rand_choice(pool)
            pool.remove(choice)

            # replace the worst
            population[len(population) - 1 - i] = choice[2]
开发者ID:erikreed-public,项目名称:Pyevolve,代码行数:45,代码来源:Migration.py


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