OpenTS Tutorial
MyMoveManager
The MyMoveManager Object

The move manager is responsible for determining which moves are valid for each iteration. If we had defined our move to be "Move from position X to position Y," we would have the same set of moves at each iteration, but we don't, so we have to determine how far each customer can move forward and back at each iteration.

As before the complete source is available, but we've duplicated it here:

import org.coinor.opents.*;

public class MyMoveManager implements MoveManager
{
    
    public Move[] getAllMoves( Solution solution )
    {   
        int[] tour = ((MySolution)solution).tour;
        Move[] buffer = new Move[ tour.length*tour.length ];
        int nextBufferPos = 0;
        
        // Generate moves that move each customer
        // forward and back up to five spaces.
        for( int i = 1; i < tour.length; i++ )
            for( int j = -5; j <= 5; j++ )
                if( (i+j >= 1) && (i+j < tour.length) && (j != 0) )
                    buffer[nextBufferPos++] = new MySwapMove( tour[i], j );
         
        // Trim buffer
        Move[] moves = new Move[ nextBufferPos];
        System.arraycopy( buffer, 0, moves, 0, nextBufferPos );
        
        return moves;
    }   // end getAllMoves
    
}   // end class MyMoveManager

The move manager generates a number of moves being careful not to generate any that are logically impossible such as moving a customer from position three to a spot five places earlier. That would be a negative position which we cannot allow.

We expect that some moves will turn out to be duplicates of each other: If Customer A is followed by Customer B, then an A+1 move would be the same as a B-1 move. Since the hash code for the move is based on the customer only, we might find that A+1 is on the tabu list but B-1 is not.