Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Mathematics and Algorithms > Optimization >

FindShortestTour

FindShortestTour[{e1, e2, ...}]
attempts to find an ordering of the ei that minimizes the total distance on a tour that visits all the ei once.
  • The following options can be given:
DistanceFunctionthe distance function to apply to pairs of objects
Methodthe method to use
  • The ei can be numbers or lists of numbers, in which case the default distance function used is EuclideanDistance.
  • If the ei are strings, the default distance function used is EditDistance.
  • For small numbers of points, FindShortestTour will usually find the shortest possible tour. For larger numbers of points it will normally find a tour whose length is at least close to the minimum.
Find the length and ordering of a shortest tour through six points in the plane:
Specify a list of points:
Order the points according to the tour found:
Plot the tour:
Find the length and ordering of a shortest tour through six points in the plane:
In[1]:=
Click for copyable input
Out[1]=
 
Specify a list of points:
In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
Order the points according to the tour found:
In[3]:=
Click for copyable input
Out[3]=
Plot the tour:
In[4]:=
Click for copyable input
Out[4]=
Find the shortest tour through points in 3D space:
Find the shortest tour through a list of strings:
Use a DistanceFunction based on a (symmetric) connectivity matrix:
This finds all points on a n xn grid with coordinates that are coprime:
Find the shortest tour using "OrZweig" method, the default for 2D real inputs:
Finding shortest tour using "OrOpt" method, the default for non-2D or nonreal inputs:
The "TwoOpt" algorithm performs exchanges of edge endpoints for improvement:
"CCA" (Convex hull, Cheapest insertion and Angle selection) intended for points in DoubleStruckCapitalRn:
The "Greedy" algorithm moves from one point to the nearest unvisited neighbor:
"GreedyCycle" is a variant of the "Greedy" algorithm with a known upper bound:
"SimulatedAnnealing" uses simulated annealing to minimize the tour length:
By default EditDistance is used for strings:
This finds the shortest tour through 100 points, with a penalty added to cross a "river":
This plots the tour, and the "river" in red :
This defines a sparse distance matrix among six points and find the shortest tour:
This plot the shortest tour in red, as well as the distance on each edge:
Find a shortest tour visiting 50 random points in the plane:
Find a shortest tour visiting 100 random points in 3D:
Find the shortest tour through 2D points whose coordinates are relatively prime:
Find a shortest tour for 3D points with relatively prime coordinates:
Find a "shortest tour" through the names of countries in Europe:
Find a traveling-salesman tour of Europe:
Plan a tour through every country of the world:
Visualize the tour:
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team