本文整理汇总了C#中Population.saveGenome方法的典型用法代码示例。如果您正苦于以下问题:C# Population.saveGenome方法的具体用法?C# Population.saveGenome怎么用?C# Population.saveGenome使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Population
的用法示例。
在下文中一共展示了Population.saveGenome方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: evolvePopulation
public static Population evolvePopulation(Population pop)
{
Population newPopulation = new Population(pop.size(), false);
Genome champion = pop.getFittest();
// Keep our best Genome
if (elitism)
{
newPopulation.saveGenome(0, champion);
}
// Crossover population
int elitismOffset;
if (elitism)
{
elitismOffset = 1;
}
else
{
elitismOffset = 0;
}
// half of the new population is the champion and mutations of him
int halfPopSize = (int)Mathf.Floor((float) pop.size() / 2);
tournamentSize = pop.size() - (halfPopSize + 1);
for (int i = elitismOffset; i < halfPopSize; i++)
{
Genome clone = champion.copy();
mutateGenome(clone);
newPopulation.saveGenome(i, clone);
}
// Loop over the population size and create new genomes with
for (int i = halfPopSize; i < pop.size(); i++)
{
Genome localChampion = tournamentSelection(pop);
Genome clone = localChampion.copy();
mutateGenome(clone);
// Genome newGenome = crossover(genome1, genome2);
newPopulation.saveGenome(i, clone);
}
/*
// Mutate population
for (int i = elitismOffset; i < newPopulation.size(); i++) {
mutate(newPopulation.getGenome(i));
}
*/
return newPopulation;
}
示例2: tournamentSelection
// Select Genomes for crossover
private static Genome tournamentSelection(Population pop)
{
// Create a tournament population
Population tournament = new Population(tournamentSize, false);
// For each place in the tournament get a random Genome
for (int i = 0; i < tournamentSize; i++)
{
int randomId = (int)(Random.value * pop.size());
tournament.saveGenome(i, pop.getGenome(randomId));
}
// Get the fittest
Genome fittest = tournament.getFittest();
return fittest;
}