View raw

1 # This file is part of Marius Peter's airfoil analysis package (this program). 2 # 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation, either version 3 of the License, or 6 # (at your option) any later version. 7 # 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 # 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <https://www.gnu.org/licenses/>. 15 """ 16 The generator.py module contains a single Population class, 17 which represents a collection of randomized airfoils. 18 """ 19 20 from tools import creator 21 22 23 def default_airfoil(): 24 """Generate the default airfoil.""" 25 airfoil = creator.Airfoil.from_dimensions(100, 200) 26 airfoil.add_naca(2412) 27 airfoil.add_mass(10) 28 29 airfoil.spar = creator.Spar() 30 airfoil.spar.add_coord(airfoil, 0.23) 31 airfoil.spar.add_coord(airfoil, 0.57) 32 airfoil.spar.add_spar_caps(0.3) 33 airfoil.spar.add_mass(10) 34 airfoil.spar.add_webs(0.4) 35 36 airfoil.stringer = creator.Stringer() 37 airfoil.stringer.add_coord(airfoil, 3, 6, 5, 4) 38 airfoil.stringer.add_area(0.1) 39 airfoil.stringer.add_mass(5) 40 airfoil.stringer.add_webs(0.1) 41 42 return airfoil 43 44 45 class Population(creator.Airfoil): 46 """Collection of random airfoils.""" 47 48 def __init__(self, size): 49 af = creator.Airfoil 50 # print(af) 51 self.size = size 52 self.gen_number = 0 # incremented for every generation 53 54 def mutate(self, prob_mt): 55 """Randomly mutate the genes of prob_mt % of the population.""" 56 57 def crossover(self, prob_cx): 58 """Combine the genes of prob_cx % of the population.""" 59 60 def reproduce(self, prob_rp): 61 """Pass on the genes of the fittest prob_rp % of the population.""" 62 63 def fitness(): 64 """Rate the fitness of an individual on a relative scale (0-100)""" 65