- Timestamp:
- 05/09/13 15:03:41 (12 years ago)
- 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 29 29 public class SingleGroupingMoveAttribute : MultiComponentVectorMoveAttribute { 30 30 [Storable] 31 public int I temIndex { get; protected set; }31 public int Index { get; protected set; } 32 32 [Storable] 33 33 public int AssignedBin { get; protected set; } … … 37 37 protected SingleGroupingMoveAttribute(SingleGroupingMoveAttribute original, Cloner cloner) 38 38 : base(original, cloner) { 39 this.I temIndex = original.ItemIndex;39 this.Index = original.Index; 40 40 this.AssignedBin = original.AssignedBin; 41 41 } 42 42 public SingleGroupingMoveAttribute() : this(-1, -1, -1) { } 43 public SingleGroupingMoveAttribute(int i temIndex, int assignedBin, double moveQuality)43 public SingleGroupingMoveAttribute(int index, int assignedBin, double moveQuality) 44 44 : base(moveQuality) { 45 I temIndex = itemIndex;45 Index = index; 46 46 AssignedBin = assignedBin; 47 47 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/ExhaustiveMultiComponentVectorMoveGenerator.cs
r9440 r9473 40 40 } 41 41 42 43 42 public static MultiComponentVectorMove[] Apply(MultiComponentVectorEncoding multiComponentVector) { 44 //NrOfMoves = nrOfRotationMoves + nrOfSingleGroupingMoves + nrOfSwap SequenceMoves43 //NrOfMoves = nrOfRotationMoves + nrOfSingleGroupingMoves + nrOfSwapPositionMoves 45 44 // nrOfRotationMoves = nrOfItems 46 45 // 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); 69 52 MultiComponentVectorMove[] moves = new MultiComponentVectorMove[totalMoves]; 70 53 int count = 0; … … 75 58 moves[count++] = move; 76 59 } 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)) { 78 64 moves[count++] = move; 79 65 } 80 66 return moves; 81 } 67 } 82 68 83 69 protected override MultiComponentVectorMove[] GenerateMoves(MultiComponentVectorEncoding multiComponentVector) { -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleGroupingMove.cs
r9440 r9473 30 30 public class SingleGroupingMove : MultiComponentVectorMove { 31 31 [Storable] 32 public int I temIndex { get; protected set; }32 public int Index { get; protected set; } 33 33 [Storable] 34 34 public int NewGroup { get; protected set; } … … 38 38 protected SingleGroupingMove(SingleGroupingMove original, Cloner cloner) 39 39 : base(original, cloner) { 40 this.I temIndex = original.ItemIndex;40 this.Index = original.Index; 41 41 this.NewGroup = original.NewGroup; 42 42 } 43 43 public SingleGroupingMove(int index, int newGroup, MultiComponentVectorEncoding multiComponentVector) 44 44 : base(multiComponentVector) { 45 I temIndex = index;45 Index = index; 46 46 NewGroup = newGroup; 47 47 } … … 52 52 53 53 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); 59 55 } 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; 61 58 var itemgene = solution.PackingInformations[itemIndex]; 62 59 solution.PackingInformations.Remove(itemgene); … … 64 61 int targetIndex = solution.PackingInformations.FindLastIndex(pi => pi.AssignedBin == binNr); 65 62 solution.PackingInformations.Insert(targetIndex + 1, itemgene); 63 //solution.PackingInformations[itemIndex].AssignedBin = binNr; 66 64 return solution; 67 65 } … … 70 68 return typeof(SingleGroupingMoveAttribute); 71 69 } 70 71 public override string ToString() { 72 return "GM(i="+Index+",g="+NewGroup+")"; 73 } 72 74 } 73 75 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/Moves/SingleItemRotationMove.cs
r9440 r9473 48 48 49 49 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; 53 55 return result; 54 56 } … … 57 59 return typeof(SingleItemRotationMoveAttribute); 58 60 } 61 62 public override string ToString() { 63 return "RM(i=" + ItemIndex+")"; 64 } 59 65 } 60 66 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveGenerator.cs
r9440 r9473 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Problems.BinPacking.Decoders; 29 30 using HeuristicLab.Problems.BinPacking.Interfaces; 31 using HeuristicLab.Problems.BinPacking.PackingBin; 32 using HeuristicLab.Problems.BinPacking.PackingItem; 30 33 31 34 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { … … 44 47 protected ScopeParameter CurrentScopeParameter { 45 48 get { return (ScopeParameter)Parameters["CurrentScope"]; } 46 } 49 } 50 47 51 48 52 [StorableConstructor] … … 57 61 58 62 59 60 63 public static int NrOfRotationMoves(MultiComponentVectorEncoding mcv) { 64 return mcv.PackingInformations.Count; 65 } 61 66 public static IEnumerable<MultiComponentVectorMove> GenerateRotationMoves(MultiComponentVectorEncoding multiComponentVector) { 62 67 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) … … 64 69 } 65 70 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 } 66 80 public static IEnumerable<MultiComponentVectorMove> GenerateSingleGroupingMoves(MultiComponentVectorEncoding multiComponentVector) { 67 81 int nrOfBins = 0; … … 78 92 } 79 93 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) { 81 112 Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>(); 82 113 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) { … … 89 120 for (int i = 0; i < entry.Value.Count - 1; i++) 90 121 for (int j = i + 1; j < entry.Value.Count; j++) 91 yield return new Swap SequenceMove(entry.Value[i], entry.Value[j], multiComponentVector);122 yield return new SwapPositionMove(entry.Value[i], entry.Value[j], multiComponentVector); 92 123 } 93 124 } 94 125 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 } 95 157 96 158 public override IOperation Apply() { -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveHardTabuCriterion.cs
r9440 r9473 94 94 private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) { 95 95 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; 99 101 var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType())); 100 102 … … 102 104 foreach (IItem tabuMove in attributes) { 103 105 SingleItemRotationMoveAttribute sirmAttr = (tabuMove as SingleItemRotationMoveAttribute); 106 if (sirmAttr.MoveQuality.Equals(moveQuality)) 107 return true; 104 108 if (sirmAttr != null 105 109 && (!useAspiration … … 114 118 foreach (IItem tabuMove in attributes) { 115 119 SingleGroupingMoveAttribute sgmAttr = (tabuMove as SingleGroupingMoveAttribute); 120 if (sgmAttr.MoveQuality.Equals(moveQuality)) 121 return true; 116 122 if (sgmAttr != null 117 123 && (!useAspiration 118 124 || maximization && moveQuality <= sgmAttr.MoveQuality 119 125 || !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) 121 128 isTabu = true; 122 129 } 123 130 if (isTabu) break; 124 131 } 125 } else if (s sm != null) {132 } else if (spm != null) { 126 133 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 129 138 && (!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 ) 136 178 isTabu = true; 137 179 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveMaker.cs
r9440 r9473 66 66 public override IOperation Apply() { 67 67 MultiComponentVectorMove move = MultiComponentVectorMoveParameter.ActualValue; 68 MultiComponentVectorEncoding MultiComponentVector = MultiComponentVectorParameter.ActualValue;68 MultiComponentVectorEncoding multiComponentVector = MultiComponentVectorParameter.ActualValue; 69 69 DoubleValue moveQuality = MoveQualityParameter.ActualValue; 70 70 DoubleValue quality = QualityParameter.ActualValue; 71 71 72 MultiComponentVector = move.GetVectorAfterMove();72 multiComponentVector.PackingInformations = move.GetVectorAfterMove().PackingInformations; 73 73 74 74 quality.Value = moveQuality.Value; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveSoftTabuCriterion.cs
r9440 r9473 65 65 public MultiComponentVectorMoveSoftTabuCriterion() 66 66 : base() { 67 67 Parameters.Add(new LookupParameter<MultiComponentVectorMove>("MultiComponentVectorMove", "The move to evaluate.")); 68 68 Parameters.Add(new LookupParameter<MultiComponentVectorEncoding>("MultiComponentVector", "The solution to evaluate.")); 69 69 Parameters.Add(new LookupParameter<BoolValue>("MoveTabu", "The variable to store if a move was tabu.")); … … 94 94 private bool IsMoveTabu(ItemList<IItem> tabuList, MultiComponentVectorMove move, MultiComponentVectorEncoding multiComponentVector, double moveQuality, bool maximization, bool useAspiration) { 95 95 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; 99 102 var attributes = tabuList.FindAll(ta => ta.GetType().Equals(move.GetMoveAttributeType())); 100 103 … … 106 109 || maximization && moveQuality <= sirmAttr.MoveQuality 107 110 || !maximization && moveQuality >= sirmAttr.MoveQuality)) { 108 109 111 if (sirm.ItemIndex == sirmAttr.ItemIndex && multiComponentVector.PackingInformations[sirm.ItemIndex].Rotated == sirmAttr.ItemRotation) 112 isTabu = true; 110 113 } 111 114 if (isTabu) break; … … 118 121 || maximization && moveQuality <= sgmAttr.MoveQuality 119 122 || !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; 122 126 } 123 127 if (isTabu) break; 124 128 } 125 } else if (s sm != null) {129 } else if (spm != null) { 126 130 foreach (IItem tabuMove in attributes) { 127 Swap SequenceMoveAttribute ssmAttr = (tabuMove as SwapSequenceMoveAttribute);128 if (s smAttr != null131 SwapPositionMoveAttribute spmAttr = (tabuMove as SwapPositionMoveAttribute); 132 if (spmAttr != null 129 133 && (!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 ) 136 170 isTabu = true; 137 171 } … … 140 174 } 141 175 142 176 143 177 144 178 return isTabu; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorTabuMaker.cs
r9440 r9473 64 64 SingleGroupingMove sgm = move as SingleGroupingMove; 65 65 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); 70 84 71 85 else return solution; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/StochasticMultiComponentVectorMoveGenerator.cs
r9440 r9473 60 60 MultiComponentVectorMove[] moves = new MultiComponentVectorMove[sampleSize]; 61 61 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)); 64 65 65 66 for (int i = 0; i < sampleSize; i++) { 66 int typeDecision = random.Next( 3);67 int typeDecision = random.Next(4); 67 68 switch (typeDecision) { 68 69 case 0: moves[i] = rm[random.Next(rm.Count)]; … … 71 72 break; 72 73 case 2: moves[i] = sm[random.Next(sm.Count)]; 74 break; 75 case 3: moves[i] = cpm[random.Next(cpm.Count)]; 73 76 break; 74 77 default: -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorEncoding.cs
r9440 r9473 68 68 MultiComponentVectorEncoding mce = obj as MultiComponentVectorEncoding; 69 69 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++) { 71 71 if (mce.PackingInformations[i] != this.PackingInformations[i]) 72 72 return false; … … 134 134 var result = new ItemList<PackingInformation>(); 135 135 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)); 137 146 } 138 147 return result; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorRandomCreator.cs
r9440 r9473 43 43 get { return (IValueLookupParameter<IntValue>)Parameters["LowerBound"]; } 44 44 } 45 public IValueParameter<BoolValue> SortedSequenceParameter { 46 get { return (IValueParameter<BoolValue>)Parameters["SortedSequence"]; } 47 } 45 48 46 49 [StorableConstructor] … … 52 55 } 53 56 54 57 public MultiComponentVectorRandomCreator() 55 58 : base() { 56 59 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator.")); 57 60 Parameters.Add(new ValueLookupParameter<IntValue>("PackingItems", "The number of packing-items handled in this problem instance.")); 58 61 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.")); 59 63 60 64 EncodedSolutionParameter.ActualName = "MultiComponentVector"; 65 SortedSequenceParameter.ActualValue = new BoolValue(false); 61 66 } 62 67 63 68 64 public static MultiComponentVectorEncoding Apply(int items, int lowerBound, IRandom random) {69 public static MultiComponentVectorEncoding Apply(int items, int lowerBound, IRandom random, bool sortedSequence) { 65 70 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); 67 75 return solution; 68 76 } 69 77 70 78 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); 72 80 } 73 81 }
Note: See TracChangeset
for help on using the changeset viewer.