Esempio n. 1
0
        public virtual double CalculateVelocityUpdate(Particle gbest, int i)
        {
            PSONS.Settings settings  = Configuration;
            Parameter      parameter = Parameters[i];

            double r1 = State.Random.Range(0, 1);
            double r2 = State.Random.Range(0, 1);

            double pg       = 0;
            double pl       = 0;
            double momentum = 0;

            // Global best difference
            if (gbest != null && (State.VelocityUpdateComponents & State.VelocityUpdateType.DisableGlobal) == 0)
            {
                pg = gbest.Parameters[i].Value - parameter.Value;
            }

            // Local best difference
            if (d_personalBest != null && (int)(State.VelocityUpdateComponents & State.VelocityUpdateType.DisableLocal) == 0)
            {
                pl = d_personalBest.Parameters[i].Value - parameter.Value;
            }

            if ((int)(State.VelocityUpdateComponents & State.VelocityUpdateType.DisableMomentum) == 0)
            {
                momentum = d_velocity[i];
            }

            // PSO velocity update rule
            return(settings.Constriction * (momentum +
                                            r1 * settings.CognitiveFactor * pl +
                                            r2 * settings.SocialFactor * pg));
        }
Esempio n. 2
0
        private void LimitVelocity(int idx)
        {
            PSONS.Settings settings = Configuration;
            double         maxvel   = settings.MaxVelocity * (Parameters[idx].Boundary.Max - Parameters[idx].Boundary.Min);

            if (maxvel > 0 && System.Math.Abs(d_velocity[idx]) > maxvel)
            {
                d_velocity[idx] = d_velocity[idx] > 0 ? maxvel : -maxvel;
            }
        }