示例#1
0
        private void mnRunVisualization_Click(object sender, EventArgs e)
        {
            if (Runtime.currentAlgorithm == null)
            {
                Log.Write("Can't determine selected algorithm.");
                return;
            }
            if (Runtime.currentGraph == null)
            {
                Log.Write("Please, load graph first.");
                return;
            }
            if (Runtime.currentAlgorithm.Instance is BaseMaxFlowAlgorithm)
            {
                //Clone selected algorithm. Won't write algorithm reset method
                BaseMaxFlowAlgorithm algorithm         = Runtime.currentAlgorithm.Instance.Clone();
                Animator             algorithmAnimator = new Animator();
                algorithmAnimator.OnAnimationTick += Visualizer.GetAnimation;

                algorithmAnimator.OnAnimationStarted += animator =>
                {
                    mnStopAnimation.Visible = true;
                };
                algorithmAnimator.OnAnimationFinished += animator =>
                {
                    mnStopAnimation.Visible = false;
                    OnAlgorithmFinished(algorithm);
                };

                algorithmAnimator.Run();

                //Subscribe for events for visualization needs
                algorithm.OnEdgeFlowChanged += algorithmAnimator.EdgeFlowChanged;
                algorithm.OnEdgeMarked      += algorithmAnimator.EdgeMarked;
                algorithm.OnEdgeUnmarked    += algorithmAnimator.EdgeUnmarked;

                algorithm.OnFinish += flowAlgorithm =>
                {
                    algorithmAnimator.AlgorithmFinished = true;
                };

                algorithm.SetGraph(Runtime.currentGraph);
                algorithm.RunAsync();
            }
        }
示例#2
0
 private void runWithoutVisualizationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (Runtime.currentAlgorithm == null)
     {
         Log.Write("Can't determine selected algorithm.");
         return;
     }
     if (Runtime.currentGraph == null)
     {
         Log.Write("Please, load graph first.");
         return;
     }
     if (Runtime.currentAlgorithm.Instance is BaseMaxFlowAlgorithm)
     {
         BaseMaxFlowAlgorithm algorithm = Runtime.currentAlgorithm.Instance.Clone();
         algorithm.OnFinish += OnAlgorithmFinished;
         algorithm.SetGraph(Runtime.currentGraph);
         algorithm.RunAsync();
     }
 }
        private void btnRun_Click(object sender, EventArgs e)
        {
            var perfTest = new PerformanceCounter();

            if (cblAlgorithms.CheckedIndices != null)
            {
                foreach (var item in cblAlgorithms.CheckedIndices)
                {
                    BaseMaxFlowAlgorithm algo = Runtime.loadedAlghoritms[(int)item].Instance;
                    for (int i = 0; i < udRunsCount.Value; i++)
                    {
                        BaseMaxFlowAlgorithm a = algo.Clone() as BaseMaxFlowAlgorithm;

                        a.OnFinish += (s) =>
                        {
                            perfTest.RegisterRun(s.GetName(), s.Elapsed, s.MaxFlow);
                        };
                        a.SetGraph(Runtime.currentGraph);
                        a.Run();
                    }
                    updateDataGrid(perfTest);
                }
            }
        }
        private void RunMultipleTests()
        {
            // тестовый метод для сбора статистики - запуск алгоритмов на нескольких файлах из директории rootDir
            var importer = new Importer();
            var rootDir  = new DirectoryInfo("E:\\wash\\test_sets");

            foreach (var workDir in rootDir.GetDirectories())
            {
                Log.Write($"Processing {workDir.Name}");
                foreach (var setDir in workDir.GetDirectories())
                {
                    Log.Write($"    Processing {setDir.Name}");
                    //файл для выгрузки собранной статистики
                    var statFile = new FileInfo(Path.Combine(setDir.FullName, "stats.csv"));
                    var counters = new Dictionary <int, PerformanceCounter>();
                    foreach (var networkFile in setDir.GetFiles())
                    {
                        if (networkFile.Extension.ToLower() != ".dimacs")
                        {
                            Log.Write($"     Skiping: {networkFile.Name}");
                            continue;
                        }
                        var name  = networkFile.Name;
                        var count = int.Parse(name.Split('n')[0]);
                        if (!counters.ContainsKey(count))
                        {
                            counters[count] = new PerformanceCounter();
                        }


                        var fn = importer.Import(networkFile);
                        if (fn != null)
                        {
                            Runtime.currentGraph = fn;
                            var pc = counters[count];
                            Log.Write($"        Processing {name} ({count})");
                            if (cblAlgorithms.CheckedIndices != null)
                            {
                                foreach (var item in cblAlgorithms.CheckedIndices)
                                {
                                    BaseMaxFlowAlgorithm algo = Runtime.loadedAlghoritms[(int)item].Instance;
                                    // диниц работает медленно - пропускаем
                                    if (count >= 500 && algo.GetName() == "Dinic")
                                    {
                                        continue;
                                    }
                                    for (int i = 0; i < udRunsCount.Value; i++)
                                    {
                                        BaseMaxFlowAlgorithm a = algo.Clone() as BaseMaxFlowAlgorithm;

                                        a.OnFinish += (s) =>
                                        {
                                            pc.RegisterRun(s.GetName(), s.Elapsed, s.MaxFlow);
                                        };

                                        a.SetGraph(Runtime.currentGraph);
                                        a.Run();
                                    }
                                }
                            }
                        }
                        else
                        {
                            Log.Write($"        Fail to load flow network from {networkFile.FullName}", Log.ERROR);
                        }
                    }
                    string header       = "";
                    var    lines        = new Dictionary <int, string>();
                    var    headerSetted = false;
                    foreach (var counter in counters)
                    {
                        if (header != "")
                        {
                            headerSetted = true;
                        }
                        foreach (var item in counter.Value.items)
                        {
                            if (!headerSetted)
                            {
                                header += $"узлы;{item.Value.Name}_Min;{item.Value.Name}_Max;{item.Value.Name}_Avg;;";
                            }

                            if (!lines.ContainsKey(counter.Key))
                            {
                                lines[counter.Key] = "";
                            }
                            lines[counter.Key] += $"{counter.Key};{item.Value.Min.TotalSeconds};{item.Value.Max.TotalSeconds};{item.Value.Avg.TotalSeconds};;";
                        }
                    }
                    using (var sw = new StreamWriter(statFile.FullName, false, Encoding.Default))
                    {
                        sw.WriteLine(header);
                        foreach (var line in lines)
                        {
                            sw.WriteLine(line.Value);
                        }
                    }
                    Log.Write($"        Saved: {statFile.FullName}");
                }
            }
            MessageBox.Show("Done");
        }