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


Python Util.list2DSwapElement方法代码示例

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


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

示例1: G2DBinaryStringMutatorSwap

# 需要导入模块: from pyevolve import Util [as 别名]
# 或者: from pyevolve.Util import list2DSwapElement [as 别名]
def G2DBinaryStringMutatorSwap(genome, **args):
   """ The mutator of G2DBinaryString, Swap Mutator

   .. versionadded:: 0.6
      The *G2DBinaryStringMutatorSwap* function
   """

   if args["pmut"] <= 0.0:
      return 0
   height, width = genome.getSize()
   elements = height * width

   mutations = args["pmut"] * elements

   if mutations < 1.0:
      mutations = 0
      for i in xrange(height):
         for j in xrange(width):
            if Util.randomFlipCoin(args["pmut"]):
               index_b = (rand_randint(0, height - 1), rand_randint(0, width - 1))
               Util.list2DSwapElement(genome.genomeString, (i, j), index_b)
               mutations += 1
   else:
      for it in xrange(int(round(mutations))):
         index_a = (rand_randint(0, height - 1), rand_randint(0, width - 1))
         index_b = (rand_randint(0, height - 1), rand_randint(0, width - 1))
         Util.list2DSwapElement(genome.genomeString, index_a, index_b)

   return int(mutations)
开发者ID:colonelzentor,项目名称:Pyevolve,代码行数:31,代码来源:Mutators.py

示例2: G2DListMutatorSwap

# 需要导入模块: from pyevolve import Util [as 别名]
# 或者: from pyevolve.Util import list2DSwapElement [as 别名]
def G2DListMutatorSwap(genome, **args):
   """ The mutator of G1DList, Swap Mutator

   .. note:: this mutator is :term:`Data Type Independent`

   """

   if args["pmut"] <= 0.0:
      return 0
   height, width = genome.getSize()
   elements = height * width

   mutations = args["pmut"] * elements

   if mutations < 1.0:
      mutations = 0
      for i in xrange(height):
         for j in xrange(width):
            if Util.randomFlipCoin(args["pmut"]):
               index_b = (rand_randint(0, height - 1), rand_randint(0, width - 1))
               Util.list2DSwapElement(genome.genomeList, (i, j), index_b)
               mutations += 1
   else:
      for it in xrange(int(round(mutations))):
         index_a = (rand_randint(0, height - 1), rand_randint(0, width - 1))
         index_b = (rand_randint(0, height - 1), rand_randint(0, width - 1))
         Util.list2DSwapElement(genome.genomeList, index_a, index_b)

   return int(mutations)
开发者ID:colonelzentor,项目名称:Pyevolve,代码行数:31,代码来源:Mutators.py

示例3: test_list2DSwapElement

# 需要导入模块: from pyevolve import Util [as 别名]
# 或者: from pyevolve.Util import list2DSwapElement [as 别名]
 def test_list2DSwapElement(self):
     _list = [[1, 2, 3], [4, 5, 6]]
     Util.list2DSwapElement(_list, (0, 1), (1, 1))
     self.assertEqual(_list, [[1, 5, 3], [4, 2, 6]])
开发者ID:ClaudomiroSales,项目名称:Pyevolve,代码行数:6,代码来源:test_util.py


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