Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/09/13 15:03:41 (12 years ago)
Author:
jhelm
Message:

#1966: Fixed some problems in MCV-move operators; Added parts of potvin-encoding implementation;

Location:
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings
Files:
13 added
2 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Attributes/SingleGroupingMoveAttribute.cs

    r9440 r9473  
    2929  public class SingleGroupingMoveAttribute : MultiComponentVectorMoveAttribute {
    3030    [Storable]
    31     public int ItemIndex { get; protected set; }
     31    public int Index { get; protected set; }
    3232    [Storable]
    3333    public int AssignedBin { get; protected set; }
     
    3737    protected SingleGroupingMoveAttribute(SingleGroupingMoveAttribute original, Cloner cloner)
    3838      : base(original, cloner) {
    39       this.ItemIndex = original.ItemIndex;
     39      this.Index = original.Index;
    4040      this.AssignedBin = original.AssignedBin;
    4141    }
    4242    public SingleGroupingMoveAttribute() : this(-1, -1, -1) { }
    43     public SingleGroupingMoveAttribute(int itemIndex, int assignedBin, double moveQuality)
     43    public SingleGroupingMoveAttribute(int index, int assignedBin, double moveQuality)
    4444      : base(moveQuality) {
    45       ItemIndex = itemIndex;
     45      Index = index;
    4646      AssignedBin = assignedBin;
    4747    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/ExhaustiveMultiComponentVectorMoveGenerator.cs

    r9440 r9473  
    4040    }
    4141
    42 
    4342    public static MultiComponentVectorMove[] Apply(MultiComponentVectorEncoding multiComponentVector) {
    44       //NrOfMoves = nrOfRotationMoves + nrOfSingleGroupingMoves + nrOfSwapSequenceMoves
     43      //NrOfMoves = nrOfRotationMoves + nrOfSingleGroupingMoves + nrOfSwapPositionMoves
    4544      //  nrOfRotationMoves       = nrOfItems
    4645      //  nrOfSingleGroupingMoves = nrOfItems * (nrOfBins - 1)
    47       //  nrOfSwapSequenceMoves   = SUM(foreach binNr: !nrOfItemsInBin)
    48 
    49       int lastBinNr = 0;
    50       foreach (var pi in multiComponentVector.PackingInformations) {
    51         if (pi.AssignedBin > lastBinNr)
    52           lastBinNr = pi.AssignedBin;
    53       }
    54       int nrOfBins = lastBinNr + 1;
    55 
    56       int nrOfRotationMoves = multiComponentVector.PackingInformations.Count;
    57       int nrOfSingleGroupingMoves = nrOfRotationMoves * (nrOfBins - 1);
    58 
    59       int[] itemsPerBin = new int[nrOfBins];
    60       foreach (var pi in multiComponentVector.PackingInformations) {
    61         itemsPerBin[pi.AssignedBin]++;
    62       }
    63       int nrOfSwapSequenceMoves = 0;
    64       foreach (int items in itemsPerBin) {
    65         nrOfSwapSequenceMoves += (items * (items - 1)) / 2;
    66       }
    67 
    68       int totalMoves = nrOfRotationMoves + nrOfSingleGroupingMoves + nrOfSwapSequenceMoves;
     46      //  nrOfSwapPositionMoves   = SUM(foreach binNr: !nrOfItemsInBin)
     47      int totalMoves =
     48        NrOfRotationMoves(multiComponentVector) +
     49        NrOfSingleGroupingMoves(multiComponentVector) +
     50        NrOfSwapPositionMoves(multiComponentVector) +
     51        NrOfChangePositionMoves(multiComponentVector);
    6952      MultiComponentVectorMove[] moves = new MultiComponentVectorMove[totalMoves];
    7053      int count = 0;
     
    7558        moves[count++] = move;
    7659      }
    77       foreach (MultiComponentVectorMove move in GenerateSwapSequenceMoves(multiComponentVector)) {
     60      foreach (MultiComponentVectorMove move in GenerateSwapPositionMoves(multiComponentVector)) {
     61        moves[count++] = move;
     62      }
     63      foreach (MultiComponentVectorMove move in GenerateChangePositionMoves(multiComponentVector)) {
    7864        moves[count++] = move;
    7965      }
    8066      return moves;
    81     }   
     67    } 
    8268
    8369    protected override MultiComponentVectorMove[] GenerateMoves(MultiComponentVectorEncoding multiComponentVector) {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleGroupingMove.cs

    r9440 r9473  
    3030  public class SingleGroupingMove : MultiComponentVectorMove {
    3131    [Storable]
    32     public int ItemIndex { get; protected set; }
     32    public int Index { get; protected set; }
    3333    [Storable]
    3434    public int NewGroup { get; protected set; }
     
    3838    protected SingleGroupingMove(SingleGroupingMove original, Cloner cloner)
    3939      : base(original, cloner) {
    40       this.ItemIndex = original.ItemIndex;
     40      this.Index = original.Index;
    4141      this.NewGroup = original.NewGroup;
    4242    }
    4343    public SingleGroupingMove(int index, int newGroup, MultiComponentVectorEncoding multiComponentVector)
    4444      : base(multiComponentVector) {
    45       ItemIndex = index;
     45      Index = index;
    4646      NewGroup = newGroup;
    4747    }
     
    5252
    5353    public override MultiComponentVectorEncoding GetVectorAfterMove() {
    54       //var result = new MultiComponentVectorEncoding();
    55       //result.PackingInformations = new ItemList<PackingInformation>(this.MultiComponentVector.PackingInformations);
    56       //result.PackingInformations[ItemIndex].AssignedBin = NewGroup;
    57       //return result;
    58       return InsertItemgeneAfterLastItemgeneOfUsedBin(MultiComponentVector, ItemIndex, NewGroup);
     54      return GetVectorAfterMove(MultiComponentVector, Index, NewGroup);
    5955    }
    60     private MultiComponentVectorEncoding InsertItemgeneAfterLastItemgeneOfUsedBin(MultiComponentVectorEncoding solution, int itemIndex, int binNr) {
     56    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding originalSolution, int itemIndex, int binNr) {
     57      var solution = originalSolution.Clone (new Cloner()) as MultiComponentVectorEncoding;
    6158      var itemgene = solution.PackingInformations[itemIndex];
    6259      solution.PackingInformations.Remove(itemgene);
     
    6461      int targetIndex = solution.PackingInformations.FindLastIndex(pi => pi.AssignedBin == binNr);
    6562      solution.PackingInformations.Insert(targetIndex + 1, itemgene);
     63      //solution.PackingInformations[itemIndex].AssignedBin = binNr;
    6664      return solution;
    6765    }
     
    7068      return typeof(SingleGroupingMoveAttribute);
    7169    }
     70
     71    public override string ToString() {
     72      return "GM(i="+Index+",g="+NewGroup+")";
     73    }
    7274  }
    7375}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleItemRotationMove.cs

    r9440 r9473  
    4848
    4949    public override MultiComponentVectorEncoding GetVectorAfterMove() {
    50       var result = new MultiComponentVectorEncoding();
    51       result.PackingInformations = new ItemList<PackingInformation>(this.MultiComponentVector.PackingInformations);
    52       result.PackingInformations[ItemIndex].Rotated = !result.PackingInformations[ItemIndex].Rotated;
     50      return GetVectorAfterMove (MultiComponentVector, ItemIndex);
     51    }
     52    public static MultiComponentVectorEncoding GetVectorAfterMove(MultiComponentVectorEncoding multiComponentVector, int itemIndex) {
     53      var result = multiComponentVector.Clone(new Cloner()) as MultiComponentVectorEncoding;
     54      result.PackingInformations[itemIndex].Rotated = !result.PackingInformations[itemIndex].Rotated;
    5355      return result;
    5456    }
     
    5759      return typeof(SingleItemRotationMoveAttribute);
    5860    }
     61
     62    public override string ToString() {
     63      return "RM(i=" + ItemIndex+")";
     64    }
    5965  }
    6066}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveGenerator.cs

    r9440 r9473  
    2727using HeuristicLab.Parameters;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Problems.BinPacking.Decoders;
    2930using HeuristicLab.Problems.BinPacking.Interfaces;
     31using HeuristicLab.Problems.BinPacking.PackingBin;
     32using HeuristicLab.Problems.BinPacking.PackingItem;
    3033
    3134namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector {
     
    4447    protected ScopeParameter CurrentScopeParameter {
    4548      get { return (ScopeParameter)Parameters["CurrentScope"]; }
    46     }
     49    }               
     50
    4751
    4852    [StorableConstructor]
     
    5761
    5862
    59 
    60 
     63    public static int NrOfRotationMoves(MultiComponentVectorEncoding mcv) {
     64      return mcv.PackingInformations.Count;
     65    }
    6166    public static IEnumerable<MultiComponentVectorMove> GenerateRotationMoves(MultiComponentVectorEncoding multiComponentVector) {
    6267      for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++)
     
    6469    }
    6570
     71    public static int NrOfSingleGroupingMoves(MultiComponentVectorEncoding mcv) {
     72      int nrOfBins = 0;
     73      foreach (var pi in mcv.PackingInformations) {
     74        if (pi.AssignedBin > nrOfBins)
     75          nrOfBins = pi.AssignedBin;
     76      }
     77      nrOfBins++;
     78      return mcv.PackingInformations.Count * (nrOfBins - 1);
     79    }
    6680    public static IEnumerable<MultiComponentVectorMove> GenerateSingleGroupingMoves(MultiComponentVectorEncoding multiComponentVector) {
    6781      int nrOfBins = 0;
     
    7892    }
    7993
    80     public static IEnumerable<MultiComponentVectorMove> GenerateSwapSequenceMoves(MultiComponentVectorEncoding multiComponentVector) {
     94    public static int NrOfSwapPositionMoves(MultiComponentVectorEncoding mcv) {
     95      int nrOfBins = 0;
     96      foreach (var pi in mcv.PackingInformations) {
     97        if (pi.AssignedBin > nrOfBins)
     98          nrOfBins = pi.AssignedBin;
     99      }
     100      nrOfBins++;
     101      int[] itemsPerBin = new int[nrOfBins];
     102      foreach (var pi in mcv.PackingInformations) {
     103        itemsPerBin[pi.AssignedBin]++;
     104      }
     105      int nrOfSwapPositionMoves = 0;
     106      foreach (int items in itemsPerBin) {
     107        nrOfSwapPositionMoves += (items * (items - 1)) / 2;
     108      }
     109      return nrOfSwapPositionMoves;
     110    }
     111    public static IEnumerable<MultiComponentVectorMove> GenerateSwapPositionMoves(MultiComponentVectorEncoding multiComponentVector) {
    81112      Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>();
    82113      for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) {
     
    89120        for (int i = 0; i < entry.Value.Count - 1; i++)
    90121          for (int j = i + 1; j < entry.Value.Count; j++)
    91             yield return new SwapSequenceMove(entry.Value[i], entry.Value[j], multiComponentVector);
     122            yield return new SwapPositionMove(entry.Value[i], entry.Value[j], multiComponentVector);
    92123      }
    93124    }
    94125
     126    public static int NrOfChangePositionMoves(MultiComponentVectorEncoding mcv) {
     127      int nrOfBins = 0;
     128      foreach (var pi in mcv.PackingInformations) {
     129        if (pi.AssignedBin > nrOfBins)
     130          nrOfBins = pi.AssignedBin;
     131      }
     132      nrOfBins++;
     133      int[] itemsPerBin = new int[nrOfBins];
     134      foreach (var pi in mcv.PackingInformations) {
     135        itemsPerBin[pi.AssignedBin]++;
     136      }
     137      int nrOfSwapPositionMoves = 0;
     138      foreach (int items in itemsPerBin) {
     139        nrOfSwapPositionMoves += (items * (items - 1)) / 2;
     140      }
     141      return nrOfSwapPositionMoves;
     142    }
     143    public static IEnumerable<MultiComponentVectorMove> GenerateChangePositionMoves(MultiComponentVectorEncoding multiComponentVector) {
     144      Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>();
     145      for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) {
     146        int currentBin = multiComponentVector.PackingInformations[i].AssignedBin;
     147        if (!indexesPerBin.ContainsKey(currentBin))
     148          indexesPerBin[currentBin] = new List<int>();
     149        indexesPerBin[currentBin].Add(i);
     150      }
     151      foreach (var entry in indexesPerBin) {
     152        for (int i = 0; i < entry.Value.Count - 1; i++)
     153          for (int j = i + 1; j < entry.Value.Count; j++)
     154            yield return new ChangePositionMove(entry.Value[i], entry.Value[j], multiComponentVector);
     155      }
     156    }
    95157
    96158    public override IOperation Apply() {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveHardTabuCriterion.cs

    r9440 r9473  
    9494    private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) {
    9595      bool isTabu = false;
    96       SingleItemRotationMove sirm = move as SingleItemRotationMove; 
    97       SingleGroupingMove sgm = move as SingleGroupingMove;   
    98       SwapSequenceMove ssm = move as SwapSequenceMove;
     96      SingleItemRotationMove sirm = move as SingleItemRotationMove;
     97      SingleGroupingMove sgm = move as SingleGroupingMove;
     98      SwapPositionMove spm = move as SwapPositionMove;
     99      ChangePositionMove cpm = move as ChangePositionMove;
     100      MCVTripleMove tm = move as MCVTripleMove;
    99101      var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType()));
    100102
     
    102104        foreach (IItem tabuMove in attributes) {
    103105          SingleItemRotationMoveAttribute sirmAttr = (tabuMove as SingleItemRotationMoveAttribute);
     106          if (sirmAttr.MoveQuality.Equals(moveQuality))
     107            return true;
    104108          if (sirmAttr != null
    105109            && (!useAspiration
     
    114118        foreach (IItem tabuMove in attributes) {
    115119          SingleGroupingMoveAttribute sgmAttr = (tabuMove as SingleGroupingMoveAttribute);
     120          if (sgmAttr.MoveQuality.Equals(moveQuality))
     121            return true;
    116122          if (sgmAttr != null
    117123            && (!useAspiration
    118124                || maximization && moveQuality <= sgmAttr.MoveQuality
    119125                || !maximization && moveQuality >= sgmAttr.MoveQuality)) {
    120                   if (sgm.ItemIndex == sgmAttr.ItemIndex || multiComponentVector.PackingInformations[sgm.ItemIndex].AssignedBin == sgmAttr.AssignedBin)
     126                  if ( multiComponentVector.PackingInformations[sgm.Index].ItemIndex ==  multiComponentVector.PackingInformations[sgmAttr.Index].ItemIndex
     127                    || multiComponentVector.PackingInformations[sgm.Index].AssignedBin == sgmAttr.AssignedBin)
    121128                    isTabu = true;
    122129          }
    123130          if (isTabu) break;
    124131        }
    125       } else if (ssm != null) {
     132      } else if (spm != null) {
    126133        foreach (IItem tabuMove in attributes) {
    127           SwapSequenceMoveAttribute ssmAttr = (tabuMove as SwapSequenceMoveAttribute);
    128           if (ssmAttr != null
     134          SwapPositionMoveAttribute spmAttr = (tabuMove as SwapPositionMoveAttribute);
     135          if (spmAttr.MoveQuality.Equals(moveQuality))
     136            return true;
     137          if (spmAttr != null
    129138            && (!useAspiration
    130                 || maximization && moveQuality <= ssmAttr.MoveQuality
    131                 || !maximization && moveQuality >= ssmAttr.MoveQuality)) {
    132                   if (ssm.Index1 == ssmAttr.Index1
    133                     || ssm.Index2 == ssmAttr.Index2
    134                     || multiComponentVector.PackingInformations[ssm.Index1].ItemIndex == ssmAttr.ItemIndex1
    135                     || multiComponentVector.PackingInformations[ssm.Index2].ItemIndex == ssmAttr.ItemIndex2)
     139                || maximization && moveQuality <= spmAttr.MoveQuality
     140                || !maximization && moveQuality >= spmAttr.MoveQuality)) {
     141            if (spm.Index1 == spmAttr.Index1
     142              || spm.Index2 == spmAttr.Index2
     143              || multiComponentVector.PackingInformations[spm.Index1].ItemIndex == spmAttr.ItemIndex1
     144              || multiComponentVector.PackingInformations[spm.Index2].ItemIndex == spmAttr.ItemIndex2)
     145              isTabu = true;
     146          }
     147          if (isTabu) break;
     148        }
     149      } else if (cpm != null) {
     150        foreach (IItem tabuMove in attributes) {
     151          ChangePositionMoveAttribute cpmAttr = (tabuMove as ChangePositionMoveAttribute);
     152          if (cpmAttr.MoveQuality.Equals(moveQuality))
     153            return true;
     154          if (cpmAttr != null
     155            && (!useAspiration
     156                || maximization && moveQuality <= cpmAttr.MoveQuality
     157                || !maximization && moveQuality >= cpmAttr.MoveQuality)) {
     158            if (cpm.Index == cpmAttr.Index
     159        || cpm.TargetIndex == cpmAttr.TargetIndex
     160        || multiComponentVector.PackingInformations[cpm.Index].ItemIndex == cpmAttr.ItemIndex)
     161              isTabu = true;
     162          }
     163          if (isTabu) break;
     164        }
     165      } else if (tm != null) {
     166        foreach (IItem tabuMove in attributes) {
     167          MCVTripleMoveAttribute tmAttr = (tabuMove as MCVTripleMoveAttribute);
     168          if (tmAttr.MoveQuality.Equals(moveQuality))
     169            return true;
     170          if (tmAttr != null
     171            && (!useAspiration
     172                || maximization && moveQuality <= tmAttr.MoveQuality
     173                || !maximization && moveQuality >= tmAttr.MoveQuality)) {
     174                  if ((tm.Index == tmAttr.Index && tm.TargetIndex == tmAttr.TargetIndex)
     175                      || tm.Index == tmAttr.Index
     176                      || multiComponentVector.PackingInformations[tm.Index].ItemIndex == tmAttr.ItemIndex
     177                    )
    136178              isTabu = true;
    137179          }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveMaker.cs

    r9440 r9473  
    6666    public override IOperation Apply() {
    6767      MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue;
    68       MultiComponentVectorEncoding MultiComponentVector = MultiComponentVectorParameter.ActualValue;
     68      MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue;
    6969      DoubleValue moveQuality = MoveQualityParameter.ActualValue;
    7070      DoubleValue quality = QualityParameter.ActualValue;
    7171
    72       MultiComponentVector = move.GetVectorAfterMove();
     72      multiComponentVector.PackingInformations = move.GetVectorAfterMove().PackingInformations;
    7373
    7474      quality.Value = moveQuality.Value;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveSoftTabuCriterion.cs

    r9440 r9473  
    6565    public MultiComponentVectorMoveSoftTabuCriterion()
    6666      : base() {
    67         Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));
     67      Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate."));
    6868      Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate."));
    6969      Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu."));
     
    9494    private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) {
    9595      bool isTabu = false;
    96       SingleItemRotationMove sirm = move as SingleItemRotationMove; 
    97       SingleGroupingMove sgm = move as SingleGroupingMove;   
    98       SwapSequenceMove ssm = move as SwapSequenceMove;
     96
     97      SingleItemRotationMove sirm = move as SingleItemRotationMove;
     98      SingleGroupingMove sgm = move as SingleGroupingMove;
     99      SwapPositionMove spm = move as SwapPositionMove;
     100      ChangePositionMove cpm = move as ChangePositionMove;
     101      MCVTripleMove tm = move as MCVTripleMove;
    99102      var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType()));
    100103
     
    106109                || maximization && moveQuality <= sirmAttr.MoveQuality
    107110                || !maximization && moveQuality >= sirmAttr.MoveQuality)) {
    108                   if (sirm.ItemIndex == sirmAttr.ItemIndex && multiComponentVector.PackingInformations[sirm.ItemIndex].Rotated == sirmAttr.ItemRotation)
    109                     isTabu = true;
     111            if (sirm.ItemIndex == sirmAttr.ItemIndex && multiComponentVector.PackingInformations[sirm.ItemIndex].Rotated == sirmAttr.ItemRotation)
     112              isTabu = true;
    110113          }
    111114          if (isTabu) break;
     
    118121                || maximization && moveQuality <= sgmAttr.MoveQuality
    119122                || !maximization && moveQuality >= sgmAttr.MoveQuality)) {
    120                   if (sgm.ItemIndex == sgmAttr.ItemIndex && multiComponentVector.PackingInformations[sgm.ItemIndex].AssignedBin == sgmAttr.AssignedBin)
    121                     isTabu = true;
     123                  if (multiComponentVector.PackingInformations[sgm.Index].ItemIndex == multiComponentVector.PackingInformations[sgmAttr.Index].ItemIndex
     124              && multiComponentVector.PackingInformations[sgm.Index].AssignedBin == sgmAttr.AssignedBin)
     125              isTabu = true;
    122126          }
    123127          if (isTabu) break;
    124128        }
    125       } else if (ssm != null) {
     129      } else if (spm != null) {
    126130        foreach (IItem tabuMove in attributes) {
    127           SwapSequenceMoveAttribute ssmAttr = (tabuMove as SwapSequenceMoveAttribute);
    128           if (ssmAttr != null
     131          SwapPositionMoveAttribute spmAttr = (tabuMove as SwapPositionMoveAttribute);
     132          if (spmAttr != null
    129133            && (!useAspiration
    130                 || maximization && moveQuality <= ssmAttr.MoveQuality
    131                 || !maximization && moveQuality >= ssmAttr.MoveQuality)) {
    132                   if (ssm.Index1 == ssmAttr.Index1
    133                     && ssm.Index2 == ssmAttr.Index2
    134                     && multiComponentVector.PackingInformations[ssm.Index1].ItemIndex == ssmAttr.ItemIndex1
    135                     && multiComponentVector.PackingInformations[ssm.Index2].ItemIndex == ssmAttr.ItemIndex2)
     134                || maximization && moveQuality <= spmAttr.MoveQuality
     135                || !maximization && moveQuality >= spmAttr.MoveQuality)) {
     136            if (spm.Index1 == spmAttr.Index1
     137              && spm.Index2 == spmAttr.Index2
     138              && multiComponentVector.PackingInformations[spm.Index1].ItemIndex == spmAttr.ItemIndex1
     139              && multiComponentVector.PackingInformations[spm.Index2].ItemIndex == spmAttr.ItemIndex2)
     140              isTabu = true;
     141          }
     142          if (isTabu) break;
     143        }
     144      } else if (cpm != null) {
     145        foreach (IItem tabuMove in attributes) {
     146          ChangePositionMoveAttribute cpmAttr = (tabuMove as ChangePositionMoveAttribute);
     147          if (cpmAttr != null
     148            && (!useAspiration
     149                || maximization && moveQuality <= cpmAttr.MoveQuality
     150                || !maximization && moveQuality >= cpmAttr.MoveQuality)) {
     151            if (cpm.Index == cpmAttr.Index
     152        && cpm.TargetIndex == cpmAttr.TargetIndex
     153        && multiComponentVector.PackingInformations[cpm.Index].ItemIndex == cpmAttr.ItemIndex)
     154              isTabu = true;
     155          }
     156          if (isTabu) break;
     157        }
     158      } else if (tm != null) {
     159        foreach (IItem tabuMove in attributes) {
     160          MCVTripleMoveAttribute tmAttr = (tabuMove as MCVTripleMoveAttribute);
     161          if (tmAttr != null
     162            && (!useAspiration
     163                || maximization && moveQuality <= tmAttr.MoveQuality
     164                || !maximization && moveQuality >= tmAttr.MoveQuality)) {
     165            if ((tm.Index == tmAttr.Index && tm.TargetIndex == tmAttr.TargetIndex)
     166                && multiComponentVector.PackingInformations[tm.Index].ItemIndex == tmAttr.ItemIndex
     167                && tm.Rotation == !(tmAttr.RotationAfter.Equals(tmAttr.RotationBefore))
     168                && (tm.Group == tmAttr.GroupAfter && multiComponentVector.PackingInformations[tm.Index].AssignedBin == tmAttr.GroupBefore)
     169              )
    136170              isTabu = true;
    137171          }
     
    140174      }
    141175
    142      
     176
    143177
    144178      return isTabu;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorTabuMaker.cs

    r9440 r9473  
    6464      SingleGroupingMove sgm = move as SingleGroupingMove;
    6565      if (sgm != null)
    66         return new SingleGroupingMoveAttribute(sgm.ItemIndex, solution.PackingInformations[sgm.ItemIndex].AssignedBin, baseQuality);
    67       SwapSequenceMove ssm = move as SwapSequenceMove;
    68       if (ssm != null)
    69         return new SwapSequenceMoveAttribute(ssm.Index1, ssm.Index2, solution.PackingInformations[ssm.Index1].ItemIndex, solution.PackingInformations[ssm.Index2].ItemIndex, baseQuality);
     66        return new SingleGroupingMoveAttribute(sgm.Index, solution.PackingInformations[sgm.Index].AssignedBin, baseQuality);
     67      SwapPositionMove spm = move as SwapPositionMove;
     68      if (spm != null)
     69        return new SwapPositionMoveAttribute(spm.Index1, spm.Index2, solution.PackingInformations[spm.Index1].ItemIndex, solution.PackingInformations[spm.Index2].ItemIndex, baseQuality);
     70      ChangePositionMove cpm = move as ChangePositionMove;
     71      if (cpm != null)
     72        return new ChangePositionMoveAttribute(cpm.Index, cpm.TargetIndex, solution.PackingInformations[cpm.Index].ItemIndex, baseQuality);
     73      MCVTripleMove tm = move as MCVTripleMove;
     74      if (tm != null)
     75        return new MCVTripleMoveAttribute(
     76          tm.Index,
     77          tm.TargetIndex,
     78          solution.PackingInformations[tm.Index].ItemIndex,
     79          solution.PackingInformations[tm.Index].Rotated,
     80          tm.Rotation ^ solution.PackingInformations[tm.Index].Rotated,
     81          solution.PackingInformations[tm.Index].AssignedBin,
     82          tm.Group,
     83          baseQuality);
    7084
    7185      else return solution;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/StochasticMultiComponentVectorMoveGenerator.cs

    r9440 r9473  
    6060      MultiComponentVectorMove[] moves = new MultiComponentVectorMove[sampleSize];
    6161      var rm = new List<MultiComponentVectorMove> (GenerateRotationMoves(multiComponentVector));
    62       var gm = new List<MultiComponentVectorMove> (GenerateSingleGroupingMoves(multiComponentVector));
    63       var sm = new List<MultiComponentVectorMove> (GenerateSwapSequenceMoves(multiComponentVector));
     62      var gm = new List<MultiComponentVectorMove>(GenerateSingleGroupingMoves(multiComponentVector));
     63      var sm = new List<MultiComponentVectorMove>(GenerateSwapPositionMoves(multiComponentVector));
     64      var cpm = new List<MultiComponentVectorMove>(GenerateChangePositionMoves(multiComponentVector));
    6465
    6566      for (int i = 0; i < sampleSize; i++) {
    66         int typeDecision = random.Next(3);
     67        int typeDecision = random.Next(4);
    6768        switch (typeDecision) {
    6869          case 0: moves[i] = rm[random.Next(rm.Count)];
     
    7172            break;
    7273          case 2: moves[i] = sm[random.Next(sm.Count)];
     74            break;
     75          case 3: moves[i] = cpm[random.Next(cpm.Count)];
    7376            break;
    7477          default:
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorEncoding.cs

    r9440 r9473  
    6868      MultiComponentVectorEncoding mce = obj as MultiComponentVectorEncoding;
    6969      if (mce != null && mce.PackingInformations != null && mce.PackingInformations.Count == this.PackingInformations.Count) {
    70         for (int i = 0; i <= mce.PackingInformations.Count; i++) {
     70        for (int i = 0; i < mce.PackingInformations.Count; i++) {
    7171          if (mce.PackingInformations[i] != this.PackingInformations[i])
    7272            return false;
     
    134134      var result = new ItemList<PackingInformation>();
    135135      foreach (int itemIndex in permutation) {
    136         result.Add(new PackingInformation (itemIndex, random.Next(0, lowerBound + 1), random.Next(0,100) > 60 ? true : false));
     136        result.Add(new PackingInformation(itemIndex, random.Next(0, lowerBound + 1), random.Next(0, 100) > 60 ? true : false));
     137      }
     138      return result;
     139    }
     140
     141    public static ItemList<PackingInformation> CreateListRandomlyWithSortedSequence(int items, int lowerBound, IRandom random) {
     142      Permutation permutation = new Permutation(PermutationTypes.Absolute, items);
     143      var result = new ItemList<PackingInformation>();
     144      foreach (int itemIndex in permutation) {
     145        result.Add(new PackingInformation(itemIndex, random.Next(0, lowerBound + 1), false));
    137146      }
    138147      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorRandomCreator.cs

    r9440 r9473  
    4343      get { return (IValueLookupParameter<IntValue>)Parameters["LowerBound"]; }
    4444    }
     45    public IValueParameter<BoolValue> SortedSequenceParameter {
     46      get { return (IValueParameter<BoolValue>)Parameters["SortedSequence"]; }
     47    }
    4548
    4649    [StorableConstructor]
     
    5255    }
    5356
    54     public MultiComponentVectorRandomCreator()
     57    public MultiComponentVectorRandomCreator()
    5558      : base() {
    5659      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator."));
    5760      Parameters.Add(new ValueLookupParameter<IntValue>("PackingItems", "The number of packing-items handled in this problem instance."));
    5861      Parameters.Add(new ValueLookupParameter<IntValue>("LowerBound", "The lower possible number of bins needed to solve this problem (taken from Dell'Amico, Martello and Vigo; 2002)"));
     62      Parameters.Add(new ValueParameter<BoolValue>("SortedSequence", "Determines if the items of the created instances are to be sorted by their size."));
    5963
    6064      EncodedSolutionParameter.ActualName = "MultiComponentVector";
     65      SortedSequenceParameter.ActualValue = new BoolValue(false);
    6166    }
    6267
    6368
    64     public static MultiComponentVectorEncoding Apply(int items, int lowerBound, IRandom random) {
     69    public static MultiComponentVectorEncoding Apply(int items, int lowerBound, IRandom random, bool sortedSequence) {
    6570      var solution = new MultiComponentVectorEncoding();
    66       solution.PackingInformations = PackingInformation.CreateListRandomly(items, lowerBound, random);
     71      if (sortedSequence)
     72        solution.PackingInformations = PackingInformation.CreateListRandomlyWithSortedSequence(items, lowerBound, random);
     73      else
     74        solution.PackingInformations = PackingInformation.CreateListRandomly(items, lowerBound, random);
    6775      return solution;
    6876    }
    6977
    7078    protected override IPackingSolutionEncoding CreateSolution() {
    71       return Apply(PackingItemsParameter.ActualValue.Value, LowerBoundParameter.ActualValue.Value, RandomParameter.ActualValue);
     79      return Apply(PackingItemsParameter.ActualValue.Value, LowerBoundParameter.ActualValue.Value, RandomParameter.ActualValue, SortedSequenceParameter.Value.Value);
    7280    }
    7381  }
Note: See TracChangeset for help on using the changeset viewer.