Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/07/10 16:29:25 (14 years ago)
Author:
abeham
Message:

#839

  • Added some checks to allow moves in permutation of length 2 or 3.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/ThreeOpt/ExhaustiveInsertionMoveGenerator.cs

    r3376 r3706  
    3535    public static TranslocationMove[] Apply(Permutation permutation) {
    3636      int length = permutation.Length;
     37      if (length == 1) throw new ArgumentException("ExhaustiveInsertionMoveGenerator: There cannot be an insertion move given a permutation of length 1.", "permutation");
    3738      TranslocationMove[] moves = null;
    3839      int count = 0;
     
    4546        }
    4647      } else {
    47         moves = new TranslocationMove[length * (length - 1) - 2];
    48         for (int i = 0; i < length; i++) {
    49           for (int j = 1; j <= length - 1; j++) {
    50             if (i == 0 && j == length - 1
    51               || i == length - 1 && j == 1) continue;
    52             moves[count++] = new TranslocationMove(i, i, (i + j) % length);
     48        if (length > 2) {
     49          moves = new TranslocationMove[length * (length - 1) - 2];
     50          for (int i = 0; i < length; i++) {
     51            for (int j = 1; j <= length - 1; j++) {
     52              if (i == 0 && j == length - 1
     53                || i == length - 1 && j == 1) continue;
     54              moves[count++] = new TranslocationMove(i, i, (i + j) % length);
     55            }
    5356          }
     57        } else { // doesn't make sense, but just create a dummy move to not crash the algorithms
     58          moves = new TranslocationMove[1];
     59          moves[0] = new TranslocationMove(0, 0, 1);
    5460        }
    5561      }
Note: See TracChangeset for help on using the changeset viewer.