Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/30/11 15:40:40 (14 years ago)
Author:
abeham
Message:

#1497

  • Added problem-specific local improvement operator (best improvement local search using swap2 moves)
    • Adapted ExhaustiveSwap2MoveGenerator to yield moves
  • Added a parameter BestKnownSolutions to collect possible optimal invariants
    • Adapted BestQAPSolutionAnalyzer to collect optimal invariants
  • Added a function to the QAP Evaluator that calculates the impact of a certain allele
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram/HeuristicLab.Encodings.PermutationEncoding/3.3/Moves/Swap2/ExhaustiveSwap2MoveGenerator.cs

    r5933 r6086  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3940    }
    4041
     42    public static IEnumerable<Swap2Move> Generate(Permutation permutation) {
     43      int length = permutation.Length;
     44      if (length == 1) throw new ArgumentException("ExhaustiveSwap2MoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation");
     45
     46      for (int i = 0; i < length - 1; i++)
     47        for (int j = i + 1; j < length; j++) {
     48          yield return new Swap2Move(i, j);
     49        }
     50    }
     51
    4152    public static Swap2Move[] Apply(Permutation permutation) {
    4253      int length = permutation.Length;
    43       if (length == 1) throw new ArgumentException("ExhaustiveSwap2MoveGenerator: There cannot be an Swap move given a permutation of length 1.", "permutation");
    4454      int totalMoves = (length) * (length - 1) / 2;
    4555      Swap2Move[] moves = new Swap2Move[totalMoves];
    4656      int count = 0;
    47 
    48       for (int i = 0; i < length - 1; i++)
    49         for (int j = i + 1; j < length; j++) {
    50           moves[count++] = new Swap2Move(i, j);
    51         }
     57      foreach (Swap2Move move in Generate(permutation)) {
     58        moves[count++] = move;
     59      }
    5260      return moves;
    5361    }
Note: See TracChangeset for help on using the changeset viewer.