(genome, **args)
return int(mutations)
The classical flip mutator for binary strings
The classical flip mutator for binary strings
The classical flip mutator for binary strings
def G1DBinaryStringMutatorFlip(genome, **args):
   """ The classical flip mutator for binary strings """
   if args["pmut"] <= 0.0:
      return 0
   stringLength = len(genome)
   mutations = args["pmut"] * (stringLength)

   if mutations < 1.0:
      mutations = 0
      for it in xrange(stringLength):
         if Util.randomFlipCoin(args["pmut"]):
            if genome[it] == 0:
               genome[it] = 1
            else:
               genome[it] = 0
            mutations += 1

   else:
      for it in xrange(int(round(mutations))):
         which = rand_randint(0, stringLength - 1)
         if genome[which] == 0:
            genome[which] = 1
         else:
            genome[which] = 0

   return int(mutations)
def G1DBinaryStringMutatorFlip ( genome , * * args ) : if args [ "pmut" ] <= 0.0 : return 0 stringLength = len ( genome ) mutations = args [ "pmut" ] * ( stringLength ) if mutations < 1.0 : mutations = 0 for it in xrange ( stringLength ) : if Util . randomFlipCoin ( args [ "pmut" ] ) : if genome [ it ] == 0 : genome [ it ] = 1 else : genome [ it ] = 0 mutations += 1 else : for it in xrange ( int ( round ( mutations ) ) ) : which = rand_randint ( 0 , stringLength - 1 ) if genome [ which ] == 0 : genome [ which ] = 1 else : genome [ which ] = 0 return int ( mutations )