public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, DoubleArray probabilities, CancellationToken cancellation)
        {
            var distanceM = (DistanceMatrix)distances;
            Func <int, int, double> distance = (a, b) => distanceM[a, b];

            for (var i = localIterations.Value; i < maxIterations; i++)
            {
                InversionMove bestMove    = null;
                var           bestQuality = quality.Value; // we have to make an improvement, so current quality is the baseline
                var           evaluations = 0.0;
                foreach (var move in ExhaustiveInversionMoveGenerator.Generate(assignment))
                {
                    var moveQuality = PTSPAnalyticalInversionMoveEvaluator.EvaluateMove(assignment, move, distance, probabilities);
                    evaluations++;
                    if (maximization && moveQuality > bestQuality ||
                        !maximization && moveQuality < bestQuality)
                    {
                        bestQuality = moveQuality;
                        bestMove    = move;
                    }
                }
                evaluatedSolutions.Value += (int)Math.Ceiling(evaluations);
                if (bestMove == null)
                {
                    break;
                }
                InversionManipulator.Apply(assignment, bestMove.Index1, bestMove.Index2);
                quality.Value = bestQuality;
                localIterations.Value++;
                cancellation.ThrowIfCancellationRequested();
            }
        }
Exemplo n.º 2
0
 public static double EvaluateMove(Permutation permutation, TwoPointFiveMove move, Func <int, int, double> distance, DoubleArray probabilities)
 {
     if (move.IsInvert)
     {
         return(PTSPAnalyticalInversionMoveEvaluator.EvaluateMove(permutation,
                                                                  new InversionMove(move.Index1, move.Index2, move.Permutation), distance, probabilities));
     }
     else
     {
         return(PTSPAnalyticalInsertionMoveEvaluator.EvaluateMove(permutation,
                                                                  new TranslocationMove(move.Index1, move.Index1, move.Index2), distance, probabilities));
     }
 }
 protected PTSPAnalyticalInversionMoveEvaluator(PTSPAnalyticalInversionMoveEvaluator original, Cloner cloner) : base(original, cloner)
 {
 }
 protected PTSPAnalyticalInversionMoveEvaluator(PTSPAnalyticalInversionMoveEvaluator original, Cloner cloner) : base(original, cloner) { }