遗传算法交叉过程的一次测试--为保证站点未被选中即x=0时,v,p,z,u=0

I=3
J=4
chrom=[[0, 1, 0, 0, 20, 0, 0, 2, 0, 0.0, 0.6893126301155467, 0.0, 0.0, 0.5924087169328368, 0.0, 0.0, 0.5101638553011607, 0.0, 0.0, 0.7554467029891929, 0.0, 0.0, 0.0, 0.0, 0.08096975101708848, 0.12403876751553977, 0.06804904606755306, 0.0, 0.0, 0.0],
[0, 0, 1, 0, 0, 19, 0, 0, 87, 0.0, 0.0, 0.3716635079738594, 0.0, 0.0, 0.6703974960504199, 0.0, 0.0, 0.7903844542394335, 0.0, 0.0, 0.030617515530527273, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.978133913013635e-05, 3.522216070198818e-05, 0.0001474749005001944]]
for i in range(2, 3 + 1):  # 遍历每个交叉点
    Ge1 = chrom[0][i] # 参与交叉的第一个染色体的i基因
    Ge2 = chrom[1][i]
if 0 <= i <=  I - 1:
    Ge1 = int(Ge2 + a * (Ge1 - Ge2))
    Ge2 = int(Ge1 + b * (Ge2 - Ge1))  # 交叉后的基因
    Ge3 = [Ge1, Ge2]
    for gene in Ge3:
        gene_index = Ge3.index(gene)  # 得到X值为0的基因的索引
        chrom_n = chrom[gene_index]  # 等于0的基因所在的染色体
        if gene==0:
            chrom_n[I+i]=0  #对应的V=0
            chrom_n[2*I+i]=0 #对应的P=0
            for j in range(3, J + 3):
                chrom_n[j*I+i]=0  #对应的z=0
            for k in range(I):
                chrom_n[(3+J+i)*I+k]=0  #对应的u=0
        else:
            chrom_n[I + i] =   # 对应的V=0
            chrom_n[2 * I + i] =   # 对应的P=0
            for j in range(3, J + 3):
                chrom_n[j * I + i] =   # 对应的z=0
            for k in range(I):
                chrom_n[(3 + J + i) * I + k] =   # 对应的u=0
发布了13 篇原创文章 · 获赞 0 · 访问量 110

猜你喜欢

转载自blog.csdn.net/huahua20190514/article/details/103500890