(genome, **args)
return int(mutations)
The mutator of G2DBinaryString, Swap Mutator

   .. versionadded:: 0.6
      The *G2DBinaryStringMutatorSwap* function
The mutator of G2DBinaryString, Swap Mutator
The mutator of G2DBinaryString Swap Mutator
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)
def G2DBinaryStringMutatorSwap ( genome , * * args ) : 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 )