/// <inheritdoc /> public void GenerateAndComputeMultiple() { var dictionary = new Dictionary <int, List <long> >(); for (var i = 2; i < 12; ++i) { dictionary.Add(i, new List <long>()); } System.IO.Directory.CreateDirectory("HamiltonPath"); System.IO.Directory.CreateDirectory("HamiltonPath\\Input"); System.IO.Directory.CreateDirectory("HamiltonPath\\Output"); foreach (var key in dictionary.Keys) { for (var i = 0; i < 100; ++i) { var inputPath = "HamiltonPath\\Input\\graph" + key + "_" + i + ".txt"; var outputPath = "HamiltonPath\\Output\\graph" + key + "_" + i + ".txt"; GenerateAndSave(key, inputPath); var graph = _serializer.Deserialize(inputPath); var sw = Stopwatch.StartNew(); var hamiltonPath = _algorithmProvider.Compute(graph).ToString(); sw.Stop(); _serializer.Serialize(outputPath, graph, hamiltonPath); dictionary[key].Add(sw.ElapsedMilliseconds); } } const string timesPath = "HamiltonPath\\times.txt"; _serializer.SerializeTimes(timesPath, dictionary); }
/// <summary> /// Compute button onclick handler /// </summary> public void Compute() { try { HamiltonPathLabel = _algorithmProvider.Compute(GraphMatrix).ToString(); } catch (Exception ex) { var dialogManager = IoC.Get <ICustomDialogManager>(); dialogManager.DisplayMessageBox(Consts.Errors.Title, Consts.Errors.Info + ex.Message); } }
public void PerformanceTest(int maxVerticles, int maxExamplesForVerticles) { Directory.CreateDirectory("HamiltonPath\\PerformanceTest"); Directory.CreateDirectory("HamiltonPath\\PerformanceTest\\Examples"); const string csvPath = "HamiltonPath\\PerformanceTest\\results.csv"; var exampleNumber = 1; using (var file = File.CreateText(csvPath)) { file.WriteLineAsync("ExampleNumber, VerticlesCount, PathCost, CalculationTimeInMiliseconds, ElapsedTime"); } //14*10 for (var i = 2; i <= maxVerticles; i++) { for (var j = 1; j <= maxExamplesForVerticles; j++) { var example = _taskGenerator.Generate(i); var watch = new Stopwatch(); watch.Start(); var computedPath = _algorithmProvider.Compute(example); watch.Stop(); SaveExampleDetailsToFile(exampleNumber, example, computedPath); using (var file = File.AppendText(csvPath)) { file.WriteLineAsync($"{exampleNumber},{i},{computedPath.Cost},{watch.ElapsedMilliseconds},{watch.Elapsed}"); } exampleNumber++; } } }
public void Should_Throw_Exception(int[,] graph) { Action act = () => _algorithmProvider.Compute(graph); act.ShouldThrow <ArgumentException>(); }
/// <summary> /// Finds Hamilton Path and saves output to file /// </summary> /// <param name="parameters">Input path file, output path file</param> public void Execute(IEnumerable <string> parameters) { var enumerable = parameters as IList <string> ?? parameters.ToList(); _serializer.Serialize(enumerable[1], _serializer.Deserialize(enumerable[0]), _algorithmProvider.Compute(_serializer.Deserialize(enumerable[0])).ToString()); }