diff options
author | blendoit <blendoit@gmail.com> | 2019-10-19 15:10:38 -0700 |
---|---|---|
committer | blendoit <blendoit@gmail.com> | 2019-10-19 15:10:38 -0700 |
commit | 4a2f29713604b5cfe86fe2367c98ff731c34166e (patch) | |
tree | 619dd8eb76d93dcea4d1eebe64e80bff6ee31510 /generator.py | |
parent | 1d6b7b1444b91949b554a314f589705535d6fc01 (diff) |
Correct randomization of aircraft and save of component tree and eval results
Diffstat (limited to 'generator.py')
-rw-r--r-- | generator.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/generator.py b/generator.py new file mode 100644 index 0000000..0ad8d0f --- /dev/null +++ b/generator.py @@ -0,0 +1,46 @@ +""" +The generator.py module contains classes describing genetic populations +and methods to generate default aircraft. +""" + +import random + +import creator + + +def default_aircraft(evaluator): + """Generate a default aircraft with a random name.""" + name = 'default_aircraft_' + str(random.randrange(1000, 9999)) + aircraft = creator.base.Aircraft(evaluator, name) + airfoil = creator.wing.Airfoil(aircraft, 'default_airfoil') + airfoil.add_naca(2412) + soar1 = creator.wing.Spar(airfoil, 'default_spar_1', 0.30) + soar2 = creator.wing.Spar(airfoil, 'default_spar_2', 0.60) + stringer = creator.wing.Stringer(airfoil, 'default_stringer') + return aircraft + + +def default_fuselage(): + pass + + +def default_propulsion(): + pass + + +class Population(): + """Collection of random airfoils.""" + def __init__(self, size): + af = creator.Airfoil + # print(af) + self.size = size + self.gen_number = 0 # incremented for every generation + + def mutate(self, prob_mt): + """Randomly mutate the genes of prob_mt % of the population.""" + def crossover(self, prob_cx): + """Combine the genes of prob_cx % of the population.""" + def reproduce(self, prob_rp): + """Pass on the genes of the fittest prob_rp % of the population.""" + def fitness(): + """Rate the fitness of an individual on a relative scale (0-100)""" |