public void doMutation ( PermutationSolution < T > solution ) { int permutationLength ; permutationLength = solution . getNumberOfVariables ( ) ; if ( ( permutationLength != 0 ) && ( permutationLength != 1 ) ) { if ( mutationRandomGenerator . getRandomValue ( ) < mutationProbability ) { int pos1 = positionRandomGenerator . getRandomValue ( 0 , permutationLength - 1 ) ; int pos2 = positionRandomGenerator . getRandomValue ( 0 , permutationLength - 1 ) ; while ( pos1 == pos2 ) { if ( pos1 == ( permutationLength - 1 ) ) pos2 = positionRandomGenerator . getRandomValue ( 0 , permutationLength - 2 ) ; else pos2 = positionRandomGenerator . getRandomValue ( pos1 , permutationLength - 1 ) ; } T temp = solution . getVariableValue ( pos1 ) ; solution . setVariableValue ( pos1 , solution . getVariableValue ( pos2 ) ) ; solution . setVariableValue ( pos2 , temp ) ; } } }
Performs the operation