summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/CS340.Plotter/Plot.Designer.cs77
-rw-r--r--src/CS340.Plotter/Plot.cs40
-rw-r--r--src/CS340.Plotter/TourPlot.cs21
3 files changed, 105 insertions, 33 deletions
diff --git a/src/CS340.Plotter/Plot.Designer.cs b/src/CS340.Plotter/Plot.Designer.cs
index 1fe8745..7a06f33 100644
--- a/src/CS340.Plotter/Plot.Designer.cs
+++ b/src/CS340.Plotter/Plot.Designer.cs
@@ -48,7 +48,7 @@ namespace Plotter
this.MSTWeight = new System.Windows.Forms.Label();
this.MSTWeightLabel = new System.Windows.Forms.Label();
this.MSTTimeLabel = new System.Windows.Forms.Label();
- this.BruteForceLabel = new System.Windows.Forms.Label();
+ this.TrueShortestLabel = new System.Windows.Forms.Label();
this.EstimatedLabel = new System.Windows.Forms.Label();
this.MSTLabel = new System.Windows.Forms.Label();
this.tableLayoutPanel7 = new System.Windows.Forms.TableLayoutPanel();
@@ -64,6 +64,9 @@ namespace Plotter
this.tableLayoutPanel4 = new System.Windows.Forms.TableLayoutPanel();
this.label8 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
+ this.tableLayoutPanel8 = new System.Windows.Forms.TableLayoutPanel();
+ this.SaveGraph = new System.Windows.Forms.Button();
+ this.SaveAll = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.BruteForcePlot)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.EstimationPlot)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.MSTPlot)).BeginInit();
@@ -75,6 +78,7 @@ namespace Plotter
this.tableLayoutPanel2.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
this.tableLayoutPanel4.SuspendLayout();
+ this.tableLayoutPanel8.SuspendLayout();
this.SuspendLayout();
//
// BruteForcePlot
@@ -115,12 +119,13 @@ namespace Plotter
this.LayoutPanel.Controls.Add(this.tableLayoutPanel5, 1, 2);
this.LayoutPanel.Controls.Add(this.tableLayoutPanel6, 2, 2);
this.LayoutPanel.Controls.Add(this.BruteForcePlot, 0, 0);
- this.LayoutPanel.Controls.Add(this.BruteForceLabel, 0, 1);
+ this.LayoutPanel.Controls.Add(this.TrueShortestLabel, 0, 1);
this.LayoutPanel.Controls.Add(this.EstimationPlot, 1, 0);
this.LayoutPanel.Controls.Add(this.EstimatedLabel, 1, 1);
this.LayoutPanel.Controls.Add(this.MSTPlot, 2, 0);
this.LayoutPanel.Controls.Add(this.MSTLabel, 2, 1);
this.LayoutPanel.Controls.Add(this.tableLayoutPanel7, 1, 4);
+ this.LayoutPanel.Controls.Add(this.tableLayoutPanel8, 2, 4);
this.LayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.LayoutPanel.Location = new System.Drawing.Point(0, 0);
this.LayoutPanel.Name = "LayoutPanel";
@@ -335,17 +340,17 @@ namespace Plotter
this.MSTTimeLabel.Text = "Runtime:";
this.MSTTimeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
- // BruteForceLabel
+ // TrueShortestLabel
//
- this.BruteForceLabel.AutoSize = true;
- this.BruteForceLabel.Dock = System.Windows.Forms.DockStyle.Top;
- this.BruteForceLabel.Font = new System.Drawing.Font("Arial", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
- this.BruteForceLabel.Location = new System.Drawing.Point(3, 279);
- this.BruteForceLabel.Name = "BruteForceLabel";
- this.BruteForceLabel.Size = new System.Drawing.Size(254, 24);
- this.BruteForceLabel.TabIndex = 3;
- this.BruteForceLabel.Text = "Brute Force";
- this.BruteForceLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
+ this.TrueShortestLabel.AutoSize = true;
+ this.TrueShortestLabel.Dock = System.Windows.Forms.DockStyle.Top;
+ this.TrueShortestLabel.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.TrueShortestLabel.Location = new System.Drawing.Point(3, 279);
+ this.TrueShortestLabel.Name = "TrueShortestLabel";
+ this.TrueShortestLabel.Size = new System.Drawing.Size(254, 22);
+ this.TrueShortestLabel.TabIndex = 3;
+ this.TrueShortestLabel.Text = "True Shortest Tour";
+ this.TrueShortestLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// EstimatedLabel
//
@@ -356,17 +361,17 @@ namespace Plotter
this.EstimatedLabel.Name = "EstimatedLabel";
this.EstimatedLabel.Size = new System.Drawing.Size(254, 24);
this.EstimatedLabel.TabIndex = 4;
- this.EstimatedLabel.Text = "Estimated";
+ this.EstimatedLabel.Text = "MST Approximation";
this.EstimatedLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// MSTLabel
//
this.MSTLabel.AutoSize = true;
this.MSTLabel.Dock = System.Windows.Forms.DockStyle.Top;
- this.MSTLabel.Font = new System.Drawing.Font("Arial", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.MSTLabel.Font = new System.Drawing.Font("Arial", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.MSTLabel.Location = new System.Drawing.Point(523, 279);
this.MSTLabel.Name = "MSTLabel";
- this.MSTLabel.Size = new System.Drawing.Size(255, 24);
+ this.MSTLabel.Size = new System.Drawing.Size(255, 22);
this.MSTLabel.TabIndex = 5;
this.MSTLabel.Text = "MST";
this.MSTLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -546,6 +551,42 @@ namespace Plotter
this.label9.Text = "123.342";
this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
+ // tableLayoutPanel8
+ //
+ this.tableLayoutPanel8.Anchor = System.Windows.Forms.AnchorStyles.Right;
+ this.tableLayoutPanel8.AutoSize = true;
+ this.tableLayoutPanel8.ColumnCount = 2;
+ this.tableLayoutPanel8.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel8.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel8.Controls.Add(this.SaveGraph, 1, 0);
+ this.tableLayoutPanel8.Controls.Add(this.SaveAll, 0, 0);
+ this.tableLayoutPanel8.Location = new System.Drawing.Point(616, 347);
+ this.tableLayoutPanel8.Name = "tableLayoutPanel8";
+ this.tableLayoutPanel8.RowCount = 1;
+ this.tableLayoutPanel8.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
+ this.tableLayoutPanel8.Size = new System.Drawing.Size(162, 29);
+ this.tableLayoutPanel8.TabIndex = 19;
+ //
+ // SaveGraph
+ //
+ this.SaveGraph.Location = new System.Drawing.Point(84, 3);
+ this.SaveGraph.Name = "SaveGraph";
+ this.SaveGraph.Size = new System.Drawing.Size(75, 23);
+ this.SaveGraph.TabIndex = 0;
+ this.SaveGraph.Text = "Save Graph";
+ this.SaveGraph.UseVisualStyleBackColor = true;
+ this.SaveGraph.Click += new System.EventHandler(this.SaveGraph_Click);
+ //
+ // SaveAll
+ //
+ this.SaveAll.Location = new System.Drawing.Point(3, 3);
+ this.SaveAll.Name = "SaveAll";
+ this.SaveAll.Size = new System.Drawing.Size(75, 23);
+ this.SaveAll.TabIndex = 1;
+ this.SaveAll.Text = "Save All";
+ this.SaveAll.UseVisualStyleBackColor = true;
+ this.SaveAll.Click += new System.EventHandler(this.SaveAll_Click);
+ //
// PlotWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@@ -575,6 +616,7 @@ namespace Plotter
this.tableLayoutPanel3.PerformLayout();
this.tableLayoutPanel4.ResumeLayout(false);
this.tableLayoutPanel4.PerformLayout();
+ this.tableLayoutPanel8.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
@@ -587,7 +629,7 @@ namespace Plotter
private System.Windows.Forms.PictureBox MSTPlot;
private System.Windows.Forms.TableLayoutPanel LayoutPanel;
private System.Windows.Forms.Label MSTLabel;
- private System.Windows.Forms.Label BruteForceLabel;
+ private System.Windows.Forms.Label TrueShortestLabel;
private System.Windows.Forms.Label EstimatedLabel;
private System.Windows.Forms.Label BruteForceTimeLabel;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
@@ -617,6 +659,9 @@ namespace Plotter
private System.Windows.Forms.Label GraphLabel;
private System.Windows.Forms.Button NextGraph;
private System.Windows.Forms.Button PrevGraph;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel8;
+ private System.Windows.Forms.Button SaveGraph;
+ private System.Windows.Forms.Button SaveAll;
}
}
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);
+ }
}
}
diff --git a/src/CS340.Plotter/TourPlot.cs b/src/CS340.Plotter/TourPlot.cs
index 7c03957..30d0f2a 100644
--- a/src/CS340.Plotter/TourPlot.cs
+++ b/src/CS340.Plotter/TourPlot.cs
@@ -24,7 +24,9 @@ namespace Plotter
public void Render()
{
- const int Scaler = 125;
+ const int Scaler = 25;
+ const int PlotSize = 100;
+
using Bitmap bmp = new(Canvas.Width, Canvas.Height);
using Graphics gfx = Graphics.FromImage(bmp);
using Pen pen = new(Color.Black);
@@ -54,6 +56,7 @@ namespace Plotter
gfx.DrawString(i.ToString(), gridFont, brush, bottom, stringFormat);
}
+ // iterate through each city and draw line from Location to parent.Location
foreach (City city in Tour.Cities.Where(city => city.Parent != -1))
{
City parent = Tour[city.Parent];
@@ -69,27 +72,23 @@ namespace Plotter
Canvas.Image?.Dispose();
Canvas.Image = (Bitmap)bmp.Clone();
+ // set runtime and weight labels
RuntimeLabel.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
RunTime.Hours, RunTime.Minutes, RunTime.Seconds, RunTime.Milliseconds / 10);
WeightLabel.Text = Tour.Weight.ToString("F3");
+ // helper function to unify the scaling of images
Point ScaleLocation(Coordinate coordinate)
{
- int x = Canvas.Width * (coordinate.X + 12) / Scaler;
- int y = Canvas.Height * ((coordinate.Y - 100) * -1 + 12) / Scaler;
+ int x = Canvas.Width * (coordinate.X + Scaler / 2) / (Scaler + PlotSize);
+ int y = Canvas.Height * ((coordinate.Y - PlotSize) * -1 + Scaler / 2) / (Scaler + PlotSize);
return new Point(x, y);
}
}
- public void WriteDebug()
- {
- Debug.WriteLine(Tour);
-
- foreach (City city in Tour.Cities)
- Debug.WriteLine(city.Location);
- }
-
+ public void Save(string filename) =>
+ Canvas.Image.Save(filename);
}
}