Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'tripletime'
- import random
- import tools
- class Individual(object):
- mutation_factor = 5
- def __init__(self, str):
- self.genome = str
- self.fitness = 100000
- @staticmethod
- def random_ind(value = 10):
- temp = ''
- for i in range(0, value):
- temp += str(random.randint(0, 1))
- return Individual(temp)
- @staticmethod
- def decide_if_mutate():
- if (Individual.mutation_factor == 5):
- return False
- else:
- return True
- def breed_with(self, value):
- temp1 = Individual(self.genome)
- temp2 = Individual(value.genome)
- return temp1, temp2
- def count_fitness(self):
- self.fitness = 2 * (int(self.genome, 2) - 567) ** 2
- return self.fitness
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement