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