Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/15 16:38:08 (9 years ago)
Author:
abeham
Message:

#2221:

  • implemented review comments
    • hid rng as private class, implemented djb2 hash function (hash function implementation may also change)
    • added missing probabilities
    • base class for instance providers
    • prebuild event events
    • build platforms
    • unit test will be removed on trunk integration
    • corrected assembly file version
    • distance calculator parameter was not hidden, can be changed by user, updates distance matrix
    • fixed performance problems (ouch!) also for estimated ptsp (inlined GetDistance method)
  • added moves (full evaluation) for analytical tsp
  • added local improvement operators for analytical ptsp
  • added recalculation of distance matrix when parameters change
  • still lots of other changes
Location:
branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt
Files:
1 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt/PTSPAnalyticalTwoPointFiveMoveEvaluator.cs

    r13451 r13470  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2829
    2930namespace HeuristicLab.Problems.PTSP {
    30   [Item("PTSP 2.5-MoveEvaluator", "Operator that evaluates 2.5-p-opt moves of PTSP")]
     31  [Item("PTSP Analytical 2.5-MoveEvaluator", "Operator that evaluates 2.5-p-opt moves of PTSP by a full solution evaluation.")]
    3132  [StorableClass]
    32   public class PTSPTwoPointFiveMoveEvaluator : EstimatedPTSPMoveEvaluator, ITwoPointFiveMoveOperator {
     33  public class PTSPAnalyticalTwoPointFiveMoveEvaluator : AnalyticalPTSPMoveEvaluator, ITwoPointFiveMoveOperator {
    3334
    3435    public ILookupParameter<TwoPointFiveMove> TwoPointFiveMoveParameter {
     
    3738
    3839    [StorableConstructor]
    39     protected PTSPTwoPointFiveMoveEvaluator(bool deserializing) : base(deserializing) { }
    40     protected PTSPTwoPointFiveMoveEvaluator(PTSPTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
    41     public PTSPTwoPointFiveMoveEvaluator()
     40    protected PTSPAnalyticalTwoPointFiveMoveEvaluator(bool deserializing) : base(deserializing) { }
     41    protected PTSPAnalyticalTwoPointFiveMoveEvaluator(PTSPAnalyticalTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
     42    public PTSPAnalyticalTwoPointFiveMoveEvaluator()
    4243      : base() {
    4344      Parameters.Add(new LookupParameter<TwoPointFiveMove>("TwoPointFiveMove", "The move to evaluate."));
     
    4546
    4647    public override IDeepCloneable Clone(Cloner cloner) {
    47       return new PTSPTwoPointFiveMoveEvaluator(this, cloner);
     48      return new PTSPAnalyticalTwoPointFiveMoveEvaluator(this, cloner);
    4849    }
    4950
    50     protected override double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates, DistanceCalculator distanceCalculator) {
    51       var move = TwoPointFiveMoveParameter.ActualValue;
    52       var realizations = RealizationsParameter.ActualValue;
    53       return EvaluateByCoordinates(permutation, coordinates, distanceCalculator, move, realizations);
     51    protected override double EvaluateMove(Permutation permutation, Func<int, int, double> distance, DoubleArray probabilities) {
     52      return EvaluateMove(permutation, TwoPointFiveMoveParameter.ActualValue, distance, probabilities);
    5453    }
    5554
    56     public static double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates, DistanceCalculator distanceCalculator, TwoPointFiveMove move, ItemList<BoolArray> realizations) {
     55    public static double EvaluateMove(Permutation permutation, TwoPointFiveMove move, Func<int, int, double> distance, DoubleArray probabilities) {
    5756      if (move.IsInvert) {
    58         return PTSPEstimatedInversionMoveEvaluator.EvaluateByCoordinates(permutation,
    59           new InversionMove(move.Index1, move.Index2, move.Permutation),
    60           coordinates, distanceCalculator, realizations);
     57        return PTSPAnalyticalInversionMoveEvaluator.EvaluateMove(permutation,
     58          new InversionMove(move.Index1, move.Index2, move.Permutation), distance, probabilities);
    6159      } else {
    62         return PTSPEstimatedInsertionMoveEvaluator.EvaluateByCoordinates(permutation,
    63           new TranslocationMove(move.Index1, move.Index1, move.Index2),
    64           coordinates, distanceCalculator, realizations);
    65       }
    66     }
    67 
    68     protected override double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix) {
    69       var move = TwoPointFiveMoveParameter.ActualValue;
    70       var realizations = RealizationsParameter.ActualValue;
    71       return EvaluateByDistanceMatrix(permutation, distanceMatrix, move, realizations);
    72     }
    73 
    74     public static double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix, TwoPointFiveMove move, ItemList<BoolArray> realizations) {
    75       if (move.IsInvert) {
    76         return PTSPEstimatedInversionMoveEvaluator.EvaluateByDistanceMatrix(permutation,
    77           new InversionMove(move.Index1, move.Index2, move.Permutation),
    78           distanceMatrix, realizations);
    79       } else {
    80         return PTSPEstimatedInsertionMoveEvaluator.EvaluateByDistanceMatrix(permutation,
    81           new TranslocationMove(move.Index1, move.Index1, move.Index2),
    82           distanceMatrix, realizations);
     60        return PTSPAnalyticalInsertionMoveEvaluator.EvaluateMove(permutation,
     61          new TranslocationMove(move.Index1, move.Index1, move.Index2), distance, probabilities);
    8362      }
    8463    }
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt/PTSPEstimatedTwoPointFiveMoveEvaluator.cs

    r13469 r13470  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2829
    2930namespace HeuristicLab.Problems.PTSP {
    30   [Item("PTSP 2.5-MoveEvaluator", "Operator that evaluates 2.5-p-opt moves of PTSP")]
     31  [Item("PTSP Estimated 2.5-MoveEvaluator", "Operator that evaluates 2.5-p-opt moves of PTSP")]
    3132  [StorableClass]
    32   public class PTSPTwoPointFiveMoveEvaluator : EstimatedPTSPMoveEvaluator, ITwoPointFiveMoveOperator {
     33  public class PTSPEstimatedTwoPointFiveMoveEvaluator : EstimatedPTSPMoveEvaluator, ITwoPointFiveMoveOperator {
    3334
    3435    public ILookupParameter<TwoPointFiveMove> TwoPointFiveMoveParameter {
     
    3738
    3839    [StorableConstructor]
    39     protected PTSPTwoPointFiveMoveEvaluator(bool deserializing) : base(deserializing) { }
    40     protected PTSPTwoPointFiveMoveEvaluator(PTSPTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
    41     public PTSPTwoPointFiveMoveEvaluator()
     40    protected PTSPEstimatedTwoPointFiveMoveEvaluator(bool deserializing) : base(deserializing) { }
     41    protected PTSPEstimatedTwoPointFiveMoveEvaluator(PTSPEstimatedTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }
     42    public PTSPEstimatedTwoPointFiveMoveEvaluator()
    4243      : base() {
    4344      Parameters.Add(new LookupParameter<TwoPointFiveMove>("TwoPointFiveMove", "The move to evaluate."));
     
    4546
    4647    public override IDeepCloneable Clone(Cloner cloner) {
    47       return new PTSPTwoPointFiveMoveEvaluator(this, cloner);
     48      return new PTSPEstimatedTwoPointFiveMoveEvaluator(this, cloner);
    4849    }
    4950
    50     protected override double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates, DistanceCalculator distanceCalculator) {
    51       var move = TwoPointFiveMoveParameter.ActualValue;
    52       var realizations = RealizationsParameter.ActualValue;
    53       return EvaluateByCoordinates(permutation, coordinates, distanceCalculator, move, realizations);
     51    protected override double EvaluateMove(Permutation permutation, Func<int, int, double> distance, ItemList<BoolArray> realizations) {
     52      return EvaluateMove(permutation, TwoPointFiveMoveParameter.ActualValue, distance, realizations);
    5453    }
    5554
    56     public static double EvaluateByCoordinates(Permutation permutation, DoubleMatrix coordinates, DistanceCalculator distanceCalculator, TwoPointFiveMove move, ItemList<BoolArray> realizations) {
     55    public static double EvaluateMove(Permutation permutation, TwoPointFiveMove move, Func<int, int, double> distance, ItemList<BoolArray> realizations) {
    5756      if (move.IsInvert) {
    58         return PTSPEstimatedInversionMoveEvaluator.EvaluateByCoordinates(permutation,
    59           new InversionMove(move.Index1, move.Index2, move.Permutation),
    60           coordinates, distanceCalculator, realizations);
     57        return PTSPEstimatedInversionMoveEvaluator.EvaluateMove(permutation,
     58          new InversionMove(move.Index1, move.Index2, move.Permutation), distance, realizations);
    6159      } else {
    62         return PTSPEstimatedInsertionMoveEvaluator.EvaluateByCoordinates(permutation,
    63           new TranslocationMove(move.Index1, move.Index1, move.Index2),
    64           coordinates, distanceCalculator, realizations);
    65       }
    66     }
    67 
    68     protected override double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix) {
    69       var move = TwoPointFiveMoveParameter.ActualValue;
    70       var realizations = RealizationsParameter.ActualValue;
    71       return EvaluateByDistanceMatrix(permutation, distanceMatrix, move, realizations);
    72     }
    73 
    74     public static double EvaluateByDistanceMatrix(Permutation permutation, DistanceMatrix distanceMatrix, TwoPointFiveMove move, ItemList<BoolArray> realizations) {
    75       if (move.IsInvert) {
    76         return PTSPEstimatedInversionMoveEvaluator.EvaluateByDistanceMatrix(permutation,
    77           new InversionMove(move.Index1, move.Index2, move.Permutation),
    78           distanceMatrix, realizations);
    79       } else {
    80         return PTSPEstimatedInsertionMoveEvaluator.EvaluateByDistanceMatrix(permutation,
    81           new TranslocationMove(move.Index1, move.Index1, move.Index2),
    82           distanceMatrix, realizations);
     60        return PTSPEstimatedInsertionMoveEvaluator.EvaluateMove(permutation,
     61          new TranslocationMove(move.Index1, move.Index1, move.Index2), distance, realizations);
    8362      }
    8463    }
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Moves/TwoPointFiveOpt/TwoPointFiveMoveMaker.cs

    r13412 r13470  
    7171      var quality = QualityParameter.ActualValue;
    7272
     73      Apply(permutation, move);
     74
     75      quality.Value = moveQuality.Value;
     76
     77      return base.Apply();
     78    }
     79
     80    public static void Apply(Permutation permutation, TwoPointFiveMove move) {
    7381      if (move.IsInvert) {
    7482        InversionManipulator.Apply(permutation, move.Index1, move.Index2);
     
    7684        TranslocationManipulator.Apply(permutation, move.Index1, move.Index1, move.Index2);
    7785      }
    78 
    79       quality.Value = moveQuality.Value;
    80 
    81       return base.Apply();
    8286    }
    8387  }
Note: See TracChangeset for help on using the changeset viewer.