コード例 #1
0
        // Иссдедование алгоритма с переданными параметрами.
        public ResearchAlgorithmResponse ResearchAlgorithm(ResearchRequest param)
        {
            Graph  graph   = _graphBL.GetById(param.GraphId);
            double avgTime = 0.0;
            int    error   = 0;
            // Инициализация алгоритма с переданными параметрами.
            GeneticAlgorithmCore ga = new GeneticAlgorithmCore(graph, param.PopulationSize, param.Pm, param.Pc);

            // Многократный запуск алгоритма для оценки времени работы и процента ошибок.
            for (int i = 0; i < _testCount; i++)
            {
                // Запуск алгоритма и получение результатов
                FindingVertexResponse algResult = ga.StartAlgorithm();
                // проверка на верность найденного решения
                if (algResult.R != graph.R)
                {
                    error++;
                }
                // увеличение суммарного времени работы
                avgTime += algResult.Time;
            }
            // возвращение результата в виде среднего
            // значения времени работы и процента неверных ответов
            return(new ResearchAlgorithmResponse()
            {
                AvgTime = avgTime / _testCount,
                Error = error / (double)_testCount * 100.0,
            });
        }
コード例 #2
0
ファイル: Algorithm.cs プロジェクト: VlasovAndrew/GAWeb
        // ������������ ��������� � ����������� �����������.
        public ResearchAlgorithmResponse ResearchAlgorithm(ResearchRequest param)
        {
            Graph  graph   = _graphBL.GetById(param.GraphId);
            double avgTime = 0.0;
            int    error   = 0;
            // ������������� ��������� � ����������� �����������.
            GeneticAlgorithmCore ga = new GeneticAlgorithmCore(graph, param.PopulationSize, param.Pm, param.Pc);

            // ������������ ������ ��������� ��� ������ ������� ������ � �������� ������.
            for (int i = 0; i < _testCount; i++)
            {
                // ������ ��������� � ��������� �����������
                FindingVertexResponse algResult = ga.StartAlgorithm();
                // �������� �� �������� ���������� �������
                if (algResult.R != graph.R)
                {
                    error++;
                }
                // ���������� ���������� ������� ������
                avgTime += algResult.Time;
            }
            // ����������� ���������� � ���� ��������
            // �������� ������� ������ � �������� �������� �������
            return(new ResearchAlgorithmResponse()
            {
                AvgTime = avgTime / _testCount,
                Error = error / (double)_testCount * 100.0,
            });
        }
コード例 #3
0
        public void GeneticAlgorithmTets()
        {
            string[]              lines       = File.ReadAllLines("BarabasiAlbertGraph1_M2.txt");
            GraphParser           graphParser = new GraphParser();
            Graph                 graph       = graphParser.ParseSimpleTxtFormat(lines);
            GeneticAlgorithmCore  ga          = new GeneticAlgorithmCore(graph, 20, 0.4, 0.4);
            FindingVertexResponse result      = ga.StartAlgorithm();

            Console.WriteLine(result.R);
        }
コード例 #4
0
ファイル: GraphController.cs プロジェクト: VlasovAndrew/GAWeb
 public ActionResult FindCentralVertex(HttpPostedFileBase upload)
 {
     if (upload == null)
     {
         return(View("~/Views/Shared/Error.cshtml", model: "���� �� ��� ������"));
     }
     try
     {
         Graph graph = ReadGraph(upload);
         FindingVertexResponse algorithmResult = _algorithmWork.FindCentralVertex(graph);
         return(View("CalculationResult", algorithmResult));
     }
     catch (FormatException e)
     {
         return(View("~/Views/Shared/Error.cshtml", model: e.Message));
     }
 }
コード例 #5
0
        // Метод для старта алгоритма.
        public FindingVertexResponse StartAlgorithm()
        {
            // Начальная инициализация
            Init();
            // Запуск измерения времени работы.
            _watch.Start();
            for (int i = 0; i < _step; i++)
            {
                EvolutionStep();
            }
            // Окончание измерений.
            _watch.Stop();

            FindingVertexResponse res = new FindingVertexResponse()
            {
                Time = _watch.ElapsedMilliseconds / (double)1000,
            };

            GetBestResult(res);
            return(res);
        }
コード例 #6
0
        // Поиск минимального эксцентриситета - центральных вершин,
        // и радиуса графа.
        private void GetBestResult(FindingVertexResponse res)
        {
            List <int> e = new List <int>();

            foreach (var v in _population)
            {
                e.Add(_graphContext.GetEccentricity(v));
            }
            int           R         = e.Min();
            HashSet <int> resVertex = new HashSet <int>();

            for (int i = 0; i < e.Count; i++)
            {
                if (e[i] == R)
                {
                    resVertex.Add(_population[i]);
                }
            }
            res.Center = resVertex.ToArray();
            res.R      = R;
        }
コード例 #7
0
        // ����� ��� ������ ���������.
        public FindingVertexResponse StartAlgorithm()
        {
            // ��������� �������������
            Init();
            // ������ ��������� ������� ������.
            _watch.Start();
            for (int i = 0; i < _step; i++)
            {
                EvolutionStep();
            }
            // ��������� ���������.
            _watch.Stop();

            FindingVertexResponse res = new FindingVertexResponse()
            {
                Time = _watch.ElapsedMilliseconds / (double)1000,
            };

            GetBestResult(res);
            return(res);
        }
コード例 #8
0
 public ActionResult FindCentralVertex(HttpPostedFileBase upload)
 {
     // проверка выбрал ли пользоватль граф
     if (upload == null)
     {
         return(View("~/Views/Shared/Error.cshtml", model: "Файл не был выбран"));
     }
     try
     {
         // чтение строк файла
         Graph graph = ReadGraph(upload);
         // запуск алгоритма
         FindingVertexResponse algorithmResult = _algorithmWork.FindCentralVertex(graph);
         // возврат представления с полученными результатами
         return(View("CalculationResult", algorithmResult));
     }
     catch (FormatException e)
     {
         // при выбрасывании исключения возвращается
         // представление с сообщением об ошибке
         return(View("~/Views/Shared/Error.cshtml", model: e.Message));
     }
 }