Code Triangle

HTML5 "Traveling Salesman Problem" (TSP)

The traveling salesman problem is a classic algorithmic problem that dynamic programming can solve. I chose this algorithm to test out HTML5's <canvas> tag with the 2D context.

You can move the nodes around on the canvas, and find the route again. Each found route in the search will display below the graph.

The algorithm I use is based on Robert Sedgewick's "Exhaustive Search" chapter in "Algorithms in C++" like this: visit(n) { val[n] = ++id; for(c=0; c < V; c++) if (a[n][c]) if (val[c] == 0) visit(c); id--; val[n] = 0; } Where V is the number of vertices or nodes, a is an adjacency matrix, val is an array of all the nodes, and id is the current depth.

Besides modifying the code to keep track of Hamilton cycles, I added heuristics to stop searching if the current weight (distance between nodes) is greater than the minimum weight of any cycles found.

HTML 5

Sorry, but your browser doesn't support HTML5. We didn't exclude anyone specifically, but this text is inside a <canvas> tag, and shouldn't be shown according to the HTML5 specs.

Further Work