Example #1
0
        private static string PrintChromosomes([NotNull] GeneticCompoundFDPOptimizer optimizer)
        {
            StringBuilder strBuilder = new StringBuilder();

            for (int i = 0; i < optimizer.Population.Length; i++)
            {
                CompoundFDPLayoutParameters chromosome = optimizer.Population[i];

                strBuilder.AppendLine($"---------- Chromosome[{i}] ---------------");
                strBuilder.AppendLine($"ElasticConstant: {chromosome.ElasticConstant}");
                strBuilder.AppendLine($"RepulsionConstant: {chromosome.RepulsionConstant}");
                strBuilder.AppendLine($"GravitationFactor: {chromosome.GravitationFactor}");
                strBuilder.AppendLine($"NestingFactor: {chromosome.NestingFactor}");
                strBuilder.AppendLine($"Phase1Iterations: {chromosome.Phase1Iterations}");
                strBuilder.AppendLine($"Phase2Iterations: {chromosome.Phase2Iterations}");
                strBuilder.AppendLine($"Phase3Iterations: {chromosome.Phase3Iterations}");
                strBuilder.AppendLine($"DisplacementLimitMultiplier: {chromosome.DisplacementLimitMultiplier}");
                strBuilder.AppendLine($"SeparationMultiplier: {chromosome.SeparationMultiplier}");
                strBuilder.AppendLine($"TemperatureDecreasing: {chromosome.TemperatureDecreasing}");
                strBuilder.AppendLine($"Fitness: {optimizer.Fitnesses[i]}");
                strBuilder.AppendLine("---------------------------------------------");
            }

            return(strBuilder.ToString());
        }
Example #2
0
        private async void RunOptimizer([NotNull] object sender, [NotNull] RoutedEventArgs args)
        {
            await Task.Run(() =>
            {
                var parameters = new GeneticAlgorithmParameters
                {
                    CrossoverRate  = 0.85,
                    ElitismRate    = 0.1,
                    Generations    = 300,
                    MutationRate   = 0.7,
                    PopulationSize = 50
                };

                var optimizer = new GeneticCompoundFDPOptimizer(parameters);

                optimizer.GenerationExtincts += OnGenerationExtincts;
                optimizer.Run();
                optimizer.GenerationExtincts -= OnGenerationExtincts;

                PrintChromosomes(optimizer);

                void OnGenerationExtincts(int generation)
                {
                    Dispatcher.Invoke(() =>
                    {
                        FeedbackLabel.Text    = $"Generation {generation}/{parameters.Generations}";
                        GenerationResult.Text = PrintChromosomes(optimizer);
                    });
                }
            });
        }
Example #3
0
 private void Run_Optimizer(object sender, RoutedEventArgs e)
 {
     var parameters = new GeneticAlgorithm.GeneticAlgorithmParameters
                          {
                              CrossoverRate = 0.85,
                              ElitismRate = 0.1,
                              Generations = 300,
                              MutationRate = 0.7,
                              PopulationSize = 50
                          };
     var optimizer = new GeneticCompoundFDPOptimizer(parameters);
     optimizer.GenerationExtincts += (generation) =>
                                         {
                                             Console.WriteLine("Generation {0}", generation);
                                             PrintChromosomes(optimizer);
                                         };
     optimizer.Run();
     Console.WriteLine("Last generation");
     PrintChromosomes(optimizer);
 }
        private void Run_Optimizer(object sender, RoutedEventArgs e)
        {
            var parameters = new GeneticAlgorithm.GeneticAlgorithmParameters
            {
                CrossoverRate  = 0.85,
                ElitismRate    = 0.1,
                Generations    = 300,
                MutationRate   = 0.7,
                PopulationSize = 50
            };
            var optimizer = new GeneticCompoundFDPOptimizer(parameters);

            optimizer.GenerationExtincts += (generation) =>
            {
                Console.WriteLine("Generation {0}", generation);
                PrintChromosomes(optimizer);
            };
            optimizer.Run();
            Console.WriteLine("Last generation");
            PrintChromosomes(optimizer);
        }
 private void PrintChromosomes(GeneticCompoundFDPOptimizer optimizer)
 {
     for (int i = 0; i < optimizer.Population.Count; i++)
     {
         var chromosome = optimizer.Population[i];
         Console.WriteLine("Chromosome[{0}]::::::", i);
         Console.WriteLine(chromosome.ElasticConstant);
         Console.WriteLine(chromosome.RepulsionConstant);
         Console.WriteLine(chromosome.GravitationFactor);
         Console.WriteLine(chromosome.NestingFactor);
         Console.WriteLine(chromosome.Phase1Iterations);
         Console.WriteLine(chromosome.Phase2Iterations);
         Console.WriteLine(chromosome.Phase3Iterations);
         Console.WriteLine(chromosome.DisplacementLimitMultiplier);
         Console.WriteLine(chromosome.SeparationMultiplier);
         Console.WriteLine(chromosome.TemperatureDecreasing);
         Console.WriteLine(chromosome.TemperatureFactor);
         Console.WriteLine("Fitness: {0}", optimizer.Fitnesses[i]);
         Console.WriteLine(
             "---------------------------------------------");
     }
 }
Example #6
0
 private void PrintChromosomes(GeneticCompoundFDPOptimizer optimizer)
 {
     for (int i = 0; i < optimizer.Population.Count; i++)
     {
         var chromosome = optimizer.Population[i];
         Console.WriteLine("Chromosome[{0}]::::::", i);
         Console.WriteLine(chromosome.ElasticConstant);
         Console.WriteLine(chromosome.RepulsionConstant);
         Console.WriteLine(chromosome.GravitationFactor);
         Console.WriteLine(chromosome.NestingFactor);
         Console.WriteLine(chromosome.Phase1Iterations);
         Console.WriteLine(chromosome.Phase2Iterations);
         Console.WriteLine(chromosome.Phase3Iterations);
         Console.WriteLine(chromosome.DisplacementLimitMultiplier);
         Console.WriteLine(chromosome.SeparationMultiplier);
         Console.WriteLine(chromosome.TemperatureDecreasing);
         Console.WriteLine(chromosome.TemperatureFactor);
         Console.WriteLine("Fitness: {0}", optimizer.Fitnesses[i]);
         Console.WriteLine(
             "---------------------------------------------");
     }
 }