コード例 #1
0
        public List <AlgorithmInfo> LoadFromNamespace(string assemblyNamespace, string assemblyFile = null)
        {
            var      list = new List <AlgorithmInfo>();
            Assembly asm;

            if (assemblyFile == null)
            {
                asm = Assembly.GetCallingAssembly();
                Log.Write($"Searching algorithms in namespace {assemblyNamespace} from {asm.EscapedCodeBase}.");
            }
            else
            {
                asm = Assembly.LoadFrom(assemblyFile);
                Log.Write($"Searching algorithms in namespace {assemblyNamespace} from {assemblyFile}.");
            }
            Type[] typelist = asm.GetTypes();

            foreach (Type type in typelist)
            {
                try
                {
                    if (type.Namespace == assemblyNamespace && type.IsSubclassOf(typeof(BaseMaxFlowAlgorithm)))
                    {
                        BaseMaxFlowAlgorithm var = (BaseMaxFlowAlgorithm)asm.CreateInstance(type.FullName);
                        Log.Write($"  Found algorithm class {type.Name}: {var.GetName()}");
                        list.Add(new AlgorithmInfo(var.GetName(), var.GetDescription(), var.GetUrl(), type.FullName, var));
                    }
                }
                catch (Exception e)
                {
                    Log.Write($"  {e.Message}", Log.ERROR);
                }
            }
            return(list);
        }
コード例 #2
0
ファイル: FMain.cs プロジェクト: dpws/FlowNetworkToolKit
        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();
            }
        }
コード例 #3
0
ファイル: FMain.cs プロジェクト: dpws/FlowNetworkToolKit
 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();
     }
 }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        public List <AlgorithmInfo> LoadFromSource(DirectoryInfo directory)
        {
            var list = new List <AlgorithmInfo>();

            Log.Write($"Loading algorithms files from {directory.FullName}");
            foreach (FileInfo file in directory.GetFiles("*.cs"))
            {
                Log.Write($"Found file {file.Name}");
                var asm = CompileExecutable(file);
                if (asm != null)
                {
                    foreach (var type in asm.GetTypes())
                    {
                        if (type.IsSubclassOf(typeof(BaseMaxFlowAlgorithm)))
                        {
                            BaseMaxFlowAlgorithm var = (BaseMaxFlowAlgorithm)asm.CreateInstance(type.FullName);
                            Log.Write($"  Found algorithm class {type.Name}: {var.GetName()}");
                            list.Add(new AlgorithmInfo(var.GetName(), var.GetDescription(), var.GetUrl(), type.FullName, var));
                        }
                    }
                }
            }
            return(list);
        }
コード例 #6
0
        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");
        }
コード例 #7
0
 public void EdgeFlowChanged(BaseMaxFlowAlgorithm algorithm, FlowNetwork network, FlowEdge edge)
 {
     AddAnimation(new Animation(edge, AnimationType.EdgeFlowChanged));
 }
コード例 #8
0
ファイル: FMain.cs プロジェクト: dpws/FlowNetworkToolKit
 private void OnAlgorithmFinished(BaseMaxFlowAlgorithm algorithm)
 {
     MessageBox.Show($"Max flow from {Runtime.currentGraph.Source} to {Runtime.currentGraph.Target}: {algorithm.MaxFlow}");
 }