protected TranslocationMoveAbsoluteAttribute(TranslocationMoveAbsoluteAttribute original, Cloner cloner)
     : base(original, cloner)
 {
     this.Number      = (int[])original.Number.Clone();
     this.OldPosition = original.OldPosition;
     this.NewPosition = original.NewPosition;
 }
Exemple #2
0
        public override IOperation Apply()
        {
            ItemList <IItem>  tabuList    = TabuListParameter.ActualValue;
            TranslocationMove move        = TranslocationMoveParameter.ActualValue;
            Permutation       permutation = PermutationParameter.ActualValue;
            int    length        = permutation.Length;
            double moveQuality   = MoveQualityParameter.ActualValue.Value;
            bool   maximization  = MaximizationParameter.ActualValue.Value;
            bool   useAspiration = UseAspirationCriterion.Value;
            bool   isTabu        = false;

            if (permutation.PermutationType == PermutationTypes.Absolute)
            {
                int   count   = move.Index2 - move.Index1 + 1;
                int[] numbers = new int[count];
                for (int i = move.Index1; i <= move.Index2; i++)
                {
                    numbers[i - move.Index1] = permutation[i];
                }

                foreach (IItem tabuMove in tabuList)
                {
                    TranslocationMoveAbsoluteAttribute attribute = (tabuMove as TranslocationMoveAbsoluteAttribute);
                    if (attribute != null)
                    {
                        if (!useAspiration ||
                            maximization && moveQuality <= attribute.MoveQuality ||
                            !maximization && moveQuality >= attribute.MoveQuality) // if the move quality is improving beyond what was recorded when the move in the tabu list was recorded the move is regarded as okay

                        {
                            for (int i = 0; i < count; i++)
                            {
                                for (int j = 0; j < attribute.Number.Length; j++)
                                {
                                    if (attribute.Number[j] == numbers[i])
                                    {
                                        isTabu = true;
                                        break;
                                    }
                                }
                                if (isTabu)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    if (isTabu)
                    {
                        break;
                    }
                }
            }
            else
            {
                int E1S = permutation.GetCircular(move.Index1 - 1);
                int E1T = permutation[move.Index1];
                int E2S = permutation[move.Index2];
                int E2T = permutation.GetCircular(move.Index2 + 1);
                int E3S, E3T;
                if (move.Index3 > move.Index1)
                {
                    E3S = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1);
                    E3T = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1 + 1);
                }
                else
                {
                    E3S = permutation.GetCircular(move.Index3 - 1);
                    E3T = permutation[move.Index3];
                }
                foreach (IItem tabuMove in tabuList)
                {
                    TranslocationMoveRelativeAttribute attribute = (tabuMove as TranslocationMoveRelativeAttribute);
                    if (attribute != null)
                    {
                        if (!useAspiration ||
                            maximization && moveQuality <= attribute.MoveQuality ||
                            !maximization && moveQuality >= attribute.MoveQuality)
                        {
                            if (permutation.PermutationType == PermutationTypes.RelativeUndirected)
                            {
                                if (// if previously added Edge3Source-Edge1Target is deleted
                                    attribute.Edge3Source == E1S && attribute.Edge1Target == E1T || attribute.Edge3Source == E1T && attribute.Edge1Target == E1S ||
                                    attribute.Edge3Source == E2S && attribute.Edge1Target == E2T || attribute.Edge3Source == E2T && attribute.Edge1Target == E2S ||
                                    attribute.Edge3Source == E3S && attribute.Edge1Target == E3T || attribute.Edge3Source == E3T && attribute.Edge1Target == E3S
                                    // if previously added Edge2Source-Edge3Target is deleted
                                    || attribute.Edge2Source == E1S && attribute.Edge3Target == E1T || attribute.Edge2Source == E1T && attribute.Edge3Target == E1S ||
                                    attribute.Edge2Source == E2S && attribute.Edge3Target == E2T || attribute.Edge2Source == E2T && attribute.Edge3Target == E2S ||
                                    attribute.Edge2Source == E3S && attribute.Edge3Target == E3T || attribute.Edge2Source == E3T && attribute.Edge3Target == E3S
                                    // if previously added Edge1Source-Edge2Target is deleted
                                    || attribute.Edge1Source == E1S && attribute.Edge2Target == E1T || attribute.Edge1Source == E1T && attribute.Edge2Target == E1S ||
                                    attribute.Edge1Source == E2S && attribute.Edge2Target == E2T || attribute.Edge1Source == E2T && attribute.Edge2Target == E2S ||
                                    attribute.Edge1Source == E3S && attribute.Edge2Target == E3T || attribute.Edge1Source == E3T && attribute.Edge2Target == E3S)
                                {
                                    isTabu = true;
                                    break;
                                }
                            }
                            else
                            {
                                if (// if previously added Edge3Source-Edge1Target is deleted
                                    attribute.Edge3Source == E1S && attribute.Edge1Target == E1T ||
                                    attribute.Edge3Source == E2S && attribute.Edge1Target == E2T ||
                                    attribute.Edge3Source == E3S && attribute.Edge1Target == E3T
                                    // if previously added Edge2Source-Edge3Target is deleted
                                    || attribute.Edge2Source == E1S && attribute.Edge3Target == E1T ||
                                    attribute.Edge2Source == E2S && attribute.Edge3Target == E2T ||
                                    attribute.Edge2Source == E3S && attribute.Edge3Target == E3T
                                    // if previously added Edge1Source-Edge2Target is deleted
                                    || attribute.Edge1Source == E1S && attribute.Edge2Target == E1T ||
                                    attribute.Edge1Source == E2S && attribute.Edge2Target == E2T ||
                                    attribute.Edge1Source == E3S && attribute.Edge2Target == E3T)
                                {
                                    isTabu = true;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            MoveTabuParameter.ActualValue = new BoolValue(isTabu);
            return(base.Apply());
        }
 protected TranslocationMoveAbsoluteAttribute(TranslocationMoveAbsoluteAttribute original, Cloner cloner)
   : base(original, cloner) {
   this.Number = (int[])original.Number.Clone();
   this.OldPosition = original.OldPosition;
   this.NewPosition = original.NewPosition;
 }