本文整理汇总了C#中World.Mutate方法的典型用法代码示例。如果您正苦于以下问题:C# World.Mutate方法的具体用法?C# World.Mutate怎么用?C# World.Mutate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.Mutate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MutateShouldCheckMutationChance
public void MutateShouldCheckMutationChance()
{
// Arrange
int worldSize = 4;
int geneCount = 6;
int swapPosition = 3;
int crossOverChance = 0;
int mutationChance = 0;
RandomStub random = new RandomStub(0, 5);
World world = new World(geneCount, worldSize, crossOverChance, mutationChance);
Genome genome1 = Genome.FromString("000 111");
Genome genome2 = Genome.FromString("111 001");
world.Population.Add(genome1);
world.Population.Add(genome2);
// Act
world.Mutate(random);
string g1 = world.Population[0].ToString();
string g2 = world.Population[1].ToString();
// Assert
Assert.That(g1, Is.StringStarting("000 111"));
Assert.That(g2, Is.StringStarting("111 001"));
}
示例2: NextGeneration
public void NextGeneration()
{
// Arrange
int worldSize = 4;
int geneCount = 6;
int crossOverChance = 30;
int mutationChance = 5;
World world = new World(geneCount, worldSize, crossOverChance, mutationChance);
world.InitializePopulation();
// Act
int generation = 0;
Genome champion = null;
while (champion == null)
{
world.Mutate();
world.CrossOver();
world.NextGeneration();
Console.WriteLine(world);
generation++;
champion = world.GetChampion();
}
Console.WriteLine("A new leader is born! generation {0} - {1}", generation, champion);
}
示例3: Mutate
public void Mutate()
{
//
// Arrange
//
int worldSize = 4;
int geneCount = 6;
int swapPosition = 3;
int crossOverChance = 0;
int mutationChance = 100;
RandomStub random = new RandomStub(0, 5);
World world = new World(geneCount, worldSize, crossOverChance, mutationChance);
// - Two genomes:
// 000 111
// 111 001
//
// Mutate both using position 1 and 5:
//
// 0[0]0 11[1] = 0[1]0 11[0]
// 1[1]1 00[1] = 0[1]0 11[1]
Genome genome1 = Genome.FromString("000 111");
Genome genome2 = Genome.FromString("111 001");
world.Population.Add(genome1);
world.Population.Add(genome2);
string g1 = genome1.ToString();
string g2 = genome2.ToString();
// Act
Console.WriteLine("Before:");
Console.WriteLine(g1);
Console.WriteLine(g2);
world.Mutate(random);
// Assert
string g1a = genome1.ToString();
string g2a = genome2.ToString();
Console.WriteLine("------");
Console.WriteLine("After:");
Console.WriteLine(g1a);
Console.WriteLine(g2a);
Assert.That(g1a, Is.StringStarting("100 110"));
Assert.That(g2a, Is.StringStarting("111 001"));
}