1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
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<TourPlot[]> Plots;
List<TourPlot[]> 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);
}
}
}
|