我在编写遗传算法时,不确定在选择父母时,是应该遍历我的种群,为每个个体使用锦标赛选择来找到一个父母,还是应该为种群中的每个解决方案使用锦标赛选择来找到两个父母。
到底是哪一种呢?
回答:
我不太明白你所提出的两种选择之间的区别,但通常来说,做法是随机选择两个个体,保留其中较好的一个作为父母1。然后再随机选择另外两个个体,保留其中较好的一个作为父母2。这两个父母随后会重新组合,产生后代,这些后代将进入子代种群。重复这一过程,直到你有足够多的后代。
所以,你可以使用类似下面的循环来生成子代种群。(你可能需要每对父母生成多个后代…根据你的具体情况调整循环边界)。
for i = 1 to N pick individual t1 at random from parent population pick individual t2 at random from parent population parent1 = winner(t1, t2) pick individual t1 at random from parent population pick individual t2 at random from parent population parent2 = winner(t1, t2) generate offspring from parent1, parent2 mutate offspring evaluate offspring add offspring to child populationend for