diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-04-23 17:06:43 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-04-23 17:06:43 -0500 |
commit | 9af3c3f53beb82efe1e690d45852a79238ac11df (patch) | |
tree | 877d9afe07e05b0d6523a15ede352a7599b3692c /src/CS340.Plotter/Plot.cs | |
parent | 66ecdbf20f2a29af26e4bfefb255e7fbe1061eac (diff) |
implimented saving graphs
Diffstat (limited to 'src/CS340.Plotter/Plot.cs')
-rw-r--r-- | src/CS340.Plotter/Plot.cs | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/CS340.Plotter/Plot.cs b/src/CS340.Plotter/Plot.cs index 7028d29..89894e4 100644 --- a/src/CS340.Plotter/Plot.cs +++ b/src/CS340.Plotter/Plot.cs @@ -23,10 +23,10 @@ namespace Plotter NextGraph.Enabled = (Plots.Count > 1); PrevGraph.Enabled = false; - RenderWindow(debug: true); + RenderWindow(); } - void RenderWindow(bool debug = false) + void RenderWindow() { Text = $"TSP: Graph {CurrentGraph + 1}"; GraphLabel.Text = $"Graph {CurrentGraph + 1}"; @@ -40,7 +40,7 @@ namespace Plotter TourPlot bruteForce = new(BruteForcePlot, BruteForceWeight, BruteForceTime); - TourPlot estimation = new(EstimationPlot, EstimatedWeight, EstimatedTime); + TourPlot approximate = new(EstimationPlot, EstimatedWeight, EstimatedTime); TourPlot mst = new(MSTPlot, MSTWeight, MSTTime); Stopwatch stopWatch = new Stopwatch(); @@ -52,9 +52,9 @@ namespace Plotter stopWatch.Reset(); stopWatch.Start(); - estimation.Tour = TSPSolver.Approximate(graphFile, coordsFile, 0); // TODO create estimation function + approximate.Tour = TSPSolver.Approximate(graphFile, coordsFile, 0); // TODO create estimation function stopWatch.Stop(); - estimation.RunTime = stopWatch.Elapsed; + approximate.RunTime = stopWatch.Elapsed; stopWatch.Reset(); @@ -63,7 +63,14 @@ namespace Plotter stopWatch.Stop(); mst.RunTime = stopWatch.Elapsed; - return new[] { bruteForce, estimation, mst }; + return new[] { bruteForce, approximate, mst }; + } + + private void SaveSet(string folderName, int graphNum) + { + Plots[graphNum][0].Save(Path.Join(folderName, $"graph{graphNum + 1}_trueshortest.png")); + Plots[graphNum][1].Save(Path.Join(folderName, $"graph{graphNum + 1}_approximate.png")); + Plots[graphNum][2].Save(Path.Join(folderName, $"graph{graphNum + 1}_mst.png")); } private void Canvas_SizeChanged(object sender, EventArgs e) @@ -86,5 +93,26 @@ namespace Plotter NextGraph.Enabled = true; PrevGraph.Enabled = (CurrentGraph > 0); } + + private void SaveGraph_Click(object sender, EventArgs e) + { + var folderBrowserDialog = new FolderBrowserDialog(); + + // Show the FolderBrowserDialog. + DialogResult result = folderBrowserDialog.ShowDialog(); + if (result == DialogResult.OK) + SaveSet(folderBrowserDialog.SelectedPath, CurrentGraph); + } + + private void SaveAll_Click(object sender, EventArgs e) + { + var folderBrowserDialog = new FolderBrowserDialog(); + + // Show the FolderBrowserDialog. + DialogResult result = folderBrowserDialog.ShowDialog(); + if (result == DialogResult.OK) + for (int i = 0; i < Plots.Count; i++) + SaveSet(folderBrowserDialog.SelectedPath, i); + } } } |