]> Skullheadx's Git Forge - The-Traveling-Salesman-Problem.git/commitdiff
One Tree Lower Bound explanation + image
authorSkullheadx <704277@pdsb.net>
Wed, 28 Dec 2022 21:20:09 +0000 (16:20 -0500)
committerSkullheadx <704277@pdsb.net>
Wed, 28 Dec 2022 21:20:09 +0000 (16:20 -0500)
NN_Heuristic+OneTree.png [new file with mode: 0644]
README.md
display.py
main.py

diff --git a/NN_Heuristic+OneTree.png b/NN_Heuristic+OneTree.png
new file mode 100644 (file)
index 0000000..e101128
Binary files /dev/null and b/NN_Heuristic+OneTree.png differ
index 76c7fb3a4c01a56ec3bcd0e508c03806aaeac80c..c87c184b32a93c292a15a68453b6604c149df170 100644 (file)
--- a/README.md
+++ b/README.md
@@ -28,14 +28,15 @@ If we start at any town and find the closest town that we haven't been to yet an
 
 In the case of the TSP, finding the optimal solution for a large number of nodes can end up taking too much time to compute, meaning that we have nothing to compare our heuristic solutions to. 
 This is where the **Minimum Spanning Tree (MST)** comes in. 
-_The minimum spanning tree is the set of edges that connects all the nodes with the minimum cost (in the case of the TSP, the costs is the distance between nodes) and no cycles._  
+_The minimum spanning tree is the set of edges that connects all the nodes with the minimum cost (in the case of the TSP, the costs is the distance between nodes) and no cycles._ A different way of thinking about it would be to find all the shortest distances between nodes and add that edge into the MST until we have connected all the nodes.
+
 **For example:** A graph with 4 nodes: A,B,C,D at (0,0), (0,10), (20,0), (20,10) respectively on the Cartesian Plane will have a MST of 40.0.
 This is because the MST only needs to connect all the nodes in the shortest distance possible, which in this case would be the edges AB + BC + CD. There is also another MST that is equally good which is simply AB + AD + CD.
 
 ![img_1.png](img_1.png)
 
-The usefulness of the MST lies in the fact that the optimal tour which in the case of the example above is highlighted in green, is always greater than the MST. 
-`MST Cost < Optimal Tour Cost` Since we are not trying to find the optimal solution, but a solution that is good enough and that we can calculate within a reasonable amount of time (heuristic solution) we can compare our solution to the minimum spanning tree and get an approximation ratio.
+The usefulness of the MST lies in the fact that the optimal tour which in the case of the example above is highlighted in green, is always greater than the MST. This is true because if you were to take the optimal solution and remove any of the edges (to create no cycles), you would be left with a spanning tree which would be greater than or equal to the minimum spanning tree. 
+Therefore, the `MST Cost < Optimal Tour Cost` Since we are not trying to find the optimal solution, but a solution that is good enough and that we can calculate within a reasonable amount of time (heuristic solution) we can compare our solution to the minimum spanning tree and get an approximation ratio.
 
 Take this graph for instance. The grey circles represent nodes or towns in the TSP, the blue line represents the Nearest Neighbor heuristic solution and the red line represents the MST. 
 ![](NN_Heuristic+MST.png)
@@ -49,4 +50,29 @@ By calculating each of the distances in the MST, we can determine that the `MST
 By manipulating the result, we can determine how much our solution overshot the lower bound.
 Of course this value does not represent to a high degree of accuracy how much we overshot the optimal solution, but it does give us ballpark numbers.
 In this case, the approximation ratio is `46.6%` of the MST.
-(As an exercise to the reader, can you determine why this is the MST?)
+(As an exercise to the reader, can you determine to why the Minimum Spanning Tree shown in the graph above is correct?)
+
+**The One Tree**
+
+The One Tree is an even better lower bound which will be greater than the MST, but still less than the optimal tour.
+`MST Cost < One Tree Lower Bound Cost < Optimal Tour Cost` This lower bound will be more useful than the MST because it will give us more precise approximation ratios as the One Tree lower bound will be closer to the optimal solution. 
+But, how do we determine the One Tree Lower Bound?
+1. If we remove any vertex from the graph and find the MST of the remaining nodes
+2. Then connect the two shortest edges to the removed vertex back into the tree
+
+This one tree is guaranteed to give a cost that is lower than the optimal cost, but still greater than the MST because by adding in the two closest distances, we create the shortest possible cycle to connect the removed vertex (and the rest of the vertices are connected using the MST)  while the optimal tour has to go all the way around to create a cycle.   
+In this example, the blue line represents the Nearest Neighbor heuristic solution, the blue dot represents the removed vertex and the green line represents the One Tree.
+
+![](NN_Heuristic+OneTree.png)
+
+Another thing we can do to ensure that the One Tree Lower Bound is maximized (since we want it as close as possible to the optimal tour cost) is to calculate the one tree, but we remove a different vertex each time until all the possible one trees have been determined.
+Using this one tree cost, we can now determine a better approximation ratio.
+In this example, the `One Tree Lower Bound Cost = 1,734.686` and the `Tour Cost = 1,994.528`. We can now determine the approximation ratio by simply dividing the tour cost by the One Tree Lower Bound Cost.
+
+
+`Tour Cost / One Tree Lower Bound Cost = 1,994.528 / 1,734.686 = 1.150`
+
+`1.150 * 100% - 100% = 15.0%`
+
+
+In this case, the approximation ratio is `15.0%` of the One Tree Lower Bound Cost! This is a significantly better approximation of how close we are to the optimal tour cost compared to the approximation ratio using the MST.  
index d6ec8d5fd8bbb95aaa82d5553dfc330dc67ddf0d..a9c7ecd4eeec7a3c4e2ab56749162199de4f11a6 100644 (file)
@@ -126,5 +126,5 @@ class Display:
 
             pygame.display.update()
             delta = clock.tick(60) / 1000  # Seconds
-            # pygame.image.save(self.screen, "NN Heuristic + MST.png")
+            # pygame.image.save(self.screen, "NN_Heuristic+OneTree.png")
             # quit()
diff --git a/main.py b/main.py
index fc2d7d5a942c613f0b8d6241f81fdb54e3135588..39d8240a1518ea14871a8959df65c14799d05c8a 100644 (file)
--- a/main.py
+++ b/main.py
@@ -34,14 +34,14 @@ def main():
     MST_distance, MST = find_MST(graph)
     print("MST_DISTANCE:", MST_distance)
     one_tree_time_start = perf_counter()
-    one_tree_distance, one_tree = find_one_tree(graph)
+    one_tree_distance, one_tree = find_one_tree(graph)
     lower_bound, one_tree, removed_vertex = find_lower_bound(graph)
     one_tree_time_end = perf_counter()
 
     print_info(route, route_time_end - route_time_start, "NN Heuristic", lower_bound,
                one_tree_time_end - one_tree_time_start, r=3000)
 
-    display = Display(os.path.join(GRAPH_PATH, filename), route, mst=MST, one_tree=None, removed_vertex = removed_vertex)
+    display = Display(os.path.join(GRAPH_PATH, filename), route, mst=None, one_tree=one_tree, removed_vertex = removed_vertex)
     display.show()