tasks
Class TSPUtils

java.lang.Object
  extended by tasks.TSPUtils
All Implemented Interfaces:
java.io.Serializable

public final class TSPUtils
extends java.lang.Object
implements java.io.Serializable

Utility class for TSP.

See Also:
Serialized Form

Method Summary
static double getDistance(int[] path, double[][] coords)
          Computes the roundtrip distance of the given path
static double getDistance(int i, int j, double[][] coords)
          Gets the distance from city i to city j
static double getLowerBound(int[] remaining, double[][] coords, int lastCoordIndex)
          Computes the lower bound on the current partial path.
static int[] getMinPath(int[] a, int[] b, double[][] coords)
          Gets the minimum path among the 2 input paths
static double getOneWayDistance(int[] path, double[][] coords)
          Computes partial path distance, without returning to city zero.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDistance

public static double getDistance(int i,
                                 int j,
                                 double[][] coords)
Gets the distance from city i to city j

Parameters:
i - city index
j - city index
coords - city coordinates
Returns:
the distance from city i to city j

getDistance

public static double getDistance(int[] path,
                                 double[][] coords)
Computes the roundtrip distance of the given path

Parameters:
path - the path tour
coords - the city coordinates
Returns:
the roundtrip distance of the given path

getOneWayDistance

public static double getOneWayDistance(int[] path,
                                       double[][] coords)
Computes partial path distance, without returning to city zero.

Parameters:
path - partial path.
coords - coordinates of the cities.
Returns:
distance of the partial path.

getLowerBound

public static double getLowerBound(int[] remaining,
                                   double[][] coords,
                                   int lastCoordIndex)
Computes the lower bound on the current partial path.

Parameters:
remaining - the list of cities that are not yet part of the path
coords - coordinates of the cities.
lastCoordIndex - index of the last coordinate in the partial path.
Returns:
lower bound distance on this path.

getMinPath

public static int[] getMinPath(int[] a,
                               int[] b,
                               double[][] coords)
Gets the minimum path among the 2 input paths

Parameters:
a - path tour
b - path tour
coords - city coordinates
Returns:
the minimum path among the 2 input paths