作家
登录

Go语言如何实现遗传算法

作者: 来源: 2017-11-16 17:01:24 阅读 我要评论

  •       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

  • 关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)