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); }
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); }
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"); }