Consider the weighted graph given from the table below. Find the nearest neighbor solution to the traveling salesperson problem starting from vertex A.
Asked
Active
Viewed 103 times
0
-
Are you supposed to solve this with Mathematica? – J. M.'s missing motivation Dec 13 '16 at 18:52
1 Answers
1
Directly employing this answer:
m1 = {{1, 2} -> 12, {1, 3} -> 14, {1, 4} -> 5, {1, 5} -> 4, {2, 3} ->
10, {2, 4} -> 3, {2, 5} -> 8, {3, 4} -> 7, {3, 5} -> 6, {4, 5} ->
9};
m2 = Reverse@#[[1]] -> #[[2]] & /@ m1;
m = m1~Join~m2;
d = SparseArray[m, {5, 5}, Infinity];
{len, tour} =
FindShortestTour[Range@5, DistanceFunction -> (d[[#1, #2]] &)]
{28, {1, 4, 2, 3, 5, 1}}
HighlightGraph[
WeightedAdjacencyGraph[d, GraphStyle -> "SmallNetwork",
EdgeLabels -> "EdgeWeight",
EdgeLabelStyle -> Directive[Black, Bold, 15]],
Style[UndirectedEdge[#1, #2], Thickness[.007], Red] & @@@
Partition[tour, 2, 1, 1]]

