import random
def crossover_first(box):
family = []
family_female = []
family_choose = []
choose_num = 5 #B-S交配选择的雌性数量,论文中是1-3,在这里选择5。
malenum = 0
son_num = 0
for i in range(30):
son = []
#box = ["A", "a", "B", "b", "C", "c"]
son.append(box[random.randint(0, 1)])
son.append(box[random.randint(0, 1)])
son.append(box[random.randint(2, 3)])
son.append(box[random.randint(2, 3)])
son.append(box[random.randint(4, 5)])
son.append(box[random.randint(4, 5)])
""" son.append(item[random.randint(6, 7)])
son.append(item[random.randint(6, 7)]) #4 loci
son.append(item[random.randint(8, 9)])
son.append(item[random.randint(8, 9)]) #5 loci
son.append(item[random.randint(10, 11)])
son.append(item[random.randint(10, 11)]) #6 loci
son.append(item[random.randint(12, 13)])
son.append(item[random.randint(12, 13)]) #7 loci
son.append(item[random.randint(14, 15)])
son.append(item[random.randint(14, 15)]) #8 loci
son.append(item[random.randint(16, 17)])
son.append(item[random.randint(16, 17)]) #9 loci
son.append(item[random.randint(18, 19)])
son.append(item[random.randint(18, 19)]) #10 loci
son.append(item[random.randint(20, 21)])
son.append(item[random.randint(20, 21)]) #11 loci """
#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 = family_female
#print(family_choose)
#count模块
son_num = len(family)
#print(son_num) # 展示这个子代种群的子代个数
print(malenum) # 展示的是纯合子的数量
print("这个是M-S杂交的结果:")
print(malenum / son_num )
family_end = random.sample(family_choose, choose_num)
#print(family_end)
return family_end
def crossover_second(boxes):
family = []
family_female = []
family_choose = []
generation = []
choose_num = 5 #B-S交配选择的雌性数量,论文中是1-3,在这里选择5。
malenum = 0
son_num = 0
for item in boxes:
for i in range(30):
son = []
#box = ["A", "a", "B", "b", "C", "c"] 示例:实际上的是好多个
son.append(item[random.randint(0, 1)])
son.append(item[random.randint(0, 1)]) #1 loci
son.append(item[random.randint(2, 3)])
son.append(item[random.randint(2, 3)]) #2 loci
son.append(item[random.randint(4, 5)])
son.append(item[random.randint(4, 5)]) #3 loci
""" son.append(item[random.randint(6, 7)])
son.append(item[random.randint(6, 7)]) #4 loci
son.append(item[random.randint(8, 9)])
son.append(item[random.randint(8, 9)]) #5 loci
son.append(item[random.randint(10, 11)])
son.append(item[random.randint(10, 11)]) #6 loci
son.append(item[random.randint(12, 13)])
son.append(item[random.randint(12, 13)]) #7 loci
son.append(item[random.randint(14, 15)])
son.append(item[random.randint(14, 15)]) #8 loci
son.append(item[random.randint(16, 17)])
son.append(item[random.randint(16, 17)]) #9 loci
son.append(item[random.randint(18, 19)])
son.append(item[random.randint(18, 19)]) #10 loci
son.append(item[random.randint(20, 21)])
son.append(item[random.randint(20, 21)]) #11 loci """
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 = family_female
#print(family_choose)
# count模块
son_num = len(family)
# print(son_num) # 展示这个子代种群的子代个数
print(malenum) # 展示的是纯合子的数量
print("这个是B-S杂交的结果:")
print(malenum / son_num)
family_end = random.sample(family_choose, choose_num)
return family_end
def count():
pass
def process():
crossover_second(
crossover_second(
crossover_second(
crossover_second(
crossover_second(
crossover_second(
crossover_second(
crossover_second(
crossover_first(box
)
)
)
)
)
)
)
)
)
box = ["A", "a", "B", "b", "C", "c"]
process()
crossover2.py
最新推荐文章于 2024-08-14 23:30:40 发布