Class Route

java.lang.Object
  extended by Route

public class Route
extends java.lang.Object

Route is a representation of a path in a TSP problem. Routes are primarily manipulated and constructed by agents. The class stores nodes in an ArrayList of Integers.


Field Summary
private  java.util.ArrayList al
           
private  boolean calculated
           
private  int length
           
 
Constructor Summary
Route()
          Constructs a blank Route.
 
Method Summary
 void addNewNode(int n)
          Adds a node onto the end of the Route.
 int calcDistanceOfRoute(PherMatrix pherMatrix)
          Returns the length of the route.
 int calcDistanceOfRouteOverride(PherMatrix pherMatrix)
          Helper method for local optimization methods, such as 2-opt and 3-opt.
 void clear()
          Clears the current Route.
 void clearRoute()
          Clears the current Route.
 Route deepCopy()
          Returns a copy of the Route.
 int get(int n)
          Returns the Node number at a particular index of the Route.
 int getCurrentNode()
          Returns the node at the end of the Route.
 int getSize()
          Returns the current size of the Route.
 int removeIndex(int x)
          Removes the node at a particular index in the Route and returns its number.
 void swap(int x, int y)
          Helper method for local optimization methods, such as 2-opt and 3-opt.
 java.lang.String toString()
          Debugging method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

al

private java.util.ArrayList al

calculated

private boolean calculated

length

private int length
Constructor Detail

Route

public Route()
Constructs a blank Route.

Method Detail

addNewNode

public void addNewNode(int n)
Adds a node onto the end of the Route.

Parameters:
n - Node to be added onto the Route

get

public int get(int n)
Returns the Node number at a particular index of the Route.

Parameters:
n - Index number of the Route
Returns:
Node number at index n in the Route

getSize

public int getSize()
Returns the current size of the Route.

Returns:
length of the Route

clearRoute

public void clearRoute()
Clears the current Route.


removeIndex

public int removeIndex(int x)
Removes the node at a particular index in the Route and returns its number.

Parameters:
x - Index of the node to be removed in the Route
Returns:
The node number

toString

public java.lang.String toString()
Debugging method. Turns the Route into a String representation.

Overrides:
toString in class java.lang.Object
Returns:
The String representation of the Route

getCurrentNode

public int getCurrentNode()
Returns the node at the end of the Route.

Returns:
The node number at the end of the Route

calcDistanceOfRoute

public int calcDistanceOfRoute(PherMatrix pherMatrix)
Returns the length of the route. Stores a boolean and int value representing the route size after it is calculated to avoid excessive calculations. For historical reasons, all TSP distance data is measured using rounded integers.

Parameters:
pherMatrix - PherMatrix storing the distance values between nodes
Returns:
The length of the Route

calcDistanceOfRouteOverride

public int calcDistanceOfRouteOverride(PherMatrix pherMatrix)
Helper method for local optimization methods, such as 2-opt and 3-opt. Ignores if the route has been calculated already or not.

Parameters:
pherMatrix - PherMatrix storing the distance values between nodes
Returns:
The length of the Route

clear

public void clear()
Clears the current Route.


swap

public void swap(int x,
                 int y)
Helper method for local optimization methods, such as 2-opt and 3-opt. Swaps the nodes in index positions x and y.

Parameters:
x - First node
y - Second node

deepCopy

public Route deepCopy()
Returns a copy of the Route.

Returns:
Copy of the Route