Beispiel #1
0
        public DEMinimizerResult Run(DEHyperParameter param, double valueToReach, int numGenerations = int.MaxValue, IEvolutionWorker worker = null)
        {
            if (worker == null)
            {
                worker = EvolutionWorkerFactory.createSingleThreaded();
            }

            // Initialize populations
            population = new double[param.Individuals][];
            cost       = new double[param.Individuals];
            cost[0]    = double.MaxValue;
            for (int n = 0; n < param.Individuals; n++)
            {
                population[n] = new double[dim];
                RandomUtils.RandomizeAgent(population[n], minRange, maxRange, rng);
                cost[n] = int.MaxValue;
            }

            int g = 0;

            for (g = 0; g < numGenerations; g++)
            {
                int[] slices = worker.SliceStrategy(param.Individuals);
                for (int i = 0; i < slices.Length; i += 2)
                {
                    int start = slices[i];
                    int end   = slices[i + 1];
                    worker.Submit(new DEMinimizerWork(this, DE, population, cost, dim, rng, param, start, end));
                }

                worker.Start();
                worker.Join();

                if (valueToReach >= cost[minCostIdx])
                {
                    break;
                }
            }

            return(new DEMinimizerResult(cost[minCostIdx], population[minCostIdx], g));
        }
Beispiel #2
0
 public override double MutateVectorElement(DEHyperParameter hp, double a, double b, double c, double min, double max, Random rng)
 {
     return(EnsureBounds(c + hp.F * (a - b), min, max, rng));
 }