Esempio n. 1
0
 private void ProgressChange(object sender, GeneticAlgorithmChangesEventArgs e)
 {
     //пересылка сообщения
     if (eventProgressChanged != null) //проверяем наличие подписчиков
     {
         eventProgressChanged(this, (int)e.Percent, "%");
     }
 }
Esempio n. 2
0
        // Уведомляет подписанные на событие объекты
        protected virtual void OnProgressChanged(GeneticAlgorithmChangesEventArgs e)
        {
            EventHandler <GeneticAlgorithmChangesEventArgs> tmp = eventProgressChanged;

            if (tmp != null)
            {
                tmp(this, e);
            }
        }
Esempio n. 3
0
        public void BackgroundCalculate()
        {
            try
            {
                tmrTimer.Start();


                int iGenerations = _gap.GenerationsCount;

                DateTime dtStart = DateTime.Now;
                string   strOut;
                maxTime = iGenerations;
                Generation gen;
                if (Cities != null)
                {
                    gen = new Generation(_gap, Cities);
                }
                else
                {
                    throw new Exception("Коллекция городов пуста...");
                }

                for (int i = 0; i < iGenerations; i++)
                {
                    gen.PerformCrossbreeding();
                    gen.PerformMutation();
                    gen.PerformSelection();
                    Agent agent = gen.GetBest();
                    Generation.IsCorruptedRoute(ref agent);
                    _liAgents.Add(agent);

                    curTime = i;

                    int iPercent = 0;
                    //Подсчитываем процент прогресса
                    if (maxTime > 0)
                    {
                        decimal dPercent = (decimal)curTime * 100 / maxTime;
                        iPercent = (int)dPercent;
                    }
                    else
                    {
                    }
                    GeneticAlgorithmChangesEventArgs e = new GeneticAlgorithmChangesEventArgs(iPercent, "%");


                    OnProgressChanged(e);
                }
                //agarrIndividuals = gen.GetAllAgents();



                // Вычисление завершено. Возвращаем результаты по событию
                OnFinally(new EventArgs());
            }
            catch (ThreadAbortException taex)
            { listrTime.Add(taex.Message); }
            catch (Exception ex)
            {
                listrTime.Add(ex.Message);
                throw new Exception(ex.Message + ex.StackTrace);
            }
        }