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
File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPAnalyticalTwoPointFiveLocalImprovement.cs

    r13451 r13470  
    3838  /// The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.
    3939  /// </remarks>
    40   [Item("PTSPExhaustiveInversionLocalImprovement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
     40  [Item("PTSP Analytical 2.5 Local Improvement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")]
    4141  [StorableClass]
    42   public sealed class PTSPExhaustiveInversionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, ILocalImprovementOperator {
     42  public sealed class PTSPAnalyticalTwoPointFiveLocalImprovement : SingleSuccessorOperator, IAnalyticalPTSPOperator, ILocalImprovementOperator {
    4343
    4444    public ILookupParameter<IntValue> LocalIterationsParameter {
     
    7474    }
    7575
    76     public ILookupParameter<ItemList<BoolArray>> RealizationsParameter {
    77       get { return (ILookupParameter<ItemList<BoolArray>>)Parameters["Realizations"]; }
     76    public ILookupParameter<DoubleArray> ProbabilitiesParameter {
     77      get { return (ILookupParameter<DoubleArray>)Parameters["Probabilities"]; }
    7878    }
    7979
    8080    [StorableConstructor]
    81     private PTSPExhaustiveInversionLocalImprovement(bool deserializing) : base(deserializing) { }
    82     private PTSPExhaustiveInversionLocalImprovement(PTSPExhaustiveInversionLocalImprovement original, Cloner cloner) : base(original, cloner) { }
    83     public PTSPExhaustiveInversionLocalImprovement()
     81    private PTSPAnalyticalTwoPointFiveLocalImprovement(bool deserializing) : base(deserializing) { }
     82    private PTSPAnalyticalTwoPointFiveLocalImprovement(PTSPAnalyticalTwoPointFiveLocalImprovement original, Cloner cloner) : base(original, cloner) { }
     83    public PTSPAnalyticalTwoPointFiveLocalImprovement()
    8484      : base() {
    8585      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The solution as permutation."));
     
    9191      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized."));
    9292      Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities."));
    93       Parameters.Add(new LookupParameter<ItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances."));
     93      Parameters.Add(new LookupParameter<DoubleArray>("Probabilities", "The list of probabilities of the cities to appear."));
    9494    }
    9595
    9696    public override IDeepCloneable Clone(Cloner cloner) {
    97       return new PTSPExhaustiveInversionLocalImprovement(this, cloner);
     97      return new PTSPAnalyticalTwoPointFiveLocalImprovement(this, cloner);
    9898    }
    9999
    100     public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, CancellationToken cancellation, ItemList<BoolArray> realizations) {
     100    public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, DoubleArray probabilities, CancellationToken cancellation) {
    101101      var distanceM = (DistanceMatrix)distances;
     102      Func<int, int, double> distance = (a, b) => distanceM[a, b];
    102103      for (var i = localIterations.Value; i < maxIterations; i++) {
    103         InversionMove bestMove = null;
    104         double bestQuality = 0; // we have to make an improvement, so 0 is the baseline
    105         double evaluations = 0.0;
    106         foreach (var move in ExhaustiveInversionMoveGenerator.Generate(assignment)) {
    107           double moveQuality = PTSPEstimatedInversionMoveEvaluator.EvaluateByDistanceMatrix(assignment, move, distanceM, realizations);
    108           evaluations += 2 * (move.Index2 - move.Index1 + 1) / (double)assignment.Length;
     104        TwoPointFiveMove bestMove = null;
     105        var bestQuality = quality.Value; // we have to make an improvement, so current quality is the baseline
     106        var evaluations = 0.0;
     107        foreach (var move in ExhaustiveTwoPointFiveMoveGenerator.Generate(assignment)) {
     108          var moveQuality = PTSPAnalyticalTwoPointFiveMoveEvaluator.EvaluateMove(assignment, move, distance, probabilities);
     109          evaluations++;
    109110          if (maximization && moveQuality > bestQuality
    110111            || !maximization && moveQuality < bestQuality) {
     
    115116        evaluatedSolutions.Value += (int)Math.Ceiling(evaluations);
    116117        if (bestMove == null) break;
    117         InversionManipulator.Apply(assignment, bestMove.Index1, bestMove.Index2);
    118         quality.Value += bestQuality;
     118        TwoPointFiveMoveMaker.Apply(assignment, bestMove);
     119        quality.Value = bestQuality;
    119120        localIterations.Value++;
    120121        cancellation.ThrowIfCancellationRequested();
     
    130131      var localIterations = LocalIterationsParameter.ActualValue;
    131132      var evaluations = EvaluatedSolutionsParameter.ActualValue;
    132       var realizations = RealizationsParameter.ActualValue;
     133      var probabilities = ProbabilitiesParameter.ActualValue;
    133134      if (localIterations == null) {
    134135        localIterations = new IntValue(0);
     
    136137      }
    137138
    138       Improve(assignment, distances, quality, localIterations, evaluations, maximization, maxIterations, CancellationToken, realizations);
     139      Improve(assignment, distances, quality, localIterations, evaluations, maximization, maxIterations, probabilities, CancellationToken);
    139140
    140141      localIterations.Value = 0;
Note: See TracChangeset for help on using the changeset viewer.