/// <summary> /// Initializes a new instance of the <see cref="GeneticSharp.Domain.Populations.Population"/> class. /// </summary> /// <param name="minSize">The minimum size (chromosomes).</param> /// <param name="maxSize">The maximum size (chromosomes).</param> /// <param name="adamChromosome">The original chromosome of all population ;).</param> public Population(int minSize, int maxSize, IChromosome adamChromosome) { if (minSize < 2) { throw new ArgumentOutOfRangeException("minSize", "The minimum size for a population is 2 chromosomes."); } if (maxSize < minSize) { throw new ArgumentOutOfRangeException("maxSize", "The maximum size for a population should be equal or greater than minimum size."); } ExceptionHelper.ThrowIfNull("adamChromosome", adamChromosome); CreationDate = DateTime.Now; MinSize = minSize; MaxSize = maxSize; AdamChromosome = adamChromosome; Generations = new List<Generation>(); GenerationStrategy = new PerformanceGenerationStrategy(10); }
/// <summary> /// Initializes a new instance of the <see cref="GeneticSharp.Domain.Populations.Population"/> class. /// </summary> /// <param name="minSize">The minimum size (chromosomes).</param> /// <param name="maxSize">The maximum size (chromosomes).</param> /// <param name="adamChromosome">The original chromosome of all population ;).</param> public Population(int minSize, int maxSize, IChromosome adamChromosome) { if (minSize < 2) { throw new ArgumentOutOfRangeException("minSize", "The minimum size for a population is 2 chromosomes."); } if (maxSize < minSize) { throw new ArgumentOutOfRangeException("maxSize", "The maximum size for a population should be equal or greater than minimum size."); } ExceptionHelper.ThrowIfNull("adamChromosome", adamChromosome); CreationDate = DateTime.Now; MinSize = minSize; MaxSize = maxSize; AdamChromosome = adamChromosome; Generations = new List <Generation>(); GenerationStrategy = new PerformanceGenerationStrategy(10); }
public void RegisterNewGeneration_GenerationExceedGenerationsNumber_RemoveOldOne() { var target = new PerformanceGenerationStrategy(); var population = new Population(2, 6, new ChromosomeStub()); population.CreateInitialGeneration(); target.RegisterNewGeneration(population); Assert.AreEqual(1, population.Generations.Count); population.CreateNewGeneration(new List<IChromosome>() { new ChromosomeStub(), new ChromosomeStub() }); target.RegisterNewGeneration(population); Assert.AreEqual(1, population.Generations.Count); population.CreateNewGeneration(new List<IChromosome>() { new ChromosomeStub(), new ChromosomeStub() }); target.RegisterNewGeneration(population); Assert.AreEqual(1, population.Generations.Count); population.CreateNewGeneration(new List<IChromosome>() { new ChromosomeStub(), new ChromosomeStub() }); target.RegisterNewGeneration(population); Assert.AreEqual(1, population.Generations.Count); }