本文整理汇总了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]