private static bool EvaluateRelativeTabuState(ItemList <IItem> tabuList, Swap2Move move, Permutation permutation, double moveQuality, bool maximization, bool useAspiration)
        {
            bool isTabu = false;
            StandardEdgeEqualityComparer eq = new StandardEdgeEqualityComparer();
            bool        bidirectional       = permutation.PermutationType == PermutationTypes.RelativeUndirected;
            List <Edge> deleted             = new List <Edge>();

            deleted.Add(new Edge(permutation.GetCircular(move.Index1 - 1), permutation[move.Index1], bidirectional));
            deleted.Add(new Edge(permutation[move.Index1], permutation.GetCircular(move.Index1 + 1), bidirectional));
            deleted.Add(new Edge(permutation.GetCircular(move.Index2 - 1), permutation[move.Index2], bidirectional));
            deleted.Add(new Edge(permutation[move.Index2], permutation.GetCircular(move.Index2 + 1), bidirectional));
            List <Edge> added = new List <Edge>();

            added.Add(new Edge(permutation.GetCircular(move.Index1 - 1), permutation[move.Index2], bidirectional));
            added.Add(new Edge(permutation[move.Index2], permutation.GetCircular(move.Index1 + 1), bidirectional));
            added.Add(new Edge(permutation.GetCircular(move.Index2 - 1), permutation[move.Index1], bidirectional));
            added.Add(new Edge(permutation[move.Index1], permutation.GetCircular(move.Index2 + 1), bidirectional));

            foreach (IItem tabuMove in tabuList)
            {
                Swap2MoveRelativeAttribute relAttrib = (tabuMove as Swap2MoveRelativeAttribute);
                if (relAttrib != null &&
                    (!useAspiration ||
                     maximization && moveQuality <= relAttrib.MoveQuality ||
                     !maximization && moveQuality >= relAttrib.MoveQuality))
                {
                    for (int i = 0; i < relAttrib.AddedEdges.Count; i++)
                    {
                        isTabu = eq.Equals(relAttrib.AddedEdges[i], deleted[0]) ||
                                 eq.Equals(relAttrib.AddedEdges[i], deleted[1]) ||
                                 eq.Equals(relAttrib.AddedEdges[i], deleted[2]) ||
                                 eq.Equals(relAttrib.AddedEdges[i], deleted[3]);
                        if (isTabu)
                        {
                            break;
                        }
                    }
                    if (isTabu)
                    {
                        break;
                    }
                    for (int i = 0; i < relAttrib.DeletedEdges.Count; i++)
                    {
                        isTabu = eq.Equals(relAttrib.DeletedEdges[i], added[0]) ||
                                 eq.Equals(relAttrib.DeletedEdges[i], added[1]) ||
                                 eq.Equals(relAttrib.DeletedEdges[i], added[2]) ||
                                 eq.Equals(relAttrib.DeletedEdges[i], added[3]);
                        if (isTabu)
                        {
                            break;
                        }
                    }
                }
                if (isTabu)
                {
                    break;
                }
            }
            return(isTabu);
        }
예제 #2
0
        protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality)
        {
            Swap2Move   move        = Swap2MoveParameter.ActualValue;
            Permutation permutation = PermutationParameter.ActualValue;
            double      baseQuality = moveQuality;

            if (maximization && quality > moveQuality || !maximization && quality < moveQuality)
            {
                baseQuality = quality;                                                                            // we make an uphill move, the lower bound is the solution quality
            }
            if (permutation.PermutationType == PermutationTypes.Absolute)
            {
                return(new Swap2MoveAbsoluteAttribute(move.Index1, permutation[move.Index1], move.Index2, permutation[move.Index2], baseQuality));
            }
            else
            {
                Swap2MoveRelativeAttribute attrib = new Swap2MoveRelativeAttribute(baseQuality);
                bool bidirectional = permutation.PermutationType == PermutationTypes.RelativeUndirected;
                attrib.DeletedEdges.Add(new Edge(permutation.GetCircular(move.Index1 - 1), permutation[move.Index1], bidirectional));
                attrib.DeletedEdges.Add(new Edge(permutation[move.Index1], permutation.GetCircular(move.Index1 + 1), bidirectional));
                attrib.DeletedEdges.Add(new Edge(permutation.GetCircular(move.Index2 - 1), permutation[move.Index2], bidirectional));
                attrib.DeletedEdges.Add(new Edge(permutation[move.Index2], permutation.GetCircular(move.Index2 + 1), bidirectional));
                attrib.AddedEdges.Add(new Edge(permutation.GetCircular(move.Index1 - 1), permutation[move.Index2], bidirectional));
                attrib.AddedEdges.Add(new Edge(permutation[move.Index2], permutation.GetCircular(move.Index1 + 1), bidirectional));
                attrib.AddedEdges.Add(new Edge(permutation.GetCircular(move.Index2 - 1), permutation[move.Index1], bidirectional));
                attrib.AddedEdges.Add(new Edge(permutation[move.Index1], permutation.GetCircular(move.Index2 + 1), bidirectional));
                return(attrib);
            }
        }
예제 #3
0
 protected override IItem GetTabuAttribute(bool maximization, double quality, double moveQuality) {
   Swap2Move move = Swap2MoveParameter.ActualValue;
   Permutation permutation = PermutationParameter.ActualValue;
   double baseQuality = moveQuality;
   if (maximization && quality > moveQuality || !maximization && quality < moveQuality) baseQuality = quality; // we make an uphill move, the lower bound is the solution quality
   if (permutation.PermutationType == PermutationTypes.Absolute)
     return new Swap2MoveAbsoluteAttribute(move.Index1, permutation[move.Index1], move.Index2, permutation[move.Index2], baseQuality);
   else {
     Swap2MoveRelativeAttribute attrib = new Swap2MoveRelativeAttribute(baseQuality);
     bool bidirectional = permutation.PermutationType == PermutationTypes.RelativeUndirected;
     attrib.DeletedEdges.Add(new Edge(permutation.GetCircular(move.Index1 - 1), permutation[move.Index1], bidirectional));
     attrib.DeletedEdges.Add(new Edge(permutation[move.Index1], permutation.GetCircular(move.Index1 + 1), bidirectional));
     attrib.DeletedEdges.Add(new Edge(permutation.GetCircular(move.Index2 - 1), permutation[move.Index2], bidirectional));
     attrib.DeletedEdges.Add(new Edge(permutation[move.Index2], permutation.GetCircular(move.Index2 + 1), bidirectional));
     attrib.AddedEdges.Add(new Edge(permutation.GetCircular(move.Index1 - 1), permutation[move.Index2], bidirectional));
     attrib.AddedEdges.Add(new Edge(permutation[move.Index2], permutation.GetCircular(move.Index1 + 1), bidirectional));
     attrib.AddedEdges.Add(new Edge(permutation.GetCircular(move.Index2 - 1), permutation[move.Index1], bidirectional));
     attrib.AddedEdges.Add(new Edge(permutation[move.Index1], permutation.GetCircular(move.Index2 + 1), bidirectional));
     return attrib;
   }
 }
 protected Swap2MoveRelativeAttribute(Swap2MoveRelativeAttribute original, Cloner cloner)
   : base(original, cloner) {
   this.DeletedEdges = cloner.Clone(original.DeletedEdges);
   this.AddedEdges = cloner.Clone(original.AddedEdges);
 }
 protected Swap2MoveRelativeAttribute(Swap2MoveRelativeAttribute original, Cloner cloner)
     : base(original, cloner)
 {
     this.DeletedEdges = cloner.Clone(original.DeletedEdges);
     this.AddedEdges   = cloner.Clone(original.AddedEdges);
 }