本文整理匯總了Golang中github.com/rqme/neat.Context.NextID方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.NextID方法的具體用法?Golang Context.NextID怎麽用?Golang Context.NextID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rqme/neat.Context
的用法示例。
在下文中一共展示了Context.NextID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: generateFirst
// Generates the initial population
func generateFirst(ctx neat.Context, cfg ClassicSettings) (next neat.Population, err error) {
// Create the first generation
next = neat.Population{
Generation: 0,
Species: make([]neat.Species, 1, 10),
Genomes: make([]neat.Genome, cfg.PopulationSize()),
}
// Create the genomes
wg := new(sync.WaitGroup)
for i := 0; i < len(next.Genomes); i++ {
wg.Add(1)
go func(i int) {
genome := createSeed(ctx, cfg)
genome.ID = ctx.NextID()
genome.SpeciesIdx = 0
next.Genomes[i] = genome
wg.Done()
}(i)
}
wg.Wait()
// Create the initial species
next.Species[0] = neat.Species{Example: next.Genomes[0]}
return
}
示例2: createOffspring
func createOffspring(ctx neat.Context, cfg ClassicSettings, cross bool, rng *rand.Rand, pool map[int]Improvements, cnts map[int]int, next *neat.Population) (err error) {
var child neat.Genome
for idx, cnt := range cnts {
l := pool[idx]
for i := 0; i < cnt; i++ {
p1, p2 := pickParents(cfg, cross, rng, l, pool)
if p1.ID == p2.ID {
child = neat.CopyGenome(p1)
} else {
child, err = ctx.Crosser().Cross(p1, p2)
if err != nil {
return
}
}
child.ID = ctx.NextID()
child.Birth = next.Generation
err = ctx.Mutator().Mutate(&child)
next.Genomes = append(next.Genomes, child)
}
}
return
}