简体   繁体   English

收敛到相同种群的遗传算法的交叉

[英]Crossover for Genetic Algorithms converging to identical population

I am doing a project for the OneMax algorithm and am having a problem with the crossover.我正在为 OneMax 算法做一个项目,但我遇到了交叉问题。

Throughout its iterations, I take the top 'division' of people and loop through them.在整个迭代过程中,我采用了人员的最高“部门”并遍历他们。

For even numbers i assign 5 odd number people who they will crossover with (ie 0,4,8,12 & 16 all match with 1,2,3,5,7 & 9 and then 2,6,10,14,18 all match with 11, 13, 15, 17, 19).对于偶数,我分配了 5 个奇数人,他们将与之交叉(即 0、4、8、12 和 16 都匹配 1、2、3、5、7 和 9,然后是 2、6、10、14、18都与 11、13、15、17、19 匹配)。 This is used in order to ensure there are no duplicates.这是为了确保没有重复。

I then choose a random cross point and split the lists, then the lists are split and returned as 2 split lists for parent A & B, which can then be used to make child A and B.然后我选择一个随机交叉点并拆分列表,然后将列表拆分并作为父 A 和 B 的 2 个拆分列表返回,然后可用于生成子 A 和 B。

My problem is the fact that after a few iterations, the population converge to be the exact same bitstring.我的问题是,经过几次迭代,总体收敛到完全相同的位串。

Any help would be greatly appreciated!任何帮助将不胜感激!

Code:代码:

Crossover分频器

def crossover(top20):
    end = len(top20) - 1

    newPop = []

    # Person A crosses over with a list of 5 people

    for i in range(0, end, 2):
        crossPoint = (random.randint(1, len(range(stringLen - 2))))
        crossPoint2 = stringLen - crossPoint

        if i % 4 == 0:
            peopleB = [1, 3, 5, 7, 9]
        else:
            peopleB = [11, 13, 15, 17, 19]

        personA = pop[top20[i]]

        for j in range(len(peopleB)):
            personB = pop[top20[peopleB[j]]]

            sizes = [crossPoint, crossPoint2]
            parA1, parA2 = splitList(sizes, personA)
            parB1, parB2 = splitList(sizes, personB)

            childA = list(chain(parA1, parB2))
            childB = list(chain(parB1, parA2))
            newPop.append(childA)
            newPop.append(childB)

return newPop

Split List拆分列表

def splitList(sizes, ls):
    par1 = []
    par2 = []

    for s in range(stringLen):
        if s < sizes[0]:
            par1.append(ls[s])
        else:
            par2.append(ls[s])

    return par1, par2

Heres a link to the gist of the file这是文件要点的链接

Edit: Another thing is the fact that it always stops at a number in exactly the hundrets for example.编辑:另一件事是它总是停在一个数字上,例如数百。 Like it would stop at an average of exactly 16.00 and the sum of the top chosen would be exactly 8000就像它会在 16.00 的平均值处停止,而选择的顶部的总和正好是 8000

Here is my final product for the OneMax problem with 3 methods, One being the regular one max problem (ie try to get to all 1s), 2 being Evolving to a target string, and number 3 being a Deceptive Landscape.这是我用 3 种方法解决 OneMax 问题的最终产品,一种是常规的最大问题(即尝试得到全 1),2 是进化到目标字符串,3 是欺骗性景观。 It can found here in this gist它可以在这个要点中找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM