-
Notifications
You must be signed in to change notification settings - Fork 0
/
evol.py
73 lines (66 loc) · 1.46 KB
/
evol.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python
import random
import string
def gen():
A=[0,0,0,0,0,0,0,0,0]
for i in range(len(A)): A[i]=random.randint(0,25)
return A
def fen(X):
B=[]
for i in range(len(X)):
if X[i] != 0 : B.append(string.ascii_lowercase[X[i]])
B=''.join(B);
return B
def selection(X):
voc=0.00
con=0.00
vot=0.00
cot=0.00
for i in range(len(X)):
if X[i] in "aeiou": voc +=1.0
else: con +=1.0
vot=(10.0 * voc) / (voc+con)
cot= 10.0 - vot
if vot == 0 : vot = 1.0
sieve = 1.7<cot/vot<2.7
if sieve is False :
C[0] = "Die"
else:
C[0] = "Survive"
return
def reproduction(y,x):
if (x and y != []) and (len(x[1]) == len(y[1])):
son[0]=[0 for k in range(len(x[0]))]
for j in range(len(x[0])) : son[0][j] = int((x[0][j]+y[0][j])/2)
son[1] = fen(son[0])
print("mum", x)
print("dad", y)
print("son", son)
print("---------------------------------")
else:
print("No breeding")
print("---------------------------------")
x=[]
y=[]
return
population=[]
cemetery=[]
breeding=[]
C=[0]
dad=[]
mum=[]
son=[0,[]]
for i in range(1000) :
tmp= gen()
population.append((tmp,fen(tmp)))
selection(population[i][1])
if C[0] is "Die" : cemetery.append(population[i])
elif C[0] is "Survive" : breeding.append(population[i])
for i in range(10):
chance = 27 < random.randint(0,len(breeding)) < 37
if chance is True:
bm= random.randint(0,len(breeding)-1)
bd= random.randint(0,len(breeding)-1)
mum = breeding[bm]
dad = breeding[bd]
reproduction(mum,dad)