當前位置: 首頁>>代碼示例>>Python>>正文


Python GPopulation.iteratePop方法代碼示例

本文整理匯總了Python中GPopulation.GPopulation.iteratePop方法的典型用法代碼示例。如果您正苦於以下問題:Python GPopulation.iteratePop方法的具體用法?Python GPopulation.iteratePop怎麽用?Python GPopulation.iteratePop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GPopulation.GPopulation的用法示例。


在下文中一共展示了GPopulation.iteratePop方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: your_func

# 需要導入模塊: from GPopulation import GPopulation [as 別名]
# 或者: from GPopulation.GPopulation import iteratePop [as 別名]

#.........這裏部分代碼省略.........
      self.internalPop.create(minimax=self.minimax)
      self.internalPop.initialize(ga_engine=self)
      logging.debug("The GA Engine was initialized !")      

   def getPopulation(self):
      """ Return the internal population of GA Engine

      :rtype: the population (:class:`GPopulation.GPopulation`)

      """
      return self.internalPop
   
   def getStatistics(self):
      """ Gets the Statistics class instance of current generation

      :rtype: the statistics instance (:class:`Statistics.Statistics`)

      """
      return self.internalPop.getStatistics()

   def getMaxList(self):
      return self.max_list
   
   def getAvgList(self):
      return self.avg_list
   
   def clear(self):
      """ Petrowski's Clearing Method """
      

   def step(self):
      """ Just do one step in evolution, one generation """
      print "Generation ", self.currentGeneration
      self.internalPop.iteratePop()
      print "\n"
      genomeMom = None
      genomeDad = None

      newPop = GPopulation(self.internalPop)
      logging.debug("Population was cloned.")
      
      size_iterate = len(self.internalPop)

      # Odd population size
      if size_iterate % 2 != 0: size_iterate -= 1

      crossover_empty = self.select(popID=self.currentGeneration).crossover.isEmpty()
      
      for i in xrange(0, size_iterate, 2):
         genomeMom = self.select(popID=self.currentGeneration)
         genomeDad = self.select(popID=self.currentGeneration)
         
         if not crossover_empty and self.pCrossover >= 1.0:
            for it in genomeMom.crossover.applyFunctions(mom=genomeMom, dad=genomeDad, count=2):
               (sister, brother) = it
         else:
            if not crossover_empty and Util.randomFlipCoin(self.pCrossover):
               for it in genomeMom.crossover.applyFunctions(mom=genomeMom, dad=genomeDad, count=2):
                  (sister, brother) = it
            else:
               sister = genomeMom.clone()
               brother = genomeDad.clone()

         sister.mutate(pmut=self.pMutation, ga_engine=self)
         brother.mutate(pmut=self.pMutation, ga_engine=self)
開發者ID:fdsscz,項目名稱:pyevolve,代碼行數:69,代碼來源:GSimpleGA.py


注:本文中的GPopulation.GPopulation.iteratePop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。