示例#1
0
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 utils.randomFlipCoin(args["pmut"]):
               index_b = (prng.randint(0, height), prng.randint(0, width))
               utils.list2DSwapElement(genome.genomeString, (i, j), index_b)
               mutations += 1
   else:
      for it in xrange(int(round(mutations))):
         index_a = (prng.randint(0, height), prng.randint(0, width))
         index_b = (prng.randint(0, height), prng.randint(0, width))
         utils.list2DSwapElement(genome.genomeString, index_a, index_b)

   return int(mutations)
示例#2
0
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 utils.randomFlipCoin(args["pmut"]):
                    index_b = (prng.randint(0, height), prng.randint(0, width))
                    utils.list2DSwapElement(genome.genomeList, (i, j), index_b)
                    mutations += 1
    else:
        for it in xrange(int(round(mutations))):
            index_a = (prng.randint(0, height), prng.randint(0, width))
            index_b = (prng.randint(0, height), prng.randint(0, width))
            utils.list2DSwapElement(genome.genomeList, index_a, index_b)

    return int(mutations)
示例#3
0
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 utils.randomFlipCoin(args["pmut"]):
               index_b = (prng.randint(0, height), prng.randint(0, width))
               utils.list2DSwapElement(genome.genomeList, (i, j), index_b)
               mutations += 1
   else:
      for it in xrange(int(round(mutations))):
         index_a = (prng.randint(0, height), prng.randint(0, width))
         index_b = (prng.randint(0, height), prng.randint(0, width))
         utils.list2DSwapElement(genome.genomeList, index_a, index_b)

   return int(mutations)
示例#4
0
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 utils.randomFlipCoin(args["pmut"]):
                    index_b = (prng.randint(0, height), prng.randint(0, width))
                    utils.list2DSwapElement(genome.genomeString, (i, j),
                                            index_b)
                    mutations += 1
    else:
        for it in xrange(int(round(mutations))):
            index_a = (prng.randint(0, height), prng.randint(0, width))
            index_b = (prng.randint(0, height), prng.randint(0, width))
            utils.list2DSwapElement(genome.genomeString, index_a, index_b)

    return int(mutations)