public static void Run()
        {
            OptimizationProblem sizingOptimizationProblem = new Truss10Benchmark();

            var builder = new DifferentialEvolutionAlgorithmConstrained.Builder(sizingOptimizationProblem);

            builder.PopulationSize       = 100;
            builder.MutationFactor       = 0.6;
            builder.CrossoverProbability = 0.9;
            builder.ConvergenceCriterion = new MaxFunctionEvaluations(200000);
            builder.Penalty = new DeathPenalty();
            IOptimizationAlgorithm de = builder.Build();

            IOptimizationAnalyzer analyzer = new OptimizationAnalyzer(de);

            analyzer.Optimize();

            // Print results
            Console.WriteLine("\n Best Position:");
            for (int i = 0; i < sizingOptimizationProblem.Dimension; i++)
            {
                Console.WriteLine(String.Format(@"  x[{0}] = {1} ", i, de.BestPosition[i]));
            }
            Console.WriteLine(String.Format(@"Best Fitness: {0}", de.BestFitness));
        }
        public static void Run()
        {
            int seed = 2;
            var rng  = new Random(seed);

            OptimizationProblem optimizationProblem = new S_CRES();

            var builder = new DifferentialEvolutionAlgorithmConstrained.Builder(optimizationProblem);

            builder.PopulationSize       = 20;
            builder.MutationFactor       = 0.6;
            builder.CrossoverProbability = 0.9;
            builder.ConvergenceCriterion = new MaxFunctionEvaluations(100000);
            builder.Penalty = new DeathPenalty();
            builder.RandomNumberGenerator = rng;
            IOptimizationAlgorithm de = builder.Build();

            IOptimizationAnalyzer analyzer = new OptimizationAnalyzer(de);

            analyzer.Optimize();

            //TODO: Not sure this is the exact solution. Needs research.
            double expectedFitness = 13.590841691859703;
            var    expectedDesign  = Vector.CreateFromArray(new double[] { 2.246825836986833, 2.3818634605759064 });

            Assert.Equal(expectedFitness, de.BestFitness, 6);
            Assert.True(Vector.CreateFromArray(de.BestPosition).Equals(expectedDesign, 1E-6));
        }
Beispiel #3
0
        public static void Run()
        {
            int seed = 1;
            var rng  = new Random(seed);

            OptimizationProblem optimizationProblem = new Rosenbrock();

            var builder = new DifferentialEvolutionAlgorithm.Builder(optimizationProblem);

            builder.PopulationSize        = 100;
            builder.MutationFactor        = 0.6;
            builder.CrossoverProbability  = 0.9;
            builder.ConvergenceCriterion  = new MaxFunctionEvaluations(100000);
            builder.RandomNumberGenerator = rng;
            IOptimizationAlgorithm de = builder.Build();

            IOptimizationAnalyzer analyzer = new OptimizationAnalyzer(de);

            analyzer.Optimize();

            double expectedFitness = 0.0;
            var    expectedDesign  = Vector.CreateWithValue(optimizationProblem.Dimension, 1.0);

            Assert.Equal(expectedFitness, de.BestFitness, 10);
            Assert.True(Vector.CreateFromArray(de.BestPosition).Equals(expectedDesign, 1E-6));
        }
        public static void Run()
        {
            int seed = 1;
            var rng  = new Random(seed);

            OptimizationProblem optimizationProblem = new Ackley(2);

            var builder = new ParticleSwarmOptimizationAlgorithm.Builder(optimizationProblem);

            builder.SwarmSize             = 10;
            builder.PhiP                  = 2.0;
            builder.PhiG                  = 2.0;
            builder.Omega                 = 0.2;
            builder.ConvergenceCriterion  = new MaxFunctionEvaluations(10000);
            builder.Logger                = new NoLogger();
            builder.RandomNumberGenerator = rng;

            IOptimizationAlgorithm pso      = builder.Build();
            IOptimizationAnalyzer  analyzer = new OptimizationAnalyzer(pso);

            analyzer.Optimize();

            double expectedFitness = 0.0;
            var    expectedDesign  = Vector.CreateZero(optimizationProblem.Dimension);

            Assert.Equal(expectedFitness, pso.BestFitness, 3);
            Assert.True(Vector.CreateFromArray(pso.BestPosition).Equals(expectedDesign, 1E-4));
        }