Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/20/12 15:45:10 (13 years ago)
Author:
abeham
Message:

#1834

  • fixed the cases where the move quality would not change
  • added unit tests for translocation and inversion move evaluators
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.TravelingSalesman/3.3/MoveEvaluators/TwoOpt/TSPInversionMovePathEvaluator.cs

    r7259 r7743  
    4646    }
    4747
    48     protected override double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates) {
    49       InversionMove move = InversionMoveParameter.ActualValue;
     48    public static double EvaluateByCoordinates(Permutation permutation, InversionMove move, DoubleMatrix coordinates, TSPInversionMovePathEvaluator evaluator) {
    5049      int edge1source = permutation.GetCircular(move.Index1 - 1);
    5150      int edge1target = permutation[move.Index1];
     
    5554      double moveQuality = 0;
    5655      // remove two edges
    57       moveQuality -= CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
     56      moveQuality -= evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
    5857            coordinates[edge1target, 0], coordinates[edge1target, 1]);
    59       moveQuality -= CalculateDistance(coordinates[edge2source, 0], coordinates[edge2source, 1],
     58      moveQuality -= evaluator.CalculateDistance(coordinates[edge2source, 0], coordinates[edge2source, 1],
    6059        coordinates[edge2target, 0], coordinates[edge2target, 1]);
    6160      // add two edges
    62       moveQuality += CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
     61      moveQuality += evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
    6362        coordinates[edge2source, 0], coordinates[edge2source, 1]);
    64       moveQuality += CalculateDistance(coordinates[edge1target, 0], coordinates[edge1target, 1],
     63      moveQuality += evaluator.CalculateDistance(coordinates[edge1target, 0], coordinates[edge1target, 1],
    6564        coordinates[edge2target, 0], coordinates[edge2target, 1]);
    6665      return moveQuality;
    6766    }
    6867
    69     protected override double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix) {
    70       InversionMove move = InversionMoveParameter.ActualValue;
     68    public static double EvaluateByDistanceMatrix(Permutation permutation, InversionMove move, DistanceMatrix distanceMatrix) {
    7169      int edge1source = permutation.GetCircular(move.Index1 - 1);
    7270      int edge1target = permutation[move.Index1];
     
    8381      return moveQuality;
    8482    }
     83
     84    protected override double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates) {
     85      return EvaluateByCoordinates(permutation, InversionMoveParameter.ActualValue, coordinates, this);
     86    }
     87
     88    protected override double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix) {
     89      return EvaluateByDistanceMatrix(permutation, InversionMoveParameter.ActualValue, distanceMatrix);
     90    }
    8591  }
    8692}
Note: See TracChangeset for help on using the changeset viewer.