comirva.util
Class TSP
java.lang.Object
comirva.util.TSP
public class TSP
- extends Object
This class implements a simple algorithm for solving
the travelling salesman problem (TSP).
Constructor Summary |
TSP(DataMatrix distances)
Creates a TSP-instance where the distances between the cities are given
by the data matrix distances . |
Method Summary |
int[] |
startIterations(int iter)
Initializes the TSP using a random tour. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
TSP
public TSP(DataMatrix distances)
- Creates a TSP-instance where the distances between the cities are given
by the data matrix
distances
.
- Parameters:
distances
- a DataMatrix containing the distances between all cities
startIterations
public int[] startIterations(int iter)
- Initializes the TSP using a random tour. To solve the TSP, an
iterative heuristical algorithm that switches two randomly
chosen cities and tests the new tour against the old one is used.
- Parameters:
iter
- the number of itarations to be performed
- Returns:
- an int[] containing the order of the passed vertices (cities according to TSP)