Message Boards Message Boards

1
|
5760 Views
|
2 Replies
|
1 Total Likes
View groups...
Share
Share this post:

TravelingSalesman Question

Posted 9 years ago

Hi. Since 10.0, the TravelingSalesman function was moved to the kernel.

Does anyone know why the following does not work? I've tried to make this example as simple as possible. This has bugged me for a while... Here is a very simple Directed graph. One can travel in either direction from 2_3, but only 1 direction elsewhere. We change 0's to Infinity to avoid self-loops.

data = {{0, 5, 0}, {0, 0, 1}, {1, 1, 0}} /. (0 -> \[Infinity];
g = WeightedAdjacencyGraph[data, VertexLabels -> "Name"];
FindShortestTour[g]

It returns unevaluated with the message: FindShortestTour::ngen: The generalized FindShortestTour[Graph[<3>, <4>]] is not implemented. >>

However, it knows the correct distance to go from 1 to 3, and then 3 back to 1.

GraphDistance[g, 1, 3]

6.

GraphDistance[g, 3, 1]

1.

I've noticed that the edge weights are changed back to zero:

WeightedAdjacencyMatrix[g]//Normal
{{0,5,0},{0,0,1},{1,1,0}}

It also seems to know the Hamiltonian Cycle.

FindHamiltonianCycle[g, All]
 {{DirectedEdge[1, 2], DirectedEdge[2, 3], DirectedEdge[3, 1]}}

Thank you in advance for any insight. As a side note, I believe these problems are suppose to be able to handle directed graphs, because one might be able to travel in one direction, and not another. Bridge might be closed in one direction, but not the other. One path might have a heavy penalty because it's uphill, etc.

Thanks again!

POSTED BY: Dana DeLouis
2 Replies
Posted 9 years ago

Thanks Sander for the feedback. I think your right. If one makes the legs Undirected, then I at least get a value. Seems a little strange to me.

Anyway, I think I can make a function to use:

FindHamiltonianCycle[g,All]

To find all possible paths, then get each leg distance, and pick the path with the shortest total distance. I'm working on it now.

Seems strange to me because a traveling salesmen problem should have directed edges. Thanks again.
Dana

POSTED BY: Dana DeLouis

I'm not 100% sure but I think it can not handle directed graphs at the moment.

POSTED BY: Sander Huisman
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract