if settings.KeepBestAcrossPopulation{ newPopIndex = 1 } for ; newPopIndex < settings.PopulationSize; newPopIndex++ { indexSelection1 := rand.Int() % len(probabilisticListOfPerformers) indexSelection2 := rand.Int() % len(probabilisticListOfPerformers) // crossover newIndividual := geneticAlgoRunner.PerformCrossover( probabilisticListOfPerformers[indexSelection1], probabilisticListOfPerformers[indexSelection2], settings.CrossoverRate) // mutate if rand.Intn(101) < settings.MutationRate { newIndividual = geneticAlgoRunner.PerformMutation(newIndividual) } newPopulation = append(newPopulation, newIndividual) } population = newPopulation // sort by performance geneticAlgoRunner.Sort(population) // keep the best so far bestSoFar = population[len(population) - 1] } return bestSoFar, nil } func createStochasticProbableListOfIndividuals(population []interface{}) []interface{} { totalCount, populationLength:= 0, len(population) for j:= 0; j < populationLength; j++ { totalCount += j } probableIndividuals := make([]interface{}, 0, totalCount) for index, individual := range population { for i:= 0; i < index; i++{ probableIndividuals = append(probableIndividuals, individual) } }
推荐阅读
主流浏览器之战:Edge惨遭微软“抛弃”,IE开始逆袭
Tech Neo技巧沙龙 | 11月25号,九州云/ZStack与您一路商量云时代收集界线治理实践
10 月浏览器市场份额数据显示,Chrome 市场份额持续晋升,下个月有望冲破 60% 。Edge 浏览器的份额出现下>>>详细阅读
本文标题:Go语言如何实现遗传算法
地址:http://www.17bianji.com/lsqh/38942.html
1/2 1