Advertisement
Guest User

Untitled

a guest
May 26th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. __author__ = 'tripletime'
  2. import random
  3. import tools
  4.  
  5. class Individual(object):
  6.  
  7. mutation_factor = 5
  8.  
  9. def __init__(self, str):
  10. self.genome = str
  11. self.fitness = 100000
  12.  
  13. @staticmethod
  14. def random_ind(value = 10):
  15. temp = ''
  16. for i in range(0, value):
  17. temp += str(random.randint(0, 1))
  18. return Individual(temp)
  19.  
  20. @staticmethod
  21. def decide_if_mutate():
  22. if (Individual.mutation_factor == 5):
  23. return False
  24. else:
  25. return True
  26.  
  27. def breed_with(self, value):
  28. temp1 = Individual(self.genome)
  29. temp2 = Individual(value.genome)
  30. return temp1, temp2
  31.  
  32. def count_fitness(self):
  33. self.fitness = 2 * (int(self.genome, 2) - 567) ** 2
  34. return self.fitness
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement