-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
48 lines (35 loc) · 1.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from Population import Population
import config
def main():
pop = Population(config.pop_size)
pop.make_population()
pop.makedir()
pop.write_input(config.patterns)
pop.simulation_nominal()
pop.simulation_void()
pop.get_k_nominal()
pop.get_k_void()
lowest = pop.worst_chromosome()
pop.calc_pop_fitness(lowest, pop.generation)
pop.write_output(0, lowest)
for generation in range(config.num_generations):
new_pop = Population(config.pop_size)
for i in range(int(config.pop_size / 2)):
parent1 = pop.roulette(lowest, pop.generation)
parent2 = pop.roulette(lowest, pop.generation)
child1, child2 = pop.crossover(parent1, parent2)
new_pop.chromosomes.append(child1)
new_pop.chromosomes.append(child2)
pop = new_pop
pop.generation = generation + 1
pop.mutation(config.mutation_prob)
pop.makedir()
pop.write_input(config.patterns)
pop.simulation_nominal()
pop.simulation_void()
pop.get_k_nominal()
pop.get_k_void()
pop.calc_pop_fitness(lowest, pop.generation)
pop.write_output(1, lowest)
if __name__ == '__main__':
main()