(genome, **args)
return int(mutations)
The mutator of G2DList, Allele Mutator

   To use this mutator, you must specify the *allele* genome parameter with the
   :class:`GAllele.GAlleles` instance.

   .. warning:: the :class:`GAllele.GAlleles` instance must have the homogeneous flag enabled
The mutator of G2DList, Allele Mutator
The mutator of G2DList Allele Mutator
def G2DListMutatorAllele(genome, **args):
   """ The mutator of G2DList, Allele Mutator

   To use this mutator, you must specify the *allele* genome parameter with the
   :class:`GAllele.GAlleles` instance.

   .. warning:: the :class:`GAllele.GAlleles` instance must have the homogeneous flag enabled

   """
   if args["pmut"] <= 0.0:
      return 0
   listSize = genome.getHeight() * genome.getWidth() - 1
   mutations = args["pmut"] * (listSize + 1)

   allele = genome.getParam("allele", None)
   if allele is None:
      Util.raiseException("to use the G2DListMutatorAllele, you must specify the 'allele' parameter", TypeError)

   if not allele.homogeneous:
      Util.raiseException("to use the G2DListMutatorAllele, the 'allele' must be homogeneous")

   if mutations < 1.0:
      mutations = 0

      for i in xrange(genome.getHeight()):
         for j in xrange(genome.getWidth()):
            if Util.randomFlipCoin(args["pmut"]):
               new_val = allele[0].getRandomAllele()
               genome.setItem(i, j, new_val)
               mutations += 1
   else:
      for it in xrange(int(round(mutations))):
         which_x = rand_randint(0, genome.getHeight() - 1)
         which_y = rand_randint(0, genome.getWidth() - 1)

         new_val = allele[0].getRandomAllele()
         genome.setItem(which_x, which_y, new_val)

   return int(mutations)
def G2DListMutatorAllele ( genome , * * args ) : if args [ "pmut" ] <= 0.0 : return 0 listSize = genome . getHeight ( ) * genome . getWidth ( ) - 1 mutations = args [ "pmut" ] * ( listSize + 1 ) allele = genome . getParam ( "allele" , None ) if allele is None : Util . raiseException ( "to use the G2DListMutatorAllele, you must specify the 'allele' parameter" , TypeError ) if not allele . homogeneous : Util . raiseException ( "to use the G2DListMutatorAllele, the 'allele' must be homogeneous" ) if mutations < 1.0 : mutations = 0 for i in xrange ( genome . getHeight ( ) ) : for j in xrange ( genome . getWidth ( ) ) : if Util . randomFlipCoin ( args [ "pmut" ] ) : new_val = allele [ 0 ] . getRandomAllele ( ) genome . setItem ( i , j , new_val ) mutations += 1 else : for it in xrange ( int ( round ( mutations ) ) ) : which_x = rand_randint ( 0 , genome . getHeight ( ) - 1 ) which_y = rand_randint ( 0 , genome . getWidth ( ) - 1 ) new_val = allele [ 0 ] . getRandomAllele ( ) genome . setItem ( which_x , which_y , new_val ) return int ( mutations )