using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Windows.Forms; using TSP; namespace Plotter { public partial class PlotWindow : Form { // List Plots; List Plots = new(); int CurrentGraph { get; set; } = 0; public PlotWindow() { InitializeComponent(); foreach (string graphFile in Directory.GetFiles("graphs/", "*.txt")) Plots.Add(GetTourSet(graphFile)); NextGraph.Enabled = (Plots.Count > 1); PrevGraph.Enabled = false; RenderWindow(debug: true); } void RenderWindow(bool debug = false) { Text = $"TSP: Graph {CurrentGraph + 1}"; GraphLabel.Text = $"Graph {CurrentGraph + 1}"; foreach (var plot in Plots[CurrentGraph]) plot.Render(); } TourPlot[] GetTourSet(string graphFile) { string coordsFile = graphFile.Replace(".txt", ".csv"); TourPlot bruteForce = new(BruteForcePlot, BruteForceWeight, BruteForceTime); TourPlot estimation = new(EstimationPlot, EstimatedWeight, EstimatedTime); TourPlot mst = new(MSTPlot, MSTWeight, MSTTime); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); bruteForce.Tour = Solve.BruteForce(graphFile, coordsFile, 0); stopWatch.Stop(); bruteForce.RunTime = stopWatch.Elapsed; stopWatch.Reset(); stopWatch.Start(); estimation.Tour = Solve.BruteForce(graphFile, coordsFile, 0); // TODO create estimation function stopWatch.Stop(); estimation.RunTime = stopWatch.Elapsed; stopWatch.Reset(); stopWatch.Start(); mst.Tour = Solve.MST(graphFile, coordsFile, 0); stopWatch.Stop(); mst.RunTime = stopWatch.Elapsed; return new[] { bruteForce, estimation, mst }; } private void Canvas_SizeChanged(object sender, EventArgs e) { RenderWindow(); } private void NextGraph_Click(object sender, EventArgs e) { CurrentGraph++; RenderWindow(); PrevGraph.Enabled = true; NextGraph.Enabled = (CurrentGraph < Plots.Count - 1); } private void PrevGraph_Click(object sender, EventArgs e) { CurrentGraph--; RenderWindow(); NextGraph.Enabled = true; PrevGraph.Enabled = (CurrentGraph > 0); } } }