本文整理汇总了C#中Engine.NextGeneration方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.NextGeneration方法的具体用法?C# Engine.NextGeneration怎么用?C# Engine.NextGeneration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Engine
的用法示例。
在下文中一共展示了Engine.NextGeneration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThreeAliveCellsRotate
public void ThreeAliveCellsRotate()
{
var p11 = new CartesianPosition(1, 1);
var p12 = new CartesianPosition(1, 2);
var p13 = new CartesianPosition(1, 3);
var stateHolder = new StateHolder();
stateHolder.SetState(p11, new Alive());
stateHolder.SetState(p12, new Alive());
stateHolder.SetState(p13, new Alive());
var engine = new Engine<CartesianPosition>(stateHolder, new CartesianSpaceLimits());
var secondGeneration = engine.NextGeneration();
Assert.Equal(new Dead(), secondGeneration.GetState(p11));
Assert.Equal(new Alive(), secondGeneration.GetState(p12));
Assert.Equal(new Dead(), secondGeneration.GetState(p13));
var thirdGeneration = engine.NextGeneration();
Assert.Equal(new Alive(), thirdGeneration.GetState(p11));
Assert.Equal(new Alive(), thirdGeneration.GetState(p12));
Assert.Equal(new Alive(), thirdGeneration.GetState(p13));
}
示例2: EasyGaTest
public void EasyGaTest()
{
MultipointCrossover<ListGenotype<BitGene>, BitGene, double> crossover =
new MultipointCrossover<ListGenotype<BitGene>, BitGene, double>(1);
EasyGa<ListGenotype<BitGene>, double> algorithm =
new EasyGa<ListGenotype<BitGene>, double>.Builder()
.WithElitismPercentage(0.5)
.WithFitnessFunction(g => g.Count(b => b.Value))
.WithStopCriteria(
StopCriteriaBuilder.StopAtGeneration<ListGenotype<BitGene>, double>(2500)
.Or(StopCriteriaBuilder.StopAtFitness<ListGenotype<BitGene>, double>(20)))
.RegisterBreeder(new BitBreeder(20, 20))
.Register(new RouletteWheelSelector<ListGenotype<BitGene>>(20))
.Register(new Recombinator<ListGenotype<BitGene>, double>(crossover, 2, 10,
Recombinator<ListGenotype<BitGene>, double>.RecombinatioNumberType.Absolute))
.Register(new BitBaseMutator<ListGenotype<BitGene>, double>(0.05))
.Build();
Engine<ListGenotype<BitGene>, double> engine = new Engine<ListGenotype<BitGene>, double>.Builder()
.WithAlgorithm(algorithm)
.Build();
while (!engine.HasReachedStopCriteria)
{
//if (engine.World != null)
//{
// TestContext.WriteLine($"Generation {engine.World.Generation} (Size: {engine.World.Population.Count})");
// foreach (Individual<ListGenotype<BitGene>, double> individual in engine.World.Population)
// {
// TestContext.WriteLine(individual);
// }
//}
engine.NextGeneration();
}
TestContext.WriteLine($"{engine.CurrentWorld.Generation} generations reached");
TestContext.WriteLine($"{engine.Statistics.BestIndividualGeneration} is best indivual's generation");
TestContext.WriteLine($"{engine.Statistics.BestFitness} is best Fitness");
TestContext.WriteLine($"{engine.Statistics.BestGenotype} is best Genotype");
}
示例3: FourAliveCellsStayAlive
public void FourAliveCellsStayAlive()
{
var p00 = new CartesianPosition(0, 0);
var p01 = new CartesianPosition(0, 1);
var p11 = new CartesianPosition(1, 1);
var p10 = new CartesianPosition(1, 0);
var stateHolder = new StateHolder();
stateHolder.SetState(p00, new Alive());
stateHolder.SetState(p01, new Alive());
stateHolder.SetState(p11, new Alive());
stateHolder.SetState(p10, new Alive());
var engine = new Engine<CartesianPosition>(stateHolder, new CartesianSpaceLimits());
var secondGeneration = engine.NextGeneration();
Assert.Equal(new Alive(), stateHolder.GetState(p00));
Assert.Equal(new Alive(), stateHolder.GetState(p01));
Assert.Equal(new Alive(), stateHolder.GetState(p11));
Assert.Equal(new Alive(), stateHolder.GetState(p10));
}