I'm writing a 3-opt algorithm for the travelling salesman problem, i already got 2-opt working and im trying to convert it to 3-opt. I don't get how to swap the 3 points, can anyone help me?
my code:
private void ThreeOptSwap(int i, int k, int l) {
int size = route.size();
new_Route = new ArrayList<Point>();
new_Route.addAll(route);
// 1. take route[0] to route[i-1] and add them in order to new_route
for ( int c = 0; c <= i - 1; c++ )
{
new_Route.set(c, route.get(c) );
}
// 2. take route[i] to route[k] and add them in reverse order to new_route
int dec = 0;
for ( int c = i; c <= k; c++ )
{
new_Route.set( c, route.get( k - dec ) );
dec++;
}
// 3. take route[k+1] to end and add them in order to new_route
for ( int c = k + 1; c < size; c++ )
{
new_Route.set( c, route.get( c ) );
}
}