crossover2.py

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()

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

终是蝶衣梦晓楼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值