(genome, **args)
return int(mutations)
A flip mutator for G2DBinaryString

   .. versionadded:: 0.6
      The *G2DBinaryStringMutatorFlip* function
A flip mutator for G2DBinaryString
A flip mutator for G2DBinaryString
def G2DBinaryStringMutatorFlip(genome, **args):
   """ A flip mutator for G2DBinaryString

   .. versionadded:: 0.6
      The *G2DBinaryStringMutatorFlip* 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(genome.getHeight()):
         for j in xrange(genome.getWidth()):
            if Util.randomFlipCoin(args["pmut"]):
               if genome[i][j] == 0:
                  genome.setItem(i, j, 1)
               else:
                  genome.setItem(i, j, 0)
               mutations += 1
   else:

      for it in xrange(int(round(mutations))):
         which_x = rand_randint(0, genome.getWidth() - 1)
         which_y = rand_randint(0, genome.getHeight() - 1)

         if genome[i][j] == 0:
            genome.setItem(which_y, which_x, 1)
         else:
            genome.setItem(which_y, which_x, 0)

   return int(mutations)
def G2DBinaryStringMutatorFlip ( 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 ( genome . getHeight ( ) ) : for j in xrange ( genome . getWidth ( ) ) : if Util . randomFlipCoin ( args [ "pmut" ] ) : if genome [ i ] [ j ] == 0 : genome . setItem ( i , j , 1 ) else : genome . setItem ( i , j , 0 ) mutations += 1 else : for it in xrange ( int ( round ( mutations ) ) ) : which_x = rand_randint ( 0 , genome . getWidth ( ) - 1 ) which_y = rand_randint ( 0 , genome . getHeight ( ) - 1 ) if genome [ i ] [ j ] == 0 : genome . setItem ( which_y , which_x , 1 ) else : genome . setItem ( which_y , which_x , 0 ) return int ( mutations )