Esempio n. 1
0
        public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, ItemList <BoolArray> realizations, CancellationToken cancellation)
        {
            var distanceM = (DistanceMatrix)distances;
            Func <int, int, double> distance = (a, b) => distanceM[a, b];

            for (var i = localIterations.Value; i < maxIterations; i++)
            {
                TwoPointFiveMove bestMove = null;
                var bestQuality           = 0.0; // we have to make an improvement, so 0 is the baseline
                var evaluations           = 0.0;
                foreach (var move in ExhaustiveTwoPointFiveMoveGenerator.Generate(assignment))
                {
                    var moveQuality = PTSPEstimatedTwoPointFiveMoveEvaluator.EvaluateMove(assignment, move, distance, realizations);
                    if (move.IsInvert)
                    {
                        evaluations += realizations.Count * 4.0 / (assignment.Length * assignment.Length);
                    }
                    else
                    {
                        evaluations += realizations.Count * 6.0 / (assignment.Length * assignment.Length);
                    }
                    if (maximization && moveQuality > bestQuality ||
                        !maximization && moveQuality < bestQuality)
                    {
                        bestQuality = moveQuality;
                        bestMove    = move;
                    }
                }
                evaluatedSolutions.Value += (int)Math.Ceiling(evaluations);
                if (bestMove == null)
                {
                    break;
                }
                TwoPointFiveMoveMaker.Apply(assignment, bestMove);
                quality.Value += bestQuality;
                localIterations.Value++;
                cancellation.ThrowIfCancellationRequested();
            }
        }
Esempio n. 2
0
 protected PTSPEstimatedTwoPointFiveMoveEvaluator(PTSPEstimatedTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner)
 {
 }
 protected PTSPEstimatedTwoPointFiveMoveEvaluator(PTSPEstimatedTwoPointFiveMoveEvaluator original, Cloner cloner) : base(original, cloner) { }