复杂环境中的搜索算法:遗传算法、连续空间搜索与非确定性行动搜索
1. 遗传算法
遗传算法模拟自然选择和遗传机制,在优化问题中寻找最优解。以下是遗传算法的代码实现:
def GENETIC-ALGORITHM(population, fitness):
while True:
weights = WEIGHTED-BY(population, fitness)
population2 = []
for i in range(len(population)):
parent1, parent2 = WEIGHTED-RANDOM-CHOICES(population, weights, 2)
child = REPRODUCE(parent1, parent2)
if random.random() < small_random_probability:
child = MUTATE(child)
population2.append(child)
population = population2
if some individual is fit enough or enough time has elapsed:
break
return the best individual in population according to fitness
def REPRODUCE(parent
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



