public override ISolution Apply(ISolution solution, Configuration configuration)
        {
            IPermutation permutation = (IPermutation)solution;
            TwoOperands  operands    = (TwoOperands)configuration;

            List <int> swapped = new List <int>(permutation.Order)
            {
                [operands.First]  = permutation.Order[operands.Second],
                [operands.Second] = permutation.Order[operands.First]
            };

            return(permutation.FetchPermutation(swapped, "swap"));
        }
예제 #2
0
        public override ISolution Apply(ISolution solution, Configuration configuration)
        {
            IPermutation permutation = (IPermutation)solution;
            TwoOperands  operands    = (TwoOperands)configuration;

            List <int> twoOpted;

            if (operands.First < operands.Second)
            {
                twoOpted = new List <int>(permutation.Order);
                twoOpted.Reverse(operands.First, operands.Second - operands.First + 1);
            }
            else
            {
                twoOpted = permutation.Order.GetRange(operands.First, permutation.Order.Count - operands.First);
                twoOpted.AddRange(permutation.Order.GetRange(0, operands.First));
                twoOpted.Reverse(0, operands.Second + twoOpted.Count - operands.First + 1);
            }

            return(permutation.FetchPermutation(twoOpted, "2opt"));
        }
        public override ISolution Apply(ISolution solution, Configuration configuration)
        {
            IPermutation permutation = (IPermutation)solution;
            TwoOperands  operands    = (TwoOperands)configuration;

            List <int> shifted = new List <int>(permutation.Order);

            int shiftedItem = shifted[operands.First];

            shifted.RemoveAt(operands.First);
            if (operands.Second <= operands.First)
            {
                shifted.Insert(operands.Second, shiftedItem);
            }
            else
            {
                shifted.Insert(operands.Second - 1, shiftedItem);
            }

            return(permutation.FetchPermutation(shifted, "shift"));
        }