public override IOperation Apply()
        {
            var    permutation = PermutationParameter.ActualValue;
            double relativeQualityDifference = 0;
            var    distanceMatrix            = DistanceMatrixParameter.ActualValue;

            if (distanceMatrix == null)
            {
                throw new InvalidOperationException("The distance matrix is not given.");
            }
            var move = InversionMoveParameter.ActualValue;

            relativeQualityDifference = TSPInversionMovePathEvaluator.EvaluateByDistanceMatrix(permutation, move, distanceMatrix);

            var moveQuality = MoveQualityParameter.ActualValue;

            if (moveQuality == null)
            {
                MoveQualityParameter.ActualValue = new DoubleValue(QualityParameter.ActualValue.Value + relativeQualityDifference);
            }
            else
            {
                moveQuality.Value = QualityParameter.ActualValue.Value + relativeQualityDifference;
            }
            return(base.Apply());
        }
Beispiel #2
0
        public override IOperation Apply()
        {
            var solution = CurrentScope.Variables[SolutionParameter.ActualName].Value as Permutation;

            if (solution == null)
            {
                throw new ArgumentException("Cannot improve solution because it has the wrong type.");
            }
            if (solution.PermutationType != PermutationTypes.RelativeUndirected)
            {
                throw new ArgumentException("Cannot improve solution because the permutation type is not supported.");
            }

            for (int i = 0; i < ImprovementAttempts.Value; i++)
            {
                var    move        = StochasticInversionSingleMoveGenerator.Apply(solution, Random);
                double moveQualtiy = TSPInversionMovePathEvaluator.EvaluateByDistanceMatrix(solution, move, DistanceMatrix);
                if (moveQualtiy < 0)
                {
                    InversionManipulator.Apply(solution, move.Index1, move.Index2);
                }
            }

            CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", ImprovementAttempts));

            return(base.Apply());
        }