Example #1
0
        // ReSharper restore ParameterTypeCanBeEnumerable.Local
        // ReSharper disable ParameterTypeCanBeEnumerable.Local
        public GeneticSolver(int maxGenerationsWithoutImprovement, ICollection<IChildGenerationStrategy> childGenerationStrategies)
        {
            _gaMaxGenerationsWithoutImprovement = maxGenerationsWithoutImprovement;

            _childGenerationStrategies = new List<Pair<decimal, IChildGenerationStrategy>>(
                childGenerationStrategies
                    .OrderBy(x => x.OrderBy)
                    .Select(x => new Pair<decimal, IChildGenerationStrategy>(100m / childGenerationStrategies.Count, x))
                );

            _randomStrategy = childGenerationStrategies.FirstOrDefault(x => x.GetType() == typeof(RandomGenes)) ?? new RandomGenes();
            _mutationStrategy = new MutationMidUnitOfMeaning();

            OnlyPermuteNewGenesWhileHillClimbing = true;
            DisplayGenes = (generation, fitness, genes, howCreated) => Console.WriteLine("Generation {0} fitness {1}: {2}", generation.ToString().PadLeft(_gaMaxGenerationsWithoutImprovement.ToString().Length), fitness, genes);
        }
Example #2
0
 public GeneSequence(char[] genes, IChildGenerationStrategy strategy)
 {
     Genes = genes;
     Fitness = DefaultFitness;
     Strategy = strategy;
 }