Esempio n. 1
0
        private void UpdatePositionAndVelocity()
        {
            for (int i = 0; i < swarmSize; i++)
            {
                int rp = randomNumberGenerator.Next(dimension);
                int rg = randomNumberGenerator.Next(dimension);

                individuals[i].Velocity = VectorOperations.Add(VectorOperations.Add(VectorOperations.Scale(omega, individuals[i].Velocity),
                                                                                    VectorOperations.Scale(phip, VectorOperations.Scale(rp, VectorOperations.Subtract(BestPosition, individuals[i].Position)))),
                                                               VectorOperations.Scale(phig, VectorOperations.Scale(rg, VectorOperations.Subtract(individuals[i].PersonalBestPosition, individuals[i].Position))));

                individuals[i].Position = VectorOperations.Add(individuals[i].Position, individuals[i].Velocity);
            }
        }
        /// <summary>
        ///     Performs mutation of the population according to de/rand/1/bin scheme
        /// </summary>
        private void Mutation()
        {
            offsprings = new Individual[populationSize];

            for (int i = 0; i < populationSize; i++)
            {
                int r1 = randomNumberGenerator.Next(populationSize);
                int r2 = randomNumberGenerator.Next(populationSize);
                int r3 = randomNumberGenerator.Next(populationSize);


                double[] donorVector = VectorOperations.Add(individuals[r1].Position, VectorOperations.Scale(mutationFactor, VectorOperations.Subtract(individuals[r2].Position, individuals[r3].Position)));

                offsprings[i] = new Individual(donorVector, double.MaxValue);
            }
        }