Beispiel #1
0
        public Particle(Swarm swarm)
        {
            //_random = new Random ();
            _swarm = swarm;

            _currentPosition = GetInitPosition(swarm);
            _localBestPosition = (double[])_currentPosition.Clone();
            _localBestFinalFunc = swarm.FinalFunction(_currentPosition);

            _velocity = GetInitVelocity(swarm);
        }
Beispiel #2
0
        public static string ResultToString(Swarm swarm)
        {
            StringBuilder builder = new StringBuilder ();

            builder.AppendFormat ("Iteration: {0}\n\n", swarm.Iteration);

            if (swarm.BestPosition != null)
            {
                for (int i = 0; i < swarm.Dimension; i++)
                {
                    builder.AppendFormat ("X[{0}] = {1}\n", i, swarm.BestPosition[i]);
                }

                builder.AppendFormat ("\nFinal function: {0}\n", swarm.BestFinalFunc);
            }
            builder.Append ("-----------\n\n");

            return builder.ToString ();
        }
Beispiel #3
0
        /// <summary>
        /// Получить начальное значение скорости
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        double[] GetInitVelocity(Swarm swarm)
        {
            double[] velocity = new double[swarm.Dimension];

            for (int i = 0; i < swarm.Dimension; i++)
            {
                double minval = -(swarm.MaxValues[i] - swarm.MinValues[i]);
                double maxval = (swarm.MaxValues[i] - swarm.MinValues[i]);

                velocity[i] = _random.NextDouble() * (maxval - minval) + minval;
            }

            Debug.Assert(velocity.Length == swarm.MinValues.Length);
            Debug.Assert(velocity.Length == swarm.MaxValues.Length);

            return velocity;
        }
Beispiel #4
0
        double[] GetInitPosition(Swarm swarm)
        {
            double[] position = new double[swarm.Dimension];

            for (int i = 0; i < swarm.Dimension; i++)
            {
                position[i] = _random.NextDouble() *
                    (swarm.MaxValues[i] - swarm.MinValues[i]) + swarm.MinValues[i];
            }

            Debug.Assert(position.Length == swarm.MinValues.Length);
            Debug.Assert(position.Length == swarm.MaxValues.Length);

            return position;
        }