예제 #1
0
        /// <summary>
        /// Найти минимум функции уже по готовому рою
        /// </summary>
        /// <param name="hive"></param>
        /// <param name="eps"></param>
        /// <param name="maxcountstep"></param>
        /// <param name="maxiter"></param>
        /// <returns></returns>
        private static Tuple <Vectors, double> Gets(Hive hive, double eps = 1e-10, int maxcountstep = 100, int maxiter = 150)
        {
            if (maxiter <= 0)
            {
                maxiter = Int32.MaxValue;
            }
            double e = hive.val;
            int    c = maxcountstep, k = 0;

            Console.WriteLine($"Погрешность после инициализации пчёл:  {e}");
            while (e > eps && maxcountstep > 0 && hive.Radius > eps)
            {
                hive.MakeStep(w, fp, fg);
                k++;
                if (hive.val < e)
                {
                    Console.WriteLine($"Hive method (iter {k}):  {e} ---> {hive.val}");
                    e            = hive.val;
                    maxcountstep = c;
                    hive.g.Save($"val = {e}.txt");
                }
                else
                {
                    maxcountstep--;
                }
                //Debug.WriteLine( $"c = {maxcountstep}  val = {hive.val}");
                if (k == maxiter)
                {
                    break;
                }
            }
            return(new Tuple <Vectors, double>(hive.g, hive.val));
        }