public async Task RunAsync() { var population = new List <Chromosome <T> >(); foreach (var _ in Enumerable.Range(0, geneticOptions.PopulationSize)) { var chromosome = await geneticAlgorithm.CreateChromosomeAsync(); population.Add(chromosome); } var sortedPopulation = population.OrderByDescending(c => c.Fitness); var generations = 1; while (sortedPopulation.First().Fitness < geneticOptions.SatisfactoryFitnessValue) { var elitesToTake = (int)Math.Floor( geneticOptions.PopulationSize * (geneticOptions.ElitismPercentage / 100)); var newPopulation = sortedPopulation.Take(elitesToTake).ToList(); ApplyCrossover(sortedPopulation, newPopulation); await ApplyMutationAsync(newPopulation); sortedPopulation = newPopulation.OrderByDescending(c => c.Fitness); generations += 1; } var bestChromosome = sortedPopulation.First(); Console.WriteLine($"Кількість поколінь: {generations}\n"); Console.WriteLine(outputManager.GetOutput(bestChromosome.Genes)); }
public async Task RunAsync() { await backtrackingAlgorithm.GenerateBasicSolutionAsync(); var items = new List <T>(); if (!backtrackingAlgorithm.BacktrackingSearch(items)) { Console.WriteLine("Розв\'язків немає"); } Console.WriteLine(outputManager.GetOutput(items)); }