]> Skullheadx's Git Forge - The-Traveling-Salesman-Problem.git/commitdiff
Christofides explanation
authorSkullheadx <704277@pdsb.net>
Sun, 8 Jan 2023 23:23:47 +0000 (18:23 -0500)
committerSkullheadx <704277@pdsb.net>
Sun, 8 Jan 2023 23:23:47 +0000 (18:23 -0500)
Christofides.png [new file with mode: 0644]
Christofides_bad.png [new file with mode: 0644]
README.md
display.py

diff --git a/Christofides.png b/Christofides.png
new file mode 100644 (file)
index 0000000..25f6177
Binary files /dev/null and b/Christofides.png differ
diff --git a/Christofides_bad.png b/Christofides_bad.png
new file mode 100644 (file)
index 0000000..23eeee2
Binary files /dev/null and b/Christofides_bad.png differ
index 07822bdd67362e1a13cdf355777a224bbd8e7b58..f4a667e9848b2ee2263e881c7775c88ac22d0282 100644 (file)
--- a/README.md
+++ b/README.md
@@ -83,4 +83,20 @@ Using these new approximation ratios, we can now determine how effective differe
 --------------------------------------------------------------------------------------------------------------
 **Method 3: Greedy Heuristic**
 
-If we use an approach similar to how we created the Minimum Spanning Tree, we can apply similar logic to create a good heuristic. In each iteration, we determine the shortest edge distance to add to the route, however we must follow the rules that each town is connected to exactly 2 other towns and by adding an edge, we do not create a cycle of length smaller than n.  
\ No newline at end of file
+If we use an approach similar to how we created the Minimum Spanning Tree, we can apply similar logic to create a good heuristic. In each iteration, we determine the shortest edge distance to add to the route, however we must follow the rules that each town is connected to exactly 2 other towns and by adding an edge, we do not create a cycle of length smaller than n.
+
+--------------------------------------------------------------------------------------------------------------
+**Method 4: The Christofides Algorithm**
+
+When we compare the MST to the optimal solution, they often share many of the same edges. Meaning that if we modify the MST into a TSP tour, it will be very similar to the optimal solution.
+![](Christofides.png)
+
+Take the above graph for instance. The blue lines represent a TSP tour created using the Christofides Algorithm while the orange lines represent the MST.
+The Christofides Algorithm creates a tour by:
+1. Finding all odd degree vertices in the MST. Each node in the MST connects a number of other nodes, this number is the degree of the node. For example, the node at (276,378) connects to 2 other nodes, namely (275, 450) and (215, 263). Therefore it has degree 2.
+2. Find the perfect matching of all odd degree vertices. By taking each odd degree vertex and creating an edge with another vertex such that all odd degree vertices have been paired up with the minimum cost, we can determine the perfect matching. (Note: In any graph, the sum of all the vertex degrees is equal to twice the number of edges. Therefore, there can not be an odd number of odd degree vertices)
+3. Combine the perfect matching and the MST into a multi-graph. This graph will by definition have only even degree vertices (since the MST's odd degree vertices will each receive one more edge therefore its odd degree will become and even degree)
+4. Construct an Eulerian Tour of the multi-graph by passing through each edge once until all edges have been passed through.
+5. Construct a TSP tour by going through the Eulerian tour and when we encounter a node we have already visited, simply skip over it and connect the previous node to the next one that has not been visited yet.
+
+--------------------------------------------------------------------------------------------------------------
index 3f080a33755247ac230d9b735c449d6d4c60ced5..b1f88b92f0104927b36ffdac2e8e6bb9284046d7 100644 (file)
@@ -135,9 +135,9 @@ class Display:
             for i, node in enumerate(self.nodes):
                 node.draw(self.screen)
 
-            self.salesman.draw(self.screen)
+            self.salesman.draw(self.screen)
 
             pygame.display.update()
             delta = clock.tick(60) / 1000  # Seconds
-            # pygame.image.save(self.screen, "Greedy_Heuristic+OneTree.png")
-            # quit()
+            # pygame.image.save(self.screen, "Christofides.png")
+            # quit()
\ No newline at end of file