-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·46 lines (34 loc) · 1.37 KB
/
main.py
File metadata and controls
executable file
·46 lines (34 loc) · 1.37 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import random
import unittest
import os
import src.constants as c
import src.alphabet as ab
from src.allele import Allele
from src.locus import Locus
from src.individual import Individual
from src.population import Population
def summarize_alleles_per_generation(p):
alleles = ab.DNA_UPPER + ab.DNA_LOWER
generations = 30
original_population_size = c.MAX_POPULATION
# print ('length at begining of generation {:d} is {:d}'.format(generation+1, len(p.individuals)))
for generation in range(0, generations):
for individual in p.individuals:
if random.random() > float(individual.get_fitness):
p.individuals.remove(individual)
missing_persons = original_population_size - len(p.individuals)
for i in range(missing_persons):
random_alleles = []
for j in range(c.ALLELE_RANGE[0], c.ALLELE_RANGE[1]):
random_alleles.append(p.get_random_allele_from_population)
p.add_new_individual_to_population(Individual(random_alleles))
print('For generation {:d} allele frequency is:'.format(generation + 1))
for allele in alleles:
print(allele, p.get_allele_frequency(allele))
def summarize_alleles_per_individual(p):
pass
if __name__ == '__main__':
p = Population()
summarize_alleles_per_generation(p)