import random
def crossover(box):
family = []
family_female = []
family_choose = []
choose_num = 5 #B-S交配选择的雌性数量,论文中是1-3,在这里选择5。
malenum = 0
son_num = 0
for i in range(100):
son = []
#box = [["A", "a"], ["B", "b"], ["C", "c"]]
son.append(box[0][random.randint(0, 1)])
son.append(box[0][random.randint(0, 1)])
son.append(box[1][random.randint(0, 1)])
son.append(box[1][random.randint(0, 1)])
son.append(box[2][random.randint(0, 1)])
son.append(box[2][random.randint(0, 1)])
#print(son)
#print(box[0][random.randint(0, 1)]+box[0][random.randint(0, 1)]+box[1][random.randint(0, 1)]+box[1][random.randint(0, 1)])
if son[0] == son[1] and son[2] == son[3] and son[4] == son[5]:
malenum = malenum + 1
family.append(son)
#print(son) #仅作调试使用
else:
family.append(son)
family_female.append(son)
family_choose = random.sample(family_female, choose_num)
print(family_choose)
son_num = len(family)
#print(son_num) # 展示这个子代种群的子代个数
#print(malenum)
print(malenum / son_num)
return family_choose
def count():
pass
def process():
print("这个是M-S杂交的结果")
for person in crossover(box):
sec = [[person[0], person[1]], [person[2], person[3]], [person[4], person[5]]]
crossover(sec)
for person in crossover(sec):
thi = [[person[0], person[1]], [person[2], person[3]], [person[4], person[5]]]
crossover(thi)
for person in crossover(thi):
fou = [[person[0], person[1]], [person[2], person[3]], [person[4], person[5]]]
crossover(fou)
for person in crossover(fou):
fif = [[person[0], person[1]], [person[2], person[3]], [person[4], person[5]]]
crossover(fif)
for person in crossover(fif):
six = [[person[0], person[1]], [person[2], person[3]], [person[4], person[5]]]
crossover(six)
for person in crossover(six):
sev = [[person[0], person[1]], [person[2], person[3]], [person[4], person[5]]]
crossover(sev)
#print(boxs)
box = [["A", "a"], ["B", "b"], ["C", "c"]]
process()
#print(crossover([["A", "a"], ["B", "b"], ["C", "c"]]))
crossover.py
最新推荐文章于 2024-08-14 23:30:40 发布