View raw

1 """ 2 The generator.py module contains classes describing genetic populations 3 and methods to generate default aircraft. 4 """ 5 6 from aircraftstudio import creator 7 8 9 def default_fuselage(): 10 pass 11 12 13 def default_propulsion(): 14 pass 15 16 17 class Population(): 18 """Represents a collection of aircraft.""" 19 def __init__(self, size): 20 self.aircrafts = [] 21 for _ in range(size): 22 self.aircrafts.append(creator.base.Aircraft.from_random()) 23 self.size = size 24 self.results = None 25 self.gen_number = 0 # incremented for every generation 26 27 #TODO class methods for default and random population 28 # def from_default(self, size): 29 # for i in range(size): 30 # self.aircrafts.append(creator.base.Aircraft.from_default()) 31 32 # def from_random(self, size): 33 # for i in range(size): 34 # self.aircrafts.append(creator.base.Aircraft.from_random()) 35 36 def mutate(self, prob_mt): 37 """Randomly mutate the genes of prob_mt % of the population.""" 38 def crossover(self, prob_cx): 39 """Combine the genes of prob_cx % of the population.""" 40 def reproduce(self, prob_rp): 41 """Pass on the genes of the fittest prob_rp % of the population.""" 42 def fitness(): 43 """Rate the fitness of an individual on a relative scale (0-100)""" 44