Пример #1
0
        /// <summary>
        /// Update the velocity of a particle
        /// </summary>
        /// <param name="particleIndex">index of the particle in the swarm</param>
        /// <param name="particlePosition">the particle current position vector</param>
        protected void UpdateVelocity(int particleIndex, double[] particlePosition)
        {
            int i = particleIndex;

            double[] vtmp = new double[particlePosition.Length];

            // Standard PSO formula

            // inertia weight
            m_va.Mul(m_velocities[i], m_inertiaWeight);

            // cognitive term
            m_va.Copy(vtmp, m_bestVectors[i]);
            m_va.Sub(vtmp, particlePosition);
            m_va.MulRand(vtmp, m_c1);
            m_va.Add(m_velocities[i], vtmp);

            // social term
            if (i != m_bestVectorIndex)
            {
                m_va.Copy(vtmp, m_pseudoAsynchronousUpdate ? m_bestVectors[m_bestVectorIndex] : m_bestVector);
                m_va.Sub(vtmp, particlePosition);
                m_va.MulRand(vtmp, m_c2);
                m_va.Add(m_velocities[i], vtmp);
            }
        }
Пример #2
0
        /**
         * Update the velocity of a particle
         *
         * @param particleIndex index of the particle in the swarm
         */
        protected void UpdateVelocity(int particleIndex)
        {
            double[] particlePosition = _particles[particleIndex].LongTermMemory;
            double[] vtmp             = new double[particlePosition.Length];


            // Standard PSO formula

            // inertia weight
            VectorAlgebra.Mul(_velocities[particleIndex], inertiaWeight);

            // cognitive term
            VectorAlgebra.Copy(vtmp, _bestVectors[particleIndex]);
            VectorAlgebra.Sub(vtmp, particlePosition);
            VectorAlgebra.MulRand(_rnd, vtmp, this.c1);
            VectorAlgebra.Add(_velocities[particleIndex], vtmp);

            // social term
            if (particleIndex != _bestVectorIndex)
            {
                VectorAlgebra.Copy(vtmp, _bestVector);
                VectorAlgebra.Sub(vtmp, particlePosition);
                VectorAlgebra.MulRand(_rnd, vtmp, c2);
                VectorAlgebra.Add(_velocities[particleIndex], vtmp);
            }
        }