summaryrefslogtreecommitdiffstats
path: root/src/CS340.Plotter/Plot.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/CS340.Plotter/Plot.cs')
-rw-r--r--src/CS340.Plotter/Plot.cs59
1 files changed, 32 insertions, 27 deletions
diff --git a/src/CS340.Plotter/Plot.cs b/src/CS340.Plotter/Plot.cs
index 0559ece..a962057 100644
--- a/src/CS340.Plotter/Plot.cs
+++ b/src/CS340.Plotter/Plot.cs
@@ -1,52 +1,57 @@
using System;
-using System.Drawing;
+using System.Collections.Generic;
+using System.IO;
using System.Windows.Forms;
+using TSP;
namespace Plotter
{
public partial class Plot : Form
{
- Random rand = new Random();
+ // List<TourPlot[]> Plots;
+ List<TourPlot[]> Plots = new();
+
public Plot()
{
InitializeComponent();
- Render();
+
+ foreach (string graphFile in Directory.GetFiles("graphs/", "*.txt"))
+ GetTours(graphFile);
+
+ RenderWindow(debug: true);
}
- void Render()
+
+ void RenderWindow(bool debug = false)
{
- using var bmp = new Bitmap(Canvas.Width, Canvas.Height);
- using var gfx = Graphics.FromImage(bmp);
- using var pen = new Pen(Color.White);
- // draw one thousand random white lines on a dark blue background
- gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- gfx.Clear(Color.Navy);
- for (int i = 0; i < 1000; i++)
+ foreach (var plot in Plots)
{
- var pt1 = new Point(rand.Next(bmp.Width), rand.Next(bmp.Height));
- var pt2 = new Point(rand.Next(bmp.Width), rand.Next(bmp.Height));
- gfx.DrawLine(pen, pt1, pt2);
+ if (debug)
+ plot[0].WriteDebug();
+
+ plot[0].Render();
+ plot[1].Render();
+ plot[2].Render();
}
-
- // copy the bitmap to the picturebox (double buffered)
- Canvas.Image?.Dispose();
- Canvas.Image = (Bitmap)bmp.Clone();
}
+ void GetTours(string graphFile)
+ {
+ string coordsFile = graphFile.Replace(".txt", ".csv");
+ TourPlot bruteForce = new(BruteForcePlot);
+ TourPlot estimation = new(EstimationPlot);
+ TourPlot mst = new(MSTPlot);
- private void Canvas_SizeChanged(object sender, EventArgs e)
- {
- Render();
- }
+ bruteForce.Tour = Solve.BruteForce(graphFile, coordsFile, 0);
+ estimation.Tour = Solve.BruteForce(graphFile, coordsFile, 0); // TODO create estimation function
+ mst.Tour = Solve.MST(graphFile, coordsFile, 0);
- private void Canvas_MouseDown(object sender, MouseEventArgs e)
- {
- Render();
+ Plots.Add(new[] { bruteForce, estimation, mst });
}
- private void Plot_Load(object sender, EventArgs e)
+ private void Canvas_SizeChanged(object sender, EventArgs e)
{
-
+ RenderWindow();
}
}
}