Пример #1
0
    def mutate(self):
        """
        Mutate this gene's value by a random amount
        within the range +/- self.mutAmt

        perform mutation IN-PLACE, ie don't return mutated copy
        """
        self.value += complex(
            uniform(-self.mutAmtReal, self.mutAmtReal),
            uniform(-self.mutAmtImag, self.mutAmtImag)
            )

        # if the gene has wandered outside the alphabet,
        # rein it back in
        real = medial(self.value.real,self.randMin,self.randMax)
        imag = medial(self.value.imag,self.randMin,self.randMax)

        self.value = complex(real, imag)
Пример #2
0
    def mutate(self):
        """
        perform gene mutation

        perform mutation IN-PLACE, ie don't return mutated copy
        """
        self.value = chr(ord(self.value) + randint(-self.mutAmt, self.mutAmt))

        # if the gene has wandered outside the alphabet,
        # rein it back in
        self.value = medial(self.value,self.randMin,self.randMax)